Hi, i create Method the Remove old mail from the Imap folder.

The folder that i want to clean are: Inbox, Sent Items, Skipped: The mail in Sent Items and skipped folder are moved by me using the Method StoreMessage.

The method works for Inbox and Sent Items, but whe i try to add an UniqueId of folder Skipped i received the below Excpetion.

Uniqueid not valid File : Rebex.Net.Imap Message : Specified message unique ID is not valid in the current folder. Parameter name: uniqueId StackTrace : at Rebex.Net.ImapMessageSet.Add(String uniqueId)

The code is the below:

try { for (int idx = 0; idx < 3; idx++) { m_Imap.SelectFolder(folder[idx]);

    messages = m_Imap.Search
    (
        ImapSearchParameter.Arrived(StartDate, EndDate),
        ImapSearchParameter.Sent(StartDate, EndDate)
    );
    m_log.Log(TraceLevel.MoreInfo, String.Format("Found {0} mail to be deleted in folder {1}", messages.Count, folder[idx]));
    foreach (ImapMessageInfo messPartial in messages)
    {
        try
        {
            mailToBeDeleted.Add(messPartial.UniqueId);
        }
        catch (Exception ex)
        {
            m_log.Log(TraceLevel.Warning, "Uniqueid not valid", ex);
        }
    } // End for
}
m_Imap.DeleteMessage(mailToBeDeleted);
m_Imap.Purge();

} catch (Exception ex) { m_log.Log (TraceLevel.Error, "CheckNotifToBeReadMail", ex); }

asked 08 Jun '11, 16:05

Enrico's gravatar image

Enrico
263
accept rate: 0%


This exception arises when you are trying to add two UniqueIds from two different folders into one ImapMessageSet.

I recommend you to use this code:

try
{
    for (int idx = 0; idx < 3; idx++)
    {
        m_Imap.SelectFolder(folder[idx]);

        messages = m_Imap.Search
        (
            ImapSearchParameter.Arrived(StartDate, EndDate),
            ImapSearchParameter.Sent(StartDate, EndDate)
        );
        m_log.Log(TraceLevel.MoreInfo, String.Format("Found {0} mail to be deleted in folder {1}", messages.Count, folder[idx]));

        mailToBeDeleted = messages.ToUniqueIdMessageSet();

        m_Imap.DeleteMessage(mailToBeDeleted);
    }
    m_Imap.Purge();
}
catch (Exception ex) { m_log.Log(TraceLevel.Error, "CheckNotifToBeReadMail", ex); }
link

answered 09 Jun '11, 13:19

Lukas%20Matyska's gravatar image

Lukas Matyska ♦♦
90117
accept rate: 28%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×76
×22

Asked: 08 Jun '11, 16:05

Seen: 716 times

Last updated: 11 Jun '11, 23:52