diff options
Diffstat (limited to 'smtp.go')
-rw-r--r-- | smtp.go | 32 |
1 files changed, 28 insertions, 4 deletions
@@ -1,14 +1,30 @@ package koushin import ( + "bufio" "fmt" - "io" "time" + "io" + "strings" "github.com/emersion/go-message/mail" "github.com/emersion/go-smtp" ) +func quote(r io.Reader) (string, error) { + scanner := bufio.NewScanner(r) + var builder strings.Builder + for scanner.Scan() { + builder.WriteString("> ") + builder.Write(scanner.Bytes()) + builder.WriteString("\n") + } + if err := scanner.Err(); err != nil { + return "", fmt.Errorf("quote: failed to read original message: %s", err) + } + return builder.String(), nil +} + func (s *Server) connectSMTP() (*smtp.Client, error) { var c *smtp.Client var err error @@ -34,10 +50,15 @@ func (s *Server) connectSMTP() (*smtp.Client, error) { } type OutgoingMessage struct { - From string - To []string + From string + To []string Subject string - Text string + InReplyTo string + Text string +} + +func (msg *OutgoingMessage) ToString() string { + return strings.Join(msg.To, ", ") } func (msg *OutgoingMessage) WriteTo(w io.Writer) error { @@ -55,6 +76,9 @@ func (msg *OutgoingMessage) WriteTo(w io.Writer) error { if msg.Subject != "" { h.SetText("Subject", msg.Subject) } + if msg.InReplyTo != "" { + h.Set("In-Reply-To", msg.InReplyTo) + } mw, err := mail.CreateWriter(w, h) if err != nil { |