From mboxrd@z Thu Jan 1 00:00:00 1970 From: brabuhr@gmail.com (brabuhr) Date: Sat, 26 Jan 2008 22:35:44 -0500 Subject: [sup-talk] [PATCH] expand file paths and rescue enoent exceptions when adding attachments In-Reply-To: <21aa9f0801261918j2890aee2yeb52484a95b786c3@mail.gmail.com> References: <21aa9f0801261918j2890aee2yeb52484a95b786c3@mail.gmail.com> Message-ID: <21aa9f0801261935i12a36782o85030b24078e7dd7@mail.gmail.com> On 1/26/08, Daniel Wagner wrote: > If I type in a filename that starts with ~ at the attachment prompt, sup > crashes. --- lib/sup/modes/edit-message-mode.rb | 4 ++++ lib/sup/util.rb | 3 ++- 2 files changed, 6 insertions(+), 1 deletions(-) diff --git a/lib/sup/modes/edit-message-mode.rb b/lib/sup/modes/edit-message-mode.rb index 6a7f273..9412235 100644 --- a/lib/sup/modes/edit-message-mode.rb +++ b/lib/sup/modes/edit-message-mode.rb @@ -151,6 +151,10 @@ EOS @attachments << RMail::Message.make_file_attachment(fn) @attachment_names << fn update + rescue Errno::ENOENT => e + Redwood::log "Cannot add attachment: #{e.message}" + Redwood::log e.backtrace.join("\n") + Redwood::BufferManager.flash "Could not add attachment: #{e.message}" end def delete_attachment diff --git a/lib/sup/util.rb b/lib/sup/util.rb index ceaf0b8..51339d6 100644 --- a/lib/sup/util.rb +++ b/lib/sup/util.rb @@ -57,8 +57,9 @@ module RMail class Message def self.make_file_attachment fn bfn = File.basename fn + fp = File.expand_path fn t = MIME::Types.type_for(bfn).first || MIME::Types.type_for ("exe").first - make_attachment IO.read(fn), t.content_type, t.encoding, bfn.to_s + make_attachment IO.read(fp), t.content_type, t.encoding, bfn.to_s end def charset -- 1.5.2.5 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/sup-talk/attachments/20080126/533da985/attachment.html