Skip to content

Commit

Permalink
use variables as regexp.MustCompile
Browse files Browse the repository at this point in the history
  • Loading branch information
linyows committed Aug 17, 2023
1 parent 8a42e9b commit 3e1447b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ const (
//codeActionCompleted int = 250
)

var (
mailFromRegex = regexp.MustCompile(mailFromPrefix + mailRegex)
mailToRegex = regexp.MustCompile(rcptToPrefix + mailRegex)
)

func (e Elapse) String() string {
if e < 0 {
return "nil"
Expand Down Expand Up @@ -133,12 +138,10 @@ func (p *Pipe) pairing(b []byte) {
p.sServerName = bytes.TrimSpace(bytes.Replace(b, []byte("EHLO"), []byte(""), 1))
}
if bytes.Contains(b, []byte(mailFromPrefix)) {
re := regexp.MustCompile(mailFromPrefix + mailRegex)
p.sMailAddr = bytes.Replace(re.Find(b), []byte(mailFromPrefix), []byte(""), 1)
p.sMailAddr = bytes.Replace(mailFromRegex.Find(b), []byte(mailFromPrefix), []byte(""), 1)
}
if bytes.Contains(b, []byte(rcptToPrefix)) {
re := regexp.MustCompile(rcptToPrefix + mailRegex)
p.rMailAddr = bytes.Replace(re.Find(b), []byte(rcptToPrefix), []byte(""), 1)
p.rMailAddr = bytes.Replace(mailToRegex.Find(b), []byte(rcptToPrefix), []byte(""), 1)
p.rServerName = bytes.Split(p.rMailAddr, []byte("@"))[1]
}
}
Expand Down

0 comments on commit 3e1447b

Please sign in to comment.