This project is read-only.

Attachments not downloading

Dec 22, 2009 at 5:21 PM

So, I'm using the following code to download attachments. The problem is that the attachments.count value is always 0 and the attachmentsavailable property is always false. However, the attachments are present in the bodyparts property of MSG, and I can see them using VS2008's object inspector. The rest of the message properties also appear to be correct.

Can anyone point me in the right direction so I can save these attachments through the attachment property please? Apologies if there's an obvious answer. I'm kinda new to c#!

Cheers,

*Code below*

 

foreach (IMAPMessage msg in MyImap.Folders["INBOX"].Messages)
{                    
Full = Inbox.GetMessageByID(msg.Uid);
Full.RefreshData(true, true);
if (Full.AttachmentsAvailable)
{
for (int idx = 0; idx == msg.Attachments.Count - 1; idx++)
{
msg.Attachments[idx].SaveFile("C:\\Attachment_" + Convert.ToString(idx) + ".test");
}
}
}
}

foreach (IMAPMessage msg in MyImap.Folders["INBOX"].Messages)

{                    

MSG = Inbox.GetMessageByID(msg.Uid);

MSG.RefreshData(true, true);

if (MSG.AttachmentsAvailable)

{

for (int idx = 0; idx == MSG.Attachments.Count - 1; idx++)

{

MSG.Attachments[idx].SaveFile("C:\\Attachment_" + Convert.ToString(idx) + ".test");

}

}

}

 

Dec 25, 2009 at 7:36 PM

Yeah, I have the same issues you are talking about.

I am using Google Apps Email Account to test.

Below is the change to the source code that I made to make the AttachmentsAvailable property and the Attachments collection work properly.

I'm not sure how good of a fix this is as I have only tested it with my Google Apps Email Account.

In the InterIMAP.Synchronous.IMAP class, with the ProcessBodyParts(IMAPMessage msg) method.

"else if (content.ContentId != null || content.ContentDescription != null)"

changed to 

"else if (content.ContentId != null || content.ContentDescription != null || disp.ToLower().Contains("attachment"))"