diff options
Diffstat (limited to 'app/mailers')
-rw-r--r-- | app/mailers/application_mailer.rb | 1 | ||||
-rw-r--r-- | app/mailers/contact_mailer.rb | 1 | ||||
-rw-r--r-- | app/mailers/info_request_batch_mailer.rb | 1 | ||||
-rw-r--r-- | app/mailers/outgoing_mailer.rb | 13 | ||||
-rw-r--r-- | app/mailers/request_mailer.rb | 98 | ||||
-rw-r--r-- | app/mailers/track_mailer.rb | 3 | ||||
-rw-r--r-- | app/mailers/user_mailer.rb | 1 |
7 files changed, 55 insertions, 63 deletions
diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index d2230bb82..cfa5603fe 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # models/application_mailer.rb: # Shared code between different mailers. # diff --git a/app/mailers/contact_mailer.rb b/app/mailers/contact_mailer.rb index 27e04ca4b..7c48bfd4b 100644 --- a/app/mailers/contact_mailer.rb +++ b/app/mailers/contact_mailer.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # models/contact_mailer.rb: # Sends contact form mails. # diff --git a/app/mailers/info_request_batch_mailer.rb b/app/mailers/info_request_batch_mailer.rb index a2becfb24..ba853db95 100644 --- a/app/mailers/info_request_batch_mailer.rb +++ b/app/mailers/info_request_batch_mailer.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # models/info_request_batch_mailer.rb: # Emails relating to user accounts. e.g. Confirming a new account # diff --git a/app/mailers/outgoing_mailer.rb b/app/mailers/outgoing_mailer.rb index 19054b4e2..78041d04b 100644 --- a/app/mailers/outgoing_mailer.rb +++ b/app/mailers/outgoing_mailer.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # models/outgoing_mailer.rb: # Emails which go to public bodies on behalf of users. # @@ -40,7 +41,7 @@ class OutgoingMailer < ApplicationMailer # TODO: also OutgoingMessage.get_salutation # TODO: these look like they should be members of IncomingMessage, but logically they # need to work even when IncomingMessage is nil - def OutgoingMailer.name_and_email_for_followup(info_request, incoming_message_followup) + def self.name_and_email_for_followup(info_request, incoming_message_followup) if incoming_message_followup.nil? || !incoming_message_followup.valid_to_reply_to? return info_request.recipient_name_and_email else @@ -50,7 +51,7 @@ class OutgoingMailer < ApplicationMailer end end # Used in the preview of followup - def OutgoingMailer.name_for_followup(info_request, incoming_message_followup) + def self.name_for_followup(info_request, incoming_message_followup) if incoming_message_followup.nil? || !incoming_message_followup.valid_to_reply_to? return info_request.public_body.name else @@ -59,7 +60,7 @@ class OutgoingMailer < ApplicationMailer end end # Used when making list of followup places to remove duplicates - def OutgoingMailer.email_for_followup(info_request, incoming_message_followup) + def self.email_for_followup(info_request, incoming_message_followup) if incoming_message_followup.nil? || !incoming_message_followup.valid_to_reply_to? return info_request.recipient_email else @@ -67,7 +68,7 @@ class OutgoingMailer < ApplicationMailer end end # Subject to use for followup - def OutgoingMailer.subject_for_followup(info_request, outgoing_message, options = {}) + def self.subject_for_followup(info_request, outgoing_message, options = {}) if outgoing_message.what_doing == 'internal_review' return "Internal review of " + info_request.email_subject_request(:html => options[:html]) else @@ -76,7 +77,7 @@ class OutgoingMailer < ApplicationMailer end end # Whether we have a valid email address for a followup - def OutgoingMailer.is_followupable?(info_request, incoming_message_followup) + def self.is_followupable?(info_request, incoming_message_followup) if incoming_message_followup.nil? || !incoming_message_followup.valid_to_reply_to? return info_request.recipient_email_valid_for_followup? else @@ -85,7 +86,7 @@ class OutgoingMailer < ApplicationMailer end end # Message-ID to use - def OutgoingMailer.id_for_message(outgoing_message) + def self.id_for_message(outgoing_message) message_id = "ogm-" + outgoing_message.id.to_s t = Time.now message_id += "+" + '%08x%05x-%04x' % [t.to_i, t.tv_usec, rand(0xffff)] diff --git a/app/mailers/request_mailer.rb b/app/mailers/request_mailer.rb index 252df861c..f12b4a0d6 100644 --- a/app/mailers/request_mailer.rb +++ b/app/mailers/request_mailer.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # models/request_mailer.rb: # Alerts relating to requests. # @@ -64,7 +65,7 @@ class RequestMailer < ApplicationMailer mail(:from => user.name_and_email, :to => contact_from_name_and_email, - :subject => _("FOI response requires admin ({{reason}}) - {{title}}", :reason => info_request.described_state, :title => info_request.title).html_safe) + :subject => _("FOI response requires admin ({{reason}}) - {{title}}", :reason => info_request.described_state, :title => info_request.title.html_safe)) end # Tell the requester that a new response has arrived @@ -80,7 +81,7 @@ class RequestMailer < ApplicationMailer mail(:from => contact_from_name_and_email, :to => info_request.user.name_and_email, - :subject => (_("New response to your FOI request - ") + info_request.title).html_safe, + :subject => _("New response to your FOI request - ") + info_request.title.html_safe, :charset => "UTF-8", # not much we can do if the user's email is broken :reply_to => contact_from_name_and_email) @@ -99,13 +100,8 @@ class RequestMailer < ApplicationMailer @url = confirm_url(:email_token => post_redirect.email_token) @info_request = info_request - headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email, # not much we can do if the user's email is broken - 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF') - - mail(:from => contact_from_name_and_email, - :to => user.name_and_email, - :subject => (_("Delayed response to your FOI request - ") + info_request.title).html_safe) + auto_generated_headers + mail_user_with_info_request_title(user, _("Delayed response to your FOI request - "), info_request) end # Tell the requester that the public body is very late in replying @@ -119,13 +115,8 @@ class RequestMailer < ApplicationMailer @url = confirm_url(:email_token => post_redirect.email_token) @info_request = info_request - headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email, # not much we can do if the user's email is broken - 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF') - - mail(:from => contact_from_name_and_email, - :to => user.name_and_email, - :subject => (_("You're long overdue a response to your FOI request - ") + info_request.title).html_safe) + auto_generated_headers + mail_user_with_info_request_title(user, _("You're long overdue a response to your FOI request - "), info_request) end # Tell the requester that they need to say if the new response @@ -141,13 +132,8 @@ class RequestMailer < ApplicationMailer @incoming_message = incoming_message @info_request = info_request - headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email, # not much we can do if the user's email is broken - 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF') - - mail(:from => contact_from_name_and_email, - :to => info_request.user.name_and_email, - :subject => _("Was the response you got to your FOI request any good?")) + auto_generated_headers + mail_user(info_request.user, _("Was the response you got to your FOI request any good?")) end # Tell the requester that someone updated their old unclassified request @@ -155,13 +141,8 @@ class RequestMailer < ApplicationMailer @url = request_url(info_request) @info_request = info_request - headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email, # not much we can do if the user's email is broken - 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF') - - mail(:from => contact_from_name_and_email, - :to => info_request.user.name_and_email, - :subject => _("Someone has updated the status of your request")) + auto_generated_headers + mail_user(info_request.user, _("Someone has updated the status of your request")) end # Tell the requester that they need to clarify their request @@ -177,13 +158,8 @@ class RequestMailer < ApplicationMailer @incoming_message = incoming_message @info_request = info_request - headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email, # not much we can do if the user's email is broken - 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF') - - mail(:from => contact_from_name_and_email, - :to => info_request.user.name_and_email, - :subject => (_("Clarify your FOI request - ") + info_request.title).html_safe) + auto_generated_headers + mail_user_with_info_request_title(info_request.user, _("Clarify your FOI request - "), info_request) end # Tell requester that somebody add an annotation to their request @@ -191,25 +167,15 @@ class RequestMailer < ApplicationMailer @comment, @info_request = comment, info_request @url = comment_url(comment) - headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email, # not much we can do if the user's email is broken - 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF') - - mail(:from => contact_from_name_and_email, - :to => info_request.user.name_and_email, - :subject => (_("Somebody added a note to your FOI request - ") + info_request.title).html_safe) + auto_generated_headers + mail_user_with_info_request_title(info_request.user, _("Somebody added a note to your FOI request - "), info_request) end def comment_on_alert_plural(info_request, count, earliest_unalerted_comment) @count, @info_request = count, info_request @url = comment_url(earliest_unalerted_comment) - headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email, # not much we can do if the user's email is broken - 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF') - - mail(:from => contact_from_name_and_email, - :to => info_request.user.name_and_email, - :subject => (_("Some notes have been added to your FOI request - ") + info_request.title).html_safe) + auto_generated_headers + mail_user_with_info_request_title(info_request.user, _("Some notes have been added to your FOI request - "), info_request) end # Class function, called by script/mailin with all incoming responses. @@ -268,7 +234,7 @@ class RequestMailer < ApplicationMailer end # Send email alerts for overdue requests - def self.alert_overdue_requests() + def self.alert_overdue_requests info_requests = InfoRequest.find(:all, :conditions => [ "described_state = 'waiting_response' @@ -372,8 +338,8 @@ class RequestMailer < ApplicationMailer # Send email alerts for requests which need clarification. Goes out 3 days # after last update of event. - def self.alert_not_clarified_request() - info_requests = InfoRequest.find(:all, :conditions => [ "awaiting_description = ? and described_state = 'waiting_clarification' and info_requests.updated_at < ?", false, Time.now() - 3.days ], :include => [ :user ], :order => "info_requests.id" ) + def self.alert_not_clarified_request + info_requests = InfoRequest.find(:all, :conditions => [ "awaiting_description = ? and described_state = 'waiting_clarification' and info_requests.updated_at < ?", false, Time.now - 3.days ], :include => [ :user ], :order => "info_requests.id" ) for info_request in info_requests alert_event_id = info_request.get_last_public_response_event_id last_response_message = info_request.get_last_public_response @@ -400,7 +366,7 @@ class RequestMailer < ApplicationMailer end # Send email alert to request submitter for new comments on the request. - def self.alert_comment_on_request() + def self.alert_comment_on_request # We only check comments made in the last month - this means if the # cron jobs broke for more than a month events would be lost, but no @@ -467,7 +433,27 @@ class RequestMailer < ApplicationMailer end end + private -end + def auto_generated_headers + headers({ + 'Return-Path' => blackhole_email, + 'Reply-To' => contact_from_name_and_email, # not much we can do if the user's email is broken + 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 + 'X-Auto-Response-Suppress' => 'OOF', + }) + end + def mail_user_with_info_request_title(user, subject, info_request) + mail_user(user, subject + info_request.title.html_safe) + end + + def mail_user(user, subject) + mail({ + :from => contact_from_name_and_email, + :to => user.name_and_email, + :subject => subject, + }) + end +end diff --git a/app/mailers/track_mailer.rb b/app/mailers/track_mailer.rb index 8e9beded6..3f5de6a1b 100644 --- a/app/mailers/track_mailer.rb +++ b/app/mailers/track_mailer.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # models/track_mailer.rb: # Emails which go to users who are tracking things. # @@ -38,7 +39,7 @@ class TrackMailer < ApplicationMailer # User.find(:all, :conditions => [ "last_daily_track_email < ?", Time.now - 1.day ]).size def self.alert_tracks done_something = false - now = Time.now() + now = Time.now one_week_ago = now - 7.days User.find_each(:conditions => [ "last_daily_track_email < ?", now - 1.day ]) do |user| diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index a351147f9..a6fed693e 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # models/user_mailer.rb: # Emails relating to user accounts. e.g. Confirming a new account # |