Skip to content

Commit

Permalink
Constants improvement: Renamed and replaced with String#start_with? o…
Browse files Browse the repository at this point in the history
…r String#include?
  • Loading branch information
azumakuniyuki committed Jan 21, 2018
1 parent 84d74d9 commit 258d4c6
Show file tree
Hide file tree
Showing 54 changed files with 561 additions and 527 deletions.
16 changes: 9 additions & 7 deletions lib/sisimai/arf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ class << self
# Netease DMARC uses: This is a spf/dkim authentication-failure report for an email message received from IP
# OpenDMARC 1.3.0 uses: This is an authentication failure report for an email message received from IP
# Abusix ARF uses this is an autogenerated email abuse complaint regarding your network.
Re1 = {
:begin => %r{\A(?>
Indicators = Sisimai::Bite::Email.INDICATORS
StartingOf = {
rfc822: ['Content-Type: message/rfc822', 'Content-Type: text/rfc822-headers'],
}.freeze
MarkingsOf = {
message: %r{\A(?>
[Tt]his[ ]is[ ].+[ ]email[ ]abuse[ ]report
|[Tt]his[ ]is[ ](?:
an[ ]autogenerated[ ]email[ ]abuse[ ]complaint
Expand All @@ -23,9 +27,7 @@ class << self
)
)
}x,
:rfc822 => %r[\AContent-Type: (:?message/rfc822|text/rfc822-headers)],
}.freeze
Indicators = Sisimai::Bite::Email.INDICATORS
LongFields = Sisimai::RFC5322.LONGFIELDS
RFC822Head = Sisimai::RFC5322.HEADERFIELDS

Expand Down Expand Up @@ -123,15 +125,15 @@ def scan(mhead, mbody)
hasdivided.each do |e|
if readcursor.zero?
# Beginning of the bounce message or delivery status part
if e =~ Re1[:begin]
if e =~ MarkingsOf[:message]
readcursor |= Indicators[:deliverystatus]
next
end
end

if (readcursor & Indicators[:'message-rfc822']).zero?
# Beginning of the original message part
if e =~ Re1[:rfc822]
if e.start_with?(StartingOf[:rfc822][0], StartingOf[:rfc822][1])
readcursor |= Indicators[:'message-rfc822']
next
end
Expand Down Expand Up @@ -245,7 +247,7 @@ def scan(mhead, mbody)
commondata[:from] = Sisimai::Address.s3s4(cv[1])
end

elsif e =~ Re1[:begin]
elsif e =~ MarkingsOf[:message]
# This is an email abuse report for an email message with the
# message-id of 0000-000000000000000000000000000000000@mx
# received from IP address 192.0.2.1 on
Expand Down
13 changes: 6 additions & 7 deletions lib/sisimai/bite/email/activehunter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ class << self
# Imported from p5-Sisimail/lib/Sisimai/Bite/Email/Activehunter.pm
require 'sisimai/bite/email'

Re1 = {
:begin => %r/\A ----- The following addresses had permanent fatal errors -----\z/,
:error => %r/\A ----- Transcript of session follows -----\z/,
:rfc822 => %r|\AContent-type: message/rfc822\z|,
}.freeze
Indicators = Sisimai::Bite::Email.INDICATORS
StartingOf = {
message: [' ----- The following addresses had permanent fatal errors -----'],
rfc822: ['Content-type: message/rfc822'],
}.freeze

def description; return 'TransWARE Active!hunter'; end
def smtpagent; return Sisimai::Bite.smtpagent(self); end
Expand Down Expand Up @@ -48,15 +47,15 @@ def scan(mhead, mbody)
hasdivided.each do |e|
if readcursor.zero?
# Beginning of the bounce message or delivery status part
if e =~ Re1[:begin]
if e.start_with?(StartingOf[:message][0])
readcursor |= Indicators[:deliverystatus]
next
end
end

if (readcursor & Indicators[:'message-rfc822']).zero?
# Beginning of the original message part
if e =~ Re1[:rfc822]
if e.start_with?(StartingOf[:rfc822][0])
readcursor |= Indicators[:'message-rfc822']
next
end
Expand Down
17 changes: 7 additions & 10 deletions lib/sisimai/bite/email/amazonses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@ class << self
require 'sisimai/bite/email'

# http://aws.amazon.com/ses/
Re1 = {
:begin => %r/\A(?:
The[ ]following[ ]message[ ]to[ ][<]
|An[ ]error[ ]occurred[ ]while[ ]trying[ ]to[ ]deliver[ ]the[ ]mail[ ]
)
/x,
:rfc822 => %r|\Acontent-type: message/rfc822\z|,
Indicators = Sisimai::Bite::Email.INDICATORS
StartingOf = {
message: ['The following message to <', 'An error occurred while trying to deliver the mail'],
rfc822: ['content-type: message/rfc822'],
}.freeze

ReFailure = {
expired: %r/Delivery[ ]expired/x,
}.freeze
Indicators = Sisimai::Bite::Email.INDICATORS

def description; return 'Amazon SES(Sending): http://aws.amazon.com/ses/'; end
def smtpagent; return Sisimai::Bite.smtpagent(self); end
Expand Down Expand Up @@ -74,15 +71,15 @@ def scan(mhead, mbody)

if readcursor.zero?
# Beginning of the bounce message or delivery status part
if e =~ Re1[:begin]
if e.start_with?(StartingOf[:message][0], StartingOf[:message][1])
readcursor |= Indicators[:deliverystatus]
next
end
end

if (readcursor & Indicators[:'message-rfc822']).zero?
# Beginning of the original message part
if e =~ Re1[:rfc822]
if e.start_with?(StartingOf[:rfc822][0])
readcursor |= Indicators[:'message-rfc822']
next
end
Expand Down
12 changes: 6 additions & 6 deletions lib/sisimai/bite/email/amazonworkmail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ class << self
require 'sisimai/bite/email'

# https://aws.amazon.com/workmail/
Re1 = {
:begin => %r/\ATechnical report:\z/,
:rfc822 => %r|\Acontent-type: message/rfc822\z|,
}.freeze
Indicators = Sisimai::Bite::Email.INDICATORS
StartingOf = {
message: ['Technical report:'],
rfc822: ['content-type: message/rfc822'],
}.freeze

def description; return 'Amazon WorkMail: https://aws.amazon.com/workmail/'; end
def smtpagent; return Sisimai::Bite.smtpagent(self); end
Expand Down Expand Up @@ -65,15 +65,15 @@ def scan(mhead, mbody)
hasdivided.each do |e|
if readcursor.zero?
# Beginning of the bounce message or delivery status part
if e =~ Re1[:begin]
if e.start_with?(StartingOf[:message][0])
readcursor |= Indicators[:deliverystatus]
next
end
end

if (readcursor & Indicators[:'message-rfc822']).zero?
# Beginning of the original message part
if e =~ Re1[:rfc822]
if e.start_with?(StartingOf[:rfc822][0])
readcursor |= Indicators[:'message-rfc822']
next
end
Expand Down
13 changes: 7 additions & 6 deletions lib/sisimai/bite/email/aol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ class << self
# Imported from p5-Sisimail/lib/Sisimai/Bite/Email/Aol.pm
require 'sisimai/bite/email'

Re1 = {
:begin => %r|\AContent-Type: message/delivery-status|,
:rfc822 => %r|\AContent-Type: message/rfc822|,
Indicators = Sisimai::Bite::Email.INDICATORS
StartingOf = {
message: ['Content-Type: message/delivery-status'],
rfc822: ['Content-Type: message/rfc822'],
}.freeze

ReFailure = {
hostunknown: %r/Host[ ]or[ ]domain[ ]name[ ]not[ ]found/,
notaccept: %r/type=MX:[ ]Malformed[ ]or[ ]unexpected[ ]name[ ]server[ ]reply/,
}.freeze
Indicators = Sisimai::Bite::Email.INDICATORS

def description; return 'Aol Mail: http://www.aol.com'; end
def smtpagent; return Sisimai::Bite.smtpagent(self); end
Expand Down Expand Up @@ -71,15 +72,15 @@ def scan(mhead, mbody)

if readcursor.zero?
# Beginning of the bounce message or delivery status part
if e =~ Re1[:begin]
if e.start_with?(StartingOf[:message][0])
readcursor |= Indicators[:deliverystatus]
next
end
end

if (readcursor & Indicators[:'message-rfc822']).zero?
# Beginning of the original message part
if e =~ Re1[:rfc822]
if e.start_with?(StartingOf[:rfc822][0])
readcursor |= Indicators[:'message-rfc822']
next
end
Expand Down
16 changes: 8 additions & 8 deletions lib/sisimai/bite/email/apachejames.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ class << self
# Imported from p5-Sisimail/lib/Sisimai/Bite/Email/ApacheJames.pm
require 'sisimai/bite/email'

Re1 = {
Indicators = Sisimai::Bite::Email.INDICATORS
StartingOf = {
# 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:");
:begin => %r/\AContent-Disposition:[ ]inline/,
:error => %r/\AError message below:\z/,
:rfc822 => %r|\AContent-Type: message/rfc822|,
message: ['Content-Disposition: inline'],
rfc822: ['Content-Type: message/rfc822'],
error: ['Error message below:'],
}.freeze
Indicators = Sisimai::Bite::Email.INDICATORS

def description; return 'Java Apache Mail Enterprise Server'; end
def smtpagent; return Sisimai::Bite.smtpagent(self); end
Expand Down Expand Up @@ -55,15 +55,15 @@ def scan(mhead, mbody)
hasdivided.each do |e|
if readcursor.zero?
# Beginning of the bounce message or delivery status part
if e =~ Re1[:begin]
if e.start_with?(StartingOf[:message][0])
readcursor |= Indicators[:deliverystatus]
next
end
end

if (readcursor & Indicators[:'message-rfc822']).zero?
# Beginning of the original message part
if e =~ Re1[:rfc822]
if e.start_with?(StartingOf[:rfc822][0])
readcursor |= Indicators[:'message-rfc822']
next
end
Expand Down Expand Up @@ -132,7 +132,7 @@ def scan(mhead, mbody)
else
# Error message below:
# 550 - Requested action not taken: no such user here
v['diagnosis'] = e if e =~ Re1[:error]
v['diagnosis'] = e if e.start_with?(StartingOf[:error][0])
end
end
end
Expand Down
14 changes: 8 additions & 6 deletions lib/sisimai/bite/email/bigfoot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ class << self
# Imported from p5-Sisimail/lib/Sisimai/Bite/Email/Bigfoot.pm
require 'sisimai/bite/email'

Re1 = {
:begin => %r/\A[ \t]+[-]+[ \t]*Transcript of session follows/,
:rfc822 => %r|\AContent-Type: message/partial|,
}.freeze
Indicators = Sisimai::Bite::Email.INDICATORS
StartingOf = {
rfc822: ['Content-Type: message/partial'],
}.freeze
MarkingsOf = {
message: %r/\A[ \t]+[-]+[ \t]*Transcript of session follows/,
}.freeze

def description; return 'Bigfoot: http://www.bigfoot.com'; end
def smtpagent; return Sisimai::Bite.smtpagent(self); end
Expand Down Expand Up @@ -61,15 +63,15 @@ def scan(mhead, mbody)

if readcursor.zero?
# Beginning of the bounce message or delivery status part
if e =~ Re1[:begin]
if e =~ MarkingsOf[:message]
readcursor |= Indicators[:deliverystatus]
next
end
end

if (readcursor & Indicators[:'message-rfc822']).zero?
# Beginning of the original message part
if e =~ Re1[:rfc822]
if e.start_with?(StartingOf[:rfc822][0])
readcursor |= Indicators[:'message-rfc822']
next
end
Expand Down
15 changes: 8 additions & 7 deletions lib/sisimai/bite/email/biglobe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ class << self
# Imported from p5-Sisimail/lib/Sisimai/Bite/Email/Biglobe.pm
require 'sisimai/bite/email'

Re1 = {
:begin => %r/\A ----- The following addresses had delivery problems -----\z/,
:error => %r/\A ----- Non-delivered information -----\z/,
:rfc822 => %r|\AContent-Type: message/rfc822\z|,
Indicators = Sisimai::Bite::Email.INDICATORS
StartingOf = {
message: [' ----- The following addresses had delivery problems -----'],
error: [' ----- Non-delivered information -----'],
rfc822: ['Content-Type: message/rfc822'],
}.freeze

ReFailure = {
filtered: %r/Mail Delivery Failed[.]+ User unknown/,
mailboxfull: %r/The number of messages in recipient's mailbox exceeded the local limit[.]/,
}.freeze
Indicators = Sisimai::Bite::Email.INDICATORS

def description; return 'BIGLOBE: http://www.biglobe.ne.jp'; end
def smtpagent; return Sisimai::Bite.smtpagent(self); end
Expand Down Expand Up @@ -50,15 +51,15 @@ def scan(mhead, mbody)
hasdivided.each do |e|
if readcursor.zero?
# Beginning of the bounce message or delivery status part
if e =~ Re1[:begin]
if e.start_with?(StartingOf[:message][0])
readcursor |= Indicators[:deliverystatus]
next
end
end

if (readcursor & Indicators[:'message-rfc822']).zero?
# Beginning of the original message part
if e =~ Re1[:rfc822]
if e.start_with?(StartingOf[:rfc822][0])
readcursor |= Indicators[:'message-rfc822']
next
end
Expand Down
25 changes: 10 additions & 15 deletions lib/sisimai/bite/email/courier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ class << self
require 'sisimai/bite/email'

# http://www.courier-mta.org/courierdsn.html
# courier/module.dsn/dsn*.txt
Re1 = {
:begin => %r{(?:
DELAYS[ ]IN[ ]DELIVERING[ ]YOUR[ ]MESSAGE
|UNDELIVERABLE[ ]MAIL
)
}x,
:rfc822 => %r{\AContent-Type:[ ]*(?:
message/rfc822
|text/rfc822-headers
)\z
}x,
Indicators = Sisimai::Bite::Email.INDICATORS
StartingOf = {
# courier/module.dsn/dsn*.txt
message: ['DELAYS IN DELIVERING YOUR MESSAGE', 'UNDELIVERABLE MAIL'],
}.freeze
MarkingsOf = {
rfc822: %r{\AContent-Type:[ ]*(?:message/rfc822|text/rfc822-headers)\z},
}.freeze

ReFailure = {
# courier/module.esmtp/esmtpclient.c:526| hard_error(del, ctf, "No such domain.");
hostunknown: %r/\ANo[ ]such[ ]domain[.]\z/x,
Expand All @@ -31,7 +27,6 @@ class << self
# courier/module.esmtp/esmtpclient.c:535| soft_error(del, ctf, "DNS lookup failed.");
networkerror: %r/\ADNS[ ]lookup[ ]failed[.]\z/x,
}.freeze
Indicators = Sisimai::Bite::Email.INDICATORS

def description; return 'Courier MTA'; end
def smtpagent; return Sisimai::Bite.smtpagent(self); end
Expand Down Expand Up @@ -84,15 +79,15 @@ def scan(mhead, mbody)

if readcursor.zero?
# Beginning of the bounce message or delivery status part
if e =~ Re1[:begin]
if e.include?(StartingOf[:message][0]) || e.include?(StartingOf[:message][1])
readcursor |= Indicators[:deliverystatus]
next
end
end

if (readcursor & Indicators[:'message-rfc822']).zero?
# Beginning of the original message part
if e =~ Re1[:rfc822]
if e =~ MarkingsOf[:rfc822]
readcursor |= Indicators[:'message-rfc822']
next
end
Expand Down
Loading

0 comments on commit 258d4c6

Please sign in to comment.