aboutsummaryrefslogtreecommitdiffstats
path: root/commands/account/reply.go
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-05-16 12:15:34 -0400
committerDrew DeVault <sir@cmpwn.com>2019-05-16 12:15:34 -0400
commit475b697bdfd7a5821282174f14f8d904e47aff4d (patch)
tree7febf2e25cede5809f1d40c934d379315e06bd64 /commands/account/reply.go
parent2b3e123cb86f9b4c5853e31d9e76c2b0d083f90a (diff)
downloadaerc-475b697bdfd7a5821282174f14f8d904e47aff4d.tar.gz
Implement (basic form) of :reply
Diffstat (limited to 'commands/account/reply.go')
-rw-r--r--commands/account/reply.go83
1 files changed, 83 insertions, 0 deletions
diff --git a/commands/account/reply.go b/commands/account/reply.go
new file mode 100644
index 00000000..d0d65a52
--- /dev/null
+++ b/commands/account/reply.go
@@ -0,0 +1,83 @@
+package account
+
+import (
+ "errors"
+ "fmt"
+ "strings"
+
+ "github.com/emersion/go-imap"
+
+ "git.sr.ht/~sircmpwn/aerc2/widgets"
+)
+
+func init() {
+ register("reply", Reply)
+}
+
+func Reply(aerc *widgets.Aerc, args []string) error {
+ if len(args) != 1 {
+ return errors.New("Usage: reply [-aq]")
+ }
+ // TODO: Reply all (w/ getopt)
+
+ acct := aerc.SelectedAccount()
+ msg := acct.Messages().Selected()
+ acct.Logger().Println("Replying to email " + msg.Envelope.MessageId)
+
+ var (
+ to []string
+ cc []string
+ toList []*imap.Address
+ )
+ if len(msg.Envelope.ReplyTo) != 0 {
+ toList = msg.Envelope.ReplyTo
+ } else {
+ toList = msg.Envelope.From
+ }
+ for _, addr := range toList {
+ if addr.PersonalName != "" {
+ to = append(to, fmt.Sprintf("%s <%s@%s>",
+ addr.PersonalName, addr.MailboxName, addr.HostName))
+ } else {
+ to = append(to, fmt.Sprintf("<%s@%s>",
+ addr.MailboxName, addr.HostName))
+ }
+ }
+ // TODO: Only if reply all
+ for _, addr := range msg.Envelope.Cc {
+ if addr.PersonalName != "" {
+ cc = append(cc, fmt.Sprintf("%s <%s@%s>",
+ addr.PersonalName, addr.MailboxName, addr.HostName))
+ } else {
+ cc = append(cc, fmt.Sprintf("<%s@%s>",
+ addr.MailboxName, addr.HostName))
+ }
+ }
+
+ subject := "Re: " + msg.Envelope.Subject
+
+ composer := widgets.NewComposer(
+ aerc.Config(), acct.AccountConfig(), acct.Worker()).
+ Defaults(map[string]string{
+ "To": strings.Join(to, ","),
+ "Cc": strings.Join(cc, ","),
+ "Subject": subject,
+ "In-Reply-To": msg.Envelope.MessageId,
+ }).
+ FocusTerminal()
+
+ tab := aerc.NewTab(composer, subject)
+
+ composer.OnSubjectChange(func(subject string) {
+ if subject == "" {
+ tab.Name = "New email"
+ } else {
+ tab.Name = subject
+ }
+ tab.Content.Invalidate()
+ })
+
+ return nil
+}
+
+