I want to provide information about email structure to a user (such as subject, number of attachments, their names and lengths). How can I retrieve such information from an IMAP server without downloading whole message?

asked 31 May '11, 14:55

Rebex%20KB's gravatar image

Rebex KB ♦♦
258519
accept rate: 63%


To retrieve inforamtion about message structure, use the ImapListFields.MessageStructure parameter in the GetMessageInfo or GetMessageList methods.

Following example prints requested information:

C#

// connect and login
Imap imap = new Imap();
imap.Connect(...);
imap.Login(...);

imap.SelectFolder("INBOX");

// retrieve information of emails envelope and structure
ImapMessageCollection col = 
    imap.GetMessageList(ImapListFields.Envelope | ImapListFields.MessageStructure);

// print the information
foreach (ImapMessageInfo item in col)
{
    Console.WriteLine("{0}: {1}", item.SequenceNumber, item.Subject);
    foreach (ImapMessagePart part in item.GetParts())
    {
        if (part.Kind == ImapMessagePartKind.Attachment)
        {
            Console.WriteLine("  {0} [{1} B]", part.FileName, part.Length);
        }
    }
}

VB.NET

''# connect and login
Dim imap = New Imap()
imap.Connect(...)
imap.Login(...)

imap.SelectFolder("INBOX")

''# retrieve information of emails envelope and structure
Dim col = imap.GetMessageList(ImapListFields.Envelope Or ImapListFields.MessageStructure)

''# print the information
For Each item As ImapMessageInfo In col
    Console.WriteLine("{0}: {1}", item.SequenceNumber, item.Subject)
    For Each part In item.GetParts()
        If part.Kind = ImapMessagePartKind.Attachment Then
            Console.WriteLine("  {0} [{1} B]", part.FileName, part.Length)
        End If
    Next part
Next item

Please note the ImapListFields flags are combined together with the OR binary operator (not AND) as shown in the imap.GetMessageList method call.

link

answered 31 May '11, 15:18

Rebex%20KB's gravatar image

Rebex KB ♦♦
258519
accept rate: 63%

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: 31 May '11, 14:55

Seen: 391 times

Last updated: 11 Jun '11, 23:56