Skip to content

Commit

Permalink
Remove constant Re0 and regular expressions defined in Re0 have been …
Browse files Browse the repository at this point in the history
…replaced with String#start_with?, String#end_with? or String#include? #99 #105
  • Loading branch information
azumakuniyuki committed Jan 15, 2018
1 parent c4e380f commit b43e64a
Show file tree
Hide file tree
Showing 54 changed files with 197 additions and 417 deletions.
21 changes: 8 additions & 13 deletions lib/sisimai/arf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ class << self
require 'sisimai/bite/email'
require 'sisimai/rfc5322'

Re0 = {
:'content-type' => %r|multipart/mixed|,
:'report-type' => %r/report-type=["]?feedback-report["]?/,
:'from' => %r{(?:
staff[@]hotmail[.]com\z
|complaints[@]email-abuse[.]amazonses[.]com\z
)
}x,
:'subject' => %r/complaint[ ]about[ ]message[ ]from[ ]/,
}.freeze
# http://tools.ietf.org/html/rfc5965
# http://en.wikipedia.org/wiki/Feedback_loop_(email)
# http://en.wikipedia.org/wiki/Abuse_Reporting_Format
Expand Down Expand Up @@ -52,14 +42,19 @@ def is_arf(heads)
return false unless heads
match = false

if heads['content-type'] =~ Re0[:'report-type']
if heads['content-type'] =~ /report-type=["]?feedback-report["]?/
# Content-Type: multipart/report; report-type=feedback-report; ...
match = true

elsif heads['content-type'] =~ Re0[:'content-type']
elsif heads['content-type'].include?('multipart/mixed')
# Microsoft (Hotmail, MSN, Live, Outlook) uses its own report format.
# Amazon SES Complaints bounces
if heads['from'] =~ Re0[:'from'] && heads['subject'] =~ Re0[:'subject']
mfrom = %r{(?:
staff[@]hotmail[.]com\z
|complaints[@]email-abuse[.]amazonses[.]com\z
)
}x
if heads['from'] =~ mfrom && heads['subject'].include?('complaint about message from ')
# From: staff@hotmail.com
# From: complaints@email-abuse.amazonses.com
# Subject: complaint about message from 192.0.2.1
Expand Down
7 changes: 3 additions & 4 deletions lib/sisimai/bite/email/activehunter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ class << self
# Imported from p5-Sisimail/lib/Sisimai/Bite/Email/Activehunter.pm
require 'sisimai/bite/email'

Re0 = {
:from => %r/\A"MAILER-DAEMON"/,
:subject => %r/FAILURE NOTICE :/,
}.freeze
Re1 = {
:begin => %r/\A ----- The following addresses had permanent fatal errors -----\z/,
:error => %r/\A ----- Transcript of session follows -----\z/,
Expand All @@ -36,6 +32,9 @@ def headerlist; return ['X-AHMAILID']; end
def scan(mhead, mbody)
return nil unless mhead
return nil unless mbody

# :from => %r/\A"MAILER-DAEMON"/,
# :subject => %r/FAILURE NOTICE :/,
return nil unless mhead['x-ahmailid']

dscontents = [Sisimai::Bite.DELIVERYSTATUS]
Expand Down
11 changes: 4 additions & 7 deletions lib/sisimai/bite/email/amazonses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ class << self
require 'sisimai/bite/email'

# http://aws.amazon.com/ses/
ReE = { :'x-mailer' => %r/Amazon[ ]WorkMail/ }.freeze
Re0 = {
:from => %r/\AMAILER-DAEMON[@]email[-]bounces[.]amazonses[.]com\z/,
:subject => %r/\ADelivery Status Notification [(]Failure[)]\z/,
}.freeze
Re1 = {
:begin => %r/\A(?:
The[ ]following[ ]message[ ]to[ ][<]
Expand Down Expand Up @@ -50,9 +45,11 @@ def scan(mhead, mbody)
return nil unless mhead
return nil unless mbody

match = 0
return nil if mhead['x-mailer'] =~ ReE[:'x-mailer']
# :from => %r/\AMAILER-DAEMON[@]email[-]bounces[.]amazonses[.]com\z/,
# :subject => %r/\ADelivery Status Notification [(]Failure[)]\z/,
return nil if mhead['x-mailer'].to_s.include?('Amazon WorkMail')

match = 0
match += 1 if mhead['x-aws-outgoing']
match += 1 if mhead['x-ses-outgoing']
return nil if match.zero?
Expand Down
10 changes: 4 additions & 6 deletions lib/sisimai/bite/email/amazonworkmail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ class << self
require 'sisimai/bite/email'

# https://aws.amazon.com/workmail/
Re0 = {
:'subject' => %r/Delivery[_ ]Status[_ ]Notification[_ ].+Failure/,
:'received' => %r/.+[.]smtp-out[.].+[.]amazonses[.]com\b/,
:'x-mailer' => %r/\AAmazon WorkMail\z/,
}.freeze
Re1 = {
:begin => %r/\ATechnical report:\z/,
:rfc822 => %r|\Acontent-type: message/rfc822\z|,
Expand Down Expand Up @@ -41,14 +36,17 @@ def scan(mhead, mbody)
return nil unless mhead
return nil unless mbody

# :'subject' => %r/Delivery[_ ]Status[_ ]Notification[_ ].+Failure/,
# :'received' => %r/.+[.]smtp-out[.].+[.]amazonses[.]com\b/,
# :'x-mailer' => %r/\AAmazon WorkMail\z/,
match = 0
xmail = mhead['x-original-mailer'] || mhead['x-mailer'] || ''

match += 1 if mhead['x-ses-outgoing']
unless xmail.empty?
# X-Mailer: Amazon WorkMail
# X-Original-Mailer: Amazon WorkMail
match += 1 if xmail =~ Re0[:'x-mailer']
match += 1 if xmail.start_with?('Amazon WorkMail')
end
return nil if match < 2

Expand Down
7 changes: 3 additions & 4 deletions lib/sisimai/bite/email/aol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ class << self
# Imported from p5-Sisimail/lib/Sisimai/Bite/Email/Aol.pm
require 'sisimai/bite/email'

Re0 = {
:from => %r/\APostmaster [<]Postmaster[@]AOL[.]com[>]\z/,
:subject => %r/\AUndeliverable: /,
}.freeze
Re1 = {
:begin => %r|\AContent-Type: message/delivery-status|,
:rfc822 => %r|\AContent-Type: message/rfc822|,
Expand Down Expand Up @@ -49,6 +45,9 @@ def headerlist; return ['X-AOL-IP']; end
def scan(mhead, mbody)
return nil unless mhead
return nil unless mbody

# :from => %r/\APostmaster [<]Postmaster[@]AOL[.]com[>]\z/,
# :subject => %r/\AUndeliverable: /,
return nil unless mhead['x-aol-ip']

dscontents = [Sisimai::Bite.DELIVERYSTATUS]
Expand Down
11 changes: 3 additions & 8 deletions lib/sisimai/bite/email/apachejames.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ class << self
# Imported from p5-Sisimail/lib/Sisimai/Bite/Email/ApacheJames.pm
require 'sisimai/bite/email'

Re0 = {
:'subject' => %r/\A\[BOUNCE\]\z/,
:'received' => %r/JAMES SMTP Server/,
:'message-id' => %r/\d+[.]JavaMail[.].+[@]/,
}.freeze
Re1 = {
# apache-james-2.3.2/src/java/org/apache/james/transport/mailets/
# AbstractNotify.java|124: out.println("Error message below:");
Expand Down Expand Up @@ -41,9 +36,9 @@ def scan(mhead, mbody)
return nil unless mbody

match = 0
match += 1 if mhead['subject'] =~ Re0[:subject]
match += 1 if mhead['message-id'] && mhead['message-id'] =~ Re0[:'message-id']
match += 1 if mhead['received'].find { |a| a =~ Re0[:received] }
match += 1 if mhead['subject'].start_with?('[BOUNCE]')
match += 1 if mhead['message-id'] && mhead['message-id'] =~ /\d+[.]JavaMail[.].+[@]/
match += 1 if mhead['received'].find { |a| a.include?('JAMES SMTP Server') }
return if match.zero?

dscontents = [Sisimai::Bite.DELIVERYSTATUS]
Expand Down
12 changes: 4 additions & 8 deletions lib/sisimai/bite/email/bigfoot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ class << self
# Imported from p5-Sisimail/lib/Sisimai/Bite/Email/Bigfoot.pm
require 'sisimai/bite/email'

Re0 = {
:from => %r/[@]bigfoot[.]com[>]/,
:subject => %r/\AReturned mail: /,
:received => %r/\w+[.]bigfoot[.]com\b/,
}.freeze
Re1 = {
:begin => %r/\A[ \t]+[-]+[ \t]*Transcript of session follows/,
:rfc822 => %r|\AContent-Type: message/partial|,
Expand All @@ -35,10 +30,11 @@ def headerlist; return []; end
def scan(mhead, mbody)
return nil unless mhead
return nil unless mbody


# :subject => %r/\AReturned mail: /,
match = 0
match += 1 if mhead['from'] =~ Re0[:from]
match += 1 if mhead['received'].find { |a| a =~ Re0[:received] }
match += 1 if mhead['from'].include?('@bigfoot.com>')
match += 1 if mhead['received'].find { |a| a =~ /\w+[.]bigfoot[.]com\b/ }
return nil if match.zero?

require 'sisimai/address'
Expand Down
8 changes: 2 additions & 6 deletions lib/sisimai/bite/email/biglobe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ class << self
# Imported from p5-Sisimail/lib/Sisimai/Bite/Email/Biglobe.pm
require 'sisimai/bite/email'

Re0 = {
:subject => %r/\AReturned mail:/,
:from => %r/postmaster[@](?:biglobe|inacatv|tmtv|ttv)[.]ne[.]jp/,
}.freeze
Re1 = {
:begin => %r/\A ----- The following addresses had delivery problems -----\z/,
:error => %r/\A ----- Non-delivered information -----\z/,
Expand Down Expand Up @@ -39,8 +35,8 @@ def headerlist; return []; end
def scan(mhead, mbody)
return nil unless mhead
return nil unless mbody
return nil unless mhead['from'] =~ Re0[:from]
return nil unless mhead['subject'] =~ Re0[:subject]
return nil unless mhead['from'] =~ /postmaster[@](?:biglobe|inacatv|tmtv|ttv)[.]ne[.]jp/
return nil unless mhead['subject'].start_with?('Returned mail:')

require 'sisimai/address'
dscontents = [Sisimai::Bite.DELIVERYSTATUS]
Expand Down
15 changes: 3 additions & 12 deletions lib/sisimai/bite/email/courier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ class << self

# http://www.courier-mta.org/courierdsn.html
# courier/module.dsn/dsn*.txt
Re0 = {
:'from' => %r/Courier mail server at /,
:'subject' => %r{(?:
NOTICE:[ ]mail[ ]delivery[ ]status[.]
|WARNING:[ ]delayed[ ]mail[.]
)
}x,
:'message-id' => %r/\A[<]courier[.][0-9A-F]+[.]/,
}.freeze
Re1 = {
:begin => %r{(?:
DELAYS[ ]IN[ ]DELIVERING[ ]YOUR[ ]MESSAGE
Expand Down Expand Up @@ -62,11 +53,11 @@ def scan(mhead, mbody)
return nil unless mbody

match = 0
match += 1 if mhead['from'] =~ Re0[:from]
match += 1 if mhead['subject'] =~ Re0[:subject]
match += 1 if mhead['from'] =~ /Courier mail server at /
match += 1 if mhead['subject'] =~ /(?:NOTICE: mail delivery status[.]|WARNING: delayed mail[.])/
if mhead['message-id']
# Message-ID: <courier.4D025E3A.00001792@5jo.example.org>
match += 1 if mhead['message-id'] =~ Re0[:'message-id']
match += 1 if mhead['message-id'] =~ /\A[<]courier[.][0-9A-F]+[.]/
end
return nil if match.zero?

Expand Down
5 changes: 1 addition & 4 deletions lib/sisimai/bite/email/domino.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ class << self
# Imported from p5-Sisimail/lib/Sisimai/Bite/Email/Domino.pm
require 'sisimai/bite/email'

Re0 = {
:subject => %r/\ADELIVERY FAILURE:/,
}.freeze
Re1 = {
:begin => %r/\AYour message/,
:rfc822 => %r|\AContent-Type: message/delivery-status\z|,
Expand Down Expand Up @@ -45,7 +42,7 @@ def headerlist; return []; end
def scan(mhead, mbody)
return nil unless mhead
return nil unless mbody
return nil unless mhead['subject'] =~ Re0[:subject]
return nil unless mhead['subject'].start_with?('DELIVERY FAILURE:')

require 'sisimai/address'
dscontents = [Sisimai::Bite.DELIVERYSTATUS]
Expand Down
8 changes: 2 additions & 6 deletions lib/sisimai/bite/email/einsundeins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ class << self
# Imported from p5-Sisimail/lib/Sisimai/Bite/Email/EinsUndEins.pm
require 'sisimai/bite/email'

Re0 = {
:from => %r/\A["]Mail Delivery System["]/,
:subject => %r/\AMail delivery failed: returning message to sender\z/,
}.freeze
Re1 = {
:begin => %r/\AThis message was created automatically by mail delivery software/,
:error => %r/\AFor the following reason:/,
Expand Down Expand Up @@ -39,8 +35,8 @@ def headerlist; return []; end
def scan(mhead, mbody)
return nil unless mhead
return nil unless mbody
return nil unless mhead['from'] =~ Re0[:from]
return nil unless mhead['subject'] =~ Re0[:subject]
return nil unless mhead['from'].start_with?('"Mail Delivery System"')
return nil unless mhead['subject'].start_with?('Mail delivery failed: returning message to sender')

dscontents = [Sisimai::Bite.DELIVERYSTATUS]
hasdivided = mbody.split("\n")
Expand Down
20 changes: 5 additions & 15 deletions lib/sisimai/bite/email/exchange2003.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@ class << self
# Imported from p5-Sisimail/lib/Sisimai/Bite/Email/Exchange2003.pm
require 'sisimai/bite/email'

Re0 = {
# X-Mailer: Internet Mail Service (5.0.1461.28)
# X-Mailer: Microsoft Exchange Server Internet Mail Connector Version ...
:'x-mailer' => %r{\A(?:
Internet[ ]Mail[ ]Service[ ][(][\d.]+[)]\z
|Microsoft[ ]Exchange[ ]Server[ ]Internet[ ]Mail[ ]Connector
)
}x,
:'x-mimeole' => %r/\AProduced By Microsoft Exchange/,
# Received: by ***.**.** with Internet Mail Service (5.5.2657.72)
:'received' => %r/\Aby .+ with Internet Mail Service [(][\d.]+[)]/,
}.freeze
Re1 = {
:begin => %r/\AYour message/,
:error => %r/\Adid not reach the following recipient[(]s[)]:/,
Expand Down Expand Up @@ -72,6 +60,7 @@ def scan(mhead, mbody)
return nil unless mhead
return nil unless mbody
match = 0
tryto = []

match += 1 if mhead['x-ms-embedded-report']
catch :EXCHANGE_OR_NOT do
Expand All @@ -81,20 +70,21 @@ def scan(mhead, mbody)
if mhead['x-mailer']
# X-Mailer: Microsoft Exchange Server Internet Mail Connector Version 4.0.994.63
# X-Mailer: Internet Mail Service (5.5.2232.9)
match += 1 if mhead['x-mailer'] =~ Re0[:'x-mailer']
tryto = ['Internet Mail Service (', 'Microsoft Exchange Server Internet Mail Connector']
match += 1 if mhead['x-mailer'].start_with?(tryto[0], tryto[1])
throw :EXCHANGE_OR_NOT if match > 0
end

if mhead['x-mimeole']
# X-MimeOLE: Produced By Microsoft Exchange V6.5
match += 1 if mhead['x-mimeole'] =~ Re0[:'x-mimeole']
match += 1 if mhead['x-mimeole'].start_with?('Produced By Microsoft Exchange')
throw :EXCHANGE_OR_NOT if match > 0
end

throw :EXCHANGE_OR_NOT if mhead['received'].size.zero?
mhead['received'].each do |e|
# Received: by ***.**.** with Internet Mail Service (5.5.2657.72)
next unless e =~ Re0[:'received']
next unless e =~ /\Aby .+ with Internet Mail Service [(][\d.]+[)]/
match += 1
throw :EXCHANGE_OR_NOT
end
Expand Down
8 changes: 2 additions & 6 deletions lib/sisimai/bite/email/exchange2007.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ class << self
# Imported from p5-Sisimail/lib/Sisimai/Bite/Email/Exchange2007.pm
require 'sisimai/bite/email'

Re0 = {
:'subject' => %r/\AUndeliverable:/,
:'content-language' => %r/\A[a-z]{2}(?:[-][A-Z]{2})?\z/,
}.freeze
Re1 = {
:begin => %r/[ ]Microsoft[ ]Exchange[ ]Server[ ]20\d{2}/,
:error => %r/[ ]((?:RESOLVER|QUEUE)[.][A-Za-z]+(?:[.]\w+)?);/,
Expand Down Expand Up @@ -52,9 +48,9 @@ def scan(mhead, mbody)
return nil unless mhead
return nil unless mbody

return nil unless mhead['subject'] =~ Re0[:'subject']
return nil unless mhead['subject'].start_with?('Undeliverable:')
return nil unless mhead['content-language']
return nil unless mhead['content-language'] =~ Re0[:'content-language']
return nil unless mhead['content-language'] =~ /\A[a-z]{2}(?:[-][A-Z]{2})?\z/

dscontents = [Sisimai::Bite.DELIVERYSTATUS]
hasdivided = mbody.split("\n")
Expand Down
Loading

0 comments on commit b43e64a

Please sign in to comment.