##// END OF EJS Templates
Ignore emails received from the application emission address to avoid hell cycles (#4139)....
Jean-Philippe Lang -
r2908:cc684803bac9
parent child
Show More
@@ -0,0 +1,19
1 Return-Path: <redmine@somenet.foo>
2 Received: from osiris ([127.0.0.1])
3 by OSIRIS
4 with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200
5 Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris>
6 From: "John Doe" <Redmine@example.net>
7 To: <redmine@somenet.foo>
8 Subject: Ticket with the Redmine emission address
9 Date: Sun, 22 Jun 2008 12:28:07 +0200
10 MIME-Version: 1.0
11 Content-Type: text/plain;
12 format=flowed;
13 charset="iso-8859-1";
14 reply-type=original
15 Content-Transfer-Encoding: 7bit
16
17 This is a ticket submitted with the Redmine emission address.
18 It should be ignored.
19
@@ -1,284 +1,290
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class MailHandler < ActionMailer::Base
19 19 include ActionView::Helpers::SanitizeHelper
20 20
21 21 class UnauthorizedAction < StandardError; end
22 22 class MissingInformation < StandardError; end
23 23
24 24 attr_reader :email, :user
25 25
26 26 def self.receive(email, options={})
27 27 @@handler_options = options.dup
28 28
29 29 @@handler_options[:issue] ||= {}
30 30
31 31 @@handler_options[:allow_override] = @@handler_options[:allow_override].split(',').collect(&:strip) if @@handler_options[:allow_override].is_a?(String)
32 32 @@handler_options[:allow_override] ||= []
33 33 # Project needs to be overridable if not specified
34 34 @@handler_options[:allow_override] << 'project' unless @@handler_options[:issue].has_key?(:project)
35 35 # Status overridable by default
36 36 @@handler_options[:allow_override] << 'status' unless @@handler_options[:issue].has_key?(:status)
37 37 super email
38 38 end
39 39
40 40 # Processes incoming emails
41 41 # Returns the created object (eg. an issue, a message) or false
42 42 def receive(email)
43 43 @email = email
44 @user = User.find_by_mail(email.from.to_a.first.to_s.strip)
44 sender_email = email.from.to_a.first.to_s.strip
45 # Ignore emails received from the application emission address to avoid hell cycles
46 if sender_email.downcase == Setting.mail_from.to_s.strip.downcase
47 logger.info "MailHandler: ignoring email from Redmine emission address [#{sender_email}]" if logger && logger.info
48 return false
49 end
50 @user = User.find_by_mail(sender_email)
45 51 if @user && !@user.active?
46 52 logger.info "MailHandler: ignoring email from non-active user [#{@user.login}]" if logger && logger.info
47 53 return false
48 54 end
49 55 if @user.nil?
50 56 # Email was submitted by an unknown user
51 57 case @@handler_options[:unknown_user]
52 58 when 'accept'
53 59 @user = User.anonymous
54 60 when 'create'
55 61 @user = MailHandler.create_user_from_email(email)
56 62 if @user
57 63 logger.info "MailHandler: [#{@user.login}] account created" if logger && logger.info
58 64 Mailer.deliver_account_information(@user, @user.password)
59 65 else
60 logger.error "MailHandler: could not create account for [#{email.from.first}]" if logger && logger.error
66 logger.error "MailHandler: could not create account for [#{sender_email}]" if logger && logger.error
61 67 return false
62 68 end
63 69 else
64 70 # Default behaviour, emails from unknown users are ignored
65 logger.info "MailHandler: ignoring email from unknown user [#{email.from.first}]" if logger && logger.info
71 logger.info "MailHandler: ignoring email from unknown user [#{sender_email}]" if logger && logger.info
66 72 return false
67 73 end
68 74 end
69 75 User.current = @user
70 76 dispatch
71 77 end
72 78
73 79 private
74 80
75 81 MESSAGE_ID_RE = %r{^<redmine\.([a-z0-9_]+)\-(\d+)\.\d+@}
76 82 ISSUE_REPLY_SUBJECT_RE = %r{\[[^\]]+#(\d+)\]}
77 83 MESSAGE_REPLY_SUBJECT_RE = %r{\[[^\]]+msg(\d+)\]}
78 84
79 85 def dispatch
80 86 headers = [email.in_reply_to, email.references].flatten.compact
81 87 if headers.detect {|h| h.to_s =~ MESSAGE_ID_RE}
82 88 klass, object_id = $1, $2.to_i
83 89 method_name = "receive_#{klass}_reply"
84 90 if self.class.private_instance_methods.collect(&:to_s).include?(method_name)
85 91 send method_name, object_id
86 92 else
87 93 # ignoring it
88 94 end
89 95 elsif m = email.subject.match(ISSUE_REPLY_SUBJECT_RE)
90 96 receive_issue_reply(m[1].to_i)
91 97 elsif m = email.subject.match(MESSAGE_REPLY_SUBJECT_RE)
92 98 receive_message_reply(m[1].to_i)
93 99 else
94 100 receive_issue
95 101 end
96 102 rescue ActiveRecord::RecordInvalid => e
97 103 # TODO: send a email to the user
98 104 logger.error e.message if logger
99 105 false
100 106 rescue MissingInformation => e
101 107 logger.error "MailHandler: missing information from #{user}: #{e.message}" if logger
102 108 false
103 109 rescue UnauthorizedAction => e
104 110 logger.error "MailHandler: unauthorized attempt from #{user}" if logger
105 111 false
106 112 end
107 113
108 114 # Creates a new issue
109 115 def receive_issue
110 116 project = target_project
111 117 tracker = (get_keyword(:tracker) && project.trackers.find_by_name(get_keyword(:tracker))) || project.trackers.find(:first)
112 118 category = (get_keyword(:category) && project.issue_categories.find_by_name(get_keyword(:category)))
113 119 priority = (get_keyword(:priority) && IssuePriority.find_by_name(get_keyword(:priority)))
114 120 status = (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status)))
115 121
116 122 # check permission
117 123 raise UnauthorizedAction unless user.allowed_to?(:add_issues, project)
118 124 issue = Issue.new(:author => user, :project => project, :tracker => tracker, :category => category, :priority => priority)
119 125 # check workflow
120 126 if status && issue.new_statuses_allowed_to(user).include?(status)
121 127 issue.status = status
122 128 end
123 129 issue.subject = email.subject.chomp
124 130 issue.subject = issue.subject.toutf8 if issue.subject.respond_to?(:toutf8)
125 131 if issue.subject.blank?
126 132 issue.subject = '(no subject)'
127 133 end
128 134 issue.description = plain_text_body
129 135 # custom fields
130 136 issue.custom_field_values = issue.available_custom_fields.inject({}) do |h, c|
131 137 if value = get_keyword(c.name, :override => true)
132 138 h[c.id] = value
133 139 end
134 140 h
135 141 end
136 142 # add To and Cc as watchers before saving so the watchers can reply to Redmine
137 143 add_watchers(issue)
138 144 issue.save!
139 145 add_attachments(issue)
140 146 logger.info "MailHandler: issue ##{issue.id} created by #{user}" if logger && logger.info
141 147 issue
142 148 end
143 149
144 150 def target_project
145 151 # TODO: other ways to specify project:
146 152 # * parse the email To field
147 153 # * specific project (eg. Setting.mail_handler_target_project)
148 154 target = Project.find_by_identifier(get_keyword(:project))
149 155 raise MissingInformation.new('Unable to determine target project') if target.nil?
150 156 target
151 157 end
152 158
153 159 # Adds a note to an existing issue
154 160 def receive_issue_reply(issue_id)
155 161 status = (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status)))
156 162
157 163 issue = Issue.find_by_id(issue_id)
158 164 return unless issue
159 165 # check permission
160 166 raise UnauthorizedAction unless user.allowed_to?(:add_issue_notes, issue.project) || user.allowed_to?(:edit_issues, issue.project)
161 167 raise UnauthorizedAction unless status.nil? || user.allowed_to?(:edit_issues, issue.project)
162 168
163 169 # add the note
164 170 journal = issue.init_journal(user, plain_text_body)
165 171 add_attachments(issue)
166 172 # check workflow
167 173 if status && issue.new_statuses_allowed_to(user).include?(status)
168 174 issue.status = status
169 175 end
170 176 issue.save!
171 177 logger.info "MailHandler: issue ##{issue.id} updated by #{user}" if logger && logger.info
172 178 journal
173 179 end
174 180
175 181 # Reply will be added to the issue
176 182 def receive_journal_reply(journal_id)
177 183 journal = Journal.find_by_id(journal_id)
178 184 if journal && journal.journalized_type == 'Issue'
179 185 receive_issue_reply(journal.journalized_id)
180 186 end
181 187 end
182 188
183 189 # Receives a reply to a forum message
184 190 def receive_message_reply(message_id)
185 191 message = Message.find_by_id(message_id)
186 192 if message
187 193 message = message.root
188 194 if user.allowed_to?(:add_messages, message.project) && !message.locked?
189 195 reply = Message.new(:subject => email.subject.gsub(%r{^.*msg\d+\]}, '').strip,
190 196 :content => plain_text_body)
191 197 reply.author = user
192 198 reply.board = message.board
193 199 message.children << reply
194 200 add_attachments(reply)
195 201 reply
196 202 else
197 203 raise UnauthorizedAction
198 204 end
199 205 end
200 206 end
201 207
202 208 def add_attachments(obj)
203 209 if email.has_attachments?
204 210 email.attachments.each do |attachment|
205 211 Attachment.create(:container => obj,
206 212 :file => attachment,
207 213 :author => user,
208 214 :content_type => attachment.content_type)
209 215 end
210 216 end
211 217 end
212 218
213 219 # Adds To and Cc as watchers of the given object if the sender has the
214 220 # appropriate permission
215 221 def add_watchers(obj)
216 222 if user.allowed_to?("add_#{obj.class.name.underscore}_watchers".to_sym, obj.project)
217 223 addresses = [email.to, email.cc].flatten.compact.uniq.collect {|a| a.strip.downcase}
218 224 unless addresses.empty?
219 225 watchers = User.active.find(:all, :conditions => ['LOWER(mail) IN (?)', addresses])
220 226 watchers.each {|w| obj.add_watcher(w)}
221 227 end
222 228 end
223 229 end
224 230
225 231 def get_keyword(attr, options={})
226 232 @keywords ||= {}
227 233 if @keywords.has_key?(attr)
228 234 @keywords[attr]
229 235 else
230 236 @keywords[attr] = begin
231 237 if (options[:override] || @@handler_options[:allow_override].include?(attr.to_s)) && plain_text_body.gsub!(/^#{attr}[ \t]*:[ \t]*(.+)\s*$/i, '')
232 238 $1.strip
233 239 elsif !@@handler_options[:issue][attr].blank?
234 240 @@handler_options[:issue][attr]
235 241 end
236 242 end
237 243 end
238 244 end
239 245
240 246 # Returns the text/plain part of the email
241 247 # If not found (eg. HTML-only email), returns the body with tags removed
242 248 def plain_text_body
243 249 return @plain_text_body unless @plain_text_body.nil?
244 250 parts = @email.parts.collect {|c| (c.respond_to?(:parts) && !c.parts.empty?) ? c.parts : c}.flatten
245 251 if parts.empty?
246 252 parts << @email
247 253 end
248 254 plain_text_part = parts.detect {|p| p.content_type == 'text/plain'}
249 255 if plain_text_part.nil?
250 256 # no text/plain part found, assuming html-only email
251 257 # strip html tags and remove doctype directive
252 258 @plain_text_body = strip_tags(@email.body.to_s)
253 259 @plain_text_body.gsub! %r{^<!DOCTYPE .*$}, ''
254 260 else
255 261 @plain_text_body = plain_text_part.body.to_s
256 262 end
257 263 @plain_text_body.strip!
258 264 @plain_text_body
259 265 end
260 266
261 267
262 268 def self.full_sanitizer
263 269 @full_sanitizer ||= HTML::FullSanitizer.new
264 270 end
265 271
266 272 # Creates a user account for the +email+ sender
267 273 def self.create_user_from_email(email)
268 274 addr = email.from_addrs.to_a.first
269 275 if addr && !addr.spec.blank?
270 276 user = User.new
271 277 user.mail = addr.spec
272 278
273 279 names = addr.name.blank? ? addr.spec.gsub(/@.*$/, '').split('.') : addr.name.split
274 280 user.firstname = names.shift
275 281 user.lastname = names.join(' ')
276 282 user.lastname = '-' if user.lastname.blank?
277 283
278 284 user.login = user.mail
279 285 user.password = ActiveSupport::SecureRandom.hex(5)
280 286 user.language = Setting.default_language
281 287 user.save ? user : nil
282 288 end
283 289 end
284 290 end
@@ -1,256 +1,263
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2009 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19
20 20 class MailHandlerTest < ActiveSupport::TestCase
21 21 fixtures :users, :projects,
22 22 :enabled_modules,
23 23 :roles,
24 24 :members,
25 25 :member_roles,
26 26 :issues,
27 27 :issue_statuses,
28 28 :workflows,
29 29 :trackers,
30 30 :projects_trackers,
31 31 :enumerations,
32 32 :issue_categories,
33 33 :custom_fields,
34 34 :custom_fields_trackers,
35 35 :boards,
36 36 :messages
37 37
38 38 FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
39 39
40 40 def setup
41 41 ActionMailer::Base.deliveries.clear
42 42 end
43 43
44 44 def test_add_issue
45 45 # This email contains: 'Project: onlinestore'
46 46 issue = submit_email('ticket_on_given_project.eml')
47 47 assert issue.is_a?(Issue)
48 48 assert !issue.new_record?
49 49 issue.reload
50 50 assert_equal 'New ticket on a given project', issue.subject
51 51 assert_equal User.find_by_login('jsmith'), issue.author
52 52 assert_equal Project.find(2), issue.project
53 53 assert_equal IssueStatus.find_by_name('Resolved'), issue.status
54 54 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
55 55 # keywords should be removed from the email body
56 56 assert !issue.description.match(/^Project:/i)
57 57 assert !issue.description.match(/^Status:/i)
58 58 end
59 59
60 60 def test_add_issue_with_status
61 61 # This email contains: 'Project: onlinestore' and 'Status: Resolved'
62 62 issue = submit_email('ticket_on_given_project.eml')
63 63 assert issue.is_a?(Issue)
64 64 assert !issue.new_record?
65 65 issue.reload
66 66 assert_equal Project.find(2), issue.project
67 67 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
68 68 end
69 69
70 70 def test_add_issue_with_attributes_override
71 71 issue = submit_email('ticket_with_attributes.eml', :allow_override => 'tracker,category,priority')
72 72 assert issue.is_a?(Issue)
73 73 assert !issue.new_record?
74 74 issue.reload
75 75 assert_equal 'New ticket on a given project', issue.subject
76 76 assert_equal User.find_by_login('jsmith'), issue.author
77 77 assert_equal Project.find(2), issue.project
78 78 assert_equal 'Feature request', issue.tracker.to_s
79 79 assert_equal 'Stock management', issue.category.to_s
80 80 assert_equal 'Urgent', issue.priority.to_s
81 81 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
82 82 end
83 83
84 84 def test_add_issue_with_partial_attributes_override
85 85 issue = submit_email('ticket_with_attributes.eml', :issue => {:priority => 'High'}, :allow_override => ['tracker'])
86 86 assert issue.is_a?(Issue)
87 87 assert !issue.new_record?
88 88 issue.reload
89 89 assert_equal 'New ticket on a given project', issue.subject
90 90 assert_equal User.find_by_login('jsmith'), issue.author
91 91 assert_equal Project.find(2), issue.project
92 92 assert_equal 'Feature request', issue.tracker.to_s
93 93 assert_nil issue.category
94 94 assert_equal 'High', issue.priority.to_s
95 95 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
96 96 end
97 97
98 98 def test_add_issue_with_spaces_between_attribute_and_separator
99 99 issue = submit_email('ticket_with_spaces_between_attribute_and_separator.eml', :allow_override => 'tracker,category,priority')
100 100 assert issue.is_a?(Issue)
101 101 assert !issue.new_record?
102 102 issue.reload
103 103 assert_equal 'New ticket on a given project', issue.subject
104 104 assert_equal User.find_by_login('jsmith'), issue.author
105 105 assert_equal Project.find(2), issue.project
106 106 assert_equal 'Feature request', issue.tracker.to_s
107 107 assert_equal 'Stock management', issue.category.to_s
108 108 assert_equal 'Urgent', issue.priority.to_s
109 109 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
110 110 end
111 111
112 112
113 113 def test_add_issue_with_attachment_to_specific_project
114 114 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
115 115 assert issue.is_a?(Issue)
116 116 assert !issue.new_record?
117 117 issue.reload
118 118 assert_equal 'Ticket created by email with attachment', issue.subject
119 119 assert_equal User.find_by_login('jsmith'), issue.author
120 120 assert_equal Project.find(2), issue.project
121 121 assert_equal 'This is a new ticket with attachments', issue.description
122 122 # Attachment properties
123 123 assert_equal 1, issue.attachments.size
124 124 assert_equal 'Paella.jpg', issue.attachments.first.filename
125 125 assert_equal 'image/jpeg', issue.attachments.first.content_type
126 126 assert_equal 10790, issue.attachments.first.filesize
127 127 end
128 128
129 129 def test_add_issue_with_custom_fields
130 130 issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'})
131 131 assert issue.is_a?(Issue)
132 132 assert !issue.new_record?
133 133 issue.reload
134 134 assert_equal 'New ticket with custom field values', issue.subject
135 135 assert_equal 'Value for a custom field', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value
136 136 assert !issue.description.match(/^searchable field:/i)
137 137 end
138 138
139 139 def test_add_issue_with_cc
140 140 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
141 141 assert issue.is_a?(Issue)
142 142 assert !issue.new_record?
143 143 issue.reload
144 144 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
145 145 assert_equal 1, issue.watchers.size
146 146 end
147 147
148 148 def test_add_issue_by_unknown_user
149 149 assert_no_difference 'User.count' do
150 150 assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'})
151 151 end
152 152 end
153 153
154 154 def test_add_issue_by_anonymous_user
155 155 Role.anonymous.add_permission!(:add_issues)
156 156 assert_no_difference 'User.count' do
157 157 issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'accept')
158 158 assert issue.is_a?(Issue)
159 159 assert issue.author.anonymous?
160 160 end
161 161 end
162 162
163 163 def test_add_issue_by_created_user
164 164 Setting.default_language = 'en'
165 165 assert_difference 'User.count' do
166 166 issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'create')
167 167 assert issue.is_a?(Issue)
168 168 assert issue.author.active?
169 169 assert_equal 'john.doe@somenet.foo', issue.author.mail
170 170 assert_equal 'John', issue.author.firstname
171 171 assert_equal 'Doe', issue.author.lastname
172 172
173 173 # account information
174 174 email = ActionMailer::Base.deliveries.first
175 175 assert_not_nil email
176 176 assert email.subject.include?('account activation')
177 177 login = email.body.match(/\* Login: (.*)$/)[1]
178 178 password = email.body.match(/\* Password: (.*)$/)[1]
179 179 assert_equal issue.author, User.try_to_login(login, password)
180 180 end
181 181 end
182 182
183 183 def test_add_issue_without_from_header
184 184 Role.anonymous.add_permission!(:add_issues)
185 185 assert_equal false, submit_email('ticket_without_from_header.eml')
186 186 end
187 187
188 def test_should_ignore_emails_from_emission_address
189 Role.anonymous.add_permission!(:add_issues)
190 assert_no_difference 'User.count' do
191 assert_equal false, submit_email('ticket_from_emission_address.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'create')
192 end
193 end
194
188 195 def test_add_issue_should_send_email_notification
189 196 ActionMailer::Base.deliveries.clear
190 197 # This email contains: 'Project: onlinestore'
191 198 issue = submit_email('ticket_on_given_project.eml')
192 199 assert issue.is_a?(Issue)
193 200 assert_equal 1, ActionMailer::Base.deliveries.size
194 201 end
195 202
196 203 def test_add_issue_note
197 204 journal = submit_email('ticket_reply.eml')
198 205 assert journal.is_a?(Journal)
199 206 assert_equal User.find_by_login('jsmith'), journal.user
200 207 assert_equal Issue.find(2), journal.journalized
201 208 assert_match /This is reply/, journal.notes
202 209 end
203 210
204 211 def test_add_issue_note_with_status_change
205 212 # This email contains: 'Status: Resolved'
206 213 journal = submit_email('ticket_reply_with_status.eml')
207 214 assert journal.is_a?(Journal)
208 215 issue = Issue.find(journal.issue.id)
209 216 assert_equal User.find_by_login('jsmith'), journal.user
210 217 assert_equal Issue.find(2), journal.journalized
211 218 assert_match /This is reply/, journal.notes
212 219 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
213 220 end
214 221
215 222 def test_add_issue_note_should_send_email_notification
216 223 ActionMailer::Base.deliveries.clear
217 224 journal = submit_email('ticket_reply.eml')
218 225 assert journal.is_a?(Journal)
219 226 assert_equal 1, ActionMailer::Base.deliveries.size
220 227 end
221 228
222 229 def test_reply_to_a_message
223 230 m = submit_email('message_reply.eml')
224 231 assert m.is_a?(Message)
225 232 assert !m.new_record?
226 233 m.reload
227 234 assert_equal 'Reply via email', m.subject
228 235 # The email replies to message #2 which is part of the thread of message #1
229 236 assert_equal Message.find(1), m.parent
230 237 end
231 238
232 239 def test_reply_to_a_message_by_subject
233 240 m = submit_email('message_reply_by_subject.eml')
234 241 assert m.is_a?(Message)
235 242 assert !m.new_record?
236 243 m.reload
237 244 assert_equal 'Reply to the first post', m.subject
238 245 assert_equal Message.find(1), m.parent
239 246 end
240 247
241 248 def test_should_strip_tags_of_html_only_emails
242 249 issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'})
243 250 assert issue.is_a?(Issue)
244 251 assert !issue.new_record?
245 252 issue.reload
246 253 assert_equal 'HTML email', issue.subject
247 254 assert_equal 'This is a html-only email.', issue.description
248 255 end
249 256
250 257 private
251 258
252 259 def submit_email(filename, options={})
253 260 raw = IO.read(File.join(FIXTURES_PATH, filename))
254 261 MailHandler.receive(raw, options)
255 262 end
256 263 end
General Comments 0
You need to be logged in to leave comments. Login now