ImapDownloadMessageHeaders Method
Downloads the header of each message in the specified set from the server.

Namespace: MailBee.ImapMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.2.0 build 630 for .NET 4.5
public MailMessageCollection DownloadMessageHeaders(
	string messageIndexSet,
	bool indexIsUid


Type: SystemString
A message sequence string containing ordinal message numbers or UIDs. Can be composed manually or using ToString.
Type: SystemBoolean
If true, messageIndexSet is treated as a sequence of UIDs; otherwise, as a sequence of ordinal message numbers.

Return Value

Type: MailMessageCollection
On success, a MailMessageCollection containing the downloaded messages; otherwise, a null reference (Nothing in Visual Basic).
MailBeeExceptionAn error occurred and ThrowExceptions is true.

To learn how to specify a valid message sequence (messageIndexSet value), see DownloadEnvelopes(String, Boolean) topic.

This method will download all the message headers in a single network operation, which greatly increases performance and reduces network traffic. However, if the application needs message headers just to get common information about messages (From, To, Date, Subject, Size, etc), it's more efficient to use DownloadEnvelopes(String, Boolean) method. Typically, IMAP4 ENVELOPE structure and related information is 200-400 bytes in size, while message header sections are usually larger 500 bytes. ENVELOPE structure, however, does not contain header fields which describe priority/importance of the message, attachments presence, etc. On other hand, the application may avoid downloading message header section and still obtain all the necessary information by requesting envelopes, body structures, and the required headers using DownloadEnvelopes(String, Boolean, EnvelopeParts, Int32, String, String) method.

Note Note
To track downloading headers, EnvelopeDownloaded event should be used. There is no MessageDownloaded event since mail messages are actually downloaded within envelopes. Once an envelope is downloaded, the mail message data is extracted from it. Generally speaking, DownloadMessageHeaders(String, Boolean) is a kind of overload of DownloadEnvelopes(String, Boolean, EnvelopeParts, Int32, String, String) method.
This console sample downloads message header sections of the last 5 messages in the inbox, and displays them.
using System;
using MailBee;
using MailBee.ImapMail;
using MailBee.Mime;

class Sample
    static void Main(string[] args)
        Imap imp = new Imap();

        // Connect to the server, login and select inbox.
        imp.Login("", "secret");

        // Download the last 5 message headers. Note: we do not check if
        // there are less than 5 messages in the inbox. See sample code
        // in DownloadEnvelopes(string, bool) overload for more details.
        MailMessageCollection msgs = imp.DownloadMessageHeaders(
            (imp.MessageCount - 4).ToString() + ":*", false);

        // Display header sections of the downloaded message headers.
        foreach (MailMessage msg in msgs)
            Console.WriteLine("Header section of message #" + msg.IndexOnServer);

        // Disconnect from the server.
See Also