Faster Folder traversal

R

ray

I'm having a performance problem with an Outlook AddIn. We need to find all
the MailItems – fast. The solution below is very slow due to “x as
Outlook.Item†call.

Is there a faster way to do this?

IEnumerable<Outlook.MailItem> GetAllMail(Outlook.Folders folders)
{
foreach (Outlook.MAPIFolder f in folders) {
foreach (var e in GetAllMail(f.Folders)) {
yield return e;
}
foreach (var x in f.Items) {
var e = x as Outlook.MailItem;
if (e != null) {
yield return e;
}
}
}
}
 
D

Dmitry Streblechenko

"Find" means you have a search criteria. What is it?
If you need to dump all the message in some kind of a list (so there is
really nothing to "find"), why would you do that?

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
R

ray

To clarify: I'd like to look through ALL the folders and "find" the
MailItems (as opposed to TaskItems, etc...).

Why? Many reasons actually. For example: to get the send dates of all the
email, or to sum up the size of all emails, etc...

In general, I’m looking for a FAST way to query all email in all folders.
 

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