aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-05-16 14:09:57 -0400
committerDrew DeVault <sir@cmpwn.com>2019-05-16 14:09:57 -0400
commit5701b6e94968e6e84dd0c197eaf1dd8eb757da7b (patch)
treef84eacc24c2474ecf74e40defeef5cb0482fd3b0
parent08855f23ec714346bf31ef7d881924e86fb8f530 (diff)
downloadaerc-5701b6e94968e6e84dd0c197eaf1dd8eb757da7b.tar.gz
Decode email when reading it for quoting
-rw-r--r--commands/account/reply.go27
-rw-r--r--widgets/compose.go1
2 files changed, 26 insertions, 2 deletions
diff --git a/commands/account/reply.go b/commands/account/reply.go
index 84e76146..211af759 100644
--- a/commands/account/reply.go
+++ b/commands/account/reply.go
@@ -7,8 +7,11 @@ import (
"io"
"strings"
- "git.sr.ht/~sircmpwn/getopt"
+ "github.com/emersion/go-message"
+ _ "github.com/emersion/go-message/charset"
+ "github.com/emersion/go-message/mail"
"github.com/emersion/go-imap"
+ "git.sr.ht/~sircmpwn/getopt"
"git.sr.ht/~sircmpwn/aerc2/widgets"
)
@@ -106,8 +109,28 @@ func Reply(aerc *widgets.Aerc, args []string) error {
if quote {
// TODO: something more intelligent than fetching the 0th part
store.FetchBodyPart(msg.Uid, 0, func(reader io.Reader) {
+ header := message.Header{}
+ header.SetText(
+ "Content-Transfer-Encoding", msg.BodyStructure.Encoding)
+ header.SetContentType(
+ msg.BodyStructure.MIMEType, msg.BodyStructure.Params)
+ header.SetText("Content-Description", msg.BodyStructure.Description)
+ entity, err := message.New(header, reader)
+ if err != nil {
+ // TODO: Do something with the error
+ addTab()
+ return
+ }
+ mreader := mail.NewReader(entity)
+ part, err := mreader.NextPart()
+ if err != nil {
+ // TODO: Do something with the error
+ addTab()
+ return
+ }
+
pipeout, pipein := io.Pipe()
- scanner := bufio.NewScanner(reader)
+ scanner := bufio.NewScanner(part.Body)
go composer.SetContents(pipeout)
// TODO: Let user customize the date format used here
io.WriteString(pipein, fmt.Sprintf("On %s %s wrote:\n",
diff --git a/widgets/compose.go b/widgets/compose.go
index 14dfaaa2..18fe38ce 100644
--- a/widgets/compose.go
+++ b/widgets/compose.go
@@ -129,6 +129,7 @@ func (c *Composer) Defaults(defaults map[string]string) *Composer {
func (c *Composer) SetContents(reader io.Reader) *Composer {
c.email.Seek(0, os.SEEK_SET)
io.Copy(c.email, reader)
+ c.email.Sync()
c.email.Seek(0, os.SEEK_SET)
return c
}