Patch #19242 ยป patch-rdm-mailhandler-options.patch
| extra/mail_handler/rdm-mailhandler.rb 2015-03-03 11:38:39.904795266 +0900 | ||
|---|---|---|
|
VERSION = '0.2.3'
|
||
|
attr_accessor :verbose, :issue_attributes, :allow_override, :unknown_user, :default_group, :no_permission_check,
|
||
|
:override_sender, :post_user, :email_header, :email_footer,
|
||
|
:url, :key, :no_check_certificate, :certificate_bundle, :no_account_notice, :no_notification
|
||
|
def initialize
|
||
| ... | ... | |
|
opts.on("--unknown-user ACTION", "how to handle emails from an unknown user",
|
||
|
"ACTION can be one of the following values:",
|
||
|
"* ignore: email is ignored (default)",
|
||
|
"* accept: accept as anonymous user",
|
||
|
"* accept: accept as anonymous user or posting user",
|
||
|
"* create: create a user account") {|v| self.unknown_user = v}
|
||
|
opts.on("--default-group GROUP", "add created user to GROUP (none by default)",
|
||
|
"GROUP can be a comma separated list of groups") { |v| self.default_group = v}
|
||
| ... | ... | |
|
opts.on("--no-notification", "disable email notifications for the created",
|
||
|
"user") { |v| self.no_notification = '1'}
|
||
|
opts.separator("")
|
||
|
opts.separator("User override options:")
|
||
|
opts.on("--override-sender YES/NO", "used in conjunction with '--post-user ADDRESS'",
|
||
|
"and will override the original email sender if set to 'yes'.") { |v| self.override_sender = v}
|
||
|
opts.on("--post-user SENDER", "can do one of the following:",
|
||
|
"* with '--unknown-user accept', accept emails as SENDER instead of anonymous",
|
||
|
"* with '--override-sender yes', submit all emails as SENDER") { |v| self.post_user = v}
|
||
|
opts.separator("")
|
||
|
opts.separator("Issue attributes control options:")
|
||
|
opts.on("-p", "--project PROJECT", "identifier of the target project") {|v| self.issue_attributes['project'] = v}
|
||
|
opts.on("-s", "--status STATUS", "name of the target status") {|v| self.issue_attributes['status'] = v}
|
||
| ... | ... | |
|
opts.on("-o", "--allow-override ATTRS", "allow email content to override attributes",
|
||
|
"specified by previous options",
|
||
|
"ATTRS is a comma separated list of attributes") {|v| self.allow_override = v}
|
||
|
opts.on("--email-header TEXT", "text added before the e-mail body when posting it") { |v| self.email_header = v}
|
||
|
opts.on("--email-footer TEXT", "text added after the e-mail body when posting it") { |v| self.email_footer = v}
|
||
|
opts.separator("")
|
||
|
opts.separator("Examples:")
|
||
|
opts.separator("No project specified, emails MUST contain the 'Project' keyword:")
|
||
| ... | ... | |
|
opts.separator(" --tracker bug \\")
|
||
|
opts.separator(" --allow-override tracker,priority")
|
||
|
opts.summary_width = 27
|
||
|
opts.summary_width = 29
|
||
|
end
|
||
|
optparse.parse!
|
||
| ... | ... | |
|
'default_group' => default_group,
|
||
|
'no_account_notice' => no_account_notice,
|
||
|
'no_notification' => no_notification,
|
||
|
'no_permission_check' => no_permission_check}
|
||
|
'no_permission_check' => no_permission_check,
|
||
|
'override_sender' => override_sender,
|
||
|
'post_user' => post_user,
|
||
|
'email_header' => email_header,
|
||
|
'email_footer' => email_footer,
|
||
|
}
|
||
|
issue_attributes.each { |attr, value| data["issue[#{attr}]"] = value }
|
||
|
debug "Posting to #{uri}..."
|
||
|
-- app/models/mail_handler.rb 2014-11-06 19:25:57.014951624 +0900
|
||
|
++ app/models/mail_handler.rb 2015-03-03 11:30:37.951652211 +0900
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
end
|
||
|
@user = User.find_by_mail(sender_email) if sender_email.present?
|
||
|
if @@handler_options[:override_sender].to_s.strip.downcase == "yes"
|
||
|
@user = User.find_by_mail(@@handler_options[:post_user]) if @@handler_options[:post_user] && !@@handler_options[:post_user].empty?
|
||
|
else
|
||
|
@user = User.find_by_mail(sender_email) if sender_email.present?
|
||
|
end
|
||
|
if @user && !@user.active?
|
||
|
if logger
|
||
|
logger.info "MailHandler: ignoring email from non-active user [#{@user.login}]"
|
||
| ... | ... | |
|
case @@handler_options[:unknown_user]
|
||
|
when 'accept'
|
||
|
@user = User.anonymous
|
||
|
if @@handler_options[:post_user]
|
||
|
post_user = User.find_by_mail(@@handler_options[:post_user])
|
||
|
if post_user
|
||
|
if post_user.active?
|
||
|
logger.info "MailHandler: e-mail from unknown users are to be processed as user [#{post_user}]"
|
||
|
@user = post_user
|
||
|
else
|
||
|
logger.info "MailHandler: user [#{post_user}] was inactive, falling back to anonymous"
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
when 'create'
|
||
|
@user = create_user_from_email
|
||
|
if @user
|
||
| ... | ... | |
|
end
|
||
|
def cleaned_up_text_body
|
||
|
cleanup_body(plain_text_body)
|
||
|
header = ""
|
||
|
footer = ""
|
||
|
header = @@handler_options[:email_header] + "\n" if @@handler_options[:email_header]
|
||
|
footer = @@handler_options[:email_footer] + "\n" if @@handler_options[:email_footer]
|
||
|
header + cleanup_body(plain_text_body) + footer
|
||
|
end
|
||
|
def cleaned_up_subject
|
||