Email Attachment Info when Downloading from IMAP without Attachments

If the Imap.AutoDownloadAttachments property is set to false, or if headers-only are downloaded, then emails will be downloaded without attachments.  However, attachment information, such as the count, and the size and filename of each attachment is still available.

When an email is downloaded from an IMAP server without the attachment data, the attachment information is added as headers to the email:

  • ckx-imap-numattach: contains the number of attachments.
  • ckx-imap-attach-nm-{N}: contains the name of the Nth attachment, where N begins at 1 for the 1st attachment.  For example “ckx-imap-attach-nm-1”
  • ckx-imap-attach-sz-{N}: contains the size in bytes of the Nth attachment.

The IMAP API provides methods for getting this information:

  • GetMailNumAttach
  • GetMailAttachSize
  • GetMailAttachFilename

Each of these methods begins with the string “GetMail”, and the 1st argument is the email object from which the information is to be retrieved.  If the “ckx-imap-*” header is not found, then it returns the information provided by the email object itself:

  • GetMailNumAttach:  If the ckx-imap-numattach header is not present, it returns the value of the emailObject.NumAttachments property.   (where emailObject is the email object passed to GetMailNumAttach)
  • GetMailAttachSize: If the ckx-imap-attach-sz-* header is not present, it calls emailObject.GetAttachmentSize and returns its value.
  • GetMailAttachFilename: If the ckx-imap-attach-nm-* header is not present, it calls emailObject.GetAttachmentFilename and returns its value.

The Chilkat.Email object (CkEmail, CkoEmail, etc.) also has properties and methods for getting attachment information.  However, these apply to attachments that are already downloaded and present within the email object.  For example:

  • Email.NumAttachments:  This property returns the number of attachments that are fully present within the email object.
  • Email.GetAttachmentFilename:  This method returns the filename of the Nth attachment that is already fully present in the email object.
  • Email.GetAttachmentSize:  Again, it returns the size in bytes of the Nth attachment that is fully present in the email object.