aboutsummaryrefslogtreecommitdiffstats
path: root/commands/eml.go
diff options
context:
space:
mode:
Diffstat (limited to 'commands/eml.go')
-rw-r--r--commands/eml.go63
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
+}