3

I am writing a program in C# to access the UNREAD emails from Gmail using ImapX (Version 2.0.0.13). I wish to download specifically the powerpoint (.ppt or .pptx) files in the attachment. I have made the download of attachment work.

However, the downloads are not saved correctly on the disk. For example, if an attachment is of size 3.5 MB only 2.4 MB of it is saved.

Am I missing a step here?

Here is my code:

using(ImapClient client = new ImapClient(host, port, true, true))
{
    if (client.Login(username, password))
    {
        FolderCollection folders = client.Folders;
        Message[] messages = client.Folders["INBOX"].Search("UNSEEN", MessageFetchMode.Attachments, 100);

        for (int i = 0; i < messages.Length; i++)
        {
            if (messages[i].Attachments.Length > 0)
            {
                Attachment[] atts = messages[i].Attachments;
                for (int j = 0; j < atts.Length; j++)
                {
                    if (atts[j].FileName.Contains("ppt") || atts[j].FileName.Contains("pptx"))
                    {
                        atts[j].Download();
                        atts[j].Save(SAVE_LOCATION, atts[j].FileName);
                    }
                }
            }
        }
    }
}
Kiquenet
  • 14,494
  • 35
  • 148
  • 243
Himanshu Verma
  • 257
  • 1
  • 3
  • 10
  • 1
    Can you try the latest code in the repository? I've updated it today, the problem should be fixed now, as well as the peformance of downloading attachments was improved significantly. – Pavel Azanov Dec 09 '13 at 16:51
  • Hi Pavel, I have downloaded the latest code and will try it now. Thank you very much for your help with the issue :) Best regards, Himanshu – Himanshu Verma Dec 11 '13 at 09:55

1 Answers1

1

The problem was solved after I downloaded the updated source code from the ImapX site. It works perfectly now with the above source code.

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
Himanshu Verma
  • 257
  • 1
  • 3
  • 10