commit 3106f6d9f270bb3d1b115d6787be470b330f5fbc
parent d83a15e9c9adf9b2c0ac211016a04330180c469f
Author: Gaute Hope <eg@gaute.vetsj.com>
Date: Mon, 7 Oct 2013 13:08:10 +0200
Merge #156: Allow attachments to be save to directory with default filename
Squashed commit of the following:
commit 0d8c10fd85ea2942977670d372df635799fcdb39
Author: Gaute Hope
Date: Wed Oct 2 10:55:44 2013 +0200
add note to history
commit a8ac40049110992cde8872b54f4d069e154d0147
Author: Gaute Hope
Date: Wed Oct 2 10:50:10 2013 +0200
Allow attachments to be saved to directory with default filename
Diffstat:
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/History.txt b/History.txt
@@ -1,3 +1,8 @@
+== 0.14.2 /
+
+* You can now save attachments to directories without specifying the full
+ filename (default filename is used).
+
== 0.14.1 / 2013-08-31
* Various bugfixes.
diff --git a/lib/sup/modes/thread_view_mode.rb b/lib/sup/modes/thread_view_mode.rb
@@ -1,3 +1,5 @@
+require 'shellwords'
+
module Redwood
class ThreadViewMode < LineCursorMode
@@ -359,8 +361,14 @@ EOS
when Chunk::Attachment
default_dir = $config[:default_attachment_save_dir]
default_dir = ENV["HOME"] if default_dir.nil? || default_dir.empty?
- default_fn = File.expand_path File.join(default_dir, chunk.filename)
- fn = BufferManager.ask_for_filename :filename, "Save attachment to file: ", default_fn
+ default_fn = File.expand_path File.join(default_dir, Shellwords.escape(chunk.filename))
+ fn = BufferManager.ask_for_filename :filename, "Save attachment to file or directory: ", default_fn, true
+
+ # if user selects directory use file name from message
+ if fn and File.directory? fn
+ fn = File.join(fn, Shellwords.escape(chunk.filename))
+ end
+
save_to_file(fn) { |f| f.print chunk.raw_content } if fn
else
m = @message_lines[curpos]
@@ -382,7 +390,7 @@ EOS
num_errors = 0
m.chunks.each do |chunk|
next unless chunk.is_a?(Chunk::Attachment)
- fn = File.join(folder, chunk.filename)
+ fn = File.join(folder, Shellwords.escape(chunk.filename))
num_errors += 1 unless save_to_file(fn, false) { |f| f.print chunk.raw_content }
num += 1
end