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.5.0 build 687 for .NET 4.5
Syntax
public MailMessageCollection DownloadMessageHeaders(
	string messageIndexSet,
	bool indexIsUid
)

Parameters

messageIndexSet
Type: SystemString
A message sequence string containing ordinal message numbers or UIDs. Can be composed manually or using ToString.
indexIsUid
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).
Exceptions
ExceptionCondition
MailBeeExceptionAn error occurred and ThrowExceptions is true.
Remarks

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.
Examples
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.Connect("mail.domain.com");
        imp.Login("jdoe@domain.com", "secret");
        imp.SelectFolder("INBOX");

        // 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);
            Console.WriteLine();
            Console.WriteLine(msg.RawHeader);
            Console.WriteLine("===============================================");
        }

        // Disconnect from the server.
        imp.Disconnect();
    }
}
See Also