Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Get Flag's value
PostPosted: 2009-12-18 11:49 
Normal user

Joined: 2009-09-12 16:32
Posts: 41
Hi

I'm using C#. And I haven't found method message.Flag(). There are message.get_flag() & message.set_flag().
They work fine. there is another problem:
I'm try to flagged unread messages:
Code:
Message mes = accountHelper.Messages.get_ItemByDBID(Id);
            bool b = mes.get_Flag(eMessageFlag.eMFSeen);
            if (hasSeen && !b)
            {
                mes.set_Flag(eMessageFlag.eMFSeen, hasSeen);
                mes.Save();
            }

This also works fine, I check it in DB and when call Messages.get_ItemByDBID(Id) it shows correct data.
But when I call accountHelper.IMAPFolders.get_ItemByDBID(folderId).Messages, changes that I've done before, hadn't considered I mean mes.set_Flag (other datas are correct). After restarting computer, accountHelper.IMAPFolders.get_ItemByDBID(folderId).Messages get datas from DB. But again after changing message's flag Messages.get_ItemByDBID(Id) get changed data and accountHelper.IMAPFolders.get_ItemByDBID(folderId) doesn't see the changes.
Why?

Thanks. Sorry for English


Top
 Profile  
 
 Post subject: Re: Get Flag's value
PostPosted: 2009-12-18 12:04 
Normal user

Joined: 2009-09-12 16:32
Posts: 41
After restarting hMailServer accountHelper.IMAPFolders.get_ItemByDBID(folderId).Messages see the changes. Also make message.RefreshContent(), but it doesn't give results.


Top
 Profile  
 
 Post subject: Re: Get Flag's value
PostPosted: 2009-12-18 14:19 
Moderator
User avatar

Joined: 2007-06-14 05:12
Posts: 9385
Location: 'The Outback' Australia
Did you message.save first?

_________________
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
Documentation


Top
 Profile  
 
 Post subject: Re: Get Flag's value
PostPosted: 2009-12-18 14:25 
Normal user

Joined: 2009-09-12 16:32
Posts: 41
Thanks for reply!
In code that I post I have mes.Save()
or what do you mean?


Top
 Profile  
 
 Post subject: Re: Get Flag's value
PostPosted: 2009-12-18 14:33 
Normal user

Joined: 2009-09-12 16:32
Posts: 41
mes.set_Flag(eMessageFlag.eMFSeen, hasSeen); works fine I check it in DB.
And if call after setting flag this code
Message mes = accountHelper.Messages.get_ItemByDBID(Id);
bool b = mes.get_Flag(eMessageFlag.eMFSeen);
the result b=true.
But if I call
Messages msgs = accountHelper.IMAPFolders.get_ItemByDBID(folderId).Messages
bool b = msgs[index].get_Flag(eMessageFlag.eMFSeen);
the result b=false.
But in debugger I see that msgs[index]=mes.ID


Top
 Profile  
 
 Post subject: Re: Get Flag's value
PostPosted: 2009-12-18 14:48 
Normal user

Joined: 2009-09-12 16:32
Posts: 41
I've wrote also this code
Code:
            row.ID = message.ID;
            row.HasSeen = message.get_Flag(eMessageFlag.eMFSeen);
            bool b = this.accountHelper.Messages.get_ItemByDBID(message.ID).get_Flag(eMessageFlag.eMFSeen);


And there is a case then row.HasSeen != b, but as you can see they must have equal values.

message is one of return messages of code
accountHelper.IMAPFolders.get_ItemByDBID(folderId).Messages


Top
 Profile  
 
 Post subject: Re: Get Flag's value
PostPosted: 2009-12-18 14:57 
Moderator
User avatar

Joined: 2007-06-14 05:12
Posts: 9385
Location: 'The Outback' Australia
Can you post the whole script and detail what exactly you are trying to do please...

I suspect that you aren't properly selecting the correct IMAP sub-folder

_________________
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
Documentation


Top
 Profile  
 
 Post subject: Re: Get Flag's value
PostPosted: 2009-12-18 15:35 
Normal user

Joined: 2009-09-12 16:32
Posts: 41
I want to count unread messages.
If I've open unread message, executes this code
Code:
public MailDataSet.MailDataSet GetMessageById(int Id, bool hasSeen)
        {
           
            Message mes = accountHelper.Messages.get_ItemByDBID(Id);
            bool b = mes.get_Flag(eMessageFlag.eMFSeen);
            //if opened unread message
            if (hasSeen && !b)
            {
                //set flag. It realy set I check its in DB
                mes.set_Flag(eMessageFlag.eMFSeen, hasSeen);
                mes.Save();
            }
            return Converter.ToMessageDataTable(accountHelper.Messages.get_ItemByDBID(Id), this._attachmentPath);
        }

ToMessageDataTable - converts messages/message to my typedDataSet
After I need to get messages from INBOX folder(I have only INBOX, SENT, DELETED, SPAM folder, no subfolders)
Code:
public MailDataSet.MailDataSet GetMessagesByIMAPFolder(int folderId)
        {
            return ToMessageDataTable(accountHelper.IMAPFolders.get_ItemByDBID(folderId).Messages);
        }

//copy all properties from message to MailDataSet.MailDataSet.MessageRow row
public  MailDataSet.MailDataSet.MessageRow ToMessageRow(Message message,         MailDataSet.MailDataSet.MessageRow row)
        {
           
            //here copy props. don't show all because it doesn't matter
            row.ID = message.ID;
            row.HasSeen = message.get_Flag(eMessageFlag.eMFSeen);         
            bool b = this.accountHelper.Messages.get_ItemByDBID(message.ID).get_Flag(eMessageFlag.eMFSeen);
            //here in case when it's before updated message b=true, row.HasSeen = false;
            //In DB mesageflag = 1;
            row.Headers = message.Headers.ToString();
            row.HTMLBody = message.HTMLBody;
            row.FromAddress = message.FromAddress;
            row.To = message.To;
            return row;
        }

        public  MailDataSet.MailDataSet ToMessageDataTable(Messages messages)
        {
            MailDataSet.MailDataSet dataSet = new MailDataSet.MailDataSet();
            MailDataSet.MailDataSet.MessageDataTable tbl = dataSet.Message;
            for (int i = 0; i < messages.Count; i++)
            {
                //just add new row
                tbl.AddMessageRow(ToMessageRow(messages[i], tbl.NewMessageRow()));
            }
            return dataSet;
        }


I don't understand why I get difference values from identic messages?
I check it every time after setting flag.
After restarting hMailServer, I get identical values in both cases. But after setting flag situation repeated


Top
 Profile  
 
 Post subject: Re: Get Flag's value
PostPosted: 2009-12-20 13:22 
Developer

Joined: 2003-11-21 01:09
Posts: 6394
Location: Sweden
When accessing messages, you must use the Messages property of the IMAPFolder object to do so.

The Messages property on the Account object returns a raw list of messages from the database. Changing the items in this list doesn't affect the in-memory cache which the IMAPFolder.Messages property works against.


Top
 Profile  
 
 Post subject: Re: Get Flag's value
PostPosted: 2009-12-21 10:20 
Normal user

Joined: 2009-09-12 16:32
Posts: 41
Thanks greate for reply.

If I understand you, I should write something like this
Code:
IMAPFolder folder = accountHelper.IMAPFolders.get_ItemByDBID(folderId);
return ToMessageDataTable(folder.Messages);

not
Code:
return ToMessageDataTable(accountHelper.IMAPFolders.get_ItemByDBID(folderId).Messages);

but this changes didn't change the situation. It still returns wrong datas


Top
 Profile  
 
 Post subject: Re: Get Flag's value
PostPosted: 2009-12-23 19:05 
Developer

Joined: 2003-11-21 01:09
Posts: 6394
Location: Sweden
AndsFenomen wrote:
If I understand you, I should write something like this
Code:
IMAPFolder folder = accountHelper.IMAPFolders.get_ItemByDBID(folderId);
return ToMessageDataTable(folder.Messages);

not
Code:
return ToMessageDataTable(accountHelper.IMAPFolders.get_ItemByDBID(folderId).Messages);

but this changes didn't change the situation. It still returns wrong datas


What's the difference between those two, except for you using a variable? I don't see those two would be any different.

In your old code, you used
Code:
accountHelper.Messages

es.get_ItemByDBID(Id);
when you should use
Code:
accountHelper.IMAPFolders.get_ItemByDBID(folderId).Messages


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest



Search for:
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group