aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2012-11-15 14:04:55 +0000
committerLouise Crow <louise.crow@gmail.com>2012-11-15 14:05:33 +0000
commit4bdab94e9d4f0a64647e5f8534c1fea8b4ba2809 (patch)
tree6071f4273cb98cedf1bfd54b7a415ac1717fce00
parent8834f67db8cd94a0285dd1bb4702db834e08e995 (diff)
Move TMail extensions to mail handler.
-rw-r--r--config/environment.rb1
-rw-r--r--lib/mail_handler/backends/tmail_backend.rb9
-rw-r--r--lib/mail_handler/backends/tmail_extensions.rb (renamed from lib/tmail_extensions.rb)6
-rw-r--r--lib/mail_handler/mail_handler.rb1
-rw-r--r--spec/lib/mail_handler/mail_handler_spec.rb11
-rw-r--r--spec/lib/tmail_extensions_spec.rb45
-rw-r--r--spec/models/incoming_message_spec.rb20
7 files changed, 38 insertions, 55 deletions
diff --git a/config/environment.rb b/config/environment.rb
index 728d2ffb7..bfa7ea869 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -142,7 +142,6 @@ WillPaginate::ViewHelpers.pagination_options[:renderer] = 'WillPaginateExtension
# Load monkey patches and other things from lib/
require 'ruby19.rb'
-require 'tmail_extensions.rb'
require 'activesupport_cache_extensions.rb'
require 'timezone_fixes.rb'
require 'use_spans_for_errors.rb'
diff --git a/lib/mail_handler/backends/tmail_backend.rb b/lib/mail_handler/backends/tmail_backend.rb
index 2f59b1161..fc675c1ed 100644
--- a/lib/mail_handler/backends/tmail_backend.rb
+++ b/lib/mail_handler/backends/tmail_backend.rb
@@ -1,12 +1,3 @@
-# Monkeypatch! Adding some extra members to store extra info in.
-module TMail
- class Mail
- attr_accessor :url_part_number
- attr_accessor :rfc822_attachment # when a whole email message is attached as text
- attr_accessor :within_rfc822_attachment # for parts within a message attached as text (for getting subject mainly)
- end
-end
-
module MailHandler
module Backends
module TmailBackend
diff --git a/lib/tmail_extensions.rb b/lib/mail_handler/backends/tmail_extensions.rb
index 6a533e658..bc994b9f3 100644
--- a/lib/tmail_extensions.rb
+++ b/lib/mail_handler/backends/tmail_extensions.rb
@@ -15,6 +15,12 @@ require 'tmail/interface'
# These mainly used in app/models/incoming_message.rb
module TMail
class Mail
+ # Monkeypatch! Adding some extra members to store extra info in.
+
+ attr_accessor :url_part_number
+ attr_accessor :rfc822_attachment # when a whole email message is attached as text
+ attr_accessor :within_rfc822_attachment # for parts within a message attached as text (for getting subject mainly)
+
# Monkeypatch! (check to see if this becomes a standard function in
# TMail::Mail, then use that, whatever it is called)
def Mail.get_part_file_name(part)
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
diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb
index fc29817f6..a3fba0698 100644
--- a/spec/lib/mail_handler/mail_handler_spec.rb
+++ b/spec/lib/mail_handler/mail_handler_spec.rb
@@ -9,4 +9,15 @@ describe 'when creating a mail object from raw data' do
mail.multipart?.should == true
end
+ it 'should parse multiple to addresses with unqoted display names' do
+ mail = get_fixture_mail('multiple-unquoted-display-names.email')
+ mail.to.should == ["request-66666-caa77777@whatdotheyknow.com", "foi@example.com"]
+ end
+
+ it 'should convert an iso8859 email to utf8' do
+ mail = get_fixture_mail('iso8859_2_raw_email.email')
+ mail.subject.should have_text(/gjatë/u)
+ mail.body.is_utf8?.should == true
+ end
+
end
diff --git a/spec/lib/tmail_extensions_spec.rb b/spec/lib/tmail_extensions_spec.rb
deleted file mode 100644
index bd89e6a84..000000000
--- a/spec/lib/tmail_extensions_spec.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-# coding: utf-8
-# This is a test of the set_content_type monkey patch in
-# lib/tmail_extensions.rb
-
-require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-
-describe "when using TMail" do
-
- before(:each) do
- ActionMailer::Base.deliveries.clear
- end
-
- it "should load an email with funny MIME settings" do
- # just send it to the holding pen
- InfoRequest.holding_pen_request.incoming_messages.size.should == 0
- receive_incoming_mail("humberside-police-odd-mime-type.email", 'dummy')
- InfoRequest.holding_pen_request.incoming_messages.size.should == 1
-
- # clear the notification of new message in holding pen
- deliveries = ActionMailer::Base.deliveries
- deliveries.size.should == 1
- deliveries.clear
-
- incoming_message = InfoRequest.holding_pen_request.incoming_messages[0]
-
- # This will raise an error if the bug in TMail hasn't been fixed
- incoming_message.get_body_for_html_display()
- end
-
- it 'should parse multiple to addresses with unqoted display names' do
- mail = TMail::Mail.parse(load_file_fixture('multiple-unquoted-display-names.email'))
- mail.to.should == ["request-66666-caa77777@whatdotheyknow.com", "foi@example.com"]
- end
-
- it 'should convert to utf8' do
- # NB this isn't actually a TMail extension, but is core TMail;
- # this was just a convenient place to assert the UTF8
- # conversion is working
- mail = TMail::Mail.parse(load_file_fixture('iso8859_2_raw_email.email'))
- mail.subject.should have_text(/gjatë/u)
- mail.body.is_utf8?.should == true
- end
-
-end
-
diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb
index 2ae98564c..fdbcd1e23 100644
--- a/spec/models/incoming_message_spec.rb
+++ b/spec/models/incoming_message_spec.rb
@@ -85,6 +85,26 @@ describe IncomingMessage, " when dealing with incoming mail" do
end
end
+
+ it "should load an email with funny MIME settings" do
+ ActionMailer::Base.deliveries.clear
+ # just send it to the holding pen
+ InfoRequest.holding_pen_request.incoming_messages.size.should == 0
+ receive_incoming_mail("humberside-police-odd-mime-type.email", 'dummy')
+ InfoRequest.holding_pen_request.incoming_messages.size.should == 1
+
+ # clear the notification of new message in holding pen
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ deliveries.clear
+
+ incoming_message = InfoRequest.holding_pen_request.incoming_messages[0]
+
+ # This will raise an error if the bug in TMail hasn't been fixed
+ incoming_message.get_body_for_html_display()
+ end
+
+
end
describe IncomingMessage, "when parsing HTML mail" do