From be5e69a7dccaa6c76408f9b7883980bd79bdba28 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 15 Nov 2012 11:00:36 +0000 Subject: First skeletal version of separate mail handling library. --- lib/mail_handler/mail_handler.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/mail_handler/mail_handler.rb (limited to 'lib/mail_handler/mail_handler.rb') diff --git a/lib/mail_handler/mail_handler.rb b/lib/mail_handler/mail_handler.rb new file mode 100644 index 000000000..5db17ae77 --- /dev/null +++ b/lib/mail_handler/mail_handler.rb @@ -0,0 +1,16 @@ +# Handles the parsing of email +module MailHandler + + if RUBY_VERSION.to_f >= 1.9 + require 'backends/mail_backend' + include Backends::MailBackend + else + require 'backends/tmail_backend' + include Backends::TmailBackend + end + + # Turn instance methods into class methods + extend self + +end + -- cgit v1.2.3 From 4bdab94e9d4f0a64647e5f8534c1fea8b4ba2809 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 15 Nov 2012 14:04:55 +0000 Subject: Move TMail extensions to mail handler. --- lib/mail_handler/mail_handler.rb | 1 + 1 file changed, 1 insertion(+) (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 5db17ae77..f0c75670a 100644 --- a/lib/mail_handler/mail_handler.rb +++ b/lib/mail_handler/mail_handler.rb @@ -5,6 +5,7 @@ module MailHandler require 'backends/mail_backend' include Backends::MailBackend else + require 'backends/tmail_extensions' require 'backends/tmail_backend' include Backends::TmailBackend end -- cgit v1.2.3 From 388c75bfbd18fcaf273d95c21dc132ad19f0cefe Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 15 Nov 2012 16:12:23 +0000 Subject: Move handling of TNEF mail attachments to mail handler --- lib/mail_handler/mail_handler.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (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 f0c75670a..0bd9a82f0 100644 --- a/lib/mail_handler/mail_handler.rb +++ b/lib/mail_handler/mail_handler.rb @@ -1,4 +1,6 @@ # Handles the parsing of email +require 'tmpdir' + module MailHandler if RUBY_VERSION.to_f >= 1.9 @@ -10,6 +12,38 @@ module MailHandler include Backends::TmailBackend 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. + def tnef_attachments(content) + attachments = [] + Dir.mktmpdir do |dir| + IO.popen("#{`which tnef`.chomp} -K -C #{dir}", "w") do |f| + f.write(content) + f.close + if $?.signaled? + raise IOError, "tnef exited with signal #{$?.termsig}" + end + if $?.exited? && $?.exitstatus != 0 + raise IOError, "tnef exited with status #{$?.exitstatus}" + end + end + found = 0 + Dir.new(dir).sort.each do |file| # sort for deterministic behaviour + if file != "." && file != ".." + file_content = File.open("#{dir}/#{file}", "r").read + attachments << { :content => file_content, + :filename => file } + found += 1 + end + end + if found == 0 + raise IOError, "tnef produced no attachments" + end + end + attachments + end + # Turn instance methods into class methods extend self -- cgit v1.2.3 From 9ef3f43fca535ffb52d2420bcfd8f18e5213b943 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 15 Nov 2012 16:21:38 +0000 Subject: Add some extra accessors to Mail::Message for now --- lib/mail_handler/mail_handler.rb | 1 + 1 file changed, 1 insertion(+) (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 0bd9a82f0..24d14b5c8 100644 --- a/lib/mail_handler/mail_handler.rb +++ b/lib/mail_handler/mail_handler.rb @@ -4,6 +4,7 @@ require 'tmpdir' module MailHandler if RUBY_VERSION.to_f >= 1.9 + require 'backends/mail_extensions' require 'backends/mail_backend' include Backends::MailBackend else -- cgit v1.2.3