@@ -31,7 +31,7 class Mailer < ActionMailer::Base | |||||
31 | h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank? |
|
31 | h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank? | |
32 | { :host => h, :protocol => Setting.protocol } |
|
32 | { :host => h, :protocol => Setting.protocol } | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | # Builds a tmail object used to email recipients of the added issue. |
|
35 | # Builds a tmail object used to email recipients of the added issue. | |
36 | # |
|
36 | # | |
37 | # Example: |
|
37 | # Example: | |
@@ -133,7 +133,7 class Mailer < ActionMailer::Base | |||||
133 | :added_to_url => added_to_url |
|
133 | :added_to_url => added_to_url | |
134 | render_multipart('attachments_added', body) |
|
134 | render_multipart('attachments_added', body) | |
135 | end |
|
135 | end | |
136 |
|
136 | |||
137 | # Builds a tmail object used to email recipients of a news' project when a news item is added. |
|
137 | # Builds a tmail object used to email recipients of a news' project when a news item is added. | |
138 | # |
|
138 | # | |
139 | # Example: |
|
139 | # Example: | |
@@ -148,7 +148,7 class Mailer < ActionMailer::Base | |||||
148 | :news_url => url_for(:controller => 'news', :action => 'show', :id => news) |
|
148 | :news_url => url_for(:controller => 'news', :action => 'show', :id => news) | |
149 | render_multipart('news_added', body) |
|
149 | render_multipart('news_added', body) | |
150 | end |
|
150 | end | |
151 |
|
151 | |||
152 | # Builds a tmail object used to email recipients of a news' project when a news comment is added. |
|
152 | # Builds a tmail object used to email recipients of a news' project when a news comment is added. | |
153 | # |
|
153 | # | |
154 | # Example: |
|
154 | # Example: | |
@@ -167,7 +167,7 class Mailer < ActionMailer::Base | |||||
167 | render_multipart('news_comment_added', body) |
|
167 | render_multipart('news_comment_added', body) | |
168 | end |
|
168 | end | |
169 |
|
169 | |||
170 |
# Builds a tmail object used to email the recipients of the specified message that was posted. |
|
170 | # Builds a tmail object used to email the recipients of the specified message that was posted. | |
171 | # |
|
171 | # | |
172 | # Example: |
|
172 | # Example: | |
173 | # message_posted(message) => tmail object |
|
173 | # message_posted(message) => tmail object | |
@@ -184,8 +184,8 class Mailer < ActionMailer::Base | |||||
184 | :message_url => url_for(message.event_url) |
|
184 | :message_url => url_for(message.event_url) | |
185 | render_multipart('message_posted', body) |
|
185 | render_multipart('message_posted', body) | |
186 | end |
|
186 | end | |
187 |
|
187 | |||
188 |
# Builds a tmail object used to email the recipients of a project of the specified wiki content was added. |
|
188 | # Builds a tmail object used to email the recipients of a project of the specified wiki content was added. | |
189 | # |
|
189 | # | |
190 | # Example: |
|
190 | # Example: | |
191 | # wiki_content_added(wiki_content) => tmail object |
|
191 | # wiki_content_added(wiki_content) => tmail object | |
@@ -201,8 +201,8 class Mailer < ActionMailer::Base | |||||
201 | :wiki_content_url => url_for(:controller => 'wiki', :action => 'show', :project_id => wiki_content.project, :id => wiki_content.page.title) |
|
201 | :wiki_content_url => url_for(:controller => 'wiki', :action => 'show', :project_id => wiki_content.project, :id => wiki_content.page.title) | |
202 | render_multipart('wiki_content_added', body) |
|
202 | render_multipart('wiki_content_added', body) | |
203 | end |
|
203 | end | |
204 |
|
204 | |||
205 |
# Builds a tmail object used to email the recipients of a project of the specified wiki content was updated. |
|
205 | # Builds a tmail object used to email the recipients of a project of the specified wiki content was updated. | |
206 | # |
|
206 | # | |
207 | # Example: |
|
207 | # Example: | |
208 | # wiki_content_updated(wiki_content) => tmail object |
|
208 | # wiki_content_updated(wiki_content) => tmail object | |
@@ -296,7 +296,7 class Mailer < ActionMailer::Base | |||||
296 | return false if (recipients.nil? || recipients.empty?) && |
|
296 | return false if (recipients.nil? || recipients.empty?) && | |
297 | (cc.nil? || cc.empty?) && |
|
297 | (cc.nil? || cc.empty?) && | |
298 | (bcc.nil? || bcc.empty?) |
|
298 | (bcc.nil? || bcc.empty?) | |
299 |
|
299 | |||
300 | # Set Message-Id and References |
|
300 | # Set Message-Id and References | |
301 | if @message_id_object |
|
301 | if @message_id_object | |
302 | mail.message_id = self.class.message_id_for(@message_id_object) |
|
302 | mail.message_id = self.class.message_id_for(@message_id_object) | |
@@ -304,7 +304,7 class Mailer < ActionMailer::Base | |||||
304 | if @references_objects |
|
304 | if @references_objects | |
305 | mail.references = @references_objects.collect {|o| self.class.message_id_for(o)} |
|
305 | mail.references = @references_objects.collect {|o| self.class.message_id_for(o)} | |
306 | end |
|
306 | end | |
307 |
|
307 | |||
308 | # Log errors when raise_delivery_errors is set to false, Rails does not |
|
308 | # Log errors when raise_delivery_errors is set to false, Rails does not | |
309 | raise_errors = self.class.raise_delivery_errors |
|
309 | raise_errors = self.class.raise_delivery_errors | |
310 | self.class.raise_delivery_errors = true |
|
310 | self.class.raise_delivery_errors = true | |
@@ -347,7 +347,7 class Mailer < ActionMailer::Base | |||||
347 | deliver_reminder(assignee, issues, days) if assignee && assignee.active? |
|
347 | deliver_reminder(assignee, issues, days) if assignee && assignee.active? | |
348 | end |
|
348 | end | |
349 | end |
|
349 | end | |
350 |
|
350 | |||
351 | # Activates/desactivates email deliveries during +block+ |
|
351 | # Activates/desactivates email deliveries during +block+ | |
352 | def self.with_deliveries(enabled = true, &block) |
|
352 | def self.with_deliveries(enabled = true, &block) | |
353 | was_enabled = ActionMailer::Base.perform_deliveries |
|
353 | was_enabled = ActionMailer::Base.perform_deliveries | |
@@ -363,7 +363,7 class Mailer < ActionMailer::Base | |||||
363 | @initial_language = current_language |
|
363 | @initial_language = current_language | |
364 | set_language_if_valid Setting.default_language |
|
364 | set_language_if_valid Setting.default_language | |
365 | from Setting.mail_from |
|
365 | from Setting.mail_from | |
366 |
|
366 | |||
367 | # Common headers |
|
367 | # Common headers | |
368 | headers 'X-Mailer' => 'Redmine', |
|
368 | headers 'X-Mailer' => 'Redmine', | |
369 | 'X-Redmine-Host' => Setting.host_name, |
|
369 | 'X-Redmine-Host' => Setting.host_name, | |
@@ -386,11 +386,11 class Mailer < ActionMailer::Base | |||||
386 | recipients.delete(@author.mail) if recipients |
|
386 | recipients.delete(@author.mail) if recipients | |
387 | cc.delete(@author.mail) if cc |
|
387 | cc.delete(@author.mail) if cc | |
388 | end |
|
388 | end | |
389 |
|
389 | |||
390 | notified_users = [recipients, cc].flatten.compact.uniq |
|
390 | notified_users = [recipients, cc].flatten.compact.uniq | |
391 | # Rails would log recipients only, not cc and bcc |
|
391 | # Rails would log recipients only, not cc and bcc | |
392 | mylogger.info "Sending email notification to: #{notified_users.join(', ')}" if mylogger |
|
392 | mylogger.info "Sending email notification to: #{notified_users.join(', ')}" if mylogger | |
393 |
|
393 | |||
394 | # Blind carbon copy recipients |
|
394 | # Blind carbon copy recipients | |
395 | if Setting.bcc_recipients? |
|
395 | if Setting.bcc_recipients? | |
396 | bcc(notified_users) |
|
396 | bcc(notified_users) | |
@@ -406,7 +406,7 class Mailer < ActionMailer::Base | |||||
406 | # |
|
406 | # | |
407 | # https://rails.lighthouseapp.com/projects/8994/tickets/2338-actionmailer-mailer-views-and-content-type |
|
407 | # https://rails.lighthouseapp.com/projects/8994/tickets/2338-actionmailer-mailer-views-and-content-type | |
408 | # https://rails.lighthouseapp.com/projects/8994/tickets/1799-actionmailer-doesnt-set-template_format-when-rendering-layouts |
|
408 | # https://rails.lighthouseapp.com/projects/8994/tickets/1799-actionmailer-doesnt-set-template_format-when-rendering-layouts | |
409 |
|
409 | |||
410 | def render_multipart(method_name, body) |
|
410 | def render_multipart(method_name, body) | |
411 | if Setting.plain_text_mail? |
|
411 | if Setting.plain_text_mail? | |
412 | content_type "text/plain" |
|
412 | content_type "text/plain" | |
@@ -422,29 +422,29 class Mailer < ActionMailer::Base | |||||
422 | def self.controller_path |
|
422 | def self.controller_path | |
423 | '' |
|
423 | '' | |
424 | end unless respond_to?('controller_path') |
|
424 | end unless respond_to?('controller_path') | |
425 |
|
425 | |||
426 | # Returns a predictable Message-Id for the given object |
|
426 | # Returns a predictable Message-Id for the given object | |
427 | def self.message_id_for(object) |
|
427 | def self.message_id_for(object) | |
428 | # id + timestamp should reduce the odds of a collision |
|
428 | # id + timestamp should reduce the odds of a collision | |
429 | # as far as we don't send multiple emails for the same object |
|
429 | # as far as we don't send multiple emails for the same object | |
430 |
timestamp = object.send(object.respond_to?(:created_on) ? :created_on : :updated_on) |
|
430 | timestamp = object.send(object.respond_to?(:created_on) ? :created_on : :updated_on) | |
431 | hash = "redmine.#{object.class.name.demodulize.underscore}-#{object.id}.#{timestamp.strftime("%Y%m%d%H%M%S")}" |
|
431 | hash = "redmine.#{object.class.name.demodulize.underscore}-#{object.id}.#{timestamp.strftime("%Y%m%d%H%M%S")}" | |
432 | host = Setting.mail_from.to_s.gsub(%r{^.*@}, '') |
|
432 | host = Setting.mail_from.to_s.gsub(%r{^.*@}, '') | |
433 | host = "#{::Socket.gethostname}.redmine" if host.empty? |
|
433 | host = "#{::Socket.gethostname}.redmine" if host.empty? | |
434 | "<#{hash}@#{host}>" |
|
434 | "<#{hash}@#{host}>" | |
435 | end |
|
435 | end | |
436 |
|
436 | |||
437 | private |
|
437 | private | |
438 |
|
438 | |||
439 | def message_id(object) |
|
439 | def message_id(object) | |
440 | @message_id_object = object |
|
440 | @message_id_object = object | |
441 | end |
|
441 | end | |
442 |
|
442 | |||
443 | def references(object) |
|
443 | def references(object) | |
444 | @references_objects ||= [] |
|
444 | @references_objects ||= [] | |
445 | @references_objects << object |
|
445 | @references_objects << object | |
446 | end |
|
446 | end | |
447 |
|
447 | |||
448 | def mylogger |
|
448 | def mylogger | |
449 | RAILS_DEFAULT_LOGGER |
|
449 | RAILS_DEFAULT_LOGGER | |
450 | end |
|
450 | end |
General Comments 0
You need to be logged in to leave comments.
Login now