Update vendor/

This commit is contained in:
2018-06-25 23:27:32 +01:00
parent 4f5e3ed906
commit d25ed6c1bd
182 changed files with 31368 additions and 6047 deletions

View File

@@ -71,6 +71,11 @@ func (bkd *Backend) Login(username, password string) (smtp.User, error) {
return &User{}, nil
}
// Require clients to authenticate using SMTP AUTH before sending emails
func (bkd *Backend) AnonymousLogin() (smtp.User, error) {
return nil, smtp.ErrAuthRequired
}
type User struct{}
func (u *User) Send(from string, to []string, r io.Reader) error {

View File

@@ -10,7 +10,7 @@ type Backend interface {
Login(username, password string) (User, error)
// Called if the client attempts to send mail without logging in first.
// Respond with smtp.AuthRequiredErr if you don't want to support this.
// Respond with smtp.ErrAuthRequired if you don't want to support this.
AnonymousLogin() (User, error)
}

View File

@@ -8,7 +8,6 @@ import (
"io/ioutil"
"net"
"net/textproto"
"regexp"
"strconv"
"strings"
"sync"
@@ -38,7 +37,7 @@ type Conn struct {
}
var (
AuthRequiredErr = fmt.Errorf("Please authenticate first.")
ErrAuthRequired = fmt.Errorf("Please authenticate first.")
)
func newConn(c net.Conn, s *Server) *Conn {
@@ -217,21 +216,27 @@ func (c *Conn) handleMail(arg string) {
c.SetUser(user)
}
// Match FROM, while accepting '>' as quoted pair and in double quoted strings
// (?i) makes the regex case insensitive, (?:) is non-grouping sub-match
re := regexp.MustCompile("(?i)^FROM:\\s*<((?:\\\\>|[^>])+|\"[^\"]+\"@[^>]+)>( [\\w= ]+)?$")
m := re.FindStringSubmatch(arg)
if m == nil {
if len(arg) < 6 || strings.ToUpper(arg[0:5]) != "FROM:" {
c.WriteResponse(501, "Was expecting MAIL arg syntax of FROM:<address>")
return
}
fromArgs := strings.Split(strings.Trim(arg[5:], " "), " ")
if c.server.Strict {
if !strings.HasPrefix(fromArgs[0], "<") || !strings.HasSuffix(fromArgs[0], ">") {
c.WriteResponse(501, "Was expecting MAIL arg syntax of FROM:<address>")
return
}
}
from := strings.Trim(fromArgs[0], "<> ")
if from == "" {
c.WriteResponse(501, "Was expecting MAIL arg syntax of FROM:<address>")
return
}
from := m[1]
// This is where the Conn may put BODY=8BITMIME, but we already
// read the DATA as bytes, so it does not effect our processing.
if m[2] != "" {
args, err := parseArgs(m[2])
if len(fromArgs) > 1 {
args, err := parseArgs(fromArgs[1:])
if err != nil {
c.WriteResponse(501, "Unable to parse MAIL ESMTP parameters")
return

View File

@@ -2,7 +2,6 @@ package smtp
import (
"fmt"
"regexp"
"strings"
)
@@ -40,18 +39,19 @@ func parseCmd(line string) (cmd string, arg string, err error) {
// string:
// " BODY=8BITMIME SIZE=1024"
// The leading space is mandatory.
func parseArgs(arg string) (args map[string]string, err error) {
args = map[string]string{}
re := regexp.MustCompile(" (\\w+)=(\\w+)")
pm := re.FindAllStringSubmatch(arg, -1)
if pm == nil {
return nil, fmt.Errorf("Failed to parse arg string: %q", arg)
func parseArgs(args []string) (map[string]string, error) {
argMap := map[string]string{}
for _, arg := range args {
if arg == "" {
continue
}
m := strings.Split(arg, "=")
if len(m) != 2 {
return nil, fmt.Errorf("Failed to parse arg string: %q", arg)
}
argMap[strings.ToUpper(m[0])] = m[1]
}
for _, m := range pm {
args[strings.ToUpper(m[1])] = m[2]
}
return args, nil
return argMap, nil
}
func parseHelloArgument(arg string) (string, error) {

View File

@@ -25,6 +25,7 @@ type Server struct {
MaxIdleSeconds int
MaxMessageBytes int
AllowInsecureAuth bool
Strict bool
Debug io.Writer
// If set, the AUTH command will not be advertised and authentication