summary refs log tree commit diff stats
path: root/commands/msg
diff options
context:
space:
mode:
authorBen Burwell <ben@benburwell.com>2019-07-07 22:43:58 -0400
committerDrew DeVault <sir@cmpwn.com>2019-07-08 16:06:28 -0400
commitc610c3cd9dd47c400e52c1858e987f5f32a7a45b (patch)
tree6e521ba706d87ea4a03ce81d57ff84317506f3df /commands/msg
parent88c379dcbaaf9fd549cd271817e79fe634b1dd84 (diff)
downloadaerc-c610c3cd9dd47c400e52c1858e987f5f32a7a45b.tar.gz
Factor IMAP-specific structs out of UI models
Before, we were using several IMAP-specific concepts to represent
information being displayed in the UI. Factor these structures out of
the IMAP package to make it easier for other backends to provide the
required information.
Diffstat (limited to 'commands/msg')
-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)