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

Mime decode improvement for issue 130 #131

Merged
merged 12 commits into from
Oct 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/sisimai/bite/email/activehunter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def scan(mhead, mbody)
# ----- Transcript of session follows -----
# 550 sorry, no mailbox here by that name (#5.1.1 - chkusr)
next unless e =~ /\A[0-9A-Za-z]+/
next unless v['diagnosis'].empty?
v['diagnosis'] = e
end
end
Expand Down
12 changes: 8 additions & 4 deletions lib/sisimai/bite/email/apachejames.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class << self
# apache-james-2.3.2/src/java/org/apache/james/transport/mailets/
# AbstractNotify.java|124: out.println("Error message below:");
# AbstractNotify.java|128: out.println("Message details:");
message: ['Content-Disposition: inline'],
message: [''],
rfc822: ['Content-Type: message/rfc822'],
error: ['Error message below:'],
}.freeze
Expand Down Expand Up @@ -46,7 +46,7 @@ def scan(mhead, mbody)
recipients = 0 # (Integer) The number of 'Final-Recipient' header
diagnostic = '' # (String) Alternative diagnostic message
subjecttxt = nil # (String) Alternative Subject text
gotmessage = -1 # (Integer) Flag for error message
gotmessage = nil # (Boolean) Flag for error message
v = nil

while e = hasdivided.shift do
Expand Down Expand Up @@ -108,14 +108,14 @@ def scan(mhead, mbody)
# Subject: Nyaaan
subjecttxt = cv[1]
else
next if gotmessage == 1
next if gotmessage
if v['diagnosis']
# Get an error message text
if e.start_with?('Message details:')
# Message details:
# Subject: nyaan
# ...
gotmessage = 1
gotmessage = true
else
# Append error message text like the followng:
# Error message below:
Expand All @@ -126,6 +126,10 @@ def scan(mhead, mbody)
# Error message below:
# 550 - Requested action not taken: no such user here
v['diagnosis'] = e if e == StartingOf[:error][0]
unless gotmessage
v['diagnosis'] ||= ''
v['diagnosis'] << ' ' + e
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/sisimai/bite/email/gsuite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def scan(mhead, mbody)
if anotherset['diagnosis']
# Continued error messages from the previous line like
# "550 #5.1.0 Address rejected."
next if e =~ /\AContent-Type:/
next if emptylines > 5
if e.empty?
# Count and next()
Expand Down
2 changes: 1 addition & 1 deletion lib/sisimai/bite/email/interscanmss.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class << self

Indicators = Sisimai::Bite::Email.INDICATORS
StartingOf = {
message: ['Content-type: text/plain'],
message: [''],
rfc822: ['Content-type: message/rfc822'],
}.freeze

Expand Down
3 changes: 1 addition & 2 deletions lib/sisimai/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def self.make(data: nil, **argvs)
return nil unless data.is_a? Sisimai::Message

messageobj = data
mailheader = data.header
rfc822data = messageobj.rfc822
fieldorder = { :recipient => [], :addresser => [] }
objectlist = []
Expand Down Expand Up @@ -218,7 +217,7 @@ def self.make(data: nil, **argvs)
next unless p['timestamp']

# OTHER_TEXT_HEADERS:
recvheader = mailheader['received'] || []
recvheader = data.header['received'] || []
unless recvheader.empty?
# Get localhost and remote host name from Received header.
%w[lhost rhost].each { |a| e[a] ||= '' }
Expand Down
18 changes: 4 additions & 14 deletions lib/sisimai/message/email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class Email
DefaultSet = Sisimai::Order::Email.another
SubjectTab = Sisimai::Order::Email.by('subject')
ExtHeaders = Sisimai::Order::Email.headers
ReEncoding = Sisimai::MIME.patterns

# Make data structure from the email message(a body part and headers)
# @param [Hash] argvs Email data
Expand Down Expand Up @@ -416,19 +415,10 @@ def self.parse(argvs)
end
else
# NOT text/plain
lowercased = bodystring.downcase
if lowercased =~ ReEncoding[:'quoted-print']
# Content-Transfer-Encoding: quoted-printable
bodystring = Sisimai::MIME.qprintd(bodystring, mailheader)
end

if lowercased =~ ReEncoding[:'7bit-encoded'] &&
cv = lowercased.match(ReEncoding[:'some-iso2022'])
# Content-Transfer-Encoding: 7bit
# Content-Type: text/plain; charset=ISO-2022-JP
if ! cv[1].include?('us-ascii') && ! cv[1].include?('utf-8')
bodystring = Sisimai::String.to_utf8(bodystring, cv[1])
end
if mesgformat.start_with?('multipart/')
# In case of Content-Type: multipart/*
p = Sisimai::MIME.makeflat(mailheader['content-type'], bodystring)
bodystring = p unless p.empty?
end
end

Expand Down
Loading