about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorinwit <inwit@sindominio.net>2021-12-13 11:28:01 +0100
committerRobin Jarry <robin@jarry.cc>2021-12-13 14:56:39 +0100
commitbc593ac7cdb20621aba685987f2a92c9bd880358 (patch)
tree26af73a75c3f5d5b44e299b8f9e29acb12ee1c95
parentbc087d9b3099ec8215bfb111c9abeb1571407a28 (diff)
downloadaerc-bc593ac7cdb20621aba685987f2a92c9bd880358.tar.gz
recall: allow recalling messages from any folder
Recall fails when called outside of the "postpone" folder (usually
"Drafts"). This makes sense for postponed messages. However, sometimes
the user would like to re-edit and re-send an old, possibly sent,
message, which would serve as a basis for the new one.

This patch allows recall to work outside the postpone folder, thus
allowing for re-edition of any message.

In the original recall function, if the recalled message is found in the
"postpone" folder, once the message has been recalled, re-edited and
sent, the original draft is deleted. With this patch, when the message
is not in the "postpone" folder, the original message is not deleted.

Signed-off-by: inwit <inwit@sindominio.net>
-rw-r--r--commands/msg/recall.go26
-rw-r--r--doc/aerc.1.scd8
2 files changed, 27 insertions, 7 deletions
diff --git a/commands/msg/recall.go b/commands/msg/recall.go
index 61c4c39..b6b850c 100644
--- a/commands/msg/recall.go
+++ b/commands/msg/recall.go
@@ -12,6 +12,7 @@ import (
 	"git.sr.ht/~rjarry/aerc/models"
 	"git.sr.ht/~rjarry/aerc/widgets"
 	"git.sr.ht/~rjarry/aerc/worker/types"
+	"git.sr.ht/~sircmpwn/getopt"
 )
 
 type Recall struct{}
@@ -29,8 +30,21 @@ func (Recall) Complete(aerc *widgets.Aerc, args []string) []string {
 }
 
 func (Recall) Execute(aerc *widgets.Aerc, args []string) error {
-	if len(args) != 1 {
-		return errors.New("Usage: recall")
+	force := false
+
+	opts, optind, err := getopt.Getopts(args, "f")
+	if err != nil {
+		return err
+	}
+	for _, opt := range opts {
+		switch opt.Option {
+		case 'f':
+			force = true
+		}
+	}
+
+	if len(args) != optind {
+		return errors.New("Usage: recall [-f]")
 	}
 
 	widget := aerc.SelectedTab().(widgets.ProvidesMessage)
@@ -38,7 +52,7 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error {
 	if acct == nil {
 		return errors.New("No account selected")
 	}
-	if acct.SelectedDirectory() != acct.AccountConfig().Postpone {
+	if acct.SelectedDirectory() != acct.AccountConfig().Postpone && !force {
 		return errors.New("Can only recall from the postpone directory: " +
 			acct.AccountConfig().Postpone)
 	}
@@ -81,6 +95,10 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error {
 			worker := composer.Worker()
 			uids := []uint32{msgInfo.Uid}
 
+			if acct.SelectedDirectory() != acct.AccountConfig().Postpone {
+				return
+			}
+
 			worker.PostAction(&types.DeleteMessages{
 				Uids: uids,
 			}, func(msg types.WorkerMessage) {
@@ -90,8 +108,6 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error {
 					composer.Close()
 				}
 			})
-
-			return
 		})
 	}
 
diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd
index dbb3cf9..aa96637 100644
--- a/doc/aerc.1.scd
+++ b/doc/aerc.1.scd
@@ -118,9 +118,13 @@ message list, the message in the message viewer, etc).
 *delete*
 	Deletes the selected message.
 
-*recall*
+*recall* [-f]
 	Opens the selected message for re-editing. Messages can only be
-	recalled from the postpone directory.
+	recalled from the postpone directory. The original message is deleted.
+
+	*-f*: Open the message for re-editing even if it is not in the postpone
+	directory. The original message will be deleted only if it is in the
+	postpone directory.
 
 *forward* [-A] [address...]
 	Opens the composer to forward the selected message to another recipient.