small pixel drawing of a pufferfish clist

Generate ToBytes for email processing
j3s j3s@cyberia.club
Sun, 24 Nov 2019 10:46:56 -0600
commit

b9a1b108aff36141fef8041f87c8f092a2079b13

parent

dd6c4815dda185fa682e497ede692a7cd459e9b1

2 files changed, 34 insertions(+), 3 deletions(-)

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

@@ -426,6 +426,38 @@ ContentType string

Data io.Reader } +func sepAddrs(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, "From: %s\r\n", sepAddrs(e.From)) + fmt.Fprintf(&buf, "To: %s\r\n", sepAddrs(e.To)) + fmt.Fprintf(&buf, "Cc: %s\r\n", sepAddrs(e.Cc)) + fmt.Fprintf(&buf, "Reply-To: %s\r\n", sepAddrs(e.ReplyTo)) + if ! e.Date.IsZero() { + fmt.Fprintf(&buf, "Date: %s\r\n", e.Date) + } + if len(e.MessageID) > 0 { + fmt.Fprintf(&buf, "Messsage-ID: %s\r\n", e.MessageID) + } + if len(e.InReplyTo) > 0 { + fmt.Fprintf(&buf, "In-Reply-To: %s\r\n", strings.Join(e.InReplyTo, ",")) + } + // go over remainer of headers + fmt.Fprintf(&buf, "Subject: %s\r\n", e.Subject) + fmt.Fprintf(&buf, "\r\n%s", e.TextBody) + + return buf.Bytes() +} + // Email with fields for all the headers defined in RFC5322 with it's attachments and type Email struct { Header mail.Header
M main.gomain.go

@@ -330,11 +330,10 @@ }

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

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

} auth := smtp.PlainAuth("", gConfig.SMTPUsername, gConfig.SMTPPassword, "mail.c3f.net") - smtp.SendMail("mail.c3f.net:587", auth, e.Sender.Address, recipients, []byte(e.TextBody)) + smtp.SendMail("mail.c3f.net:587", auth, e.Sender.Address, recipients, e.ToBytes()) } // MAILING LIST LOGIC /////////////////////////////////////////////////////////