aboutsummaryrefslogtreecommitdiffstats
path: root/commands/msg
diff options
context:
space:
mode:
Diffstat (limited to 'commands/msg')
-rw-r--r--commands/msg/forward.go26
-rw-r--r--commands/msg/recall.go10
-rw-r--r--commands/msg/reply.go20
-rw-r--r--commands/msg/unsubscribe.go12
4 files changed, 35 insertions, 33 deletions
diff --git a/commands/msg/forward.go b/commands/msg/forward.go
index b17482f9..475d6805 100644
--- a/commands/msg/forward.go
+++ b/commands/msg/forward.go
@@ -15,6 +15,7 @@ import (
"git.sr.ht/~sircmpwn/aerc/models"
"git.sr.ht/~sircmpwn/aerc/widgets"
"git.sr.ht/~sircmpwn/aerc/worker/types"
+ "github.com/emersion/go-message/mail"
"git.sr.ht/~sircmpwn/getopt"
)
@@ -49,11 +50,6 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error {
}
}
- to := ""
- if len(args) != 1 {
- to = strings.Join(args[optind:], ", ")
- }
-
widget := aerc.SelectedTab().(widgets.ProvidesMessage)
acct := widget.SelectedAccount()
if acct == nil {
@@ -69,11 +65,19 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error {
}
acct.Logger().Println("Forwarding email " + msg.Envelope.MessageId)
+ h := &mail.Header{}
subject := "Fwd: " + msg.Envelope.Subject
- defaults := map[string]string{
- "To": to,
- "Subject": subject,
+ h.SetSubject(subject)
+
+ if len(args) != 1 {
+ to := strings.Join(args[optind:], ", ")
+ tolist, err := mail.ParseAddressList(to)
+ if err != nil {
+ return fmt.Errorf("invalid to address(es): %v", err)
+ }
+ h.SetAddressList("to", tolist)
}
+
original := models.OriginalMail{
From: format.FormatAddresses(msg.Envelope.From),
Date: msg.Envelope.Date,
@@ -81,15 +85,15 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error {
}
addTab := func() (*widgets.Composer, error) {
- composer, err := widgets.NewComposer(aerc, acct, aerc.Config(), acct.AccountConfig(),
- acct.Worker(), template, defaults, original)
+ composer, err := widgets.NewComposer(aerc, acct, aerc.Config(),
+ acct.AccountConfig(), acct.Worker(), template, h, original)
if err != nil {
aerc.PushError("Error: " + err.Error())
return nil, err
}
tab := aerc.NewTab(composer, subject)
- if to == "" {
+ if !h.Has("to") {
composer.FocusRecipient()
} else {
composer.FocusTerminal()
diff --git a/commands/msg/recall.go b/commands/msg/recall.go
index 5212041e..b6c7f65d 100644
--- a/commands/msg/recall.go
+++ b/commands/msg/recall.go
@@ -53,15 +53,9 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error {
}
acct.Logger().Println("Recalling message " + msgInfo.Envelope.MessageId)
- // copy the headers to the defaults map for addition to the composition
- defaults := make(map[string]string)
- headerFields := msgInfo.RFC822Headers.Fields()
- for headerFields.Next() {
- defaults[headerFields.Key()] = headerFields.Value()
- }
-
composer, err := widgets.NewComposer(aerc, acct, aerc.Config(),
- acct.AccountConfig(), acct.Worker(), "", defaults, models.OriginalMail{})
+ acct.AccountConfig(), acct.Worker(), "", msgInfo.RFC822Headers,
+ models.OriginalMail{})
if err != nil {
return errors.Wrap(err, "Cannot open a new composer")
}
diff --git a/commands/msg/reply.go b/commands/msg/reply.go
index 0298ac20..863c7d25 100644
--- a/commands/msg/reply.go
+++ b/commands/msg/reply.go
@@ -145,22 +145,22 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
subject = msg.Envelope.Subject
}
- defaults := map[string]string{
- "To": format.FormatAddresses(to),
- "Cc": format.FormatAddresses(cc),
- "From": format.AddressForHumans(from),
- "Subject": subject,
- "In-Reply-To": msg.Envelope.MessageId,
- }
+ h := &mail.Header{}
+ h.SetAddressList("to", to)
+ h.SetAddressList("cc", cc)
+ h.SetAddressList("from", []*mail.Address{from})
+ h.SetSubject(subject)
+ h.SetMsgIDList("in-reply-to", []string{msg.Envelope.MessageId})
+ //TODO: references header
original := models.OriginalMail{
- From: format.FormatAddresses(msg.Envelope.From),
- Date: msg.Envelope.Date,
+ From: format.FormatAddresses(msg.Envelope.From),
+ Date: msg.Envelope.Date,
RFC822Headers: msg.RFC822Headers,
}
addTab := func() error {
composer, err := widgets.NewComposer(aerc, acct, aerc.Config(),
- acct.AccountConfig(), acct.Worker(), template, defaults, original)
+ acct.AccountConfig(), acct.Worker(), template, h, original)
if err != nil {
aerc.PushError("Error: " + err.Error())
return err
diff --git a/commands/msg/unsubscribe.go b/commands/msg/unsubscribe.go
index dec90d5e..205a255d 100644
--- a/commands/msg/unsubscribe.go
+++ b/commands/msg/unsubscribe.go
@@ -9,6 +9,7 @@ import (
"git.sr.ht/~sircmpwn/aerc/lib"
"git.sr.ht/~sircmpwn/aerc/models"
"git.sr.ht/~sircmpwn/aerc/widgets"
+ "github.com/emersion/go-message/mail"
)
// Unsubscribe helps people unsubscribe from mailing lists by way of the
@@ -84,10 +85,13 @@ func parseUnsubscribeMethods(header string) (methods []*url.URL) {
func unsubscribeMailto(aerc *widgets.Aerc, u *url.URL) error {
widget := aerc.SelectedTab().(widgets.ProvidesMessage)
acct := widget.SelectedAccount()
- defaults := map[string]string{
- "To": u.Opaque,
- "Subject": u.Query().Get("subject"),
+
+ h := &mail.Header{}
+ h.SetSubject(u.Query().Get("subject"))
+ if to, err := mail.ParseAddressList(u.Opaque); err == nil {
+ h.SetAddressList("to", to)
}
+
composer, err := widgets.NewComposer(
aerc,
acct,
@@ -95,7 +99,7 @@ func unsubscribeMailto(aerc *widgets.Aerc, u *url.URL) error {
acct.AccountConfig(),
acct.Worker(),
"",
- defaults,
+ h,
models.OriginalMail{},
)
if err != nil {