diff options
author | Koni Marti <koni.marti@gmail.com> | 2024-06-14 23:06:58 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-08-20 11:54:34 +0200 |
commit | a64563466ddcb9fc321b8dd540f929c979310af9 (patch) | |
tree | 41d822caf8d08527f5275bdf06ffc78d03531efa | |
parent | 658ddc8abad1b64eeed2670b8534dc9855400992 (diff) | |
download | aerc-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>
-rw-r--r-- | commands/msg/copy.go | 32 | ||||
-rw-r--r-- | doc/aerc.1.scd | 6 |
2 files changed, 36 insertions, 2 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 diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd index 7d6da4b9..26713206 100644 --- a/doc/aerc.1.scd +++ b/doc/aerc.1.scd @@ -319,10 +319,12 @@ message list, the message in the message viewer, etc). *-E*: Forces *[compose].edit-headers* = _false_ for this message only. -*:copy* [*-p*] [*-a* _<account>_] [*-m* _<strategy>_] _<folder>_++ -*:cp* [*-p*] [*-a* _<account>_] [*-m* _<strategy>_] _<folder>_ +*:copy* [*-dp*] [*-a* _<account>_] [*-m* _<strategy>_] _<folder>_++ +*:cp* [*-dp*] [*-a* _<account>_] [*-m* _<strategy>_] _<folder>_ Copies the selected message(s) to _<folder>_. + *-d*: Decrypt the message before copying. + *-p*: Create _<folder>_ if it does not exist. *-a*: Copy to _<folder>_ of _<account>_. If _<folder>_ does |