aboutsummaryrefslogtreecommitdiff
path: root/commands/msg/reply.go
diff options
context:
space:
mode:
authorBen Burwell <ben@benburwell.com>2019-07-04 22:34:52 -0400
committerBen Burwell <ben@benburwell.com>2019-07-04 22:37:29 -0400
commitb46b497f99d7f4dcba8936ce0ebfe8cf982cec1f (patch)
treeb9212d4b196706d3c0e2d93b8dfd8cc39cbacf3b /commands/msg/reply.go
parent6574dedd8a4afdaedd3677283955a866214bd99a (diff)
Factor UI models out of the worker message packagemdps1
Before, the information needed to display different parts of the UI was tightly coupled to the specific messages being sent back and forth to the backend worker. Separating out a models package allows us to be more specific about exactly what a backend is able to and required to provide for the UI.
Diffstat (limited to 'commands/msg/reply.go')
-rw-r--r--commands/msg/reply.go28
1 files changed, 13 insertions, 15 deletions
diff --git a/commands/msg/reply.go b/commands/msg/reply.go
index 7a64d21..68c2089 100644
--- a/commands/msg/reply.go
+++ b/commands/msg/reply.go
@@ -9,12 +9,11 @@ import (
"strings"
"git.sr.ht/~sircmpwn/getopt"
- "github.com/emersion/go-imap"
"github.com/emersion/go-message"
_ "github.com/emersion/go-message/charset"
"github.com/emersion/go-message/mail"
- "git.sr.ht/~sircmpwn/aerc/lib"
+ "git.sr.ht/~sircmpwn/aerc/models"
"git.sr.ht/~sircmpwn/aerc/widgets"
)
@@ -67,7 +66,7 @@ func (_ reply) Execute(aerc *widgets.Aerc, args []string) error {
var (
to []string
cc []string
- toList []*imap.Address
+ toList []*models.Address
)
if args[0] == "reply" {
if len(msg.Envelope.ReplyTo) != 0 {
@@ -76,24 +75,23 @@ func (_ reply) Execute(aerc *widgets.Aerc, args []string) error {
toList = msg.Envelope.From
}
for _, addr := range toList {
- if addr.PersonalName != "" {
+ if addr.Name != "" {
to = append(to, fmt.Sprintf("%s <%s@%s>",
- addr.PersonalName, addr.MailboxName, addr.HostName))
+ addr.Name, addr.Mailbox, addr.Host))
} else {
- to = append(to, fmt.Sprintf("<%s@%s>",
- addr.MailboxName, addr.HostName))
+ to = append(to, fmt.Sprintf("<%s@%s>", addr.Mailbox, addr.Host))
}
}
if replyAll {
for _, addr := range msg.Envelope.Cc {
- cc = append(cc, lib.FormatAddress(addr))
+ cc = append(cc, addr.Format())
}
for _, addr := range msg.Envelope.To {
- address := fmt.Sprintf("%s@%s", addr.MailboxName, addr.HostName)
+ address := fmt.Sprintf("%s@%s", addr.Mailbox, addr.Host)
if address == us.Address {
continue
}
- to = append(to, lib.FormatAddress(addr))
+ to = append(to, addr.Format())
}
}
}
@@ -163,7 +161,7 @@ func (_ reply) Execute(aerc *widgets.Aerc, args []string) error {
go composer.SetContents(pipeout)
// TODO: Let user customize the date format used here
io.WriteString(pipein, fmt.Sprintf("Forwarded message from %s on %s:\n\n",
- msg.Envelope.From[0].PersonalName,
+ msg.Envelope.From[0].Name,
msg.Envelope.Date.Format("Mon Jan 2, 2006 at 3:04 PM")))
for scanner.Scan() {
io.WriteString(pipein, fmt.Sprintf("%s\n", scanner.Text()))
@@ -176,7 +174,7 @@ func (_ reply) Execute(aerc *widgets.Aerc, args []string) error {
if quote {
var (
path []int
- part *imap.BodyStructure
+ part *models.BodyStructure
)
if len(msg.BodyStructure.Parts) != 0 {
part, path = findPlaintext(msg.BodyStructure, path)
@@ -212,7 +210,7 @@ func (_ reply) Execute(aerc *widgets.Aerc, args []string) error {
// TODO: Let user customize the date format used here
io.WriteString(pipein, fmt.Sprintf("On %s %s wrote:\n",
msg.Envelope.Date.Format("Mon Jan 2, 2006 at 3:04 PM"),
- msg.Envelope.From[0].PersonalName))
+ msg.Envelope.From[0].Name))
for scanner.Scan() {
io.WriteString(pipein, fmt.Sprintf("> %s\n", scanner.Text()))
}
@@ -228,8 +226,8 @@ func (_ reply) Execute(aerc *widgets.Aerc, args []string) error {
return nil
}
-func findPlaintext(bs *imap.BodyStructure,
- path []int) (*imap.BodyStructure, []int) {
+func findPlaintext(bs *models.BodyStructure,
+ path []int) (*models.BodyStructure, []int) {
for i, part := range bs.Parts {
cur := append(path, i+1)