aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/incoming_message.rb24
-rw-r--r--db/migrate/108_change_safe_mail_from_to_mail_from.rb11
-rw-r--r--doc/CHANGES.md1
-rw-r--r--spec/models/incoming_message_spec.rb8
4 files changed, 27 insertions, 17 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index dfd9a4b6d..a4519a17d 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -356,15 +356,6 @@ class IncomingMessage < ActiveRecord::Base
# there isn't one or if there is only an email address. XXX can probably
# remove from_name_if_present (which is a monkey patch) by just calling
# .from_addrs[0].name here instead?
- def _calculate_safe_mail_from
- name = self.mail.from_name_if_present
- if name.nil?
- return nil
- end
- name = name.dup
- self.info_request.apply_censor_rules_to_text!(name)
- return name
- end
# Return false if for some reason this is a message that we shouldn't let them reply to
def _calculate_valid_to_reply_to
@@ -403,7 +394,10 @@ class IncomingMessage < ActiveRecord::Base
self.extract_attachments!
self.sent_at = self.mail.date || self.created_at
self.subject = self.mail.subject
- self.safe_mail_from = self._calculate_safe_mail_from
+ # XXX can probably remove from_name_if_present (which is a
+ # monkey patch) by just calling .from_addrs[0].name here
+ # instead?
+ self.mail_from = self.mail.from_name_if_present
begin
self.mail_from_domain = PublicBody.extract_domain_from_email(self.mail.from_addrs[0].spec)
rescue NoMethodError
@@ -435,10 +429,17 @@ class IncomingMessage < ActiveRecord::Base
parse_raw_email!
super
end
- def safe_mail_from
+ def mail_from
parse_raw_email!
super
end
+ def safe_mail_from
+ if !self.mail_from.nil?
+ mail_from = self.mail_from.dup
+ self.info_request.apply_censor_rules_to_text!(mail_from)
+ return mail_from
+ end
+ end
def mail_from_domain
parse_raw_email!
super
@@ -848,7 +849,6 @@ class IncomingMessage < ActiveRecord::Base
# search results
def _cache_main_body_text
text = self.get_main_body_text_internal
-
# Strip the uudecode parts from main text
# - this also effectively does a .dup as well, so text mods don't alter original
text = text.split(/^begin.+^`\n^end\n/sm).join(" ")
diff --git a/db/migrate/108_change_safe_mail_from_to_mail_from.rb b/db/migrate/108_change_safe_mail_from_to_mail_from.rb
new file mode 100644
index 000000000..57997f674
--- /dev/null
+++ b/db/migrate/108_change_safe_mail_from_to_mail_from.rb
@@ -0,0 +1,11 @@
+class ChangeSafeMailFromToMailFrom < ActiveRecord::Migration
+ def self.up
+ remove_column :incoming_messages, :safe_mail_from
+ add_column :incoming_messages, :mail_from, :text
+ end
+
+ def self.down
+ remove_column :incoming_messages, :mail_from
+ add_column :incoming_messages, :safe_mail_from, :text
+ end
+end
diff --git a/doc/CHANGES.md b/doc/CHANGES.md
index 9afdc9e7c..758e6b56e 100644
--- a/doc/CHANGES.md
+++ b/doc/CHANGES.md
@@ -5,6 +5,7 @@
* Base design refactored: CSS simplified and reduced, base design colours removed, now provided in example Alaveteli theme override
* It is now possible to rebuild the xapian index for specific terms, rather than having to drop and rebuild the entire database every time (as previously). See rake xapian:rebuild_index for more info.
* When listing authorities, show all authorities in default locale, rather than only those in the currently selected locale.
+* Ensure incoming emails are only ever parsed once (should give a performance boost)
## Upgrade notes
* **IMPORTANT! We now depend on Xapian 1.2**, which means you may need to install Xapian from backports. See [issue #159] for more info.
diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb
index 417a9b06c..ed31b7c5c 100644
--- a/spec/models/incoming_message_spec.rb
+++ b/spec/models/incoming_message_spec.rb
@@ -284,11 +284,9 @@ describe IncomingMessage, " when censoring data" do
end
it "should apply censor rules to From: addresses" do
- mock_mail = mock('Email object')
- mock_mail.stub!(:from_name_if_present).and_return("Stilton Mouse")
- @im.stub!(:mail).and_return(mock_mail)
-
- safe_mail_from = @im._calculate_safe_mail_from
+ @im.stub!(:mail_from).and_return("Stilton Mouse")
+ @im.stub!(:last_parsed).and_return(Time.now)
+ safe_mail_from = @im.safe_mail_from
safe_mail_from.should == "Jarlsberg Mouse"
end