From 3a6bada4e3490c91bf266acc7bcc9407c5e90d4d Mon Sep 17 00:00:00 2001 From: azumakuniyuki Date: Mon, 23 Sep 2024 20:33:42 +0900 Subject: [PATCH] Use sisimai/string.ContainsAny() instead of for { ... for {}} #6 --- sisimai/rhost/apple.go | 10 ++++------ sisimai/rhost/cox.go | 11 +++++------ sisimai/rhost/franceptt.go | 11 ++++------- sisimai/rhost/godaddy.go | 11 ++++------- sisimai/rhost/nttdocomo.go | 11 ++++------- sisimai/rhost/tencent.go | 9 +++------ sisimai/rhost/yahooinc.go | 9 +++------ 7 files changed, 27 insertions(+), 45 deletions(-) diff --git a/sisimai/rhost/apple.go b/sisimai/rhost/apple.go index a7b2267..f336259 100644 --- a/sisimai/rhost/apple.go +++ b/sisimai/rhost/apple.go @@ -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 @@ -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 } diff --git a/sisimai/rhost/cox.go b/sisimai/rhost/cox.go index 58d7699..68b60bd 100644 --- a/sisimai/rhost/cox.go +++ b/sisimai/rhost/cox.go @@ -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 @@ -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 diff --git a/sisimai/rhost/franceptt.go b/sisimai/rhost/franceptt.go index e8f0b54..f6ad77e 100644 --- a/sisimai/rhost/franceptt.go +++ b/sisimai/rhost/franceptt.go @@ -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 @@ -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 diff --git a/sisimai/rhost/godaddy.go b/sisimai/rhost/godaddy.go index b24263f..6ae7bcb 100644 --- a/sisimai/rhost/godaddy.go +++ b/sisimai/rhost/godaddy.go @@ -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 @@ -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 diff --git a/sisimai/rhost/nttdocomo.go b/sisimai/rhost/nttdocomo.go index 939a858..67092d5 100644 --- a/sisimai/rhost/nttdocomo.go +++ b/sisimai/rhost/nttdocomo.go @@ -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 @@ -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 } diff --git a/sisimai/rhost/tencent.go b/sisimai/rhost/tencent.go index a8d7b66..2d8bbab 100644 --- a/sisimai/rhost/tencent.go +++ b/sisimai/rhost/tencent.go @@ -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 @@ -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 } diff --git a/sisimai/rhost/yahooinc.go b/sisimai/rhost/yahooinc.go index e9b4fa8..f6e61a9 100644 --- a/sisimai/rhost/yahooinc.go +++ b/sisimai/rhost/yahooinc.go @@ -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 @@ -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 }