small pixel drawing of a pufferfish clist

Strip parsemail decoding, pass emails through list verbatim

Signed-off-by: j3s <j3s@c3f.net>
j3s j3s@c3f.net
Tue, 31 Dec 2019 10:45:57 -0600
commit

b0773b4cd217af956221e7f62084998feed3604b

parent

37ba8777b3ea6056d147548e7ac18784ecb7de81

2 files changed, 18 insertions(+), 87 deletions(-)

jump to
M mail/main.gomail/main.go

@@ -31,30 +31,13 @@ if err != nil {

return } - contentType, params, err := parseContentType(msg.Header.Get("Content-Type")) - if err != nil { - return - } - - switch contentType { - case contentTypeMultipartMixed: - email.TextBody, email.HTMLBody, email.Attachments, email.EmbeddedFiles, err = parseMultipartMixed(msg.Body, params["boundary"]) - case contentTypeMultipartAlternative: - email.TextBody, email.HTMLBody, email.EmbeddedFiles, err = parseMultipartAlternative(msg.Body, params["boundary"]) - case contentTypeTextPlain: - message, _ := ioutil.ReadAll(msg.Body) - email.TextBody = strings.TrimSuffix(string(message[:]), "\n") - case contentTypeTextHtml: - message, _ := ioutil.ReadAll(msg.Body) - email.HTMLBody = strings.TrimSuffix(string(message[:]), "\n") - default: - err = fmt.Errorf("Unknown top level mime type: %s", contentType) - } - + body, _ := ioutil.ReadAll(msg.Body) + email.Body = string(body) return } func createEmailFromHeader(header mail.Header) (email Email, err error) { + // todo: strip this down enormously, replace with anon funcs for email (mail.Subject, mail.To, etc) hp := headerParser{header: &header} email.Subject = decodeMimeSentence(header.Get("Subject"))

@@ -438,64 +421,15 @@ ContentType string

Data io.Reader } -func commaSep(mails []*mail.Address) string { - var response []string - var sm string - for _, m := range mails { - sm = m.String() - response = append(response, sm) - } - return strings.Join(response, ",") -} - func (e *Email) ToBytes() []byte { var buf bytes.Buffer - fmt.Fprintf(&buf, "Sender: %s\r\n", e.Sender) - fmt.Fprintf(&buf, "From: %s\r\n", commaSep(e.From)) - if len(e.To) > 0 { - fmt.Fprintf(&buf, "To: %s\r\n", commaSep(e.To)) - } - if len(e.Cc) > 0 { - fmt.Fprintf(&buf, "Cc: %s\r\n", commaSep(e.Cc)) - } - if !e.Date.IsZero() { - fmt.Fprintf(&buf, "Date: %s\r\n", e.Date.Format(time.RFC1123Z)) - } - if len(e.MessageID) > 0 { - fmt.Fprintf(&buf, "Message-Id: <%s>\r\n", e.MessageID) - } - if len(e.InReplyTo) > 0 { - fmt.Fprintf(&buf, "In-Reply-To: <%s>\r\n", strings.Join(e.InReplyTo, "> <")) - } - if len(e.References) > 0 { - fmt.Fprintf(&buf, "References: <%s>\r\n", strings.Join(e.References, "> <")) - } - if len(e.Header.Get("List-Id")) > 0 { - fmt.Fprintf(&buf, "List-Id: %s\r\n", e.Header.Get("List-Id")) + + // print the headers in whatever darn order, who cares + for k, v := range e.Header { + fmt.Fprintf(&buf, "%s: %s\r\n", k, strings.Join(v, " ")) } - if len(e.Header.Get("List-Post")) > 0 { - fmt.Fprintf(&buf, "List-Post: %s\r\n", e.Header.Get("List-Post")) - } - if len(e.Header.Get("List-Help")) > 0 { - fmt.Fprintf(&buf, "List-Help: %s\r\n", e.Header.Get("List-Help")) - } - if len(e.Header.Get("List-Subscribe")) > 0 { - fmt.Fprintf(&buf, "List-Subscribe: %s\r\n", e.Header.Get("List-Subscribe")) - } - if len(e.Header.Get("List-Unsubscribe")) > 0 { - fmt.Fprintf(&buf, "List-Unsubscribe: %s\r\n", e.Header.Get("List-Unsubscribe")) - } - if len(e.Header.Get("List-Owner")) > 0 { - fmt.Fprintf(&buf, "List-Owner: %s\r\n", e.Header.Get("List-Owner")) - } - if len(e.Header.Get("Precedence")) > 0 { - fmt.Fprintf(&buf, "Precedence: %s\r\n", e.Header.Get("Precedence")) - } - if len(e.Header.Get("List-Archive")) > 0 { - fmt.Fprintf(&buf, "List-Archive: %s\r\n", e.Header.Get("List-Archive")) - } - fmt.Fprintf(&buf, "Subject: %s\r\n", e.Subject) - fmt.Fprintf(&buf, "\r\n%s", e.TextBody) + + fmt.Fprintf(&buf, "\r\n%s", e.Body) return buf.Bytes() }

@@ -524,8 +458,7 @@ ResentCc []*mail.Address

ResentBcc []*mail.Address ResentMessageID string - HTMLBody string - TextBody string + Body string Attachments []Attachment EmbeddedFiles []EmbeddedFile
M main.gomain.go

@@ -213,12 +213,10 @@ list.Id, list.Description)

} } - log.Printf("SEND") fmt.Fprintf(&body, "\r\nTo subscribe to a mailing list, email %s with 'subscribe <list-id>' as the subject.\r\n", gConfig.CommandAddress) - log.Printf("SEND") email := buildCommandEmail(msg, body) send(email) log.Printf("LIST_SENT To=%q", msg.From)

@@ -298,19 +296,19 @@ }

func buildCommandEmail(e *parsemail.Email, t bytes.Buffer) *parsemail.Email { response := parsemail.Email{} - response.Sender = &mail.Address{"", gConfig.CommandAddress} - from := &mail.Address{"clist", gConfig.CommandAddress} - response.From = []*mail.Address{from} - response.To = e.From response.Bcc = e.From - response.Subject = "Re: " + e.Subject + header := make(map[string][]string) + header["Sender"] = []string{gConfig.CommandAddress} + header["From"] = []string{gConfig.CommandAddress} + header["To"] = []string{e.Header.Get("From")} + header["Subject"] = []string{"Re: " + e.Subject} header["Date"] = []string{time.Now().Format("Mon, 2 Jan 2006 15:04:05 -0700")} header["Precedence"] = []string{"list"} header["List-Help"] = []string{"<mailto:" + gConfig.CommandAddress + "?subject=help>"} response.Header = header response.Bcc = e.From - response.TextBody = t.String() + response.Body = t.String() log.Printf("%q", response) return &response }

@@ -334,8 +332,8 @@ }

} post := e - post.Sender = &mail.Address{l.Name, l.Address} post.Bcc = recipients + post.Header["Sender"] = []string{l.Address} post.Header["Return-Path"] = []string{"bounce-" + l.Address} post.Header["Precedence"] = []string{"list"} post.Header["List-Id"] = []string{"<" + strings.Replace(l.Address, "@", ".", -1) + ">"}

@@ -356,7 +354,7 @@ recipients = append(recipients, a.Address)

} auth := smtp.PlainAuth("", gConfig.SMTPUsername, gConfig.SMTPPassword, "mail.c3f.net") - err := smtp.SendMail("mail.c3f.net:587", auth, e.Sender.Address, recipients, e.ToBytes()) + err := smtp.SendMail("mail.c3f.net:587", auth, e.Header.Get("Sender"), recipients, e.ToBytes()) if err != nil { log.Printf("ERROR_SENDING_MAIL: Error=%q\n", err.Error()) }