./lib/mail/part.rb in mail-1.0.0 vs ./lib/mail/part.rb in mail-1.1.0

- old
+ new

@@ -11,14 +11,14 @@ self.content_transfer_encoding = "Base64" self.content_disposition = "attachment; filename=\"#{attachment.filename}\"" self.body = attachment.encoded else super - if content_type.parameters['filename'] - @attachment = Mail::Attachment.new(:filename => content_type.parameters['filename'], + if filename = attachment? + @attachment = Mail::Attachment.new(:filename => filename, :data => body.to_s, - :encoding => content_transfer_encoding.to_s) + :encoding => content_transfer_encoding.encoding) end end end # Creates a new empty Content-ID field and inserts it in the correct order @@ -31,11 +31,11 @@ header['content-id'] = content_id_val end # Returns true if this part is an attachment def attachment? - @attachment ? true : false + find_attachment end # Returns the attachment data if there is any def attachment @attachment @@ -111,9 +111,24 @@ end end def parse_delivery_status_report @delivery_status_data ||= Header.new(body.to_s.gsub("\r\n\r\n", "\r\n")) + end + + # Returns the filename of the attachment (if it exists) or returns nil + def find_attachment + case + when content_type && content_type.filename + filename = content_type.filename + when content_disposition && content_disposition.filename + filename = content_disposition.filename + when content_location && content_location.location + filename = content_location.location + else + filename = nil + end + filename end end end \ No newline at end of file