Mark Unread To Read

T

tedy

Hello,
I`m having the following problem. I try to find out all unread
messages in the Inbox Folder,
save some of them and then mark them as read (Unread = false). First I
get with Restrict method only the unread messages. When I check some
message with Unread = false, I suppose that the items list is getting
confused and "GetNext()" never gets to the end of the list.The while
loop iterates only through about the half items.Is it the problem that
the items object is changed immediately when message unread flag is
marked (and then contains fewer messages) and how could be this
problem solved ?

Outlook.Items items = olInboxFolder.Items.Restrict(
"[MessageClass] = 'IPM.Note' and [Unread] = true");
String subject = null;
Console.WriteLine(items.Count);
Outlook.MailItem mi = (Outlook.MailItem) items.GetFirst();
Outlook.Items unread = new Outlook.Items();
while(mi != null)
{
subject = mi.Subject;
if(subjPattern.IsMatch(mi.Subject) &&
sendPattern.IsMatch(mi.SenderName))
{ subject = subject.Replace('/','_');
mi.SaveAs(path + subject + ".txt",
Outlook.OlSaveAsType.olTXT);
mi.UnRead = false; // !!!!
Console.WriteLine(mi.Subject);
}
mi = (Outlook.MailItem) items.GetNext();
}
 
T

tedy

I answered the question myself :).
I just replaced GetFirst and GetNext with the methods Find and FindNext
and so there is no confusion and all items are read.


Outlook.Items items = olInboxFolder.Items.Restrict(unreadPattern);
Outlook.MailItem mi = (Outlook.MailItem)items.Find(unreadPattern);
String subject = null;
while(mi != null)
{
subject = mi.Subject;
if(subjPattern.IsMatch(mi.Subject) &&
sendPattern.IsMatch(mi.SenderName))
{ subject = subject.Replace('/','_');
mi.SaveAs(path + subject + ".txt",
Outlook.OlSaveAsType.olTXT);
mi.UnRead = false;
}
Console.WriteLine(mi.Subject);
mi = (Outlook.MailItem)items.FindNext();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top