MailKit.Net.Imap read Gmail attachments when "Content-Disposition; inline" is set

Viewed 916

I have a c# console application that I use to search a Gmail account for emails with attachments and download them. I am using MailKit.Net.Imap.ImapClient to do this.

If the email has been sent with the "Content-Disposition; attachment" set then all works well. If the email has been sent with "Content-Disposition; inline" set, the ImapClient does not see the attachments and I can't download them.

Below is the code I use to do this. Does anyone have any idea how to fix this?

        static public void mail_ReadEmail()
        {
            string mail_login = "your login here";
            string mail_password = "your password here";
            string mail_folderName = "your gmail folder name here";

            // Get client & open folder
            ImapClient client = mail_GetImapClient(mail_login, mail_password);
            IMailFolder folder = mail_GetIMailFolder(client, mail_folderName);

            // Get emails
            DateTime startTime = DateTime.Now.AddMonths(-6);
            IList<UniqueId> email = folder.Search(SearchQuery
                .DeliveredAfter(startTime)
                .And(SearchQuery
                .FromContains("canon.co.nz")));

            // Loop through emails (oldest first)
            for (int i = email.Count - 1; i >= 0; i--)
            {
                // Get message and display subject and date
                MimeMessage message = folder.GetMessage(email[i]);
                Console.WriteLine(message.Subject + " - " + message.Date.DateTime.ToShortDateString());

                // Show all attachments for this message
                foreach (MimePart part in message.Attachments)
                    Console.WriteLine("\t* " + part.FileName);
            }
        }

1 Answers
Related