ImapDownloadMessageHeaders Method |
Namespace: MailBee.ImapMail
public MailMessageCollection DownloadMessageHeaders( string messageIndexSet, bool indexIsUid )
Exception | Condition |
---|---|
MailBeeException | An 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 |
---|
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. |
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(); } }