diff options
author | Koni Marti <koni.marti@gmail.com> | 2022-10-23 21:27:07 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-11-09 21:14:28 +0100 |
commit | 492f89d7cde937011ebb8bce245eedd0e44e9839 (patch) | |
tree | ce7da66e4eef1a5773090af14d6a9671b8b21ff7 /commands | |
parent | 0f78cb2ea97ca501b6eb0d659f883197753ee075 (diff) | |
download | aerc-492f89d7cde937011ebb8bce245eedd0e44e9839.tar.gz |
commands/eml: open and view eml files
Open and view eml data from a file. Call the eml command and use the
completion feature to select an eml file from disk. The eml data will be
opened in the message viewer.
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands')
-rw-r--r-- | commands/eml.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/commands/eml.go b/commands/eml.go new file mode 100644 index 00000000..a88a13b3 --- /dev/null +++ b/commands/eml.go @@ -0,0 +1,63 @@ +package commands + +import ( + "fmt" + "io" + "os" + "strings" + + "git.sr.ht/~rjarry/aerc/lib" + "git.sr.ht/~rjarry/aerc/widgets" +) + +type Eml struct{} + +func init() { + register(Eml{}) +} + +func (Eml) Aliases() []string { + return []string{"eml"} +} + +func (Eml) Complete(aerc *widgets.Aerc, args []string) []string { + return CompletePath(strings.Join(args, " ")) +} + +func (Eml) Execute(aerc *widgets.Aerc, args []string) error { + acct := aerc.SelectedAccount() + if acct == nil { + return fmt.Errorf("no account selected") + } + + showEml := func(r io.Reader) { + data, err := io.ReadAll(r) + if err != nil { + aerc.PushError(err.Error()) + return + } + lib.NewEmlMessageView(data, aerc.Crypto, aerc.DecryptKeys, + func(view lib.MessageView, err error) { + if err != nil { + aerc.PushError(err.Error()) + return + } + msgView := widgets.NewMessageViewer(acct, + aerc.Config(), view) + aerc.NewTab(msgView, + view.MessageInfo().Envelope.Subject) + }) + } + + path := strings.Join(args[1:], " ") + if _, err := os.Stat(path); err != nil { + return err + } + f, err := os.Open(path) + if err != nil { + return err + } + defer f.Close() + showEml(f) + return nil +} |