diff options
author | Drew DeVault <sir@cmpwn.com> | 2020-11-19 13:06:38 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2020-11-19 13:06:38 -0500 |
commit | 8cc742f45df7544c20f43e781d2c7e4aa6a3f4f5 (patch) | |
tree | ddff4511c6096169e046444c7337a910af1ac95c /plugins/base | |
parent | 61cdb93e484c5ef7af7b3893db52dcf4b3be4791 (diff) | |
download | alps-8cc742f45df7544c20f43e781d2c7e4aa6a3f4f5.tar.gz alps-8cc742f45df7544c20f43e781d2c7e4aa6a3f4f5.zip |
Fix issues with to/from headers
Diffstat (limited to 'plugins/base')
-rw-r--r-- | plugins/base/routes.go | 15 | ||||
-rw-r--r-- | plugins/base/smtp.go | 22 |
2 files changed, 28 insertions, 9 deletions
diff --git a/plugins/base/routes.go b/plugins/base/routes.go index 7a8b845..61d92a6 100644 --- a/plugins/base/routes.go +++ b/plugins/base/routes.go @@ -691,10 +691,13 @@ func handleComposeNew(ctx *alps.Context) error { // These are common mailto URL query parameters // TODO: cc, bcc + var hdr mail.Header + hdr.GenerateMessageID() + mid, _ := hdr.MessageID() return handleCompose(ctx, &OutgoingMessage{ To: strings.Split(ctx.QueryParam("to"), ","), Subject: ctx.QueryParam("subject"), - MessageID: mail.GenerateMessageID(), + MessageID: "<" + mid + ">", InReplyTo: ctx.QueryParam("in-reply-to"), Text: text, }, &composeOptions{}) @@ -803,7 +806,10 @@ func handleReply(ctx *alps.Context) error { return echo.NewHTTPError(http.StatusBadRequest, err) } - msg.MessageID = mail.GenerateMessageID() + var hdr mail.Header + hdr.GenerateMessageID() + mid, _ := hdr.MessageID() + msg.MessageID = "<" + mid + ">" msg.InReplyTo = inReplyTo.Envelope.MessageId // TODO: populate From from known user addresses and inReplyTo.Envelope.To replyTo := inReplyTo.Envelope.ReplyTo @@ -867,7 +873,10 @@ func handleForward(ctx *alps.Context) error { return echo.NewHTTPError(http.StatusBadRequest, err) } - msg.MessageID = mail.GenerateMessageID() + var hdr mail.Header + hdr.GenerateMessageID() + mid, _ := hdr.MessageID() + msg.MessageID = "<" + mid + ">" msg.Subject = source.Envelope.Subject if !strings.HasPrefix(strings.ToLower(msg.Subject), "fwd:") && !strings.HasPrefix(strings.ToLower(msg.Subject), "fw:") { diff --git a/plugins/base/smtp.go b/plugins/base/smtp.go index f098506..1809059 100644 --- a/plugins/base/smtp.go +++ b/plugins/base/smtp.go @@ -123,11 +123,19 @@ func writeAttachment(mw *mail.Writer, att Attachment) error { } func (msg *OutgoingMessage) WriteTo(w io.Writer) error { - from := []*mail.Address{{"", msg.From}} + fromAddr, err := mail.ParseAddress(msg.From) + if err != nil { + return err + } + from := []*mail.Address{fromAddr} to := make([]*mail.Address, len(msg.To)) - for i, addr := range msg.To { - to[i] = &mail.Address{"", addr} + for i, rcpt := range msg.To { + addr, err := mail.ParseAddress(rcpt) + if err != nil { + return err + } + to[i] = addr } var h mail.Header @@ -182,13 +190,15 @@ func (msg *OutgoingMessage) WriteTo(w io.Writer) error { } func sendMessage(c *smtp.Client, msg *OutgoingMessage) error { - if err := c.Mail(msg.From, nil); err != nil { + addr, _ := mail.ParseAddress(msg.From) + if err := c.Mail(addr.Address, nil); err != nil { return fmt.Errorf("MAIL FROM failed: %v", err) } for _, to := range msg.To { - if err := c.Rcpt(to); err != nil { - return fmt.Errorf("RCPT TO failed: %v", err) + addr, _ := mail.ParseAddress(to) + if err := c.Rcpt(addr.Address); err != nil { + return fmt.Errorf("RCPT TO failed: %v (%s)", err, addr.Address) } } |