Do not show text alternative attachments (already shown in view). Add html alternative attachments only one.

This commit is contained in:
Martin Edenhofer 2014-12-29 00:11:37 +01:00
parent 80ed5a3331
commit e4de2f8dee

View file

@ -167,28 +167,20 @@ class Channel::EmailParser
# get attachments # get attachments
if mail.parts if mail.parts
attachment_count_total = 0
mail.parts.each { |part| mail.parts.each { |part|
attachment_count_total += 1
# protect process to work fine with spam emails, see test/fixtures/mail15.box # protect process to work fine with spam emails, see test/fixtures/mail15.box
begin begin
if mail.text_part && mail.text_part == part attachs = self._get_attachment( part, data[:attachments], mail )
# ignore text/plain attachments - already shown in view data[:attachments].concat( attachs )
elsif mail.html_part && mail.html_part == part
# ignore text/html - html part, already shown in view
else
attachs = self._get_attachment( part, data[:attachments] )
data[:attachments].concat( attachs )
end
rescue rescue
attachs = self._get_attachment( part, data[:attachments] ) attachs = self._get_attachment( part, data[:attachments], mail )
data[:attachments].concat( attachs ) data[:attachments].concat( attachs )
end end
} }
end end
# not multipart email # not multipart email
else else
# text part # text part
@ -238,23 +230,31 @@ class Channel::EmailParser
end end
# strip not wanted chars # strip not wanted chars
data[:body].gsub!( /\n\r/, "\n" )
data[:body].gsub!( /\r\n/, "\n" ) data[:body].gsub!( /\r\n/, "\n" )
data[:body].gsub!( /\r/, "\n" ) data[:body].gsub!( /\r/, "\n" )
return data return data
end end
def _get_attachment( file, attachments ) def _get_attachment( file, attachments, mail )
# check if sub parts are available # check if sub parts are available
if !file.parts.empty? if !file.parts.empty?
a = [] a = []
file.parts.each {|p| file.parts.each {|p|
a.concat( self._get_attachment( p, attachments ) ) attachment = self._get_attachment( p, attachments, mail )
a.concat( attachment )
} }
return a return a
end end
# ignore text/plain attachments - already shown in view
return [] if mail.text_part && mail.text_part.body.to_s == file.body.to_s
# ignore text/html - html part, already shown in view
return [] if mail.html_part && mail.html_part.body.to_s == file.body.to_s
# get file preferences # get file preferences
headers_store = {} headers_store = {}
file.header.fields.each { |field| file.header.fields.each { |field|
@ -313,7 +313,7 @@ class Channel::EmailParser
:filename => filename, :filename => filename,
:preferences => headers_store, :preferences => headers_store,
} }
return [attach] [attach]
end end
def process(channel, msg) def process(channel, msg)