0 votes
by (370 points)
edited

Hi, i've the below question!

i want to delete all mail older than a range of date in Inbox an Sent Item.

In order to do this i've write this code:

m_Imap.SelectFolder("Inbox");

messages = m_Imap.Search
(
       ImapSearchParameter.Arrived(StartDate, EndDate),
       ImapSearchParameter.Sent(StartDate, EndDate)
);

ImapMessageSet mailToBeDeleted = new ImapMessageSet();

foreach (ImapMessageInfo messPartial in messages)
{
    mailToBeDeleted.Add(messPartial.UniqueId);
} // End for
m_Imap.DeleteMessage(mailToBeDeleted);
m_Imap.Purge();

This code works for inbox mail bath not for sent mail;

What's wrong?

Other Question. if i use getfolderlist i don't see any folder "Sent Items". Why? My imap server is gmail. My end server is exchage.

Best Regards Enrico

Applies to: Rebex Secure Mail

2 Answers

0 votes
by (147k points)
edited

The default overload of GetFolderList method only returns folders located in the root folder. In Gmail, the "Sent Items" folder is a subfolder of "[Gmail]" folder. To get a list of folders at all levels, call m_Imap.GetFolderList(null, ImapFolderListMode.All, true).

Please note that the "Sent Items" folder might use a different name when Gmail's web interface is set to a non-English language. Even the "[Gmail]" folder name might also be different for German users.

The following code locates the sent items folder regardless its name:

        string folderSent = null;
        foreach (ImapFolder folder in imap.GetFolderList(null, ImapFolderListMode.All, true))
        {
            if (folder.Purpose == "Sent")
            {
                folderSent = folder.Name;
                break;
            }
        }

        if (folderSent == null)
            throw new ApplicationException("Gmail 'Sent items' folder not found.");
0 votes
by (72.7k points)
edited

To search within the "Sent Items" folder, you have to select it first:

m_Imap.SelectFolder(folderSent);
messages = m_Imap.Search(ImapSearchParameter.Sent(StartDate, EndDate));

Please also mind the IMAP behaviour for searching dates:
1. Only date component take effect (time component is ignored)
2. StartDate is inclusive condition (mail.Date is >= StartDate)
3. EndDate is exclusive condition (mail.Date is < EndDate)

For example, if you want to find all mails sent in the past up to today, you have to call m_Imap.Search(ImapSearchParameter.Sent(StartDate, DateTime.Today.AddDays(1)));

...