diff options
author | Koni Marti <koni.marti@gmail.com> | 2024-06-14 23:06:57 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-08-20 11:54:34 +0200 |
commit | 658ddc8abad1b64eeed2670b8534dc9855400992 (patch) | |
tree | 9e49eb18733ddfadcb3a93577e6550c02e1ed5f0 /commands/msg | |
parent | 108a8ca1d2728dc7b4258fb455b78fab1f6a063d (diff) | |
download | aerc-658ddc8abad1b64eeed2670b8534dc9855400992.tar.gz |
pipe: add -d flag to decrypt message
Add -d flag to the pipe command to decrypt a message before it is piped.
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/msg')
-rw-r--r-- | commands/msg/pipe.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/commands/msg/pipe.go b/commands/msg/pipe.go index 980ba38d..6ba57089 100644 --- a/commands/msg/pipe.go +++ b/commands/msg/pipe.go @@ -1,6 +1,7 @@ package msg import ( + "bytes" "errors" "fmt" "io" @@ -12,6 +13,7 @@ import ( "git.sr.ht/~rjarry/aerc/app" "git.sr.ht/~rjarry/aerc/commands" + cryptoutil "git.sr.ht/~rjarry/aerc/lib/crypto/util" "git.sr.ht/~rjarry/aerc/lib/log" mboxer "git.sr.ht/~rjarry/aerc/worker/mbox" "git.sr.ht/~rjarry/aerc/worker/types" @@ -21,6 +23,7 @@ type Pipe struct { Background bool `opt:"-b"` Silent bool `opt:"-s"` Full bool `opt:"-m"` + Decrypt bool `opt:"-d"` Part bool `opt:"-p"` Command string `opt:"..."` } @@ -42,6 +45,10 @@ func (p Pipe) Execute(args []string) error { } func (p Pipe) Run(cb func()) error { + if p.Decrypt { + // Decrypt implies fetching the full message + p.Full = true + } if p.Full && p.Part { return errors.New("-m and -p are mutually exclusive") } @@ -157,6 +164,24 @@ func (p Pipe) Run(cb func()) error { done := make(chan bool, 1) store.FetchFull(uids, func(fm *types.FullMessage) { + if p.Decrypt { + info := store.Messages[fm.Content.Uid] + if info == nil { + goto addMessage + } + var buf bytes.Buffer + cleartext, err := cryptoutil.Cleartext( + io.TeeReader(fm.Content.Reader, &buf), + info.RFC822Headers.Copy(), + ) + if err != nil { + log.Warnf("continue encrypted: %v", err) + fm.Content.Reader = bytes.NewReader(buf.Bytes()) + } else { + fm.Content.Reader = bytes.NewReader(cleartext) + } + } + addMessage: messages = append(messages, fm) if len(messages) == len(uids) { done <- true |