@@ -22,28 +22,33 class MailHandler < ActionMailer::Base | |||
|
22 | 22 | class UnauthorizedAction < StandardError; end |
|
23 | 23 | class MissingInformation < StandardError; end |
|
24 | 24 | |
|
25 | attr_reader :email, :user | |
|
25 | attr_reader :email, :user, :handler_options | |
|
26 | 26 | |
|
27 |
def self.receive( |
|
|
28 |
|
|
|
27 | def self.receive(raw_mail, options={}) | |
|
28 | options = options.deep_dup | |
|
29 | 29 | |
|
30 |
|
|
|
30 | options[:issue] ||= {} | |
|
31 | 31 | |
|
32 |
if |
|
|
33 |
|
|
|
32 | if options[:allow_override].is_a?(String) | |
|
33 | options[:allow_override] = options[:allow_override].split(',').collect(&:strip) | |
|
34 | 34 | end |
|
35 |
|
|
|
35 | options[:allow_override] ||= [] | |
|
36 | 36 | # Project needs to be overridable if not specified |
|
37 |
|
|
|
37 | options[:allow_override] << 'project' unless options[:issue].has_key?(:project) | |
|
38 | 38 | # Status overridable by default |
|
39 |
|
|
|
39 | options[:allow_override] << 'status' unless options[:issue].has_key?(:status) | |
|
40 | 40 | |
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
|
41 | options[:no_account_notice] = (options[:no_account_notice].to_s == '1') | |
|
42 | options[:no_notification] = (options[:no_notification].to_s == '1') | |
|
43 | options[:no_permission_check] = (options[:no_permission_check].to_s == '1') | |
|
44 | 44 | |
|
45 |
|
|
|
46 | super(email) | |
|
45 | raw_mail.force_encoding('ASCII-8BIT') | |
|
46 | ||
|
47 | ActiveSupport::Notifications.instrument("receive.action_mailer") do |payload| | |
|
48 | mail = Mail.new(raw_mail) | |
|
49 | set_payload_for_mail(payload, mail) | |
|
50 | new.receive(mail, options) | |
|
51 | end | |
|
47 | 52 | end |
|
48 | 53 | |
|
49 | 54 | # Receives an email and rescues any exception |
@@ -79,8 +84,9 class MailHandler < ActionMailer::Base | |||
|
79 | 84 | |
|
80 | 85 | # Processes incoming emails |
|
81 | 86 | # Returns the created object (eg. an issue, a message) or false |
|
82 | def receive(email) | |
|
87 | def receive(email, options={}) | |
|
83 | 88 | @email = email |
|
89 | @handler_options = options | |
|
84 | 90 | sender_email = email.from.to_a.first.to_s.strip |
|
85 | 91 | # Ignore emails received from the application emission address to avoid hell cycles |
|
86 | 92 | if sender_email.downcase == Setting.mail_from.to_s.strip.downcase |
@@ -111,7 +117,7 class MailHandler < ActionMailer::Base | |||
|
111 | 117 | end |
|
112 | 118 | if @user.nil? |
|
113 | 119 | # Email was submitted by an unknown user |
|
114 |
case |
|
|
120 | case handler_options[:unknown_user] | |
|
115 | 121 | when 'accept' |
|
116 | 122 | @user = User.anonymous |
|
117 | 123 | when 'create' |
@@ -120,8 +126,8 class MailHandler < ActionMailer::Base | |||
|
120 | 126 | if logger |
|
121 | 127 | logger.info "MailHandler: [#{@user.login}] account created" |
|
122 | 128 | end |
|
123 |
add_user_to_group( |
|
|
124 |
unless |
|
|
129 | add_user_to_group(handler_options[:default_group]) | |
|
130 | unless handler_options[:no_account_notice] | |
|
125 | 131 | Mailer.account_information(@user, @user.password).deliver |
|
126 | 132 | end |
|
127 | 133 | else |
@@ -186,7 +192,7 class MailHandler < ActionMailer::Base | |||
|
186 | 192 | def receive_issue |
|
187 | 193 | project = target_project |
|
188 | 194 | # check permission |
|
189 |
unless |
|
|
195 | unless handler_options[:no_permission_check] | |
|
190 | 196 | raise UnauthorizedAction unless user.allowed_to?(:add_issues, project) |
|
191 | 197 | end |
|
192 | 198 | |
@@ -213,7 +219,7 class MailHandler < ActionMailer::Base | |||
|
213 | 219 | issue = Issue.find_by_id(issue_id) |
|
214 | 220 | return unless issue |
|
215 | 221 | # check permission |
|
216 |
unless |
|
|
222 | unless handler_options[:no_permission_check] | |
|
217 | 223 | unless user.allowed_to?(:add_issue_notes, issue.project) || |
|
218 | 224 | user.allowed_to?(:edit_issues, issue.project) |
|
219 | 225 | raise UnauthorizedAction |
@@ -221,7 +227,7 class MailHandler < ActionMailer::Base | |||
|
221 | 227 | end |
|
222 | 228 | |
|
223 | 229 | # ignore CLI-supplied defaults for new issues |
|
224 |
|
|
|
230 | handler_options[:issue].clear | |
|
225 | 231 | |
|
226 | 232 | journal = issue.init_journal(user) |
|
227 | 233 | if from_journal && from_journal.private_notes? |
@@ -253,7 +259,7 class MailHandler < ActionMailer::Base | |||
|
253 | 259 | if message |
|
254 | 260 | message = message.root |
|
255 | 261 | |
|
256 |
unless |
|
|
262 | unless handler_options[:no_permission_check] | |
|
257 | 263 | raise UnauthorizedAction unless user.allowed_to?(:add_messages, message.project) |
|
258 | 264 | end |
|
259 | 265 | |
@@ -318,11 +324,11 class MailHandler < ActionMailer::Base | |||
|
318 | 324 | @keywords[attr] |
|
319 | 325 | else |
|
320 | 326 | @keywords[attr] = begin |
|
321 |
if (options[:override] || |
|
|
327 | if (options[:override] || handler_options[:allow_override].include?(attr.to_s)) && | |
|
322 | 328 | (v = extract_keyword!(cleaned_up_text_body, attr, options[:format])) |
|
323 | 329 | v |
|
324 |
elsif ! |
|
|
325 |
|
|
|
330 | elsif !handler_options[:issue][attr].blank? | |
|
331 | handler_options[:issue][attr] | |
|
326 | 332 | end |
|
327 | 333 | end |
|
328 | 334 | end |
@@ -359,7 +365,7 class MailHandler < ActionMailer::Base | |||
|
359 | 365 | target = Project.find_by_identifier(get_keyword(:project)) |
|
360 | 366 | if target.nil? |
|
361 | 367 | # Invalid project keyword, use the project specified as the default one |
|
362 |
default_project = |
|
|
368 | default_project = handler_options[:issue][:project] | |
|
363 | 369 | if default_project.present? |
|
364 | 370 | target = Project.find_by_identifier(default_project) |
|
365 | 371 | end |
@@ -485,7 +491,7 class MailHandler < ActionMailer::Base | |||
|
485 | 491 | end |
|
486 | 492 | if addr.present? |
|
487 | 493 | user = self.class.new_user_from_attributes(addr, name) |
|
488 |
if |
|
|
494 | if handler_options[:no_notification] | |
|
489 | 495 | user.mail_notification = 'none' |
|
490 | 496 | end |
|
491 | 497 | if user.save |
General Comments 0
You need to be logged in to leave comments.
Login now