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

Change Message#without_attachments! to delete attachments recursively #858

Closed
wants to merge 3 commits into from

Conversation

TylerRick
Copy link
Contributor

No description provided.

@jeremy
Copy link
Collaborator

jeremy commented May 17, 2017

Nice implementation. But why? What motivates this change?

@jeremy
Copy link
Collaborator

jeremy commented Jul 6, 2017

Saw the motivation in #278. Fixed the immediate bug in #1131. Lining this up next.

@ahmeij
Copy link

ahmeij commented Nov 21, 2017

Is there something blocking this pull request? I am especially interested in recursive_delete_if method in parts list.

If there is something specific to be done I'd love to help.

@barodeur
Copy link

barodeur commented Jan 3, 2018

Here is a small module I've been using as a workaround. I'll be very happy to submit something similar as a PR.

module MailHelper
  module_function

  def delete_parts_if(mail, &block)
    removed_parts = []

    mail.parts.each do |part|
      if yield(part)
        mail.parts.delete(part)
        removed_parts << part
      end

      if part.mime_type == 'message/rfc822'
        sub_mail, sub_removed_parts = delete_parts_if(Mail.new(part.decoded), &block)
        part.body = sub_mail.encoded
        removed_parts += sub_removed_parts
      end
    end

    [mail, removed_parts]
  end

  def delete_attachment_parts(mail)
    delete_parts_if(mail, &:attachment?)
  end
end

…, no matter

how deeply they are nested.

Now it is consistent with #attachments, which returns a list of attachments
no matter how deeply they are nested.

It was only deleting attachments from the top level (parts) but not those in
parts[0].parts, for example.
@TylerRick
Copy link
Contributor Author

@jeremy I've rebased this PR. Let me know if there's anything else I can do to get it merged.

jeremy pushed a commit that referenced this pull request Feb 15, 2018
@jeremy jeremy closed this in cb3946b Feb 15, 2018
@jeremy jeremy added this to the 2.8.0 milestone Feb 15, 2018
@TylerRick TylerRick deleted the without_attachments branch February 16, 2018 16:51
jeremy added a commit to jeremy/mail that referenced this pull request Feb 16, 2018
jeremy added a commit that referenced this pull request Feb 16, 2018
@weilandia
Copy link

Hello, I'm hoping to use the recursive_each method to parse emails with message/rfc822 parts, but I'm seeing it hasn't made it into a stable release.

Any suggestions for parsing those emails? I'm thinking I'll just monkey-patch that method onto PartsList for now, but would be great to hear if that's not a good use case of the method.

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.

5 participants