summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2019-06-25 09:23:52 +0200
committerDrew DeVault <sir@cmpwn.com>2019-06-25 10:38:55 -0400
commitccf5c02c3815efbe3b2e495cbc6eaca9f017aefd (patch)
tree87322ef29bf403981d40dde34d01c029fb101fee
parentee242a3d0ffc4d9cca884a2ad9047cdd16cd713e (diff)
downloadaerc-ccf5c02c3815efbe3b2e495cbc6eaca9f017aefd.tar.gz
msgview/save: Use defaultSavePath if no path is provided
-rw-r--r--commands/msgview/save.go22
-rw-r--r--doc/aerc-config.5.scd7
-rw-r--r--doc/aerc.1.scd3
3 files changed, 26 insertions, 6 deletions
diff --git a/commands/msgview/save.go b/commands/msgview/save.go
index eff9c66..59d94b2 100644
--- a/commands/msgview/save.go
+++ b/commands/msgview/save.go
@@ -3,6 +3,7 @@ package msgview
 import (
 	"encoding/base64"
 	"errors"
+	"fmt"
 	"io"
 	"mime/quotedprintable"
 	"os"
@@ -34,10 +35,13 @@ func Save(aerc *widgets.Aerc, args []string) error {
 			mkdirs = true
 		}
 	}
-	if len(args) <= optind {
+	if len(args) == optind+1 {
+		path = args[optind]
+	} else if defaultPath := aerc.Config().General.DefaultSavePath; defaultPath != "" {
+		path = defaultPath
+	} else {
 		return errors.New("Usage: :save [-p] <path>")
 	}
-	path = args[optind]
 
 	mv := aerc.SelectedTab().(*widgets.MessageViewer)
 	p := mv.CurrentPart()
@@ -68,15 +72,21 @@ func Save(aerc *widgets.Aerc, args []string) error {
 		} else if os.IsExist(err) && pathIsDir {
 			aerc.PushError("The given directory is an existing file")
 		}
-
-		// Use attachment name as filename if given path is a directory
-		save_file := filepath.Base(path)
-		save_dir := filepath.Dir(path)
+		var (
+			save_file string
+			save_dir  string
+		)
 		if pathIsDir {
 			save_dir = path
 			if filename, ok := p.Part.DispositionParams["filename"]; ok {
 				save_file = filename
+			} else {
+				timestamp := time.Now().Format("2006-01-02-150405")
+				save_file = fmt.Sprintf("aerc_%v", timestamp)
 			}
+		} else {
+			save_file = filepath.Base(path)
+			save_dir = filepath.Dir(path)
 		}
 		if _, err := os.Stat(save_dir); os.IsNotExist(err) {
 			if mkdirs {
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index b5e3505..8e0e056 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -23,6 +23,13 @@ separated with "=".
 
 This file is used for configuring the general appearance and behavior of aerc.
 
+## GENERAL OPTIONS
+
+These options are configured in the *[general]* section of aerc.conf.
+
+*default-save-path*
+	Used as a default path for save operations if no other path is specified.
+
 ## UI OPTIONS
 
 These options are configured in the *[ui]* section of aerc.conf.
diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd
index 4fdd91a..f97d01d 100644
--- a/doc/aerc.1.scd
+++ b/doc/aerc.1.scd
@@ -131,6 +131,9 @@ message list, the message in the message viewer, etc).
 *save* [-p] <path>
 	Saves the current message part to the given path.
 
+	If no path is given but general.default-save-path is set, the
+	file will be saved there.
+
 	*-p*: Make any directories in the path that do not exist
 
 *close*