Skip to content

Commit

Permalink
Tiny code improvement: a if block for capturing was converted to a on…
Browse files Browse the repository at this point in the history
…e line
  • Loading branch information
azumakuniyuki committed Oct 20, 2018
1 parent fd3beb2 commit 7c94831
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 114 deletions.
4 changes: 1 addition & 3 deletions lib/sisimai/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,7 @@ def self.expand_alias(email)

local = email.split('@')
value = ''
if cv = local[0].match(/\A([-_\w]+?)[+].+\z/)
value = cv[1] + '@' + local[1]
end
if cv = local[0].match(/\A([-_\w]+?)[+].+\z/) then value = cv[1] + '@' + local[1] end
return value
end

Expand Down
6 changes: 2 additions & 4 deletions lib/sisimai/bite/email/amazonses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,8 @@ def scan(mhead, mbody)
# Get other D.S.N. value from the error message
errormessage = e['diagnosis']

if cv = e['diagnosis'].match(/["'](\d[.]\d[.]\d.+)['"]/)
# 5.1.0 - Unknown address error 550-'5.7.1 ...
errormessage = cv[1]
end
# 5.1.0 - Unknown address error 550-'5.7.1 ...
if cv = e['diagnosis'].match(/["'](\d[.]\d[.]\d.+)['"]/) then errormessage = cv[1] end
pseudostatus = Sisimai::SMTP::Status.find(errormessage)
e['status'] = pseudostatus unless pseudostatus.empty?
end
Expand Down
14 changes: 5 additions & 9 deletions lib/sisimai/bite/email/amazonworkmail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,16 @@ def scan(mhead, mbody)
# Get other D.S.N. value from the error message
errormessage = e['diagnosis']

if cv = e['diagnosis'].match(/["'](\d[.]\d[.]\d.+)['"]/)
# 5.1.0 - Unknown address error 550-'5.7.1 ...
errormessage = cv[1]
end
# 5.1.0 - Unknown address error 550-'5.7.1 ...
if cv = e['diagnosis'].match(/["'](\d[.]\d[.]\d.+)['"]/) then errormessage = cv[1] end

pseudostatus = Sisimai::SMTP::Status.find(errormessage)
e['status'] = pseudostatus unless pseudostatus.empty?
end

if cv = e['diagnosis'].match(/[<]([245]\d\d)[ ].+[>]/)
# 554 4.4.7 Message expired: unable to deliver in 840 minutes.
# <421 4.4.2 Connection timed out>
e['replycode'] = cv[1]
end
# 554 4.4.7 Message expired: unable to deliver in 840 minutes.
# <421 4.4.2 Connection timed out>
if cv = e['diagnosis'].match(/[<]([245]\d\d)[ ].+[>]/) then e['replycode'] = cv[1] end

e['reason'] ||= Sisimai::SMTP::Status.name(e['status'])
e['agent'] = self.smtpagent
Expand Down
10 changes: 3 additions & 7 deletions lib/sisimai/bite/email/exim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,7 @@ def scan(mhead, mbody)
unless mhead['received'].empty?
# Get the name of local MTA
# Received: from marutamachi.example.org (c192128.example.net [192.0.2.128])
if cv = mhead['received'][-1].match(/from[ \t]([^ ]+)/)
localhost0 = cv[1]
end
if cv = mhead['received'][-1].match(/from[ \t]([^ ]+)/) then localhost0 = cv[1] end
end

dscontents.each do |e|
Expand Down Expand Up @@ -418,10 +416,8 @@ def scan(mhead, mbody)

unless e['rhost']
# Get the remote host name
if cv = e['diagnosis'].match(/host[ \t]+([^ \t]+)[ \t]\[.+\]:[ \t]/)
# host neko.example.jp [192.0.2.222]: 550 5.1.1 <kijitora@example.jp>... User Unknown
e['rhost'] = cv[1]
end
# host neko.example.jp [192.0.2.222]: 550 5.1.1 <kijitora@example.jp>... User Unknown
if cv = e['diagnosis'].match(/host[ \t]+([^ \t]+)[ \t]\[.+\]:[ \t]/) then e['rhost'] = cv[1] end

unless e['rhost']
# Get localhost and remote host name from Received header.
Expand Down
4 changes: 1 addition & 3 deletions lib/sisimai/bite/email/google.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@ def scan(mhead, mbody)
end
end

if cv = e['diagnosis'].match(/[(]state[ ](\d+)[)][.]/)
statecode0 = cv[1]
end
if cv = e['diagnosis'].match(/[(]state[ ](\d+)[)][.]/) then statecode0 = cv[1] end
if StateTable[statecode0]
# (state *)
e['reason'] = StateTable[statecode0]['reason']
Expand Down
10 changes: 3 additions & 7 deletions lib/sisimai/bite/email/mailru.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@ def scan(mhead, mbody)
unless mhead['received'].empty?
# Get the name of local MTA
# Received: from marutamachi.example.org (c192128.example.net [192.0.2.128])
if cv = mhead['received'][-1].match(/from[ \t]([^ ]+)/)
localhost0 = cv[1]
end
if cv = mhead['received'][-1].match(/from[ \t]([^ ]+)/) then localhost0 = cv[1] end
end

dscontents.each do |e|
Expand All @@ -205,10 +203,8 @@ def scan(mhead, mbody)

unless e['rhost']
# Get the remote host name
if cv = e['diagnosis'].match(/host[ ]+([^ \t]+)[ ]\[.+\]:[ ]/)
# host neko.example.jp [192.0.2.222]: 550 5.1.1 <kijitora@example.jp>... User Unknown
e['rhost'] = cv[1]
end
# host neko.example.jp [192.0.2.222]: 550 5.1.1 <kijitora@example.jp>... User Unknown
if cv = e['diagnosis'].match(/host[ ]+([^ \t]+)[ ]\[.+\]:[ ]/) then e['rhost'] = cv[1] end

unless e['rhost']
# Get localhost and remote host name from Received header.
Expand Down
10 changes: 3 additions & 7 deletions lib/sisimai/bite/email/mxlogic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ def scan(mhead, mbody)
unless mhead['received'].empty?
# Get the name of local MTA
# Received: from marutamachi.example.org (c192128.example.net [192.0.2.128])
if cv = mhead['received'][-1].match(/from[ ]([^ ]+) /)
localhost0 = cv[1]
end
if cv = mhead['received'][-1].match(/from[ ]([^ ]+) /) then localhost0 = cv[1] end
end

dscontents.each do |e|
Expand All @@ -192,10 +190,8 @@ def scan(mhead, mbody)

unless e['rhost']
# Get the remote host name
if cv = e['diagnosis'].match(/host[ ]+([^ \t]+)[ ]\[.+\]:[ ]/)
# host neko.example.jp [192.0.2.222]: 550 5.1.1 <kijitora@example.jp>... User Unknown
e['rhost'] = cv[1]
end
# host neko.example.jp [192.0.2.222]: 550 5.1.1 <kijitora@example.jp>... User Unknown
if cv = e['diagnosis'].match(/host[ ]+([^ \t]+)[ ]\[.+\]:[ ]/) then e['rhost'] = cv[1] end

unless e['rhost']
# Get localhost and remote host name from Received header.
Expand Down
9 changes: 3 additions & 6 deletions lib/sisimai/bite/email/qmail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,8 @@ def scan(mhead, mbody)
v['alterrors'] = e if e.start_with?(StartingOf[:error][0])

next if v['rhost']
if cv = e.match(ReHost)
v['rhost'] = cv[1]
end
next unless cv = e.match(ReHost)
v['rhost'] = cv[1]
end
end
end
Expand All @@ -210,9 +209,7 @@ def scan(mhead, mbody)

unless e['command']
# Verify each regular expression of patches
if cv = e['diagnosis'].match(ReCommands)
e['command'] = cv[1].upcase
end
if cv = e['diagnosis'].match(ReCommands) then e['command'] = cv[1].upcase end
e['command'] ||= ''
end
end
Expand Down
9 changes: 3 additions & 6 deletions lib/sisimai/bite/email/x4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,8 @@ def scan(mhead, mbody)
v['alterrors'] = e if e.start_with?(StartingOf[:error][0])

next if v['rhost']
if cv = e.match(ReHost)
v['rhost'] = cv[1]
end
next unless cv = e.match(ReHost)
v['rhost'] = cv[1]
end
end
end
Expand All @@ -230,9 +229,7 @@ def scan(mhead, mbody)

unless e['command']
# Verify each regular expression of patches
if cv = e['diagnosis'].match(ReCommands)
e['command'] = cv[1].upcase
end
if cv = e['diagnosis'].match(ReCommands) then e['command'] = cv[1].upcase end
e['command'] ||= ''
end
end
Expand Down
6 changes: 2 additions & 4 deletions lib/sisimai/bite/email/yahoo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,8 @@ def scan(mhead, mbody)
# Remote host said: 550 5.1.1 <kijitora@example.org>... User Unknown [RCPT_TO]
v['diagnosis'] = e

if cv = e.match(/\[([A-Z]{4}).*\]\z/)
# Get SMTP command from the value of "Remote host said:"
v['command'] = cv[1]
end
# Get SMTP command from the value of "Remote host said:"
if cv = e.match(/\[([A-Z]{4}).*\]\z/) then v['command'] = cv[1] end
else
# <mailboxfull@example.jp>:
# Remote host said:
Expand Down
6 changes: 2 additions & 4 deletions lib/sisimai/bite/json/amazonses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,8 @@ def adapt(argvs)
v['diagnosis'] = e['diagnosticCode']
end

if cv = o['reportingMTA'].match(/\Adsn;[ ](.+)\z/)
# 'reportingMTA' => 'dsn; a27-23.smtp-out.us-west-2.amazonses.com',
v['lhost'] = cv[1]
end
# 'reportingMTA' => 'dsn; a27-23.smtp-out.us-west-2.amazonses.com',
if cv = o['reportingMTA'].match(/\Adsn;[ ](.+)\z/) then v['lhost'] = cv[1] end

if BounceType.key?(o['bounceType'].to_sym) &&
BounceType[o['bounceType'].to_sym].key?(o['bounceSubType'].to_sym)
Expand Down
25 changes: 9 additions & 16 deletions lib/sisimai/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,12 @@ def self.make(data: nil, **argvs)
break if datestring
end

if datestring
if datestring && cv = datestring.match(/\A(.+)[ ]+([-+]\d{4})\z/)
# Get the value of timezone offset from datestring
if cv = datestring.match(/\A(.+)[ ]+([-+]\d{4})\z/)
# Wed, 26 Feb 2014 06:05:48 -0500
datestring = cv[1]
zoneoffset = Sisimai::DateTime.tz2second(cv[2])
p['timezoneoffset'] = cv[2]
end
# Wed, 26 Feb 2014 06:05:48 -0500
datestring = cv[1]
zoneoffset = Sisimai::DateTime.tz2second(cv[2])
p['timezoneoffset'] = cv[2]
end

begin
Expand Down Expand Up @@ -243,11 +241,8 @@ def self.make(data: nil, **argvs)
# The value of "List-Id" header
p['listid'] = rfc822data['list-id'] || ''
unless p['listid'].empty?
# Get the value of List-Id header
if cv = p['listid'].match(/\A.*([<].+[>]).*\z/)
# List name <list-id@example.org>
p['listid'] = cv[1]
end
# Get the value of List-Id header like "List name <list-id@example.org>"
if cv = p['listid'].match(/\A.*([<].+[>]).*\z/) then p['listid'] = cv[1] end
p['listid'] = p['listid'].delete('<>').chomp("\r")
p['listid'] = '' if p['listid'].include?(' ')
end
Expand Down Expand Up @@ -304,10 +299,8 @@ def self.make(data: nil, **argvs)

# Check the value of "action"
if p['action'].size > 0
if cv = p['action'].match(/\A(.+?) .+/)
# Action: expanded (to multi-recipient alias)
p['action'] = cv[1]
end
# Action: expanded (to multi-recipient alias)
if cv = p['action'].match(/\A(.+?) .+/) then p['action'] = cv[1] end

unless %w[failed delayed delivered relayed expanded].index(p['action'])
# The value of "action" is not in the following values:
Expand Down
54 changes: 23 additions & 31 deletions lib/sisimai/mime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,23 @@ def mimedecode(argvs = [])
e = e.strip.delete('"')

if self.is_mimeencoded(e)
# MIME Encoded string
if cv = e.match(/\A(.*)=[?]([-_0-9A-Za-z]+)[?]([BbQq])[?](.+)[?]=?(.*)\z/)
# =?utf-8?B?55m954yr44Gr44KD44KT44GT?=
characterset ||= cv[2]
encodingname ||= cv[3]
mimeencoded0 = cv[4]

decodedtext0 << cv[1]
if encodingname == 'Q'
# Quoted-Printable
decodedtext0 << mimeencoded0.unpack('M').first

elsif encodingname == 'B'
# Base64
decodedtext0 << Base64.decode64(mimeencoded0)
end
decodedtext0 << cv[5]
# MIME Encoded string like "=?utf-8?B?55m954yr44Gr44KD44KT44GT?="
next unless cv = e.match(/\A(.*)=[?]([-_0-9A-Za-z]+)[?]([BbQq])[?](.+)[?]=?(.*)\z/)

characterset ||= cv[2]
encodingname ||= cv[3]
mimeencoded0 = cv[4]
decodedtext0 << cv[1]

if encodingname == 'Q'
# Quoted-Printable
decodedtext0 << mimeencoded0.unpack('M').first

elsif encodingname == 'B'
# Base64
decodedtext0 << Base64.decode64(mimeencoded0)
end
decodedtext0 << cv[5]
else
decodedtext0 << e
end
Expand Down Expand Up @@ -227,10 +226,7 @@ def base64d(argv1)
return nil unless argv1

plain = nil
if cv = argv1.match(%r|([+/\=0-9A-Za-z\r\n]+)|)
# Decode BASE64
plain = Base64.decode64(cv[1])
end
if cv = argv1.match(%r|([+/\=0-9A-Za-z\r\n]+)|) then plain = Base64.decode64(cv[1]) end
return plain.force_encoding('UTF-8')
end

Expand Down Expand Up @@ -277,11 +273,9 @@ def breaksup(argv0 = nil, argv1 = '')
mimeformat = '' # MIME type string of this part
alternates = argv1.start_with?('multipart/alternative') ? true : false

if cv = argv0.match(thisformat)
# Get MIME type string from Content-Type: "..." field at the first line
# or the second line of the part.
mimeformat = cv[1].downcase
end
# Get MIME type string from Content-Type: "..." field at the first line
# or the second line of the part.
if cv = argv0.match(thisformat) then mimeformat = cv[1].downcase end

# Sisimai require only MIME types defined in $leavesonly variable
return '' unless mimeformat =~ leavesonly
Expand Down Expand Up @@ -348,7 +342,6 @@ def breaksup(argv0 = nil, argv1 = '')
end
getdecoded.gsub!(/\r\n/, "\n") # Convert CRLF to LF


if mimeformat =~ alsoappend
# Append field when the value of Content-Type: begins with
# message/ or equals text/rfc822-headers.
Expand Down Expand Up @@ -406,10 +399,9 @@ def makeflat(argv0 = nil, argv1 = nil)
mimeformat = ''
bodystring = ''

if cv = argv0.match(%r|\A([0-9a-z]+/[^ ;]+)|)
# Get MIME type string from an email header given as the 1st argument
mimeformat = cv[1]
end
# Get MIME type string from an email header given as the 1st argument
if cv = argv0.match(%r|\A([0-9a-z]+/[^ ;]+)|) then mimeformat = cv[1] end

return '' unless mimeformat.include?('multipart/')
return '' if ehboundary.empty?

Expand Down
4 changes: 1 addition & 3 deletions lib/sisimai/reason.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ def match(argv1)
diagnostic = argv1.downcase

statuscode = Sisimai::SMTP::Status.find(argv1)
if cv = argv1.match(/\A(SMTP|X-.+);/i)
typestring = cv[1].upcase
end
if cv = argv1.match(/\A(SMTP|X-.+);/i) then typestring = cv[1].upcase end

# Diagnostic-Code: SMTP; ... or empty value
ClassOrder[2].each do |e|
Expand Down
7 changes: 3 additions & 4 deletions lib/sisimai/rfc3464.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,9 @@ def scan(mhead, mbody)
# case characters.
v['action'] = cv[1].downcase

if cv = v['action'].match(/\A([^ ]+)[ ]/)
# failed (bad destination mailbox address)
v['action'] = cv[1]
end
# failed (bad destination mailbox address)
if cv = v['action'].match(/\A([^ ]+)[ ]/) then v['action'] = cv[1] end

elsif cv = e.match(/\AStatus:[ ]*(\d[.]\d+[.]\d+)/)
# 2.3.4 Status field
# The per-recipient Status field contains a transport-independent
Expand Down

0 comments on commit 7c94831

Please sign in to comment.