Re: [gmime-devel] Accessing attachments including inline-parts.



Hi Steve,

On 5/23/2014 2:07 PM, Steve Kemp wrote:
[snip]

    I identify attachments by:

     const char *filename = g_mime_object_get_content_disposition_parameter(part, "filename");
     if ( filename != NULL )
     {
         .. attachment ..
         }

   As inline-parts don't contain filenames this results in the
  inline-parts not being visible.

Be careful with this approach because this general rule isn't necessarily true. The best way to determine if a MIME part is meant to be treated as an attachment or not is to check that the Content-Disposition value matches "attachment" (instead of "inline") in a case-insensitive comparison.


   Is there a simple way that I can handle getting both "attachments"
  and "inline parts"?  I looked at the content-disposition functions,
  but didn't see a simple way to go from there.

Your iterator loop above will iterate over all attachment and inline parts. You can use the following logic to determine if a part is an attachment (if it's not an attachment, then it is an inline part):

GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (part);

if (disposition != null && disposition->disposition != null && !g_strcasecmp (disposition->disposition, "attachment")) {
    // the part is an attachment
} else {
    // the part is an inline part
}


I got this question a few times with the C# version of GMime (aka MimeKit) that I've been working on and I ended up adding a ContentDisposition.IsAttachment property (I think I also added a MimePart.IsAttachment property as well). Perhaps I can do something similar in GMime to make this a bit easier...

Hope that helps,

Jeff


Attachment: smime.p7s
Description: S/MIME Cryptographic Signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]