Sha256: 087ced1504ffc8419764078c4b1421429493e7be1a7e8a9551b70474476c425c
Contents?: true
Size: 1.03 KB
Versions: 5
Compression:
Stored size: 1.03 KB
Contents
require 'stringio' module TMail class Attachment < StringIO attr_accessor :original_filename, :content_type end class Mail def has_attachments? multipart? && parts.any? { |part| part.header["content-type"].main_type != "text" } end def attachments if multipart? parts.collect { |part| if part.header["content-type"].main_type != "text" content = part.body # unquoted automatically by TMail#body file_name = (part['content-location'] && part['content-location'].body) || part.sub_header("content-type", "name") || part.sub_header("content-disposition", "filename") next if file_name.blank? || content.blank? attachment = Attachment.new(content) attachment.original_filename = file_name.strip attachment.content_type = part.content_type attachment end }.compact end end end end
Version data entries
5 entries across 5 versions & 1 rubygems