aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/account.go9
-rw-r--r--commands/msg/recall.go22
-rw-r--r--config/aerc.conf4
-rw-r--r--config/hooks.go1
-rw-r--r--doc/aerc-config.5.scd13
-rw-r--r--lib/hooks/mail-deleted.go23
-rw-r--r--lib/msgstore.go10
7 files changed, 69 insertions, 13 deletions
diff --git a/app/account.go b/app/account.go
index 817b9b74..b5bed86e 100644
--- a/app/account.go
+++ b/app/account.go
@@ -256,6 +256,15 @@ func (acct *AccountView) newStore(name string) *lib.MessageStore {
if uiConf.NewMessageBell {
aerc.Beep()
}
+ }, func() {
+ err := hooks.RunHook(&hooks.MailDeleted{
+ Account: acct.Name(),
+ Folder: name,
+ })
+ if err != nil {
+ msg := fmt.Sprintf("mail-deleted hook: %s", err)
+ PushError(msg)
+ }
},
acct.updateSplitView,
acct.dirlist.UiConfig(name).ThreadContext,
diff --git a/commands/msg/recall.go b/commands/msg/recall.go
index cea02ddb..a676010a 100644
--- a/commands/msg/recall.go
+++ b/commands/msg/recall.go
@@ -61,20 +61,20 @@ func (r Recall) Execute(args []string) error {
}
composer.Tab = app.NewTab(composer, subject)
composer.OnClose(func(composer *app.Composer) {
- worker := composer.Worker()
uids := []uint32{msgInfo.Uid}
deleteMessage := func() {
- worker.PostAction(&types.DeleteMessages{
- Uids: uids,
- }, func(msg types.WorkerMessage) {
- switch msg := msg.(type) {
- case *types.Done:
- app.PushStatus("Recalled message deleted", 10*time.Second)
- case *types.Error:
- app.PushError(msg.Error.Error())
- }
- })
+ store.Delete(
+ uids,
+ func(msg types.WorkerMessage) {
+ switch msg := msg.(type) {
+ case *types.Done:
+ app.PushStatus("Recalled message deleted", 10*time.Second)
+ case *types.Error:
+ app.PushError(msg.Error.Error())
+ }
+ },
+ )
}
if composer.Sent() || composer.Postponed() {
diff --git a/config/aerc.conf b/config/aerc.conf
index 1d5ffe8b..cf9aafa2 100644
--- a/config/aerc.conf
+++ b/config/aerc.conf
@@ -581,6 +581,10 @@ message/rfc822=colorize
#mail-received=notify-send "[$AERC_ACCOUNT/$AERC_FOLDER] New mail from $AERC_FROM_NAME" "$AERC_SUBJECT"
#
+# Executed when mail is deleted from a folder
+#mail-deleted=mbsync "$AERC_ACCOUNT:$AERC_FOLDER" &
+
+#
# Executed when aerc starts
#aerc-startup=aerc :terminal calcurse && aerc :next-tab
diff --git a/config/hooks.go b/config/hooks.go
index bfdf4fe1..7a6047c1 100644
--- a/config/hooks.go
+++ b/config/hooks.go
@@ -11,6 +11,7 @@ type HooksConfig struct {
AercStartup string `ini:"aerc-startup"`
AercShutdown string `ini:"aerc-shutdown"`
MailReceived string `ini:"mail-received"`
+ MailDeleted string `ini:"mail-deleted"`
}
var Hooks HooksConfig
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index a45e2443..200c0609 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -958,6 +958,19 @@ They are configured in the *[hooks]* section of aerc.conf.
*mail-received* = _notify-send "[$AERC_ACCOUNT/$AERC_FOLDER] New mail from $AERC_FROM_NAME" "$AERC_SUBJECT"_
+*mail-deleted* = _<command>_
+ Executed when a message is deleted from a folder. Note that this hook is
+ triggered when moving a message from one folder to another.
+
+ Variables:
+
+ - *AERC_ACCOUNT*
+ - *AERC_FOLDER*
+
+ Example:
+
+ *mail-deleted* = _mbsync "$AERC_ACCOUNT:$AERC_FOLDER"_
+
*aerc-shutdown* = _<command>_
Executed when aerc shuts down. Aerc will wait for the command to finish
before exiting.
diff --git a/lib/hooks/mail-deleted.go b/lib/hooks/mail-deleted.go
new file mode 100644
index 00000000..e9f13105
--- /dev/null
+++ b/lib/hooks/mail-deleted.go
@@ -0,0 +1,23 @@
+package hooks
+
+import (
+ "fmt"
+
+ "git.sr.ht/~rjarry/aerc/config"
+)
+
+type MailDeleted struct {
+ Account string
+ Folder string
+}
+
+func (m *MailDeleted) Cmd() string {
+ return config.Hooks.MailDeleted
+}
+
+func (m *MailDeleted) Env() []string {
+ return []string{
+ fmt.Sprintf("AERC_ACCOUNT=%s", m.Account),
+ fmt.Sprintf("AERC_FOLDER=%s", m.Folder),
+ }
+}
diff --git a/lib/msgstore.go b/lib/msgstore.go
index e54c2565..9c6b750d 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -68,6 +68,7 @@ type MessageStore struct {
triggerNewEmail func(*models.MessageInfo)
triggerDirectoryChange func()
+ triggerMailDeleted func()
threadBuilderDebounce *time.Timer
threadBuilderDelay time.Duration
@@ -87,8 +88,8 @@ func NewMessageStore(worker *types.Worker,
thread bool, clientThreads bool, clientThreadsDelay time.Duration,
reverseOrder bool, reverseThreadOrder bool, sortThreadSiblings bool,
triggerNewEmail func(*models.MessageInfo),
- triggerDirectoryChange func(), onSelect func(*models.MessageInfo),
- threadContext bool,
+ triggerDirectoryChange func(), triggerMailDeleted func(),
+ onSelect func(*models.MessageInfo), threadContext bool,
) *MessageStore {
if !worker.Backend.Capabilities().Thread {
clientThreads = true
@@ -122,6 +123,7 @@ func NewMessageStore(worker *types.Worker,
triggerNewEmail: triggerNewEmail,
triggerDirectoryChange: triggerDirectoryChange,
+ triggerMailDeleted: triggerMailDeleted,
threadBuilderDelay: clientThreadsDelay,
@@ -580,6 +582,9 @@ func (store *MessageStore) Delete(uids []uint32,
if _, ok := msg.(*types.Unsupported); ok {
store.revertDeleted(uids)
}
+ if _, ok := msg.(*types.Done); ok {
+ store.triggerMailDeleted()
+ }
cb(msg)
})
}
@@ -629,6 +634,7 @@ func (store *MessageStore) Move(uids []uint32, dest string, createDest bool,
store.revertDeleted(uids)
cb(msg)
case *types.Done:
+ store.triggerMailDeleted()
cb(msg)
}
})