aboutsummaryrefslogtreecommitdiffstats
path: root/commands/msgview/save.go
diff options
context:
space:
mode:
authorRobin Opletal <me@robinopletal.com>2021-01-12 21:58:54 +0100
committerReto Brunner <reto@labrat.space>2021-01-14 07:17:23 +0100
commit3720c8623687d7a3fb978492ecd1ab2180823cf4 (patch)
tree184f78878713d9264b055467aa8701cb448ba36e /commands/msgview/save.go
parentbbe8ba5b3160d1fa28f02371ac9a9660079d3ca9 (diff)
downloadaerc-3720c8623687d7a3fb978492ecd1ab2180823cf4.tar.gz
save: if part name is a path, only use the filename
Diffstat (limited to 'commands/msgview/save.go')
-rw-r--r--commands/msgview/save.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/commands/msgview/save.go b/commands/msgview/save.go
index ef6bba8a..5d01e4d8 100644
--- a/commands/msgview/save.go
+++ b/commands/msgview/save.go
@@ -182,9 +182,17 @@ func generateFilename(part *models.BodyStructure) string {
filename = fn
} else if fn, ok := part.Params["name"]; ok {
filename = fn
- } else {
+ }
+ // Some MUAs send attachments with names like /some/stupid/idea/happy.jpeg
+ // Assuming non hostile intent it does make sense to use just the last
+ // portion of the pathname as the filename for saving it.
+ filename = filename[strings.LastIndex(filename, "/")+1:]
+ switch filename {
+ case "", ".", "..":
timestamp := time.Now().Format("2006-01-02-150405")
filename = fmt.Sprintf("aerc_%v", timestamp)
+ default:
+ // already have a valid name
}
return filename
}