msgview/save: Use defaultSavePath if no path is provided
This commit is contained in:
parent
ee242a3d0f
commit
ccf5c02c38
3 changed files with 26 additions and 6 deletions
|
@ -3,6 +3,7 @@ package msgview
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"mime/quotedprintable"
|
"mime/quotedprintable"
|
||||||
"os"
|
"os"
|
||||||
|
@ -34,10 +35,13 @@ func Save(aerc *widgets.Aerc, args []string) error {
|
||||||
mkdirs = true
|
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>")
|
return errors.New("Usage: :save [-p] <path>")
|
||||||
}
|
}
|
||||||
path = args[optind]
|
|
||||||
|
|
||||||
mv := aerc.SelectedTab().(*widgets.MessageViewer)
|
mv := aerc.SelectedTab().(*widgets.MessageViewer)
|
||||||
p := mv.CurrentPart()
|
p := mv.CurrentPart()
|
||||||
|
@ -68,15 +72,21 @@ func Save(aerc *widgets.Aerc, args []string) error {
|
||||||
} else if os.IsExist(err) && pathIsDir {
|
} else if os.IsExist(err) && pathIsDir {
|
||||||
aerc.PushError("The given directory is an existing file")
|
aerc.PushError("The given directory is an existing file")
|
||||||
}
|
}
|
||||||
|
var (
|
||||||
// Use attachment name as filename if given path is a directory
|
save_file string
|
||||||
save_file := filepath.Base(path)
|
save_dir string
|
||||||
save_dir := filepath.Dir(path)
|
)
|
||||||
if pathIsDir {
|
if pathIsDir {
|
||||||
save_dir = path
|
save_dir = path
|
||||||
if filename, ok := p.Part.DispositionParams["filename"]; ok {
|
if filename, ok := p.Part.DispositionParams["filename"]; ok {
|
||||||
save_file = filename
|
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 _, err := os.Stat(save_dir); os.IsNotExist(err) {
|
||||||
if mkdirs {
|
if mkdirs {
|
||||||
|
|
|
@ -23,6 +23,13 @@ separated with "=".
|
||||||
|
|
||||||
This file is used for configuring the general appearance and behavior of aerc.
|
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
|
## UI OPTIONS
|
||||||
|
|
||||||
These options are configured in the *[ui]* section of aerc.conf.
|
These options are configured in the *[ui]* section of aerc.conf.
|
||||||
|
|
|
@ -131,6 +131,9 @@ message list, the message in the message viewer, etc).
|
||||||
*save* [-p] <path>
|
*save* [-p] <path>
|
||||||
Saves the current message part to the given 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
|
*-p*: Make any directories in the path that do not exist
|
||||||
|
|
||||||
*close*
|
*close*
|
||||||
|
|
Loading…
Reference in a new issue