1package mox
2
3import (
4 "strconv"
5 "strings"
6
7 "github.com/mjl-/mox/smtp"
8)
9
10func LocalserveNeedsError(lp smtp.Localpart) (code int, timeout bool) {
11 s := string(lp)
12 if strings.HasSuffix(s, "temperror") {
13 return smtp.C451LocalErr, false
14 } else if strings.HasSuffix(s, "permerror") {
15 return smtp.C550MailboxUnavail, false
16 } else if strings.HasSuffix(s, "timeout") {
17 return 0, true
18 }
19 if len(s) < 3 {
20 return 0, false
21 }
22 s = s[len(s)-3:]
23 v, err := strconv.ParseInt(s, 10, 32)
24 if err != nil {
25 return 0, false
26 }
27 if v < 400 || v > 600 {
28 return 0, false
29 }
30 return int(v), false
31}
32