aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/compose/send.go25
-rw-r--r--commands/msg/archive.go16
-rw-r--r--commands/msg/reply.go7
3 files changed, 36 insertions, 12 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()
}()
}
diff --git a/commands/msg/archive.go b/commands/msg/archive.go
index 149d7a5f..aeb65738 100644
--- a/commands/msg/archive.go
+++ b/commands/msg/archive.go
@@ -39,29 +39,35 @@ func (Archive) Execute(aerc *widgets.Aerc, args []string) error {
return errors.New("Usage: archive <flat|year|month>")
}
h := newHelper(aerc)
- acct, err := h.account()
+ msgs, err := h.messages()
if err != nil {
return err
}
- store, err := h.store()
+ err = archive(aerc, msgs, args[1])
+ return err
+}
+
+func archive(aerc *widgets.Aerc, msgs []*models.MessageInfo, archiveType string) error {
+ h := newHelper(aerc)
+ acct, err := h.account()
if err != nil {
return err
}
- msgs, err := h.messages()
+ store, err := h.store()
if err != nil {
return err
}
- archiveDir := acct.AccountConfig().Archive
var uids []uint32
for _, msg := range msgs {
uids = append(uids, msg.Uid)
}
+ archiveDir := acct.AccountConfig().Archive
marker := store.Marker()
marker.ClearVisualMark()
next := findNextNonDeleted(uids, store)
var uidMap map[string][]uint32
- switch args[1] {
+ switch archiveType {
case ARCHIVE_MONTH:
uidMap = groupBy(msgs, func(msg *models.MessageInfo) string {
dir := path.Join(archiveDir,
diff --git a/commands/msg/reply.go b/commands/msg/reply.go
index 8f536c14..52265950 100644
--- a/commands/msg/reply.go
+++ b/commands/msg/reply.go
@@ -7,6 +7,7 @@ import (
"io"
"regexp"
"strings"
+ "time"
"git.sr.ht/~sircmpwn/getopt"
@@ -210,6 +211,12 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
composer.OnClose(func(c *widgets.Composer) {
switch {
+ case c.Sent() && c.Archive() != "":
+ store.Answered([]uint32{msg.Uid}, true, nil)
+ err := archive(aerc, []*models.MessageInfo{msg}, c.Archive())
+ if err != nil {
+ aerc.PushStatus("Archive failed", 10*time.Second)
+ }
case c.Sent():
store.Answered([]uint32{msg.Uid}, true, nil)
case mv != nil && closeOnReply: