diff options
author | 2019-12-03 18:41:23 +0100 | |
---|---|---|
committer | 2019-12-03 18:41:23 +0100 | |
commit | a103309935c4a2c72770343542493d1c285d94dd (patch) | |
tree | 8d030950cf75f4b10f1cc657b56a0079b027b7b5 /smtp.go | |
parent | b386d1c2bb0efacea2484b4aa2088c769e048a9c (diff) | |
download | alps-a103309935c4a2c72770343542493d1c285d94dd.tar.gz alps-a103309935c4a2c72770343542493d1c285d94dd.tar.bz2 alps-a103309935c4a2c72770343542493d1c285d94dd.zip |
Add support for replying to a message
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 { |