From f07444d80961fcd3e7bb9555f5ed4a4e0b65b5db Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Wed, 27 Feb 2013 14:17:16 +1100 Subject: Remove Tmail and use the Mail gem under Ruby 1.8.7 as well --- lib/mail_handler/mail_handler.rb | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'lib/mail_handler/mail_handler.rb') diff --git a/lib/mail_handler/mail_handler.rb b/lib/mail_handler/mail_handler.rb index 8b227b9ca..d9ebee854 100644 --- a/lib/mail_handler/mail_handler.rb +++ b/lib/mail_handler/mail_handler.rb @@ -3,17 +3,10 @@ require 'tmpdir' module MailHandler - if RUBY_VERSION.to_f >= 1.9 - require 'mail' - require 'backends/mail_extensions' - require 'backends/mail_backend' - include Backends::MailBackend - else - require 'action_mailer' - require 'backends/tmail_extensions' - require 'backends/tmail_backend' - include Backends::TmailBackend - end + require 'mail' + require 'backends/mail_extensions' + require 'backends/mail_backend' + include Backends::MailBackend # Returns a set of attachments from the given TNEF contents # The TNEF contents also contains the message body, but in general this is the -- cgit v1.2.3 From be5077d5f1af176c34aadd3dcfc6fd3ac9422a3d Mon Sep 17 00:00:00 2001 From: Mark Longair Date: Tue, 30 Apr 2013 11:42:44 +0100 Subject: Remove an unnecessary use of 'which' in backticks The use of backticks in `which tnef` means that which(1) is invoked under /bin/sh, and returns the first executable matching 'tnef' in the default PATH for /bin/sh. In this usage, however, Popen also uses /bin/sh to execute the command, which would run that same executable if just a bare 'tnef' were used. In summary, I can't see any reason for the convolution of: IO.popen("#{`which tnef`.chomp} -K -C #{dir}", "wb") do |f| ... over just: IO.popen("tnef -K -C #{dir}", "wb") do |f| ... so switch to the latter. --- lib/mail_handler/mail_handler.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/mail_handler/mail_handler.rb') diff --git a/lib/mail_handler/mail_handler.rb b/lib/mail_handler/mail_handler.rb index d9ebee854..e5c6b1087 100644 --- a/lib/mail_handler/mail_handler.rb +++ b/lib/mail_handler/mail_handler.rb @@ -14,7 +14,7 @@ module MailHandler def tnef_attachments(content) attachments = [] Dir.mktmpdir do |dir| - IO.popen("#{`which tnef`.chomp} -K -C #{dir}", "wb") do |f| + IO.popen("tnef -K -C #{dir}", "wb") do |f| f.write(content) f.close if $?.signaled? -- cgit v1.2.3 From 2805cc72a21089ea9725352b1d4d39d7d929a7a0 Mon Sep 17 00:00:00 2001 From: Mark Longair Date: Thu, 2 May 2013 15:34:08 +0100 Subject: Ignore common TNEF attachment parsing errors This also introduces a custom error class so that we don't accidentally catch other problems. Fixes #920 --- lib/mail_handler/mail_handler.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/mail_handler/mail_handler.rb') diff --git a/lib/mail_handler/mail_handler.rb b/lib/mail_handler/mail_handler.rb index e5c6b1087..4d942768b 100644 --- a/lib/mail_handler/mail_handler.rb +++ b/lib/mail_handler/mail_handler.rb @@ -8,6 +8,9 @@ module MailHandler require 'backends/mail_backend' include Backends::MailBackend + class TNEFParsingError < StandardError + end + # Returns a set of attachments from the given TNEF contents # The TNEF contents also contains the message body, but in general this is the # same as the message body in the message proper. @@ -21,7 +24,7 @@ module MailHandler raise IOError, "tnef exited with signal #{$?.termsig}" end if $?.exited? && $?.exitstatus != 0 - raise IOError, "tnef exited with status #{$?.exitstatus}" + raise TNEFParsingError, "tnef exited with status #{$?.exitstatus}" end end found = 0 @@ -34,7 +37,7 @@ module MailHandler end end if found == 0 - raise IOError, "tnef produced no attachments" + raise TNEFParsingError, "tnef produced no attachments" end end attachments -- cgit v1.2.3 From dad07c7d5c5116a95dc55fb391b36e4aa0055d53 Mon Sep 17 00:00:00 2001 From: Mark Longair Date: Wed, 22 May 2013 13:55:36 +0100 Subject: Suppress STDERR noise from the tnef binary --- lib/mail_handler/mail_handler.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/mail_handler/mail_handler.rb') diff --git a/lib/mail_handler/mail_handler.rb b/lib/mail_handler/mail_handler.rb index 4d942768b..e199ae8b6 100644 --- a/lib/mail_handler/mail_handler.rb +++ b/lib/mail_handler/mail_handler.rb @@ -17,7 +17,7 @@ module MailHandler def tnef_attachments(content) attachments = [] Dir.mktmpdir do |dir| - IO.popen("tnef -K -C #{dir}", "wb") do |f| + IO.popen("tnef -K -C #{dir} 2> /dev/null", "wb") do |f| f.write(content) f.close if $?.signaled? -- cgit v1.2.3