aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/admin_request_controller.rb4
-rw-r--r--app/models/incoming_message.rb18
-rw-r--r--app/models/outgoing_mailer.rb4
3 files changed, 17 insertions, 9 deletions
diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb
index 5c91cb7b1..6b6a8525e 100644
--- a/app/controllers/admin_request_controller.rb
+++ b/app/controllers/admin_request_controller.rb
@@ -313,12 +313,12 @@ class AdminRequestController < AdminController
@raw_email = RawEmail.find(params[:id])
# For the holding pen, try to guess where it should be ...
@holding_pen = false
- if (@raw_email.incoming_message.info_request == InfoRequest.holding_pen_request && !@raw_email.incoming_message.mail.from_addrs.nil? && @raw_email.incoming_message.mail.from_addrs.size > 0)
+ if (@raw_email.incoming_message.info_request == InfoRequest.holding_pen_request && !@raw_email.incoming_message.empty_from_field?)
@holding_pen = true
# 1. Use domain of email to try and guess which public body it
# is associated with, so we can display that.
- email = @raw_email.incoming_message.mail.from_addrs[0].spec
+ email = @raw_email.incoming_message.from_email
domain = PublicBody.extract_domain_from_email(email)
if domain.nil?
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index cfa0d59da..21c15607e 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -89,6 +89,14 @@ class IncomingMessage < ActiveRecord::Base
self.mail.from_addrs[0].address
end
+ def empty_from_field?
+ self.mail.from_addrs.nil? || self.mail.from_addrs.size == 0
+ end
+
+ def from_email
+ self.mail.from_addrs[0].spec
+ end
+
# Returns the name of the person the incoming message is from, or nil if
# 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
@@ -97,10 +105,10 @@ class IncomingMessage < ActiveRecord::Base
# Return false if for some reason this is a message that we shouldn't let them reply to
def _calculate_valid_to_reply_to
# check validity of email
- if self.mail.from_addrs.nil? || self.mail.from_addrs.size == 0
+ if empty_from_field?
return false
end
- email = self.mail.from_addrs[0].spec
+ email = self.from_email
if !MySociety::Validate.is_valid_email(email)
return false
end
@@ -140,7 +148,7 @@ class IncomingMessage < ActiveRecord::Base
# 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)
+ self.mail_from_domain = PublicBody.extract_domain_from_email(self.from_email)
rescue NoMethodError
self.mail_from_domain = ""
end
@@ -1066,10 +1074,10 @@ class IncomingMessage < ActiveRecord::Base
# Return false if for some reason this is a message that we shouldn't let them reply to
def valid_to_reply_to?
# check validity of email
- if self.mail.from_addrs.nil? || self.mail.from_addrs.size == 0
+ if empty_from_field?
return false
end
- email = self.mail.from_addrs[0].spec
+ email = self.from_email
if !MySociety::Validate.is_valid_email(email)
return false
end
diff --git a/app/models/outgoing_mailer.rb b/app/models/outgoing_mailer.rb
index a307bb778..277794c69 100644
--- a/app/models/outgoing_mailer.rb
+++ b/app/models/outgoing_mailer.rb
@@ -47,7 +47,7 @@ class OutgoingMailer < ApplicationMailer
return info_request.recipient_name_and_email
else
# calling safe_mail_from from so censor rules are run
- return TMail::Address.address_from_name_and_email(incoming_message_followup.safe_mail_from, incoming_message_followup.mail.from_addrs[0].spec).to_s
+ return TMail::Address.address_from_name_and_email(incoming_message_followup.safe_mail_from, incoming_message_followup.from_email).to_s
end
end
# Used in the preview of followup
@@ -64,7 +64,7 @@ class OutgoingMailer < ApplicationMailer
if incoming_message_followup.nil? || !incoming_message_followup.valid_to_reply_to?
return info_request.recipient_email
else
- return incoming_message_followup.mail.from_addrs[0].spec
+ return incoming_message_followup.from_email
end
end
# Subject to use for followup