ExchangeMessageInfo/IMapMessageInfo/PST Size Info?

The documentation is very sparse when it comes to describing various size or length properties. In some cases, the online documentation is completely blank and we believe there could be a misunderstanding on our end with 1 or more of these properties. I'm asking because we store a bunch of mail metadata on a backend SQL database and our QA team has been comparing these numbers to what you would see in a client like Outlook and the numbers don't make a lot of sense.

Could somebody provide details on the following classes and properties:
  • ExchangeMessageInfo - Size property.
  • IMapMessageInfo - Length property.
  • MapiMessage - Getting the size via PR_MESSAGE_SIZE
Ultimately, we're trying to figure out the most accurate way to know how large an email is before we ever attempt to retrieve it.

Regards,
Scott

Hi Scott,

Thank you for posting your query.

We have gone through existing samples available in documentation and forum and here are our findings.

  1. ExchangeMessageInfo.Size property returns the size of the message in bytes
  2. ImapMessageInfo.Length property returns the size of the message in bytes

This information you can validate from the following tests by appending a sample message and then retreiving it back using Exchange and IMAP clients. For some reason, the PR_MESSAGE_SIZE value is not available for the downloaded messages. However, the values returned by ExchangeMessageInfo.Size and ImapMessageInfo.Length are the same. Please try the following sample code at your end and share your feedback with us.

Code:

public static void GetMessageSizeUsingImap()
{
    ImapClient client = GetAsposeEWSImapClient1();
    client.SelectFolder(ImapFolderInfo.InBox);
    Console.WriteLine("Message size using ImapClient: " + client.ListMessages()[0].Length);
}

public static void GetMessageSizeUsingEWS()
{
    IEWSClient client = GetAsposeEWSClient1();
    Console.WriteLine("Message size using EWS: " + client.ListMessages(client.MailboxInfo.InboxUri)[0].Size);
    MailMessage msg = client.FetchMessage(client.ListMessages(client.MailboxInfo.InboxUri)[0].UniqueUri);
    MapiMessage mapiMsg = MapiMessage.FromMailMessage(msg);
    if (mapiMsg.Properties[MapiPropertyTag.PR_MESSAGE_SIZE] != null)
        Console.WriteLine("PR_MESSAGE_SIZE: " + mapiMsg.Properties[MapiPropertyTag.PR_MESSAGE_SIZE].ToString());
}

public static void AppendMsgToTest4()
{
    IEWSClient client = GetAsposeEWSClient1();
    MailMessage message = new MailMessage(
        "user@domain.com",
        "asposeemail.test3@aspose.com",
        "EMAILNET-34717 - " + Guid.NewGuid().ToString(),
        "EMAILNET-34717 EWS: Can there be any way of retreiving Message size before actually fetching it?");
    byte[] data = new byte[1000000];
    MemoryStream ms = new MemoryStream(data);
    Attachment attachment = new Attachment(ms, "test.txt");
    message.Attachments.Add(attachment);
    client.AppendMessage(client.MailboxInfo.InboxUri, message);
    client.Dispose();
}