Fix/optimize isTempError method

Not that this particular part of the code is performance critical, but I figured that the `strconv.Atoi()` is actually useless in here.

Since all we want to know is if the error code from the SMTP server is a 4xx error, we can just check the first rune of the returned error. The `Atoi` provides us with no advantage over the simple rune compare (except of taking about 3ns longer to execute)
This commit is contained in:
Winni Neessen 2023-01-01 20:35:21 +01:00
parent 43efd6b3a8
commit 15b3a0028a
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D

View file

@ -7,7 +7,6 @@ package mail
import (
"errors"
"fmt"
"strconv"
"strings"
)
@ -132,12 +131,5 @@ func (r SendErrReason) String() string {
// isTempError checks the given SMTP error and returns true if the given error is of temporary nature
// and should be retried
func isTempError(e error) bool {
ec, err := strconv.Atoi(e.Error()[:3])
if err != nil {
return false
}
if ec >= 400 && ec <= 500 {
return true
}
return false
return e.Error()[0] == '4'
}