Skip to content

New method AttachmentsList.add(attachment) #926

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TomFreudenberg
Copy link

I added a new function to the AttachmentsList class to manipulate attachments without decode/encode and rewriting id's etc.

We are using the Mail gem for a message router and need everytime to copy the original attachments.

Instead of re-creating that attachments like

mail_in = Mail.read_from_string(mail_source)
mail_out = Mail.new
# copy attachments
mail_in.attachments.each do |a| 
  mail_out.attachments[a.filename] = { 
    :mime_type => a.mime_type, 
    :encoding => a.content_transfer_encoding,
    :content_id => a.content_id,
    :content_disposition => a.content_disposition,
    :content => a.decoded
  } 
end

now you just can append the already processed attachment from original message.

mail_in = Mail.read_from_string(mail_source)
mail_out = Mail.new
# copy attachments
mail_in.attachments.each { |a| mail_out.attachments.add(a) }

Hopefully this change makes sense for you.

Looking for your feedback
Tom

@jeremy
Copy link
Collaborator

jeremy commented May 17, 2017

Can these be added using the existing parts API?

@TomFreudenberg
Copy link
Author

Hi @jeremy

what does that mean: "Can these be added using the existing parts API?"

Should I check it with latest sources?

Thanks for some more info
Tom

@jeremy
Copy link
Collaborator

jeremy commented May 17, 2017

Give this a shot:

mail_in = Mail.new(mail_source)
mail_out = Mail.new
mail_in.attachments.each { |part| mail_out.body << part }

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

Successfully merging this pull request may close these issues.

2 participants