aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2024-06-14 23:06:58 +0200
committerRobin Jarry <robin@jarry.cc>2024-08-20 11:54:34 +0200
commita64563466ddcb9fc321b8dd540f929c979310af9 (patch)
tree41d822caf8d08527f5275bdf06ffc78d03531efa /commands
parent658ddc8abad1b64eeed2670b8534dc9855400992 (diff)
downloadaerc-a64563466ddcb9fc321b8dd540f929c979310af9.tar.gz
copy: add -d flag to decrypt before copying
Add -d flag to the copy command to decrypt a message before copying it. Implements: https://todo.sr.ht/~rjarry/aerc/238 Signed-off-by: Koni Marti <koni.marti@gmail.com> Tested-by: Jens Grassel <jens@wegtam.com> Reviewed-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands')
-rw-r--r--commands/msg/copy.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/commands/msg/copy.go b/commands/msg/copy.go
index 9ea81055..d9c40ee2 100644
--- a/commands/msg/copy.go
+++ b/commands/msg/copy.go
@@ -8,13 +8,17 @@ import (
"git.sr.ht/~rjarry/aerc/app"
"git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/lib"
+ cryptoutil "git.sr.ht/~rjarry/aerc/lib/crypto/util"
"git.sr.ht/~rjarry/aerc/lib/log"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/types"
+ "github.com/emersion/go-message/mail"
+ "github.com/pkg/errors"
)
type Copy struct {
CreateFolders bool `opt:"-p"`
+ Decrypt bool `opt:"-d"`
Account string `opt:"-a" complete:"CompleteAccount"`
MultiFileStrategy *types.MultiFileStrategy `opt:"-m" action:"ParseMFS" complete:"CompleteMFS"`
Folder string `opt:"folder" complete:"CompleteFolder"`
@@ -75,6 +79,16 @@ func (c Copy) Execute(args []string) error {
return err
}
+ // when the decrypt flag is set, add the current account to c.Account to
+ // ensure that we do not take the store.Copy route.
+ if c.Decrypt {
+ if acct := app.SelectedAccount(); acct != nil {
+ c.Account = acct.Name()
+ } else {
+ return errors.New("no account name found")
+ }
+ }
+
if len(c.Account) == 0 {
store.Copy(uids, c.Folder, c.CreateFolders, c.MultiFileStrategy,
func(msg types.WorkerMessage) {
@@ -97,6 +111,24 @@ func (c Copy) Execute(args []string) error {
var messages []*types.FullMessage
fetchDone := make(chan bool, 1)
store.FetchFull(uids, func(fm *types.FullMessage) {
+ if fm == nil {
+ return
+ }
+
+ if c.Decrypt {
+ h := new(mail.Header)
+ msg, ok := store.Messages[fm.Content.Uid]
+ if ok {
+ h = msg.RFC822Headers
+ }
+ cleartext, err := cryptoutil.Cleartext(fm.Content.Reader, *h)
+ if err != nil {
+ log.Debugf("could not decrypt message %v", fm.Content.Uid)
+ } else {
+ fm.Content.Reader = bytes.NewReader(cleartext)
+ }
+ }
+
messages = append(messages, fm)
if len(messages) == len(uids) {
fetchDone <- true