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

Attachment download without basing on BodyPart #130

Closed
WesolyPierozek opened this issue Dec 11, 2014 · 6 comments
Closed

Attachment download without basing on BodyPart #130

WesolyPierozek opened this issue Dec 11, 2014 · 6 comments

Comments

@WesolyPierozek
Copy link

I noticed one thing which is slightly problematic for me. I have scenario:

  • get list of all attachments metadata from email box
  • analyse attachments they are necessary or not - basing only of basic mail message data and attachment header data.
  • download specified attachments.
    At the moment i used GetBodyPart, but unfortunately it base on BodyPart class. Is it possible to use something another which is better than class to get part of email? Like index, part descriptor etc - and also is easily serializable for further access.

Maybe i'm annoying with creating issues, but is it possible to create "requests"?

@jstedfast
Copy link
Owner

BodyPart is serializable via the ToString() method and can be deserialized via BodyPart.TryParse (string text, out BodyPart body).

Does that meet your needs?

@WesolyPierozek
Copy link
Author

Generally yes, but would be possible to store only something like attachment id/part number?
But for now i will go with approach which you suggested.

I noticed if two different attachments with same name are in message they have same BodyPart.ToString().

Another update:
I'm trying to get specific attachments basing on e-mail massage uid and let's say unique_attachment_id.
I wanted use BodyPart.ToString() for that but i'm failed because it may contains same attachments names with same length. GetBodyPart fails.
I wanted use BodyPart.PartSpecifier but i failed also, it isn't provided in MimePart and MimeEntity. So using GetMessage cannot help.
I wanted use created int index of BodyPart/Attachment but it isn't deterministic. MimeMessage.Attachments is IEnumerable so i won't trust in order.
Attachment FileName is insufficient.

Basically i will ask: is it possible to download specific attachment having email uid and some unique value from IMessageSummary received by Client.Inbox.Fetch(messagesUids, MessageSummaryItems.Full | MessageSummaryItems.BodyStructure); ?

@jstedfast
Copy link
Owner

I should have probably explained better. You need to ToString() the top-level BodyPart and then, when you are ready to download the specific part, traverse the tree structure again.

The PartSpecifier property is calculated based on the nested level of the BodyPart from the root.

jstedfast added a commit that referenced this issue Dec 12, 2014
@jstedfast
Copy link
Owner

The BodyPart.PartSpecifier is the only unique identifier for a specific MIME part that you can use. I didn't want people to have to know the details of the PartSpecifier string because most people calculate it incorrectly, so that is why I was forcing the use of BodyPart objects.

I've added new overrides of GetBodyPart() that take a part specifier string. How you get that is up to you, but I would recommend getting it via the BodyPart object.

@WesolyPierozek
Copy link
Author

Yes, I wanted use BodyPart for getting PartSpecifier. Thanks a lot! This is exactly that, what and how i wanted use.

@jstedfast
Copy link
Owner

excellent :-)

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

2 participants