package emailsend import ( "context" "html" "net/url" "regexp" "strings" "time" "github.com/google/uuid" "github.com/warmbly/warmbly/internal/models" "github.com/warmbly/warmbly/internal/pkg/mailhtml" ) const forwardSeparator = "---------- Forwarded message ---------" // forwardDateLayout is Gmail's forward header date, plus the zone it is read in. const forwardDateLayout = "Mon, Jan 2, 2006 at 3:04 PM MST" // bodyTag matches the tags sanitizing keeps. Nested in the forward, a // parser would merge its attributes onto the whole email's body. var bodyTag = regexp.MustCompile(`(?i)<(/?)body\b`) // renderForwarded renders the message a forward carries in the shape Gmail // writes: a separator, the original envelope, then the original body. func renderForwarded(m *models.ForwardedMessage, loc *time.Location) (htmlBody, plain string) { type field struct{ name, value string } fields := []field{{"From", strings.Join(m.From, ", ")}} if !m.Date.IsZero() { fields = append(fields, field{"Date", m.Date.In(loc).Format(forwardDateLayout)}) } fields = append(fields, field{"Subject", m.Subject}, field{"To", strings.Join(m.To, ", ")}) if len(m.CC) > 0 { fields = append(fields, field{"Cc", strings.Join(m.CC, ", ")}) } bodyPlain := strings.TrimSpace(m.BodyPlain) if bodyPlain == "" { bodyPlain = mailhtml.ToPlainText(m.BodyHTML) } // Inlined before sanitizing, which drops