Skip to content

Commit

Permalink
Use sisimai/string.ContainsAny() instead of for { ... for {}} #6
Browse files Browse the repository at this point in the history
  • Loading branch information
azumakuniyuki committed Sep 23, 2024
1 parent d892348 commit 3a6bada
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 45 deletions.
10 changes: 4 additions & 6 deletions sisimai/rhost/apple.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package rhost
// |_| |_|
import "strings"
import "sisimai/sis"
import sisimoji "sisimai/string"

func init() {
// Detect the reason of the bounce returned by this email service
Expand Down Expand Up @@ -78,13 +79,10 @@ func init() {
issuedcode := strings.ToLower(fo.DiagnosticCode)
reasontext := ""

FINDREASON: for e := range messagesof {
for e := range messagesof {
// Each key is an error reason name
for _, f := range messagesof[e] {
// Try to match each SMTP reply code, status code, error message
if strings.Contains(issuedcode, f) == false { continue }
reasontext = e; break FINDREASON
}
if sisimoji.ContainsAny(issuedcode, messagesof[e]) == false { continue }
reasontext = e; break
}
return reasontext
}
Expand Down
11 changes: 5 additions & 6 deletions sisimai/rhost/cox.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package rhost
// |_| |_| |_|\___/|___/\__/_/ \____\___/_/\_\
import "strings"
import "sisimai/sis"
import sisimoji "sisimai/string"

func init() {
// Detect the reason of the bounce returned by this email service
Expand Down Expand Up @@ -147,13 +148,11 @@ func init() {
if reasontext == "" {
// There is no error code in the error message
issuedcode = strings.ToLower(issuedcode)
FINDREASON: for e := range messagesof {

for e := range messagesof {
// Try to find with each error message defined in "messagesof"
for _, f := range messagesof[e] {
// Check the error message includes each sub string or not
if strings.Contains(issuedcode, f) == false { continue }
reasontext = e; break FINDREASON
}
if sisimoji.ContainsAny(issuedcode, messagesof[e]) == false { continue }
reasontext = e; break
}
}
return reasontext
Expand Down
11 changes: 4 additions & 7 deletions sisimai/rhost/franceptt.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package rhost
// |_| |_| |_|\___/|___/\__/_/ |_| |_| \__,_|_| |_|\___\___|_| |_| |_|
import "strings"
import "sisimai/sis"
import sisimoji "sisimai/string"

func init() {
// Detect the reason of the bounce returned by this email service
Expand Down Expand Up @@ -162,14 +163,10 @@ func init() {

if reasontext == "" {
// There is no error label in the error message
FINDREASON: for e := range messagesof {
for e := range messagesof {
// The key name is a bounce reason name
for _, f := range messagesof[e] {
// Try to find the text listed in messagesof from the error message
if strings.Contains(issuedcode, f) == false { continue }
reasontext = e
break FINDREASON
}
if sisimoji.ContainsAny(issuedcode, messagesof[e]) == false { continue }
reasontext = e; break
}
}
return reasontext
Expand Down
11 changes: 4 additions & 7 deletions sisimai/rhost/godaddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package rhost
// |___/
import "strings"
import "sisimai/sis"
import sisimoji "sisimai/string"

func init() {
// Detect the reason of the bounce returned by this email service
Expand Down Expand Up @@ -226,14 +227,10 @@ func init() {
} else {
// There is no " IB***" error code in the error message
issuedcode = strings.ToLower(issuedcode)
FINDREASON: for e := range messagesof {
for e := range messagesof {
// The key is a bounce reason name
for _, f := range messagesof[e] {
// Try to find the text listed in messagesof from the error message
if strings.Contains(issuedcode, f) == false { continue }
reasontext = e
break FINDREASON
}
if sisimoji.ContainsAny(issuedcode, messagesof[e]) == false { continue }
reasontext = e; break
}
}
return reasontext
Expand Down
11 changes: 4 additions & 7 deletions sisimai/rhost/nttdocomo.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package rhost
// |_| |_| |_|\___/|___/\__/_/ |_| \_| |_| |_| |____/ \___/ \____\___/|_| |_|\___/
import "strings"
import "sisimai/sis"
import sisimoji "sisimai/string"

func init() {
// Detect the reason of the bounce returned by this email service
Expand Down Expand Up @@ -53,14 +54,10 @@ func init() {

} else {
// The value of "Diagnostic-Code:" field is not empty
FINDREASON: for e := range messagesof {
for e := range messagesof {
// The key name is a bounce reason name
for _, f := range messagesof[e] {
// Try to find each error message pattern from the fo.DiagnosticCode
if strings.Contains(issuedcode, f) == false { continue }
reasontext = e
break FINDREASON
}
if sisimoji.ContainsAny(issuedcode, messagesof[e]) == false { continue }
reasontext = e; break
}
}
if reasontext != "" { return reasontext }
Expand Down
9 changes: 3 additions & 6 deletions sisimai/rhost/tencent.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package rhost
// |_| |_| |_|\___/|___/\__/_/ |_|\___|_| |_|\___\___|_| |_|\__|
import "strings"
import "sisimai/sis"
import sisimoji "sisimai/string"

func init() {
// Detect the reason of the bounce returned by this email service
Expand Down Expand Up @@ -58,17 +59,13 @@ func init() {
"mailbox not found", // https://service.mail.qq.com/detail/122/169
},
}

issuedcode := strings.ToLower(fo.DiagnosticCode)
reasontext := ""

for e := range messagesof {
// The key name is a bounce reason name
for _, f := range messagesof[e] {
// Try to find the text listed in messagesof from the error message
if strings.Contains(issuedcode, f) == false { continue }
reasontext = e; break
}
if sisimoji.ContainsAny(issuedcode, messagesof[e]) == false { continue }
reasontext = e; break
}
return reasontext
}
Expand Down
9 changes: 3 additions & 6 deletions sisimai/rhost/yahooinc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package rhost
// |_| |_| |_|\___/|___/\__/_/ |_|\__,_|_| |_|\___/ \___/___|_| |_|\___|
import "strings"
import "sisimai/sis"
import sisimoji "sisimai/string"

func init() {
// Detect the reason of the bounce returned by this email service
Expand Down Expand Up @@ -94,17 +95,13 @@ func init() {
"mailbox not found",
},
}

issuedcode := strings.ToLower(fo.DiagnosticCode)
reasontext := ""

for e := range messagesof {
// The key name is a bounce reason name
for _, f := range messagesof[e] {
// Try to find the text listed in messagesof from the error message
if strings.Contains(issuedcode, f) == false { continue }
reasontext = e; break
}
if sisimoji.ContainsAny(issuedcode, messagesof[e]) == false { continue }
reasontext = e; break
}
return reasontext
}
Expand Down

0 comments on commit 3a6bada

Please sign in to comment.