Hi Lukas,

Some days back, you gave us below code for resolving issue while accessing a large mailbox account. In this code, first we are fetching all messages in "ImapMessageCollection ids" using imap.Search() method. And then again we are setting as per chunk size ImapMessageSet. After this again we are doing imap.GetMessageList() and fetching the messages. Aren't we doing repetitive actions? Please explain.

    private ImapMessageCollection ImapSearch(Imap imap, ImapSearchParameter imapSearchParameter)
    {
        try
        {
            // search for messages, receive only Unique ids
            ImapMessageCollection ids = imap.Search(ImapListFields.UniqueId, imapSearchParameter);

            // get only necessary information in small chunks
            ImapMessageCollection messages = new ImapMessageCollection();

            for (int i = 0; i < ids.Count; )
            {
                if (i > 0)
                    System.Threading.Thread.Sleep(DELAY_TIME);

                ImapMessageSet set = new ImapMessageSet();
                for (int j = 0; j < CHUNK_SIZE && i < ids.Count; j++, i++)
                {
                    set.Add(ids[i].UniqueId);
                }

                ImapMessageCollection list = imap.GetMessageList(set, ImapListFields.Envelope | ImapListFields.Body);
                foreach (ImapMessageInfo info in list)
                {
                    messages.Add(info);
                }
            }

            return messages;
        }
        catch (Exception ex)
        {
            logger.Error(string.Format("Error Occured at ImapSearch. Error :{0} ", ex));

            throw ex;
        }
    }

asked 19 Aug '11, 11:09

SanjayN's gravatar image

SanjayN
212
accept rate: 0%

edited 19 Aug '11, 13:24

Lukas%20Matyska's gravatar image

Lukas Matyska ♦♦
90117

Any updates?

(19 Aug '11, 13:58) SanjayN

Please note the server response to a SEARCH command is only collection of UniqueIds (or SequenceNumbers), but the imap.Search() method do more than just the SEARCH command. It depends which ImapListFields you want to receive.

If you want to receive only ImapListFields.UniqueId or only ImapListFields.SequenceNumber the imap.Search() method only parses the response of the SEARCH command.

If you want to receive more than ImapListFields.UniqueId the imap.Search() method requests two commands. The SEARCH command at first and then appropriate FETCH command according to the SEARCH response and a value of the ImapListFields parameter.

Please compare the log file of the imap.Search(ImapListFields.UniqueId, ImapSearchParameter.All) and the imap.Search(ImapListFields.Envelope | ImapListFields.Body, ImapSearchParameter.All) calls.

Therefore the code above doesn't do repetitive actions. It decreases server load.

link

answered 19 Aug '11, 14:08

Lukas%20Matyska's gravatar image

Lukas Matyska ♦♦
90117
accept rate: 28%

Thanks Lukas for your continued support.

(19 Aug '11, 15:11) SanjayN
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

Asked: 19 Aug '11, 11:09

Seen: 348 times

Last updated: 19 Aug '11, 15:11