aboutsummaryrefslogtreecommitdiffstats
path: root/commands/compose
diff options
context:
space:
mode:
authorBence Ferdinandy <bence@ferdinandy.com>2023-01-03 12:13:14 +0100
committerRobin Jarry <robin@jarry.cc>2023-01-04 22:57:25 +0100
commit36fded03e762da97edde61559c8bf60d5749d6a2 (patch)
tree6a55c921e71390f550b56a8c222d17487e433983 /commands/compose
parenta42042f494cc3a3e7a34bc13525c7a95cad3174f (diff)
downloadaerc-36fded03e762da97edde61559c8bf60d5749d6a2.tar.gz
send: add option to send&archive
Add `:send -a flat|month|year` to send, which archives the message being replied to. Extract most of archive logic into a separate function to make sure it behaves as manual archiving. Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands/compose')
-rw-r--r--commands/compose/send.go25
1 files changed, 18 insertions, 7 deletions
diff --git a/commands/compose/send.go b/commands/compose/send.go
index 9edb168e..c5f4be3b 100644
--- a/commands/compose/send.go
+++ b/commands/compose/send.go
@@ -10,6 +10,7 @@ import (
"strings"
"time"
+ "git.sr.ht/~sircmpwn/getopt"
"github.com/emersion/go-sasl"
"github.com/emersion/go-smtp"
"github.com/google/shlex"
@@ -40,8 +41,18 @@ func (Send) Complete(aerc *widgets.Aerc, args []string) []string {
}
func (Send) Execute(aerc *widgets.Aerc, args []string) error {
- if len(args) > 1 {
- return errors.New("Usage: send")
+ opts, optind, err := getopt.Getopts(args, "a:")
+ if err != nil {
+ return err
+ }
+ if optind != len(args) {
+ return errors.New("Usage: send [-a <flat|year|month>]")
+ }
+ var archive string
+ for _, opt := range opts {
+ if opt.Option == 'a' {
+ archive = opt.Value
+ }
}
tab := aerc.SelectedTab()
if tab == nil {
@@ -112,7 +123,7 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
msg+" Abort send? [Y/n] ",
func(text string) {
if text == "n" || text == "N" {
- send(aerc, composer, ctx, header, tabName)
+ send(aerc, composer, ctx, header, tabName, archive)
}
}, func(cmd string) ([]string, string) {
if cmd == "" {
@@ -125,14 +136,14 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
aerc.PushPrompt(prompt)
} else {
- send(aerc, composer, ctx, header, tabName)
+ send(aerc, composer, ctx, header, tabName, archive)
}
return nil
}
func send(aerc *widgets.Aerc, composer *widgets.Composer, ctx sendCtx,
- header *mail.Header, tabName string,
+ header *mail.Header, tabName string, archive string,
) {
// we don't want to block the UI thread while we are sending
// so we do everything in a goroutine and hide the composer from the user
@@ -203,13 +214,13 @@ func send(aerc *widgets.Aerc, composer *widgets.Composer, ctx sendCtx,
"message sent, but copying to %v failed: %v",
config.CopyTo, err.Error())
aerc.PushError(errmsg)
- composer.SetSent()
+ composer.SetSent(archive)
composer.Close()
return
}
}
aerc.PushStatus("Message sent.", 10*time.Second)
- composer.SetSent()
+ composer.SetSent(archive)
composer.Close()
}()
}