##// END OF EJS Templates
Don't notify users about relations that are not visible (#1005)....
Jean-Philippe Lang -
r11785:0087d237f764
parent child
Show More
@@ -1,155 +1,168
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class Journal < ActiveRecord::Base
18 class Journal < ActiveRecord::Base
19 belongs_to :journalized, :polymorphic => true
19 belongs_to :journalized, :polymorphic => true
20 # added as a quick fix to allow eager loading of the polymorphic association
20 # added as a quick fix to allow eager loading of the polymorphic association
21 # since always associated to an issue, for now
21 # since always associated to an issue, for now
22 belongs_to :issue, :foreign_key => :journalized_id
22 belongs_to :issue, :foreign_key => :journalized_id
23
23
24 belongs_to :user
24 belongs_to :user
25 has_many :details, :class_name => "JournalDetail", :dependent => :delete_all
25 has_many :details, :class_name => "JournalDetail", :dependent => :delete_all
26 attr_accessor :indice
26 attr_accessor :indice
27
27
28 acts_as_event :title => Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.id}#{status}: #{o.issue.subject}" },
28 acts_as_event :title => Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.id}#{status}: #{o.issue.subject}" },
29 :description => :notes,
29 :description => :notes,
30 :author => :user,
30 :author => :user,
31 :group => :issue,
31 :group => :issue,
32 :type => Proc.new {|o| (s = o.new_status) ? (s.is_closed? ? 'issue-closed' : 'issue-edit') : 'issue-note' },
32 :type => Proc.new {|o| (s = o.new_status) ? (s.is_closed? ? 'issue-closed' : 'issue-edit') : 'issue-note' },
33 :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id, :anchor => "change-#{o.id}"}}
33 :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id, :anchor => "change-#{o.id}"}}
34
34
35 acts_as_activity_provider :type => 'issues',
35 acts_as_activity_provider :type => 'issues',
36 :author_key => :user_id,
36 :author_key => :user_id,
37 :find_options => {:include => [{:issue => :project}, :details, :user],
37 :find_options => {:include => [{:issue => :project}, :details, :user],
38 :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" +
38 :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" +
39 " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
39 " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
40
40
41 before_create :split_private_notes
41 before_create :split_private_notes
42
42
43 scope :visible, lambda {|*args|
43 scope :visible, lambda {|*args|
44 user = args.shift || User.current
44 user = args.shift || User.current
45
45
46 includes(:issue => :project).
46 includes(:issue => :project).
47 where(Issue.visible_condition(user, *args)).
47 where(Issue.visible_condition(user, *args)).
48 where("(#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(user, :view_private_notes, *args)}))", false)
48 where("(#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(user, :view_private_notes, *args)}))", false)
49 }
49 }
50
50
51 def save(*args)
51 def save(*args)
52 # Do not save an empty journal
52 # Do not save an empty journal
53 (details.empty? && notes.blank?) ? false : super
53 (details.empty? && notes.blank?) ? false : super
54 end
54 end
55
55
56 # Returns journal details that are visible to user
56 # Returns journal details that are visible to user
57 def visible_details(user=User.current)
57 def visible_details(user=User.current)
58 details.select do |detail|
58 details.select do |detail|
59 if detail.property == 'cf'
59 if detail.property == 'cf'
60 field_id = detail.prop_key
60 field_id = detail.prop_key
61 field = CustomField.find_by_id(field_id)
61 field = CustomField.find_by_id(field_id)
62 field && field.visible_by?(project, user)
62 field && field.visible_by?(project, user)
63 elsif detail.property == 'relation'
63 elsif detail.property == 'relation'
64 Issue.find_by_id(detail.value || detail.old_value).try(:visible?, user)
64 Issue.find_by_id(detail.value || detail.old_value).try(:visible?, user)
65 else
65 else
66 true
66 true
67 end
67 end
68 end
68 end
69 end
69 end
70
70
71 def each_notification(users, &block)
72 if users.any?
73 users_by_details_visibility = users.group_by do |user|
74 visible_details(user)
75 end
76 users_by_details_visibility.each do |visible_details, users|
77 if notes? || visible_details.any?
78 yield(users)
79 end
80 end
81 end
82 end
83
71 # Returns the new status if the journal contains a status change, otherwise nil
84 # Returns the new status if the journal contains a status change, otherwise nil
72 def new_status
85 def new_status
73 c = details.detect {|detail| detail.prop_key == 'status_id'}
86 c = details.detect {|detail| detail.prop_key == 'status_id'}
74 (c && c.value) ? IssueStatus.find_by_id(c.value.to_i) : nil
87 (c && c.value) ? IssueStatus.find_by_id(c.value.to_i) : nil
75 end
88 end
76
89
77 def new_value_for(prop)
90 def new_value_for(prop)
78 c = details.detect {|detail| detail.prop_key == prop}
91 c = details.detect {|detail| detail.prop_key == prop}
79 c ? c.value : nil
92 c ? c.value : nil
80 end
93 end
81
94
82 def editable_by?(usr)
95 def editable_by?(usr)
83 usr && usr.logged? && (usr.allowed_to?(:edit_issue_notes, project) || (self.user == usr && usr.allowed_to?(:edit_own_issue_notes, project)))
96 usr && usr.logged? && (usr.allowed_to?(:edit_issue_notes, project) || (self.user == usr && usr.allowed_to?(:edit_own_issue_notes, project)))
84 end
97 end
85
98
86 def project
99 def project
87 journalized.respond_to?(:project) ? journalized.project : nil
100 journalized.respond_to?(:project) ? journalized.project : nil
88 end
101 end
89
102
90 def attachments
103 def attachments
91 journalized.respond_to?(:attachments) ? journalized.attachments : nil
104 journalized.respond_to?(:attachments) ? journalized.attachments : nil
92 end
105 end
93
106
94 # Returns a string of css classes
107 # Returns a string of css classes
95 def css_classes
108 def css_classes
96 s = 'journal'
109 s = 'journal'
97 s << ' has-notes' unless notes.blank?
110 s << ' has-notes' unless notes.blank?
98 s << ' has-details' unless details.blank?
111 s << ' has-details' unless details.blank?
99 s << ' private-notes' if private_notes?
112 s << ' private-notes' if private_notes?
100 s
113 s
101 end
114 end
102
115
103 def notify?
116 def notify?
104 @notify != false
117 @notify != false
105 end
118 end
106
119
107 def notify=(arg)
120 def notify=(arg)
108 @notify = arg
121 @notify = arg
109 end
122 end
110
123
111 def notified_users
124 def notified_users
112 notified = journalized.notified_users
125 notified = journalized.notified_users
113 if private_notes?
126 if private_notes?
114 notified = notified.select {|user| user.allowed_to?(:view_private_notes, journalized.project)}
127 notified = notified.select {|user| user.allowed_to?(:view_private_notes, journalized.project)}
115 end
128 end
116 notified
129 notified
117 end
130 end
118
131
119 def recipients
132 def recipients
120 notified_users.map(&:mail)
133 notified_users.map(&:mail)
121 end
134 end
122
135
123 def notified_watchers
136 def notified_watchers
124 notified = journalized.notified_watchers
137 notified = journalized.notified_watchers
125 if private_notes?
138 if private_notes?
126 notified = notified.select {|user| user.allowed_to?(:view_private_notes, journalized.project)}
139 notified = notified.select {|user| user.allowed_to?(:view_private_notes, journalized.project)}
127 end
140 end
128 notified
141 notified
129 end
142 end
130
143
131 def watcher_recipients
144 def watcher_recipients
132 notified_watchers.map(&:mail)
145 notified_watchers.map(&:mail)
133 end
146 end
134
147
135 private
148 private
136
149
137 def split_private_notes
150 def split_private_notes
138 if private_notes?
151 if private_notes?
139 if notes.present?
152 if notes.present?
140 if details.any?
153 if details.any?
141 # Split the journal (notes/changes) so we don't have half-private journals
154 # Split the journal (notes/changes) so we don't have half-private journals
142 journal = Journal.new(:journalized => journalized, :user => user, :notes => nil, :private_notes => false)
155 journal = Journal.new(:journalized => journalized, :user => user, :notes => nil, :private_notes => false)
143 journal.details = details
156 journal.details = details
144 journal.save
157 journal.save
145 self.details = []
158 self.details = []
146 self.created_on = journal.created_on
159 self.created_on = journal.created_on
147 end
160 end
148 else
161 else
149 # Blank notes should not be private
162 # Blank notes should not be private
150 self.private_notes = false
163 self.private_notes = false
151 end
164 end
152 end
165 end
153 true
166 true
154 end
167 end
155 end
168 end
@@ -1,488 +1,489
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class Mailer < ActionMailer::Base
18 class Mailer < ActionMailer::Base
19 layout 'mailer'
19 layout 'mailer'
20 helper :application
20 helper :application
21 helper :issues
21 helper :issues
22 helper :custom_fields
22 helper :custom_fields
23
23
24 include Redmine::I18n
24 include Redmine::I18n
25
25
26 def self.default_url_options
26 def self.default_url_options
27 { :host => Setting.host_name, :protocol => Setting.protocol }
27 { :host => Setting.host_name, :protocol => Setting.protocol }
28 end
28 end
29
29
30 # Builds a mail for notifying to_users and cc_users about a new issue
30 # Builds a mail for notifying to_users and cc_users about a new issue
31 def issue_add(issue, to_users, cc_users)
31 def issue_add(issue, to_users, cc_users)
32 redmine_headers 'Project' => issue.project.identifier,
32 redmine_headers 'Project' => issue.project.identifier,
33 'Issue-Id' => issue.id,
33 'Issue-Id' => issue.id,
34 'Issue-Author' => issue.author.login
34 'Issue-Author' => issue.author.login
35 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
35 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
36 message_id issue
36 message_id issue
37 references issue
37 references issue
38 @author = issue.author
38 @author = issue.author
39 @issue = issue
39 @issue = issue
40 @users = to_users + cc_users
40 @users = to_users + cc_users
41 @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue)
41 @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue)
42 mail :to => to_users.map(&:mail),
42 mail :to => to_users.map(&:mail),
43 :cc => cc_users.map(&:mail),
43 :cc => cc_users.map(&:mail),
44 :subject => "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}"
44 :subject => "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}"
45 end
45 end
46
46
47 # Notifies users about a new issue
47 # Notifies users about a new issue
48 def self.deliver_issue_add(issue)
48 def self.deliver_issue_add(issue)
49 to = issue.notified_users
49 to = issue.notified_users
50 cc = issue.notified_watchers - to
50 cc = issue.notified_watchers - to
51 issue.each_notification(to + cc) do |users|
51 issue.each_notification(to + cc) do |users|
52 Mailer.issue_add(issue, to & users, cc & users).deliver
52 Mailer.issue_add(issue, to & users, cc & users).deliver
53 end
53 end
54 end
54 end
55
55
56 # Builds a mail for notifying to_users and cc_users about an issue update
56 # Builds a mail for notifying to_users and cc_users about an issue update
57 def issue_edit(journal, to_users, cc_users)
57 def issue_edit(journal, to_users, cc_users)
58 issue = journal.journalized
58 issue = journal.journalized
59 redmine_headers 'Project' => issue.project.identifier,
59 redmine_headers 'Project' => issue.project.identifier,
60 'Issue-Id' => issue.id,
60 'Issue-Id' => issue.id,
61 'Issue-Author' => issue.author.login
61 'Issue-Author' => issue.author.login
62 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
62 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
63 message_id journal
63 message_id journal
64 references issue
64 references issue
65 @author = journal.user
65 @author = journal.user
66 s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] "
66 s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] "
67 s << "(#{issue.status.name}) " if journal.new_value_for('status_id')
67 s << "(#{issue.status.name}) " if journal.new_value_for('status_id')
68 s << issue.subject
68 s << issue.subject
69 @issue = issue
69 @issue = issue
70 @users = to_users + cc_users
70 @users = to_users + cc_users
71 @journal = journal
71 @journal = journal
72 @journal_details = journal.visible_details(@users.first)
72 @journal_details = journal.visible_details(@users.first)
73 @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue, :anchor => "change-#{journal.id}")
73 @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue, :anchor => "change-#{journal.id}")
74 mail :to => to_users.map(&:mail),
74 mail :to => to_users.map(&:mail),
75 :cc => cc_users.map(&:mail),
75 :cc => cc_users.map(&:mail),
76 :subject => s
76 :subject => s
77 end
77 end
78
78
79 # Notifies users about an issue update
79 # Notifies users about an issue update
80 def self.deliver_issue_edit(journal)
80 def self.deliver_issue_edit(journal)
81 issue = journal.journalized.reload
81 issue = journal.journalized.reload
82 to = journal.notified_users
82 to = journal.notified_users
83 cc = journal.notified_watchers
83 cc = journal.notified_watchers
84 issue.each_notification(to + cc) do |users|
84 journal.each_notification(to + cc) do |users|
85 next unless journal.notes? || journal.visible_details(users.first).any?
85 issue.each_notification(users) do |users2|
86 Mailer.issue_edit(journal, to & users, cc & users).deliver
86 Mailer.issue_edit(journal, to & users2, cc & users2).deliver
87 end
87 end
88 end
88 end
89 end
89
90
90 def reminder(user, issues, days)
91 def reminder(user, issues, days)
91 set_language_if_valid user.language
92 set_language_if_valid user.language
92 @issues = issues
93 @issues = issues
93 @days = days
94 @days = days
94 @issues_url = url_for(:controller => 'issues', :action => 'index',
95 @issues_url = url_for(:controller => 'issues', :action => 'index',
95 :set_filter => 1, :assigned_to_id => user.id,
96 :set_filter => 1, :assigned_to_id => user.id,
96 :sort => 'due_date:asc')
97 :sort => 'due_date:asc')
97 mail :to => user.mail,
98 mail :to => user.mail,
98 :subject => l(:mail_subject_reminder, :count => issues.size, :days => days)
99 :subject => l(:mail_subject_reminder, :count => issues.size, :days => days)
99 end
100 end
100
101
101 # Builds a Mail::Message object used to email users belonging to the added document's project.
102 # Builds a Mail::Message object used to email users belonging to the added document's project.
102 #
103 #
103 # Example:
104 # Example:
104 # document_added(document) => Mail::Message object
105 # document_added(document) => Mail::Message object
105 # Mailer.document_added(document).deliver => sends an email to the document's project recipients
106 # Mailer.document_added(document).deliver => sends an email to the document's project recipients
106 def document_added(document)
107 def document_added(document)
107 redmine_headers 'Project' => document.project.identifier
108 redmine_headers 'Project' => document.project.identifier
108 @author = User.current
109 @author = User.current
109 @document = document
110 @document = document
110 @document_url = url_for(:controller => 'documents', :action => 'show', :id => document)
111 @document_url = url_for(:controller => 'documents', :action => 'show', :id => document)
111 mail :to => document.recipients,
112 mail :to => document.recipients,
112 :subject => "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
113 :subject => "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
113 end
114 end
114
115
115 # Builds a Mail::Message object used to email recipients of a project when an attachements are added.
116 # Builds a Mail::Message object used to email recipients of a project when an attachements are added.
116 #
117 #
117 # Example:
118 # Example:
118 # attachments_added(attachments) => Mail::Message object
119 # attachments_added(attachments) => Mail::Message object
119 # Mailer.attachments_added(attachments).deliver => sends an email to the project's recipients
120 # Mailer.attachments_added(attachments).deliver => sends an email to the project's recipients
120 def attachments_added(attachments)
121 def attachments_added(attachments)
121 container = attachments.first.container
122 container = attachments.first.container
122 added_to = ''
123 added_to = ''
123 added_to_url = ''
124 added_to_url = ''
124 @author = attachments.first.author
125 @author = attachments.first.author
125 case container.class.name
126 case container.class.name
126 when 'Project'
127 when 'Project'
127 added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container)
128 added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container)
128 added_to = "#{l(:label_project)}: #{container}"
129 added_to = "#{l(:label_project)}: #{container}"
129 recipients = container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)}.collect {|u| u.mail}
130 recipients = container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)}.collect {|u| u.mail}
130 when 'Version'
131 when 'Version'
131 added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container.project)
132 added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container.project)
132 added_to = "#{l(:label_version)}: #{container.name}"
133 added_to = "#{l(:label_version)}: #{container.name}"
133 recipients = container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)}.collect {|u| u.mail}
134 recipients = container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)}.collect {|u| u.mail}
134 when 'Document'
135 when 'Document'
135 added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id)
136 added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id)
136 added_to = "#{l(:label_document)}: #{container.title}"
137 added_to = "#{l(:label_document)}: #{container.title}"
137 recipients = container.recipients
138 recipients = container.recipients
138 end
139 end
139 redmine_headers 'Project' => container.project.identifier
140 redmine_headers 'Project' => container.project.identifier
140 @attachments = attachments
141 @attachments = attachments
141 @added_to = added_to
142 @added_to = added_to
142 @added_to_url = added_to_url
143 @added_to_url = added_to_url
143 mail :to => recipients,
144 mail :to => recipients,
144 :subject => "[#{container.project.name}] #{l(:label_attachment_new)}"
145 :subject => "[#{container.project.name}] #{l(:label_attachment_new)}"
145 end
146 end
146
147
147 # Builds a Mail::Message object used to email recipients of a news' project when a news item is added.
148 # Builds a Mail::Message object used to email recipients of a news' project when a news item is added.
148 #
149 #
149 # Example:
150 # Example:
150 # news_added(news) => Mail::Message object
151 # news_added(news) => Mail::Message object
151 # Mailer.news_added(news).deliver => sends an email to the news' project recipients
152 # Mailer.news_added(news).deliver => sends an email to the news' project recipients
152 def news_added(news)
153 def news_added(news)
153 redmine_headers 'Project' => news.project.identifier
154 redmine_headers 'Project' => news.project.identifier
154 @author = news.author
155 @author = news.author
155 message_id news
156 message_id news
156 references news
157 references news
157 @news = news
158 @news = news
158 @news_url = url_for(:controller => 'news', :action => 'show', :id => news)
159 @news_url = url_for(:controller => 'news', :action => 'show', :id => news)
159 mail :to => news.recipients,
160 mail :to => news.recipients,
160 :subject => "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
161 :subject => "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
161 end
162 end
162
163
163 # Builds a Mail::Message object used to email recipients of a news' project when a news comment is added.
164 # Builds a Mail::Message object used to email recipients of a news' project when a news comment is added.
164 #
165 #
165 # Example:
166 # Example:
166 # news_comment_added(comment) => Mail::Message object
167 # news_comment_added(comment) => Mail::Message object
167 # Mailer.news_comment_added(comment) => sends an email to the news' project recipients
168 # Mailer.news_comment_added(comment) => sends an email to the news' project recipients
168 def news_comment_added(comment)
169 def news_comment_added(comment)
169 news = comment.commented
170 news = comment.commented
170 redmine_headers 'Project' => news.project.identifier
171 redmine_headers 'Project' => news.project.identifier
171 @author = comment.author
172 @author = comment.author
172 message_id comment
173 message_id comment
173 references news
174 references news
174 @news = news
175 @news = news
175 @comment = comment
176 @comment = comment
176 @news_url = url_for(:controller => 'news', :action => 'show', :id => news)
177 @news_url = url_for(:controller => 'news', :action => 'show', :id => news)
177 mail :to => news.recipients,
178 mail :to => news.recipients,
178 :cc => news.watcher_recipients,
179 :cc => news.watcher_recipients,
179 :subject => "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}"
180 :subject => "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}"
180 end
181 end
181
182
182 # Builds a Mail::Message object used to email the recipients of the specified message that was posted.
183 # Builds a Mail::Message object used to email the recipients of the specified message that was posted.
183 #
184 #
184 # Example:
185 # Example:
185 # message_posted(message) => Mail::Message object
186 # message_posted(message) => Mail::Message object
186 # Mailer.message_posted(message).deliver => sends an email to the recipients
187 # Mailer.message_posted(message).deliver => sends an email to the recipients
187 def message_posted(message)
188 def message_posted(message)
188 redmine_headers 'Project' => message.project.identifier,
189 redmine_headers 'Project' => message.project.identifier,
189 'Topic-Id' => (message.parent_id || message.id)
190 'Topic-Id' => (message.parent_id || message.id)
190 @author = message.author
191 @author = message.author
191 message_id message
192 message_id message
192 references message.root
193 references message.root
193 recipients = message.recipients
194 recipients = message.recipients
194 cc = ((message.root.watcher_recipients + message.board.watcher_recipients).uniq - recipients)
195 cc = ((message.root.watcher_recipients + message.board.watcher_recipients).uniq - recipients)
195 @message = message
196 @message = message
196 @message_url = url_for(message.event_url)
197 @message_url = url_for(message.event_url)
197 mail :to => recipients,
198 mail :to => recipients,
198 :cc => cc,
199 :cc => cc,
199 :subject => "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}"
200 :subject => "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}"
200 end
201 end
201
202
202 # Builds a Mail::Message object used to email the recipients of a project of the specified wiki content was added.
203 # Builds a Mail::Message object used to email the recipients of a project of the specified wiki content was added.
203 #
204 #
204 # Example:
205 # Example:
205 # wiki_content_added(wiki_content) => Mail::Message object
206 # wiki_content_added(wiki_content) => Mail::Message object
206 # Mailer.wiki_content_added(wiki_content).deliver => sends an email to the project's recipients
207 # Mailer.wiki_content_added(wiki_content).deliver => sends an email to the project's recipients
207 def wiki_content_added(wiki_content)
208 def wiki_content_added(wiki_content)
208 redmine_headers 'Project' => wiki_content.project.identifier,
209 redmine_headers 'Project' => wiki_content.project.identifier,
209 'Wiki-Page-Id' => wiki_content.page.id
210 'Wiki-Page-Id' => wiki_content.page.id
210 @author = wiki_content.author
211 @author = wiki_content.author
211 message_id wiki_content
212 message_id wiki_content
212 recipients = wiki_content.recipients
213 recipients = wiki_content.recipients
213 cc = wiki_content.page.wiki.watcher_recipients - recipients
214 cc = wiki_content.page.wiki.watcher_recipients - recipients
214 @wiki_content = wiki_content
215 @wiki_content = wiki_content
215 @wiki_content_url = url_for(:controller => 'wiki', :action => 'show',
216 @wiki_content_url = url_for(:controller => 'wiki', :action => 'show',
216 :project_id => wiki_content.project,
217 :project_id => wiki_content.project,
217 :id => wiki_content.page.title)
218 :id => wiki_content.page.title)
218 mail :to => recipients,
219 mail :to => recipients,
219 :cc => cc,
220 :cc => cc,
220 :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :id => wiki_content.page.pretty_title)}"
221 :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :id => wiki_content.page.pretty_title)}"
221 end
222 end
222
223
223 # Builds a Mail::Message object used to email the recipients of a project of the specified wiki content was updated.
224 # Builds a Mail::Message object used to email the recipients of a project of the specified wiki content was updated.
224 #
225 #
225 # Example:
226 # Example:
226 # wiki_content_updated(wiki_content) => Mail::Message object
227 # wiki_content_updated(wiki_content) => Mail::Message object
227 # Mailer.wiki_content_updated(wiki_content).deliver => sends an email to the project's recipients
228 # Mailer.wiki_content_updated(wiki_content).deliver => sends an email to the project's recipients
228 def wiki_content_updated(wiki_content)
229 def wiki_content_updated(wiki_content)
229 redmine_headers 'Project' => wiki_content.project.identifier,
230 redmine_headers 'Project' => wiki_content.project.identifier,
230 'Wiki-Page-Id' => wiki_content.page.id
231 'Wiki-Page-Id' => wiki_content.page.id
231 @author = wiki_content.author
232 @author = wiki_content.author
232 message_id wiki_content
233 message_id wiki_content
233 recipients = wiki_content.recipients
234 recipients = wiki_content.recipients
234 cc = wiki_content.page.wiki.watcher_recipients + wiki_content.page.watcher_recipients - recipients
235 cc = wiki_content.page.wiki.watcher_recipients + wiki_content.page.watcher_recipients - recipients
235 @wiki_content = wiki_content
236 @wiki_content = wiki_content
236 @wiki_content_url = url_for(:controller => 'wiki', :action => 'show',
237 @wiki_content_url = url_for(:controller => 'wiki', :action => 'show',
237 :project_id => wiki_content.project,
238 :project_id => wiki_content.project,
238 :id => wiki_content.page.title)
239 :id => wiki_content.page.title)
239 @wiki_diff_url = url_for(:controller => 'wiki', :action => 'diff',
240 @wiki_diff_url = url_for(:controller => 'wiki', :action => 'diff',
240 :project_id => wiki_content.project, :id => wiki_content.page.title,
241 :project_id => wiki_content.project, :id => wiki_content.page.title,
241 :version => wiki_content.version)
242 :version => wiki_content.version)
242 mail :to => recipients,
243 mail :to => recipients,
243 :cc => cc,
244 :cc => cc,
244 :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :id => wiki_content.page.pretty_title)}"
245 :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :id => wiki_content.page.pretty_title)}"
245 end
246 end
246
247
247 # Builds a Mail::Message object used to email the specified user their account information.
248 # Builds a Mail::Message object used to email the specified user their account information.
248 #
249 #
249 # Example:
250 # Example:
250 # account_information(user, password) => Mail::Message object
251 # account_information(user, password) => Mail::Message object
251 # Mailer.account_information(user, password).deliver => sends account information to the user
252 # Mailer.account_information(user, password).deliver => sends account information to the user
252 def account_information(user, password)
253 def account_information(user, password)
253 set_language_if_valid user.language
254 set_language_if_valid user.language
254 @user = user
255 @user = user
255 @password = password
256 @password = password
256 @login_url = url_for(:controller => 'account', :action => 'login')
257 @login_url = url_for(:controller => 'account', :action => 'login')
257 mail :to => user.mail,
258 mail :to => user.mail,
258 :subject => l(:mail_subject_register, Setting.app_title)
259 :subject => l(:mail_subject_register, Setting.app_title)
259 end
260 end
260
261
261 # Builds a Mail::Message object used to email all active administrators of an account activation request.
262 # Builds a Mail::Message object used to email all active administrators of an account activation request.
262 #
263 #
263 # Example:
264 # Example:
264 # account_activation_request(user) => Mail::Message object
265 # account_activation_request(user) => Mail::Message object
265 # Mailer.account_activation_request(user).deliver => sends an email to all active administrators
266 # Mailer.account_activation_request(user).deliver => sends an email to all active administrators
266 def account_activation_request(user)
267 def account_activation_request(user)
267 # Send the email to all active administrators
268 # Send the email to all active administrators
268 recipients = User.active.where(:admin => true).all.collect { |u| u.mail }.compact
269 recipients = User.active.where(:admin => true).all.collect { |u| u.mail }.compact
269 @user = user
270 @user = user
270 @url = url_for(:controller => 'users', :action => 'index',
271 @url = url_for(:controller => 'users', :action => 'index',
271 :status => User::STATUS_REGISTERED,
272 :status => User::STATUS_REGISTERED,
272 :sort_key => 'created_on', :sort_order => 'desc')
273 :sort_key => 'created_on', :sort_order => 'desc')
273 mail :to => recipients,
274 mail :to => recipients,
274 :subject => l(:mail_subject_account_activation_request, Setting.app_title)
275 :subject => l(:mail_subject_account_activation_request, Setting.app_title)
275 end
276 end
276
277
277 # Builds a Mail::Message object used to email the specified user that their account was activated by an administrator.
278 # Builds a Mail::Message object used to email the specified user that their account was activated by an administrator.
278 #
279 #
279 # Example:
280 # Example:
280 # account_activated(user) => Mail::Message object
281 # account_activated(user) => Mail::Message object
281 # Mailer.account_activated(user).deliver => sends an email to the registered user
282 # Mailer.account_activated(user).deliver => sends an email to the registered user
282 def account_activated(user)
283 def account_activated(user)
283 set_language_if_valid user.language
284 set_language_if_valid user.language
284 @user = user
285 @user = user
285 @login_url = url_for(:controller => 'account', :action => 'login')
286 @login_url = url_for(:controller => 'account', :action => 'login')
286 mail :to => user.mail,
287 mail :to => user.mail,
287 :subject => l(:mail_subject_register, Setting.app_title)
288 :subject => l(:mail_subject_register, Setting.app_title)
288 end
289 end
289
290
290 def lost_password(token)
291 def lost_password(token)
291 set_language_if_valid(token.user.language)
292 set_language_if_valid(token.user.language)
292 @token = token
293 @token = token
293 @url = url_for(:controller => 'account', :action => 'lost_password', :token => token.value)
294 @url = url_for(:controller => 'account', :action => 'lost_password', :token => token.value)
294 mail :to => token.user.mail,
295 mail :to => token.user.mail,
295 :subject => l(:mail_subject_lost_password, Setting.app_title)
296 :subject => l(:mail_subject_lost_password, Setting.app_title)
296 end
297 end
297
298
298 def register(token)
299 def register(token)
299 set_language_if_valid(token.user.language)
300 set_language_if_valid(token.user.language)
300 @token = token
301 @token = token
301 @url = url_for(:controller => 'account', :action => 'activate', :token => token.value)
302 @url = url_for(:controller => 'account', :action => 'activate', :token => token.value)
302 mail :to => token.user.mail,
303 mail :to => token.user.mail,
303 :subject => l(:mail_subject_register, Setting.app_title)
304 :subject => l(:mail_subject_register, Setting.app_title)
304 end
305 end
305
306
306 def test_email(user)
307 def test_email(user)
307 set_language_if_valid(user.language)
308 set_language_if_valid(user.language)
308 @url = url_for(:controller => 'welcome')
309 @url = url_for(:controller => 'welcome')
309 mail :to => user.mail,
310 mail :to => user.mail,
310 :subject => 'Redmine test'
311 :subject => 'Redmine test'
311 end
312 end
312
313
313 # Sends reminders to issue assignees
314 # Sends reminders to issue assignees
314 # Available options:
315 # Available options:
315 # * :days => how many days in the future to remind about (defaults to 7)
316 # * :days => how many days in the future to remind about (defaults to 7)
316 # * :tracker => id of tracker for filtering issues (defaults to all trackers)
317 # * :tracker => id of tracker for filtering issues (defaults to all trackers)
317 # * :project => id or identifier of project to process (defaults to all projects)
318 # * :project => id or identifier of project to process (defaults to all projects)
318 # * :users => array of user/group ids who should be reminded
319 # * :users => array of user/group ids who should be reminded
319 def self.reminders(options={})
320 def self.reminders(options={})
320 days = options[:days] || 7
321 days = options[:days] || 7
321 project = options[:project] ? Project.find(options[:project]) : nil
322 project = options[:project] ? Project.find(options[:project]) : nil
322 tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil
323 tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil
323 user_ids = options[:users]
324 user_ids = options[:users]
324
325
325 scope = Issue.open.where("#{Issue.table_name}.assigned_to_id IS NOT NULL" +
326 scope = Issue.open.where("#{Issue.table_name}.assigned_to_id IS NOT NULL" +
326 " AND #{Project.table_name}.status = #{Project::STATUS_ACTIVE}" +
327 " AND #{Project.table_name}.status = #{Project::STATUS_ACTIVE}" +
327 " AND #{Issue.table_name}.due_date <= ?", days.day.from_now.to_date
328 " AND #{Issue.table_name}.due_date <= ?", days.day.from_now.to_date
328 )
329 )
329 scope = scope.where(:assigned_to_id => user_ids) if user_ids.present?
330 scope = scope.where(:assigned_to_id => user_ids) if user_ids.present?
330 scope = scope.where(:project_id => project.id) if project
331 scope = scope.where(:project_id => project.id) if project
331 scope = scope.where(:tracker_id => tracker.id) if tracker
332 scope = scope.where(:tracker_id => tracker.id) if tracker
332
333
333 issues_by_assignee = scope.includes(:status, :assigned_to, :project, :tracker).all.group_by(&:assigned_to)
334 issues_by_assignee = scope.includes(:status, :assigned_to, :project, :tracker).all.group_by(&:assigned_to)
334 issues_by_assignee.keys.each do |assignee|
335 issues_by_assignee.keys.each do |assignee|
335 if assignee.is_a?(Group)
336 if assignee.is_a?(Group)
336 assignee.users.each do |user|
337 assignee.users.each do |user|
337 issues_by_assignee[user] ||= []
338 issues_by_assignee[user] ||= []
338 issues_by_assignee[user] += issues_by_assignee[assignee]
339 issues_by_assignee[user] += issues_by_assignee[assignee]
339 end
340 end
340 end
341 end
341 end
342 end
342
343
343 issues_by_assignee.each do |assignee, issues|
344 issues_by_assignee.each do |assignee, issues|
344 reminder(assignee, issues, days).deliver if assignee.is_a?(User) && assignee.active?
345 reminder(assignee, issues, days).deliver if assignee.is_a?(User) && assignee.active?
345 end
346 end
346 end
347 end
347
348
348 # Activates/desactivates email deliveries during +block+
349 # Activates/desactivates email deliveries during +block+
349 def self.with_deliveries(enabled = true, &block)
350 def self.with_deliveries(enabled = true, &block)
350 was_enabled = ActionMailer::Base.perform_deliveries
351 was_enabled = ActionMailer::Base.perform_deliveries
351 ActionMailer::Base.perform_deliveries = !!enabled
352 ActionMailer::Base.perform_deliveries = !!enabled
352 yield
353 yield
353 ensure
354 ensure
354 ActionMailer::Base.perform_deliveries = was_enabled
355 ActionMailer::Base.perform_deliveries = was_enabled
355 end
356 end
356
357
357 # Sends emails synchronously in the given block
358 # Sends emails synchronously in the given block
358 def self.with_synched_deliveries(&block)
359 def self.with_synched_deliveries(&block)
359 saved_method = ActionMailer::Base.delivery_method
360 saved_method = ActionMailer::Base.delivery_method
360 if m = saved_method.to_s.match(%r{^async_(.+)$})
361 if m = saved_method.to_s.match(%r{^async_(.+)$})
361 synched_method = m[1]
362 synched_method = m[1]
362 ActionMailer::Base.delivery_method = synched_method.to_sym
363 ActionMailer::Base.delivery_method = synched_method.to_sym
363 ActionMailer::Base.send "#{synched_method}_settings=", ActionMailer::Base.send("async_#{synched_method}_settings")
364 ActionMailer::Base.send "#{synched_method}_settings=", ActionMailer::Base.send("async_#{synched_method}_settings")
364 end
365 end
365 yield
366 yield
366 ensure
367 ensure
367 ActionMailer::Base.delivery_method = saved_method
368 ActionMailer::Base.delivery_method = saved_method
368 end
369 end
369
370
370 def mail(headers={})
371 def mail(headers={})
371 headers.merge! 'X-Mailer' => 'Redmine',
372 headers.merge! 'X-Mailer' => 'Redmine',
372 'X-Redmine-Host' => Setting.host_name,
373 'X-Redmine-Host' => Setting.host_name,
373 'X-Redmine-Site' => Setting.app_title,
374 'X-Redmine-Site' => Setting.app_title,
374 'X-Auto-Response-Suppress' => 'OOF',
375 'X-Auto-Response-Suppress' => 'OOF',
375 'Auto-Submitted' => 'auto-generated',
376 'Auto-Submitted' => 'auto-generated',
376 'From' => Setting.mail_from,
377 'From' => Setting.mail_from,
377 'List-Id' => "<#{Setting.mail_from.to_s.gsub('@', '.')}>"
378 'List-Id' => "<#{Setting.mail_from.to_s.gsub('@', '.')}>"
378
379
379 # Removes the author from the recipients and cc
380 # Removes the author from the recipients and cc
380 # if the author does not want to receive notifications
381 # if the author does not want to receive notifications
381 # about what the author do
382 # about what the author do
382 if @author && @author.logged? && @author.pref.no_self_notified
383 if @author && @author.logged? && @author.pref.no_self_notified
383 headers[:to].delete(@author.mail) if headers[:to].is_a?(Array)
384 headers[:to].delete(@author.mail) if headers[:to].is_a?(Array)
384 headers[:cc].delete(@author.mail) if headers[:cc].is_a?(Array)
385 headers[:cc].delete(@author.mail) if headers[:cc].is_a?(Array)
385 end
386 end
386
387
387 if @author && @author.logged?
388 if @author && @author.logged?
388 redmine_headers 'Sender' => @author.login
389 redmine_headers 'Sender' => @author.login
389 end
390 end
390
391
391 # Blind carbon copy recipients
392 # Blind carbon copy recipients
392 if Setting.bcc_recipients?
393 if Setting.bcc_recipients?
393 headers[:bcc] = [headers[:to], headers[:cc]].flatten.uniq.reject(&:blank?)
394 headers[:bcc] = [headers[:to], headers[:cc]].flatten.uniq.reject(&:blank?)
394 headers[:to] = nil
395 headers[:to] = nil
395 headers[:cc] = nil
396 headers[:cc] = nil
396 end
397 end
397
398
398 if @message_id_object
399 if @message_id_object
399 headers[:message_id] = "<#{self.class.message_id_for(@message_id_object)}>"
400 headers[:message_id] = "<#{self.class.message_id_for(@message_id_object)}>"
400 end
401 end
401 if @references_objects
402 if @references_objects
402 headers[:references] = @references_objects.collect {|o| "<#{self.class.references_for(o)}>"}.join(' ')
403 headers[:references] = @references_objects.collect {|o| "<#{self.class.references_for(o)}>"}.join(' ')
403 end
404 end
404
405
405 super headers do |format|
406 super headers do |format|
406 format.text
407 format.text
407 format.html unless Setting.plain_text_mail?
408 format.html unless Setting.plain_text_mail?
408 end
409 end
409
410
410 set_language_if_valid @initial_language
411 set_language_if_valid @initial_language
411 end
412 end
412
413
413 def initialize(*args)
414 def initialize(*args)
414 @initial_language = current_language
415 @initial_language = current_language
415 set_language_if_valid Setting.default_language
416 set_language_if_valid Setting.default_language
416 super
417 super
417 end
418 end
418
419
419 def self.deliver_mail(mail)
420 def self.deliver_mail(mail)
420 return false if mail.to.blank? && mail.cc.blank? && mail.bcc.blank?
421 return false if mail.to.blank? && mail.cc.blank? && mail.bcc.blank?
421 begin
422 begin
422 # Log errors when raise_delivery_errors is set to false, Rails does not
423 # Log errors when raise_delivery_errors is set to false, Rails does not
423 mail.raise_delivery_errors = true
424 mail.raise_delivery_errors = true
424 super
425 super
425 rescue Exception => e
426 rescue Exception => e
426 if ActionMailer::Base.raise_delivery_errors
427 if ActionMailer::Base.raise_delivery_errors
427 raise e
428 raise e
428 else
429 else
429 Rails.logger.error "Email delivery error: #{e.message}"
430 Rails.logger.error "Email delivery error: #{e.message}"
430 end
431 end
431 end
432 end
432 end
433 end
433
434
434 def self.method_missing(method, *args, &block)
435 def self.method_missing(method, *args, &block)
435 if m = method.to_s.match(%r{^deliver_(.+)$})
436 if m = method.to_s.match(%r{^deliver_(.+)$})
436 ActiveSupport::Deprecation.warn "Mailer.deliver_#{m[1]}(*args) is deprecated. Use Mailer.#{m[1]}(*args).deliver instead."
437 ActiveSupport::Deprecation.warn "Mailer.deliver_#{m[1]}(*args) is deprecated. Use Mailer.#{m[1]}(*args).deliver instead."
437 send(m[1], *args).deliver
438 send(m[1], *args).deliver
438 else
439 else
439 super
440 super
440 end
441 end
441 end
442 end
442
443
443 private
444 private
444
445
445 # Appends a Redmine header field (name is prepended with 'X-Redmine-')
446 # Appends a Redmine header field (name is prepended with 'X-Redmine-')
446 def redmine_headers(h)
447 def redmine_headers(h)
447 h.each { |k,v| headers["X-Redmine-#{k}"] = v.to_s }
448 h.each { |k,v| headers["X-Redmine-#{k}"] = v.to_s }
448 end
449 end
449
450
450 def self.token_for(object, rand=true)
451 def self.token_for(object, rand=true)
451 timestamp = object.send(object.respond_to?(:created_on) ? :created_on : :updated_on)
452 timestamp = object.send(object.respond_to?(:created_on) ? :created_on : :updated_on)
452 hash = [
453 hash = [
453 "redmine",
454 "redmine",
454 "#{object.class.name.demodulize.underscore}-#{object.id}",
455 "#{object.class.name.demodulize.underscore}-#{object.id}",
455 timestamp.strftime("%Y%m%d%H%M%S")
456 timestamp.strftime("%Y%m%d%H%M%S")
456 ]
457 ]
457 if rand
458 if rand
458 hash << Redmine::Utils.random_hex(8)
459 hash << Redmine::Utils.random_hex(8)
459 end
460 end
460 host = Setting.mail_from.to_s.gsub(%r{^.*@}, '')
461 host = Setting.mail_from.to_s.gsub(%r{^.*@}, '')
461 host = "#{::Socket.gethostname}.redmine" if host.empty?
462 host = "#{::Socket.gethostname}.redmine" if host.empty?
462 "#{hash.join('.')}@#{host}"
463 "#{hash.join('.')}@#{host}"
463 end
464 end
464
465
465 # Returns a Message-Id for the given object
466 # Returns a Message-Id for the given object
466 def self.message_id_for(object)
467 def self.message_id_for(object)
467 token_for(object, true)
468 token_for(object, true)
468 end
469 end
469
470
470 # Returns a uniq token for a given object referenced by all notifications
471 # Returns a uniq token for a given object referenced by all notifications
471 # related to this object
472 # related to this object
472 def self.references_for(object)
473 def self.references_for(object)
473 token_for(object, false)
474 token_for(object, false)
474 end
475 end
475
476
476 def message_id(object)
477 def message_id(object)
477 @message_id_object = object
478 @message_id_object = object
478 end
479 end
479
480
480 def references(object)
481 def references(object)
481 @references_objects ||= []
482 @references_objects ||= []
482 @references_objects << object
483 @references_objects << object
483 end
484 end
484
485
485 def mylogger
486 def mylogger
486 Rails.logger
487 Rails.logger
487 end
488 end
488 end
489 end
@@ -1,704 +1,720
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class MailerTest < ActiveSupport::TestCase
20 class MailerTest < ActiveSupport::TestCase
21 include Redmine::I18n
21 include Redmine::I18n
22 include ActionDispatch::Assertions::SelectorAssertions
22 include ActionDispatch::Assertions::SelectorAssertions
23 fixtures :projects, :enabled_modules, :issues, :users, :members,
23 fixtures :projects, :enabled_modules, :issues, :users, :members,
24 :member_roles, :roles, :documents, :attachments, :news,
24 :member_roles, :roles, :documents, :attachments, :news,
25 :tokens, :journals, :journal_details, :changesets,
25 :tokens, :journals, :journal_details, :changesets,
26 :trackers, :projects_trackers,
26 :trackers, :projects_trackers,
27 :issue_statuses, :enumerations, :messages, :boards, :repositories,
27 :issue_statuses, :enumerations, :messages, :boards, :repositories,
28 :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions,
28 :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions,
29 :versions,
29 :versions,
30 :comments
30 :comments
31
31
32 def setup
32 def setup
33 ActionMailer::Base.deliveries.clear
33 ActionMailer::Base.deliveries.clear
34 Setting.host_name = 'mydomain.foo'
34 Setting.host_name = 'mydomain.foo'
35 Setting.protocol = 'http'
35 Setting.protocol = 'http'
36 Setting.plain_text_mail = '0'
36 Setting.plain_text_mail = '0'
37 end
37 end
38
38
39 def test_generated_links_in_emails
39 def test_generated_links_in_emails
40 Setting.default_language = 'en'
40 Setting.default_language = 'en'
41 Setting.host_name = 'mydomain.foo'
41 Setting.host_name = 'mydomain.foo'
42 Setting.protocol = 'https'
42 Setting.protocol = 'https'
43
43
44 journal = Journal.find(3)
44 journal = Journal.find(3)
45 assert Mailer.deliver_issue_edit(journal)
45 assert Mailer.deliver_issue_edit(journal)
46
46
47 mail = last_email
47 mail = last_email
48 assert_not_nil mail
48 assert_not_nil mail
49
49
50 assert_select_email do
50 assert_select_email do
51 # link to the main ticket
51 # link to the main ticket
52 assert_select 'a[href=?]',
52 assert_select 'a[href=?]',
53 'https://mydomain.foo/issues/2#change-3',
53 'https://mydomain.foo/issues/2#change-3',
54 :text => 'Feature request #2: Add ingredients categories'
54 :text => 'Feature request #2: Add ingredients categories'
55 # link to a referenced ticket
55 # link to a referenced ticket
56 assert_select 'a[href=?][title=?]',
56 assert_select 'a[href=?][title=?]',
57 'https://mydomain.foo/issues/1',
57 'https://mydomain.foo/issues/1',
58 'Can&#x27;t print recipes (New)',
58 'Can&#x27;t print recipes (New)',
59 :text => '#1'
59 :text => '#1'
60 # link to a changeset
60 # link to a changeset
61 assert_select 'a[href=?][title=?]',
61 assert_select 'a[href=?][title=?]',
62 'https://mydomain.foo/projects/ecookbook/repository/revisions/2',
62 'https://mydomain.foo/projects/ecookbook/repository/revisions/2',
63 'This commit fixes #1, #2 and references #1 &amp; #3',
63 'This commit fixes #1, #2 and references #1 &amp; #3',
64 :text => 'r2'
64 :text => 'r2'
65 # link to a description diff
65 # link to a description diff
66 assert_select 'a[href=?][title=?]',
66 assert_select 'a[href=?][title=?]',
67 'https://mydomain.foo/journals/diff/3?detail_id=4',
67 'https://mydomain.foo/journals/diff/3?detail_id=4',
68 'View differences',
68 'View differences',
69 :text => 'diff'
69 :text => 'diff'
70 # link to an attachment
70 # link to an attachment
71 assert_select 'a[href=?]',
71 assert_select 'a[href=?]',
72 'https://mydomain.foo/attachments/download/4/source.rb',
72 'https://mydomain.foo/attachments/download/4/source.rb',
73 :text => 'source.rb'
73 :text => 'source.rb'
74 end
74 end
75 end
75 end
76
76
77 def test_generated_links_with_prefix
77 def test_generated_links_with_prefix
78 Setting.default_language = 'en'
78 Setting.default_language = 'en'
79 relative_url_root = Redmine::Utils.relative_url_root
79 relative_url_root = Redmine::Utils.relative_url_root
80 Setting.host_name = 'mydomain.foo/rdm'
80 Setting.host_name = 'mydomain.foo/rdm'
81 Setting.protocol = 'http'
81 Setting.protocol = 'http'
82
82
83 journal = Journal.find(3)
83 journal = Journal.find(3)
84 assert Mailer.deliver_issue_edit(journal)
84 assert Mailer.deliver_issue_edit(journal)
85
85
86 mail = last_email
86 mail = last_email
87 assert_not_nil mail
87 assert_not_nil mail
88
88
89 assert_select_email do
89 assert_select_email do
90 # link to the main ticket
90 # link to the main ticket
91 assert_select 'a[href=?]',
91 assert_select 'a[href=?]',
92 'http://mydomain.foo/rdm/issues/2#change-3',
92 'http://mydomain.foo/rdm/issues/2#change-3',
93 :text => 'Feature request #2: Add ingredients categories'
93 :text => 'Feature request #2: Add ingredients categories'
94 # link to a referenced ticket
94 # link to a referenced ticket
95 assert_select 'a[href=?][title=?]',
95 assert_select 'a[href=?][title=?]',
96 'http://mydomain.foo/rdm/issues/1',
96 'http://mydomain.foo/rdm/issues/1',
97 'Can&#x27;t print recipes (New)',
97 'Can&#x27;t print recipes (New)',
98 :text => '#1'
98 :text => '#1'
99 # link to a changeset
99 # link to a changeset
100 assert_select 'a[href=?][title=?]',
100 assert_select 'a[href=?][title=?]',
101 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
101 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
102 'This commit fixes #1, #2 and references #1 &amp; #3',
102 'This commit fixes #1, #2 and references #1 &amp; #3',
103 :text => 'r2'
103 :text => 'r2'
104 # link to a description diff
104 # link to a description diff
105 assert_select 'a[href=?][title=?]',
105 assert_select 'a[href=?][title=?]',
106 'http://mydomain.foo/rdm/journals/diff/3?detail_id=4',
106 'http://mydomain.foo/rdm/journals/diff/3?detail_id=4',
107 'View differences',
107 'View differences',
108 :text => 'diff'
108 :text => 'diff'
109 # link to an attachment
109 # link to an attachment
110 assert_select 'a[href=?]',
110 assert_select 'a[href=?]',
111 'http://mydomain.foo/rdm/attachments/download/4/source.rb',
111 'http://mydomain.foo/rdm/attachments/download/4/source.rb',
112 :text => 'source.rb'
112 :text => 'source.rb'
113 end
113 end
114 end
114 end
115
115
116 def test_generated_links_with_prefix_and_no_relative_url_root
116 def test_generated_links_with_prefix_and_no_relative_url_root
117 Setting.default_language = 'en'
117 Setting.default_language = 'en'
118 relative_url_root = Redmine::Utils.relative_url_root
118 relative_url_root = Redmine::Utils.relative_url_root
119 Setting.host_name = 'mydomain.foo/rdm'
119 Setting.host_name = 'mydomain.foo/rdm'
120 Setting.protocol = 'http'
120 Setting.protocol = 'http'
121 Redmine::Utils.relative_url_root = nil
121 Redmine::Utils.relative_url_root = nil
122
122
123 journal = Journal.find(3)
123 journal = Journal.find(3)
124 assert Mailer.deliver_issue_edit(journal)
124 assert Mailer.deliver_issue_edit(journal)
125
125
126 mail = last_email
126 mail = last_email
127 assert_not_nil mail
127 assert_not_nil mail
128
128
129 assert_select_email do
129 assert_select_email do
130 # link to the main ticket
130 # link to the main ticket
131 assert_select 'a[href=?]',
131 assert_select 'a[href=?]',
132 'http://mydomain.foo/rdm/issues/2#change-3',
132 'http://mydomain.foo/rdm/issues/2#change-3',
133 :text => 'Feature request #2: Add ingredients categories'
133 :text => 'Feature request #2: Add ingredients categories'
134 # link to a referenced ticket
134 # link to a referenced ticket
135 assert_select 'a[href=?][title=?]',
135 assert_select 'a[href=?][title=?]',
136 'http://mydomain.foo/rdm/issues/1',
136 'http://mydomain.foo/rdm/issues/1',
137 'Can&#x27;t print recipes (New)',
137 'Can&#x27;t print recipes (New)',
138 :text => '#1'
138 :text => '#1'
139 # link to a changeset
139 # link to a changeset
140 assert_select 'a[href=?][title=?]',
140 assert_select 'a[href=?][title=?]',
141 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
141 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
142 'This commit fixes #1, #2 and references #1 &amp; #3',
142 'This commit fixes #1, #2 and references #1 &amp; #3',
143 :text => 'r2'
143 :text => 'r2'
144 # link to a description diff
144 # link to a description diff
145 assert_select 'a[href=?][title=?]',
145 assert_select 'a[href=?][title=?]',
146 'http://mydomain.foo/rdm/journals/diff/3?detail_id=4',
146 'http://mydomain.foo/rdm/journals/diff/3?detail_id=4',
147 'View differences',
147 'View differences',
148 :text => 'diff'
148 :text => 'diff'
149 # link to an attachment
149 # link to an attachment
150 assert_select 'a[href=?]',
150 assert_select 'a[href=?]',
151 'http://mydomain.foo/rdm/attachments/download/4/source.rb',
151 'http://mydomain.foo/rdm/attachments/download/4/source.rb',
152 :text => 'source.rb'
152 :text => 'source.rb'
153 end
153 end
154 ensure
154 ensure
155 # restore it
155 # restore it
156 Redmine::Utils.relative_url_root = relative_url_root
156 Redmine::Utils.relative_url_root = relative_url_root
157 end
157 end
158
158
159 def test_email_headers
159 def test_email_headers
160 issue = Issue.find(1)
160 issue = Issue.find(1)
161 Mailer.deliver_issue_add(issue)
161 Mailer.deliver_issue_add(issue)
162 mail = last_email
162 mail = last_email
163 assert_not_nil mail
163 assert_not_nil mail
164 assert_equal 'OOF', mail.header['X-Auto-Response-Suppress'].to_s
164 assert_equal 'OOF', mail.header['X-Auto-Response-Suppress'].to_s
165 assert_equal 'auto-generated', mail.header['Auto-Submitted'].to_s
165 assert_equal 'auto-generated', mail.header['Auto-Submitted'].to_s
166 assert_equal '<redmine.example.net>', mail.header['List-Id'].to_s
166 assert_equal '<redmine.example.net>', mail.header['List-Id'].to_s
167 end
167 end
168
168
169 def test_email_headers_should_include_sender
169 def test_email_headers_should_include_sender
170 issue = Issue.find(1)
170 issue = Issue.find(1)
171 Mailer.deliver_issue_add(issue)
171 Mailer.deliver_issue_add(issue)
172 mail = last_email
172 mail = last_email
173 assert_equal issue.author.login, mail.header['X-Redmine-Sender'].to_s
173 assert_equal issue.author.login, mail.header['X-Redmine-Sender'].to_s
174 end
174 end
175
175
176 def test_plain_text_mail
176 def test_plain_text_mail
177 Setting.plain_text_mail = 1
177 Setting.plain_text_mail = 1
178 journal = Journal.find(2)
178 journal = Journal.find(2)
179 Mailer.deliver_issue_edit(journal)
179 Mailer.deliver_issue_edit(journal)
180 mail = last_email
180 mail = last_email
181 assert_equal "text/plain; charset=UTF-8", mail.content_type
181 assert_equal "text/plain; charset=UTF-8", mail.content_type
182 assert_equal 0, mail.parts.size
182 assert_equal 0, mail.parts.size
183 assert !mail.encoded.include?('href')
183 assert !mail.encoded.include?('href')
184 end
184 end
185
185
186 def test_html_mail
186 def test_html_mail
187 Setting.plain_text_mail = 0
187 Setting.plain_text_mail = 0
188 journal = Journal.find(2)
188 journal = Journal.find(2)
189 Mailer.deliver_issue_edit(journal)
189 Mailer.deliver_issue_edit(journal)
190 mail = last_email
190 mail = last_email
191 assert_equal 2, mail.parts.size
191 assert_equal 2, mail.parts.size
192 assert mail.encoded.include?('href')
192 assert mail.encoded.include?('href')
193 end
193 end
194
194
195 def test_from_header
195 def test_from_header
196 with_settings :mail_from => 'redmine@example.net' do
196 with_settings :mail_from => 'redmine@example.net' do
197 Mailer.test_email(User.find(1)).deliver
197 Mailer.test_email(User.find(1)).deliver
198 end
198 end
199 mail = last_email
199 mail = last_email
200 assert_equal 'redmine@example.net', mail.from_addrs.first
200 assert_equal 'redmine@example.net', mail.from_addrs.first
201 end
201 end
202
202
203 def test_from_header_with_phrase
203 def test_from_header_with_phrase
204 with_settings :mail_from => 'Redmine app <redmine@example.net>' do
204 with_settings :mail_from => 'Redmine app <redmine@example.net>' do
205 Mailer.test_email(User.find(1)).deliver
205 Mailer.test_email(User.find(1)).deliver
206 end
206 end
207 mail = last_email
207 mail = last_email
208 assert_equal 'redmine@example.net', mail.from_addrs.first
208 assert_equal 'redmine@example.net', mail.from_addrs.first
209 assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s
209 assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s
210 end
210 end
211
211
212 def test_should_not_send_email_without_recipient
212 def test_should_not_send_email_without_recipient
213 news = News.first
213 news = News.first
214 user = news.author
214 user = news.author
215 # Remove members except news author
215 # Remove members except news author
216 news.project.memberships.each {|m| m.destroy unless m.user == user}
216 news.project.memberships.each {|m| m.destroy unless m.user == user}
217
217
218 user.pref.no_self_notified = false
218 user.pref.no_self_notified = false
219 user.pref.save
219 user.pref.save
220 User.current = user
220 User.current = user
221 Mailer.news_added(news.reload).deliver
221 Mailer.news_added(news.reload).deliver
222 assert_equal 1, last_email.bcc.size
222 assert_equal 1, last_email.bcc.size
223
223
224 # nobody to notify
224 # nobody to notify
225 user.pref.no_self_notified = true
225 user.pref.no_self_notified = true
226 user.pref.save
226 user.pref.save
227 User.current = user
227 User.current = user
228 ActionMailer::Base.deliveries.clear
228 ActionMailer::Base.deliveries.clear
229 Mailer.news_added(news.reload).deliver
229 Mailer.news_added(news.reload).deliver
230 assert ActionMailer::Base.deliveries.empty?
230 assert ActionMailer::Base.deliveries.empty?
231 end
231 end
232
232
233 def test_issue_add_message_id
233 def test_issue_add_message_id
234 issue = Issue.find(2)
234 issue = Issue.find(2)
235 Mailer.deliver_issue_add(issue)
235 Mailer.deliver_issue_add(issue)
236 mail = last_email
236 mail = last_email
237 assert_match /^redmine\.issue-2\.20060719190421\.[a-f0-9]+@example\.net/, mail.message_id
237 assert_match /^redmine\.issue-2\.20060719190421\.[a-f0-9]+@example\.net/, mail.message_id
238 assert_include "redmine.issue-2.20060719190421@example.net", mail.references
238 assert_include "redmine.issue-2.20060719190421@example.net", mail.references
239 end
239 end
240
240
241 def test_issue_edit_message_id
241 def test_issue_edit_message_id
242 journal = Journal.find(3)
242 journal = Journal.find(3)
243 journal.issue = Issue.find(2)
243 journal.issue = Issue.find(2)
244
244
245 Mailer.deliver_issue_edit(journal)
245 Mailer.deliver_issue_edit(journal)
246 mail = last_email
246 mail = last_email
247 assert_match /^redmine\.journal-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id
247 assert_match /^redmine\.journal-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id
248 assert_include "redmine.issue-2.20060719190421@example.net", mail.references
248 assert_include "redmine.issue-2.20060719190421@example.net", mail.references
249 assert_select_email do
249 assert_select_email do
250 # link to the update
250 # link to the update
251 assert_select "a[href=?]",
251 assert_select "a[href=?]",
252 "http://mydomain.foo/issues/#{journal.journalized_id}#change-#{journal.id}"
252 "http://mydomain.foo/issues/#{journal.journalized_id}#change-#{journal.id}"
253 end
253 end
254 end
254 end
255
255
256 def test_message_posted_message_id
256 def test_message_posted_message_id
257 message = Message.find(1)
257 message = Message.find(1)
258 Mailer.message_posted(message).deliver
258 Mailer.message_posted(message).deliver
259 mail = last_email
259 mail = last_email
260 assert_match /^redmine\.message-1\.\d+\.[a-f0-9]+@example\.net/, mail.message_id
260 assert_match /^redmine\.message-1\.\d+\.[a-f0-9]+@example\.net/, mail.message_id
261 assert_include "redmine.message-1.20070512151532@example.net", mail.references
261 assert_include "redmine.message-1.20070512151532@example.net", mail.references
262 assert_select_email do
262 assert_select_email do
263 # link to the message
263 # link to the message
264 assert_select "a[href=?]",
264 assert_select "a[href=?]",
265 "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.id}",
265 "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.id}",
266 :text => message.subject
266 :text => message.subject
267 end
267 end
268 end
268 end
269
269
270 def test_reply_posted_message_id
270 def test_reply_posted_message_id
271 message = Message.find(3)
271 message = Message.find(3)
272 Mailer.message_posted(message).deliver
272 Mailer.message_posted(message).deliver
273 mail = last_email
273 mail = last_email
274 assert_match /^redmine\.message-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id
274 assert_match /^redmine\.message-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id
275 assert_include "redmine.message-1.20070512151532@example.net", mail.references
275 assert_include "redmine.message-1.20070512151532@example.net", mail.references
276 assert_select_email do
276 assert_select_email do
277 # link to the reply
277 # link to the reply
278 assert_select "a[href=?]",
278 assert_select "a[href=?]",
279 "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}",
279 "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}",
280 :text => message.subject
280 :text => message.subject
281 end
281 end
282 end
282 end
283
283
284 test "#issue_add should notify project members" do
284 test "#issue_add should notify project members" do
285 issue = Issue.find(1)
285 issue = Issue.find(1)
286 assert Mailer.deliver_issue_add(issue)
286 assert Mailer.deliver_issue_add(issue)
287 assert last_email.bcc.include?('dlopper@somenet.foo')
287 assert last_email.bcc.include?('dlopper@somenet.foo')
288 end
288 end
289
289
290 test "#issue_add should not notify project members that are not allow to view the issue" do
290 test "#issue_add should not notify project members that are not allow to view the issue" do
291 issue = Issue.find(1)
291 issue = Issue.find(1)
292 Role.find(2).remove_permission!(:view_issues)
292 Role.find(2).remove_permission!(:view_issues)
293 assert Mailer.deliver_issue_add(issue)
293 assert Mailer.deliver_issue_add(issue)
294 assert !last_email.bcc.include?('dlopper@somenet.foo')
294 assert !last_email.bcc.include?('dlopper@somenet.foo')
295 end
295 end
296
296
297 test "#issue_add should notify issue watchers" do
297 test "#issue_add should notify issue watchers" do
298 issue = Issue.find(1)
298 issue = Issue.find(1)
299 user = User.find(9)
299 user = User.find(9)
300 # minimal email notification options
300 # minimal email notification options
301 user.pref.no_self_notified = '1'
301 user.pref.no_self_notified = '1'
302 user.pref.save
302 user.pref.save
303 user.mail_notification = false
303 user.mail_notification = false
304 user.save
304 user.save
305
305
306 Watcher.create!(:watchable => issue, :user => user)
306 Watcher.create!(:watchable => issue, :user => user)
307 assert Mailer.deliver_issue_add(issue)
307 assert Mailer.deliver_issue_add(issue)
308 assert last_email.bcc.include?(user.mail)
308 assert last_email.bcc.include?(user.mail)
309 end
309 end
310
310
311 test "#issue_add should not notify watchers not allowed to view the issue" do
311 test "#issue_add should not notify watchers not allowed to view the issue" do
312 issue = Issue.find(1)
312 issue = Issue.find(1)
313 user = User.find(9)
313 user = User.find(9)
314 Watcher.create!(:watchable => issue, :user => user)
314 Watcher.create!(:watchable => issue, :user => user)
315 Role.non_member.remove_permission!(:view_issues)
315 Role.non_member.remove_permission!(:view_issues)
316 assert Mailer.deliver_issue_add(issue)
316 assert Mailer.deliver_issue_add(issue)
317 assert !last_email.bcc.include?(user.mail)
317 assert !last_email.bcc.include?(user.mail)
318 end
318 end
319
319
320 # test mailer methods for each language
320 # test mailer methods for each language
321 def test_issue_add
321 def test_issue_add
322 issue = Issue.find(1)
322 issue = Issue.find(1)
323 valid_languages.each do |lang|
323 valid_languages.each do |lang|
324 Setting.default_language = lang.to_s
324 Setting.default_language = lang.to_s
325 assert Mailer.deliver_issue_add(issue)
325 assert Mailer.deliver_issue_add(issue)
326 end
326 end
327 end
327 end
328
328
329 def test_issue_edit
329 def test_issue_edit
330 journal = Journal.find(1)
330 journal = Journal.find(1)
331 valid_languages.each do |lang|
331 valid_languages.each do |lang|
332 Setting.default_language = lang.to_s
332 Setting.default_language = lang.to_s
333 assert Mailer.deliver_issue_edit(journal)
333 assert Mailer.deliver_issue_edit(journal)
334 end
334 end
335 end
335 end
336
336
337 def test_issue_edit_should_send_private_notes_to_users_with_permission_only
337 def test_issue_edit_should_send_private_notes_to_users_with_permission_only
338 journal = Journal.find(1)
338 journal = Journal.find(1)
339 journal.private_notes = true
339 journal.private_notes = true
340 journal.save!
340 journal.save!
341
341
342 Role.find(2).add_permission! :view_private_notes
342 Role.find(2).add_permission! :view_private_notes
343 Mailer.deliver_issue_edit(journal)
343 Mailer.deliver_issue_edit(journal)
344 assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort
344 assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort
345
345
346 Role.find(2).remove_permission! :view_private_notes
346 Role.find(2).remove_permission! :view_private_notes
347 Mailer.deliver_issue_edit(journal)
347 Mailer.deliver_issue_edit(journal)
348 assert_equal %w(jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort
348 assert_equal %w(jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort
349 end
349 end
350
350
351 def test_issue_edit_should_send_private_notes_to_watchers_with_permission_only
351 def test_issue_edit_should_send_private_notes_to_watchers_with_permission_only
352 Issue.find(1).set_watcher(User.find_by_login('someone'))
352 Issue.find(1).set_watcher(User.find_by_login('someone'))
353 journal = Journal.find(1)
353 journal = Journal.find(1)
354 journal.private_notes = true
354 journal.private_notes = true
355 journal.save!
355 journal.save!
356
356
357 Role.non_member.add_permission! :view_private_notes
357 Role.non_member.add_permission! :view_private_notes
358 Mailer.deliver_issue_edit(journal)
358 Mailer.deliver_issue_edit(journal)
359 assert_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort
359 assert_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort
360
360
361 Role.non_member.remove_permission! :view_private_notes
361 Role.non_member.remove_permission! :view_private_notes
362 Mailer.deliver_issue_edit(journal)
362 Mailer.deliver_issue_edit(journal)
363 assert_not_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort
363 assert_not_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort
364 end
364 end
365
365
366 def test_issue_edit_should_mark_private_notes
366 def test_issue_edit_should_mark_private_notes
367 journal = Journal.find(2)
367 journal = Journal.find(2)
368 journal.private_notes = true
368 journal.private_notes = true
369 journal.save!
369 journal.save!
370
370
371 with_settings :default_language => 'en' do
371 with_settings :default_language => 'en' do
372 Mailer.deliver_issue_edit(journal)
372 Mailer.deliver_issue_edit(journal)
373 end
373 end
374 assert_mail_body_match '(Private notes)', last_email
374 assert_mail_body_match '(Private notes)', last_email
375 end
375 end
376
376
377 def test_issue_edit_with_relation_should_notify_users_who_can_see_the_related_issue
378 issue = Issue.generate!
379 private_issue = Issue.generate!(:is_private => true)
380 IssueRelation.create!(:issue_from => issue, :issue_to => private_issue, :relation_type => 'relates')
381 issue.reload
382 assert_equal 1, issue.journals.size
383 journal = issue.journals.first
384 ActionMailer::Base.deliveries.clear
385
386 Mailer.deliver_issue_edit(journal)
387 last_email.bcc.each do |email|
388 user = User.find_by_mail(email)
389 assert private_issue.visible?(user), "Issue was not visible to #{user}"
390 end
391 end
392
377 def test_document_added
393 def test_document_added
378 document = Document.find(1)
394 document = Document.find(1)
379 valid_languages.each do |lang|
395 valid_languages.each do |lang|
380 Setting.default_language = lang.to_s
396 Setting.default_language = lang.to_s
381 assert Mailer.document_added(document).deliver
397 assert Mailer.document_added(document).deliver
382 end
398 end
383 end
399 end
384
400
385 def test_attachments_added
401 def test_attachments_added
386 attachements = [ Attachment.find_by_container_type('Document') ]
402 attachements = [ Attachment.find_by_container_type('Document') ]
387 valid_languages.each do |lang|
403 valid_languages.each do |lang|
388 Setting.default_language = lang.to_s
404 Setting.default_language = lang.to_s
389 assert Mailer.attachments_added(attachements).deliver
405 assert Mailer.attachments_added(attachements).deliver
390 end
406 end
391 end
407 end
392
408
393 def test_version_file_added
409 def test_version_file_added
394 attachements = [ Attachment.find_by_container_type('Version') ]
410 attachements = [ Attachment.find_by_container_type('Version') ]
395 assert Mailer.attachments_added(attachements).deliver
411 assert Mailer.attachments_added(attachements).deliver
396 assert_not_nil last_email.bcc
412 assert_not_nil last_email.bcc
397 assert last_email.bcc.any?
413 assert last_email.bcc.any?
398 assert_select_email do
414 assert_select_email do
399 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files"
415 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files"
400 end
416 end
401 end
417 end
402
418
403 def test_project_file_added
419 def test_project_file_added
404 attachements = [ Attachment.find_by_container_type('Project') ]
420 attachements = [ Attachment.find_by_container_type('Project') ]
405 assert Mailer.attachments_added(attachements).deliver
421 assert Mailer.attachments_added(attachements).deliver
406 assert_not_nil last_email.bcc
422 assert_not_nil last_email.bcc
407 assert last_email.bcc.any?
423 assert last_email.bcc.any?
408 assert_select_email do
424 assert_select_email do
409 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files"
425 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files"
410 end
426 end
411 end
427 end
412
428
413 def test_news_added
429 def test_news_added
414 news = News.first
430 news = News.first
415 valid_languages.each do |lang|
431 valid_languages.each do |lang|
416 Setting.default_language = lang.to_s
432 Setting.default_language = lang.to_s
417 assert Mailer.news_added(news).deliver
433 assert Mailer.news_added(news).deliver
418 end
434 end
419 end
435 end
420
436
421 def test_news_comment_added
437 def test_news_comment_added
422 comment = Comment.find(2)
438 comment = Comment.find(2)
423 valid_languages.each do |lang|
439 valid_languages.each do |lang|
424 Setting.default_language = lang.to_s
440 Setting.default_language = lang.to_s
425 assert Mailer.news_comment_added(comment).deliver
441 assert Mailer.news_comment_added(comment).deliver
426 end
442 end
427 end
443 end
428
444
429 def test_message_posted
445 def test_message_posted
430 message = Message.first
446 message = Message.first
431 recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}
447 recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}
432 recipients = recipients.compact.uniq
448 recipients = recipients.compact.uniq
433 valid_languages.each do |lang|
449 valid_languages.each do |lang|
434 Setting.default_language = lang.to_s
450 Setting.default_language = lang.to_s
435 assert Mailer.message_posted(message).deliver
451 assert Mailer.message_posted(message).deliver
436 end
452 end
437 end
453 end
438
454
439 def test_wiki_content_added
455 def test_wiki_content_added
440 content = WikiContent.find(1)
456 content = WikiContent.find(1)
441 valid_languages.each do |lang|
457 valid_languages.each do |lang|
442 Setting.default_language = lang.to_s
458 Setting.default_language = lang.to_s
443 assert_difference 'ActionMailer::Base.deliveries.size' do
459 assert_difference 'ActionMailer::Base.deliveries.size' do
444 assert Mailer.wiki_content_added(content).deliver
460 assert Mailer.wiki_content_added(content).deliver
445 assert_select_email do
461 assert_select_email do
446 assert_select 'a[href=?]',
462 assert_select 'a[href=?]',
447 'http://mydomain.foo/projects/ecookbook/wiki/CookBook_documentation',
463 'http://mydomain.foo/projects/ecookbook/wiki/CookBook_documentation',
448 :text => 'CookBook documentation'
464 :text => 'CookBook documentation'
449 end
465 end
450 end
466 end
451 end
467 end
452 end
468 end
453
469
454 def test_wiki_content_updated
470 def test_wiki_content_updated
455 content = WikiContent.find(1)
471 content = WikiContent.find(1)
456 valid_languages.each do |lang|
472 valid_languages.each do |lang|
457 Setting.default_language = lang.to_s
473 Setting.default_language = lang.to_s
458 assert_difference 'ActionMailer::Base.deliveries.size' do
474 assert_difference 'ActionMailer::Base.deliveries.size' do
459 assert Mailer.wiki_content_updated(content).deliver
475 assert Mailer.wiki_content_updated(content).deliver
460 assert_select_email do
476 assert_select_email do
461 assert_select 'a[href=?]',
477 assert_select 'a[href=?]',
462 'http://mydomain.foo/projects/ecookbook/wiki/CookBook_documentation',
478 'http://mydomain.foo/projects/ecookbook/wiki/CookBook_documentation',
463 :text => 'CookBook documentation'
479 :text => 'CookBook documentation'
464 end
480 end
465 end
481 end
466 end
482 end
467 end
483 end
468
484
469 def test_account_information
485 def test_account_information
470 user = User.find(2)
486 user = User.find(2)
471 valid_languages.each do |lang|
487 valid_languages.each do |lang|
472 user.update_attribute :language, lang.to_s
488 user.update_attribute :language, lang.to_s
473 user.reload
489 user.reload
474 assert Mailer.account_information(user, 'pAsswORd').deliver
490 assert Mailer.account_information(user, 'pAsswORd').deliver
475 end
491 end
476 end
492 end
477
493
478 def test_lost_password
494 def test_lost_password
479 token = Token.find(2)
495 token = Token.find(2)
480 valid_languages.each do |lang|
496 valid_languages.each do |lang|
481 token.user.update_attribute :language, lang.to_s
497 token.user.update_attribute :language, lang.to_s
482 token.reload
498 token.reload
483 assert Mailer.lost_password(token).deliver
499 assert Mailer.lost_password(token).deliver
484 end
500 end
485 end
501 end
486
502
487 def test_register
503 def test_register
488 token = Token.find(1)
504 token = Token.find(1)
489 Setting.host_name = 'redmine.foo'
505 Setting.host_name = 'redmine.foo'
490 Setting.protocol = 'https'
506 Setting.protocol = 'https'
491
507
492 valid_languages.each do |lang|
508 valid_languages.each do |lang|
493 token.user.update_attribute :language, lang.to_s
509 token.user.update_attribute :language, lang.to_s
494 token.reload
510 token.reload
495 ActionMailer::Base.deliveries.clear
511 ActionMailer::Base.deliveries.clear
496 assert Mailer.register(token).deliver
512 assert Mailer.register(token).deliver
497 mail = last_email
513 mail = last_email
498 assert_select_email do
514 assert_select_email do
499 assert_select "a[href=?]",
515 assert_select "a[href=?]",
500 "https://redmine.foo/account/activate?token=#{token.value}",
516 "https://redmine.foo/account/activate?token=#{token.value}",
501 :text => "https://redmine.foo/account/activate?token=#{token.value}"
517 :text => "https://redmine.foo/account/activate?token=#{token.value}"
502 end
518 end
503 end
519 end
504 end
520 end
505
521
506 def test_test
522 def test_test
507 user = User.find(1)
523 user = User.find(1)
508 valid_languages.each do |lang|
524 valid_languages.each do |lang|
509 user.update_attribute :language, lang.to_s
525 user.update_attribute :language, lang.to_s
510 assert Mailer.test_email(user).deliver
526 assert Mailer.test_email(user).deliver
511 end
527 end
512 end
528 end
513
529
514 def test_reminders
530 def test_reminders
515 Mailer.reminders(:days => 42)
531 Mailer.reminders(:days => 42)
516 assert_equal 1, ActionMailer::Base.deliveries.size
532 assert_equal 1, ActionMailer::Base.deliveries.size
517 mail = last_email
533 mail = last_email
518 assert mail.bcc.include?('dlopper@somenet.foo')
534 assert mail.bcc.include?('dlopper@somenet.foo')
519 assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail
535 assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail
520 assert_equal '1 issue(s) due in the next 42 days', mail.subject
536 assert_equal '1 issue(s) due in the next 42 days', mail.subject
521 end
537 end
522
538
523 def test_reminders_should_not_include_closed_issues
539 def test_reminders_should_not_include_closed_issues
524 with_settings :default_language => 'en' do
540 with_settings :default_language => 'en' do
525 Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 5,
541 Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 5,
526 :subject => 'Closed issue', :assigned_to_id => 3,
542 :subject => 'Closed issue', :assigned_to_id => 3,
527 :due_date => 5.days.from_now,
543 :due_date => 5.days.from_now,
528 :author_id => 2)
544 :author_id => 2)
529 ActionMailer::Base.deliveries.clear
545 ActionMailer::Base.deliveries.clear
530
546
531 Mailer.reminders(:days => 42)
547 Mailer.reminders(:days => 42)
532 assert_equal 1, ActionMailer::Base.deliveries.size
548 assert_equal 1, ActionMailer::Base.deliveries.size
533 mail = last_email
549 mail = last_email
534 assert mail.bcc.include?('dlopper@somenet.foo')
550 assert mail.bcc.include?('dlopper@somenet.foo')
535 assert_mail_body_no_match 'Closed issue', mail
551 assert_mail_body_no_match 'Closed issue', mail
536 end
552 end
537 end
553 end
538
554
539 def test_reminders_for_users
555 def test_reminders_for_users
540 Mailer.reminders(:days => 42, :users => ['5'])
556 Mailer.reminders(:days => 42, :users => ['5'])
541 assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper
557 assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper
542 Mailer.reminders(:days => 42, :users => ['3'])
558 Mailer.reminders(:days => 42, :users => ['3'])
543 assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper
559 assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper
544 mail = last_email
560 mail = last_email
545 assert mail.bcc.include?('dlopper@somenet.foo')
561 assert mail.bcc.include?('dlopper@somenet.foo')
546 assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail
562 assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail
547 end
563 end
548
564
549 def test_reminder_should_include_issues_assigned_to_groups
565 def test_reminder_should_include_issues_assigned_to_groups
550 with_settings :default_language => 'en' do
566 with_settings :default_language => 'en' do
551 group = Group.generate!
567 group = Group.generate!
552 group.users << User.find(2)
568 group.users << User.find(2)
553 group.users << User.find(3)
569 group.users << User.find(3)
554
570
555 Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1,
571 Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1,
556 :subject => 'Assigned to group', :assigned_to => group,
572 :subject => 'Assigned to group', :assigned_to => group,
557 :due_date => 5.days.from_now,
573 :due_date => 5.days.from_now,
558 :author_id => 2)
574 :author_id => 2)
559 ActionMailer::Base.deliveries.clear
575 ActionMailer::Base.deliveries.clear
560
576
561 Mailer.reminders(:days => 7)
577 Mailer.reminders(:days => 7)
562 assert_equal 2, ActionMailer::Base.deliveries.size
578 assert_equal 2, ActionMailer::Base.deliveries.size
563 assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.map(&:bcc).flatten.sort
579 assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.map(&:bcc).flatten.sort
564 ActionMailer::Base.deliveries.each do |mail|
580 ActionMailer::Base.deliveries.each do |mail|
565 assert_mail_body_match 'Assigned to group', mail
581 assert_mail_body_match 'Assigned to group', mail
566 end
582 end
567 end
583 end
568 end
584 end
569
585
570 def test_mailer_should_not_change_locale
586 def test_mailer_should_not_change_locale
571 Setting.default_language = 'en'
587 Setting.default_language = 'en'
572 # Set current language to italian
588 # Set current language to italian
573 set_language_if_valid 'it'
589 set_language_if_valid 'it'
574 # Send an email to a french user
590 # Send an email to a french user
575 user = User.find(1)
591 user = User.find(1)
576 user.language = 'fr'
592 user.language = 'fr'
577 Mailer.account_activated(user).deliver
593 Mailer.account_activated(user).deliver
578 mail = last_email
594 mail = last_email
579 assert_mail_body_match 'Votre compte', mail
595 assert_mail_body_match 'Votre compte', mail
580
596
581 assert_equal :it, current_language
597 assert_equal :it, current_language
582 end
598 end
583
599
584 def test_with_deliveries_off
600 def test_with_deliveries_off
585 Mailer.with_deliveries false do
601 Mailer.with_deliveries false do
586 Mailer.test_email(User.find(1)).deliver
602 Mailer.test_email(User.find(1)).deliver
587 end
603 end
588 assert ActionMailer::Base.deliveries.empty?
604 assert ActionMailer::Base.deliveries.empty?
589 # should restore perform_deliveries
605 # should restore perform_deliveries
590 assert ActionMailer::Base.perform_deliveries
606 assert ActionMailer::Base.perform_deliveries
591 end
607 end
592
608
593 def test_layout_should_include_the_emails_header
609 def test_layout_should_include_the_emails_header
594 with_settings :emails_header => "*Header content*" do
610 with_settings :emails_header => "*Header content*" do
595 with_settings :plain_text_mail => 0 do
611 with_settings :plain_text_mail => 0 do
596 assert Mailer.test_email(User.find(1)).deliver
612 assert Mailer.test_email(User.find(1)).deliver
597 assert_select_email do
613 assert_select_email do
598 assert_select ".header" do
614 assert_select ".header" do
599 assert_select "strong", :text => "Header content"
615 assert_select "strong", :text => "Header content"
600 end
616 end
601 end
617 end
602 end
618 end
603 with_settings :plain_text_mail => 1 do
619 with_settings :plain_text_mail => 1 do
604 assert Mailer.test_email(User.find(1)).deliver
620 assert Mailer.test_email(User.find(1)).deliver
605 mail = last_email
621 mail = last_email
606 assert_not_nil mail
622 assert_not_nil mail
607 assert_include "*Header content*", mail.body.decoded
623 assert_include "*Header content*", mail.body.decoded
608 end
624 end
609 end
625 end
610 end
626 end
611
627
612 def test_layout_should_not_include_empty_emails_header
628 def test_layout_should_not_include_empty_emails_header
613 with_settings :emails_header => "", :plain_text_mail => 0 do
629 with_settings :emails_header => "", :plain_text_mail => 0 do
614 assert Mailer.test_email(User.find(1)).deliver
630 assert Mailer.test_email(User.find(1)).deliver
615 assert_select_email do
631 assert_select_email do
616 assert_select ".header", false
632 assert_select ".header", false
617 end
633 end
618 end
634 end
619 end
635 end
620
636
621 def test_layout_should_include_the_emails_footer
637 def test_layout_should_include_the_emails_footer
622 with_settings :emails_footer => "*Footer content*" do
638 with_settings :emails_footer => "*Footer content*" do
623 with_settings :plain_text_mail => 0 do
639 with_settings :plain_text_mail => 0 do
624 assert Mailer.test_email(User.find(1)).deliver
640 assert Mailer.test_email(User.find(1)).deliver
625 assert_select_email do
641 assert_select_email do
626 assert_select ".footer" do
642 assert_select ".footer" do
627 assert_select "strong", :text => "Footer content"
643 assert_select "strong", :text => "Footer content"
628 end
644 end
629 end
645 end
630 end
646 end
631 with_settings :plain_text_mail => 1 do
647 with_settings :plain_text_mail => 1 do
632 assert Mailer.test_email(User.find(1)).deliver
648 assert Mailer.test_email(User.find(1)).deliver
633 mail = last_email
649 mail = last_email
634 assert_not_nil mail
650 assert_not_nil mail
635 assert_include "\n-- \n", mail.body.decoded
651 assert_include "\n-- \n", mail.body.decoded
636 assert_include "*Footer content*", mail.body.decoded
652 assert_include "*Footer content*", mail.body.decoded
637 end
653 end
638 end
654 end
639 end
655 end
640
656
641 def test_layout_should_not_include_empty_emails_footer
657 def test_layout_should_not_include_empty_emails_footer
642 with_settings :emails_footer => "" do
658 with_settings :emails_footer => "" do
643 with_settings :plain_text_mail => 0 do
659 with_settings :plain_text_mail => 0 do
644 assert Mailer.test_email(User.find(1)).deliver
660 assert Mailer.test_email(User.find(1)).deliver
645 assert_select_email do
661 assert_select_email do
646 assert_select ".footer", false
662 assert_select ".footer", false
647 end
663 end
648 end
664 end
649 with_settings :plain_text_mail => 1 do
665 with_settings :plain_text_mail => 1 do
650 assert Mailer.test_email(User.find(1)).deliver
666 assert Mailer.test_email(User.find(1)).deliver
651 mail = last_email
667 mail = last_email
652 assert_not_nil mail
668 assert_not_nil mail
653 assert_not_include "\n-- \n", mail.body.decoded
669 assert_not_include "\n-- \n", mail.body.decoded
654 end
670 end
655 end
671 end
656 end
672 end
657
673
658 def test_should_escape_html_templates_only
674 def test_should_escape_html_templates_only
659 Issue.generate!(:project_id => 1, :tracker_id => 1, :subject => 'Subject with a <tag>')
675 Issue.generate!(:project_id => 1, :tracker_id => 1, :subject => 'Subject with a <tag>')
660 mail = last_email
676 mail = last_email
661 assert_equal 2, mail.parts.size
677 assert_equal 2, mail.parts.size
662 assert_include '<tag>', text_part.body.encoded
678 assert_include '<tag>', text_part.body.encoded
663 assert_include '&lt;tag&gt;', html_part.body.encoded
679 assert_include '&lt;tag&gt;', html_part.body.encoded
664 end
680 end
665
681
666 def test_should_raise_delivery_errors_when_raise_delivery_errors_is_true
682 def test_should_raise_delivery_errors_when_raise_delivery_errors_is_true
667 mail = Mailer.test_email(User.find(1))
683 mail = Mailer.test_email(User.find(1))
668 mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error"))
684 mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error"))
669
685
670 ActionMailer::Base.raise_delivery_errors = true
686 ActionMailer::Base.raise_delivery_errors = true
671 assert_raise Exception, "delivery error" do
687 assert_raise Exception, "delivery error" do
672 mail.deliver
688 mail.deliver
673 end
689 end
674 ensure
690 ensure
675 ActionMailer::Base.raise_delivery_errors = false
691 ActionMailer::Base.raise_delivery_errors = false
676 end
692 end
677
693
678 def test_should_log_delivery_errors_when_raise_delivery_errors_is_false
694 def test_should_log_delivery_errors_when_raise_delivery_errors_is_false
679 mail = Mailer.test_email(User.find(1))
695 mail = Mailer.test_email(User.find(1))
680 mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error"))
696 mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error"))
681
697
682 Rails.logger.expects(:error).with("Email delivery error: delivery error")
698 Rails.logger.expects(:error).with("Email delivery error: delivery error")
683 ActionMailer::Base.raise_delivery_errors = false
699 ActionMailer::Base.raise_delivery_errors = false
684 assert_nothing_raised do
700 assert_nothing_raised do
685 mail.deliver
701 mail.deliver
686 end
702 end
687 end
703 end
688
704
689 private
705 private
690
706
691 def last_email
707 def last_email
692 mail = ActionMailer::Base.deliveries.last
708 mail = ActionMailer::Base.deliveries.last
693 assert_not_nil mail
709 assert_not_nil mail
694 mail
710 mail
695 end
711 end
696
712
697 def text_part
713 def text_part
698 last_email.parts.detect {|part| part.content_type.include?('text/plain')}
714 last_email.parts.detect {|part| part.content_type.include?('text/plain')}
699 end
715 end
700
716
701 def html_part
717 def html_part
702 last_email.parts.detect {|part| part.content_type.include?('text/html')}
718 last_email.parts.detect {|part| part.content_type.include?('text/html')}
703 end
719 end
704 end
720 end
General Comments 0
You need to be logged in to leave comments. Login now