Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"True" Attachments In Mails #562

Closed
dispatchai opened this issue Feb 18, 2019 · 5 comments
Closed

"True" Attachments In Mails #562

dispatchai opened this issue Feb 18, 2019 · 5 comments

Comments

@dispatchai
Copy link

Hi,

This issue of mine is probably not directly related with the exchangelib library itself but maybe someone can help me. I download and save the attachments of mails into varios folders using exchangelib and my problem is that not only the files that are attached to mails but also the embedded images are retrieved in the form of attachments. When I query the same mail on Outlook, such embedded images are not seen as attachments (there is to attach picture displayed for them), yet the images are retrieved anyway through the library. Is there a way to only look for the "real" file attachments?

@ecederstrand
Copy link
Owner

I'm not sure how to do that. If you look at Attachment.FIELDS:

there are a number of extra fields that may help you determine which attachments are interesting for you.

Another possibility is to go through the HTML body of the messages and find references to the attachments that are supposed to be shown in-line, and ignore those.

@dispatchai
Copy link
Author

Thanks, fields list will be of help for this, I believe.

@nstr10
Copy link

nstr10 commented Feb 27, 2019

I believe what you're referring to are inline attachments. Here's how I deal with that using the is_inline field:

if hasattr(email_item, "attachments"):
  for attachment in item.attachments:
    if hasattr(attachment, "item"):
      # Do things with attached Exchange items like .eml attachments
    if attachment.is_inline:
      continue # or do something else

I believe any attachment that makes it past those checks should be a regular attached file. Hope this helps!

@ecederstrand
Copy link
Owner

Yes, is_inline seems like the best solution.

@adeolaibigbemi
Copy link

Thanks, nstr10. This helped me too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants