| 45 |
45 |
VERSION = '0.2.3'
|
| 46 |
46 |
|
| 47 |
47 |
attr_accessor :verbose, :issue_attributes, :allow_override, :unknown_user, :default_group, :no_permission_check,
|
|
48 |
:override_sender, :post_user, :email_header, :email_footer,
|
| 48 |
49 |
:url, :key, :no_check_certificate, :certificate_bundle, :no_account_notice, :no_notification
|
| 49 |
50 |
|
| 50 |
51 |
def initialize
|
| ... | ... | |
| 76 |
77 |
opts.on("--unknown-user ACTION", "how to handle emails from an unknown user",
|
| 77 |
78 |
"ACTION can be one of the following values:",
|
| 78 |
79 |
"* ignore: email is ignored (default)",
|
| 79 |
|
"* accept: accept as anonymous user",
|
|
80 |
"* accept: accept as anonymous user or posting user",
|
| 80 |
81 |
"* create: create a user account") {|v| self.unknown_user = v}
|
| 81 |
82 |
opts.on("--default-group GROUP", "add created user to GROUP (none by default)",
|
| 82 |
83 |
"GROUP can be a comma separated list of groups") { |v| self.default_group = v}
|
| ... | ... | |
| 85 |
86 |
opts.on("--no-notification", "disable email notifications for the created",
|
| 86 |
87 |
"user") { |v| self.no_notification = '1'}
|
| 87 |
88 |
opts.separator("")
|
|
89 |
opts.separator("User override options:")
|
|
90 |
opts.on("--override-sender YES/NO", "used in conjunction with '--post-user ADDRESS'",
|
|
91 |
"and will override the original email sender if set to 'yes'.") { |v| self.override_sender = v}
|
|
92 |
opts.on("--post-user SENDER", "can do one of the following:",
|
|
93 |
"* with '--unknown-user accept', accept emails as SENDER instead of anonymous",
|
|
94 |
"* with '--override-sender yes', submit all emails as SENDER") { |v| self.post_user = v}
|
|
95 |
opts.separator("")
|
| 88 |
96 |
opts.separator("Issue attributes control options:")
|
| 89 |
97 |
opts.on("-p", "--project PROJECT", "identifier of the target project") {|v| self.issue_attributes['project'] = v}
|
| 90 |
98 |
opts.on("-s", "--status STATUS", "name of the target status") {|v| self.issue_attributes['status'] = v}
|
| ... | ... | |
| 94 |
102 |
opts.on("-o", "--allow-override ATTRS", "allow email content to override attributes",
|
| 95 |
103 |
"specified by previous options",
|
| 96 |
104 |
"ATTRS is a comma separated list of attributes") {|v| self.allow_override = v}
|
|
105 |
opts.on("--email-header TEXT", "text added before the e-mail body when posting it") { |v| self.email_header = v}
|
|
106 |
opts.on("--email-footer TEXT", "text added after the e-mail body when posting it") { |v| self.email_footer = v}
|
| 97 |
107 |
opts.separator("")
|
| 98 |
108 |
opts.separator("Examples:")
|
| 99 |
109 |
opts.separator("No project specified, emails MUST contain the 'Project' keyword:")
|
| ... | ... | |
| 106 |
116 |
opts.separator(" --tracker bug \\")
|
| 107 |
117 |
opts.separator(" --allow-override tracker,priority")
|
| 108 |
118 |
|
| 109 |
|
opts.summary_width = 27
|
|
119 |
opts.summary_width = 29
|
| 110 |
120 |
end
|
| 111 |
121 |
optparse.parse!
|
| 112 |
122 |
|
| ... | ... | |
| 127 |
137 |
'default_group' => default_group,
|
| 128 |
138 |
'no_account_notice' => no_account_notice,
|
| 129 |
139 |
'no_notification' => no_notification,
|
| 130 |
|
'no_permission_check' => no_permission_check}
|
|
140 |
'no_permission_check' => no_permission_check,
|
|
141 |
'override_sender' => override_sender,
|
|
142 |
'post_user' => post_user,
|
|
143 |
'email_header' => email_header,
|
|
144 |
'email_footer' => email_footer,
|
|
145 |
}
|
| 131 |
146 |
issue_attributes.each { |attr, value| data["issue[#{attr}]"] = value }
|
| 132 |
147 |
|
| 133 |
148 |
debug "Posting to #{uri}..."
|
| 134 |
|
-- app/models/mail_handler.rb 2014-11-06 19:25:57.014951624 +0900
|
|
149 |
++ app/models/mail_handler.rb 2015-03-03 11:30:37.951652211 +0900
|
| ... | ... | |
| 94 |
94 |
end
|
| 95 |
95 |
end
|
| 96 |
96 |
end
|
| 97 |
|
@user = User.find_by_mail(sender_email) if sender_email.present?
|
|
97 |
if @@handler_options[:override_sender].to_s.strip.downcase == "yes"
|
|
98 |
@user = User.find_by_mail(@@handler_options[:post_user]) if @@handler_options[:post_user] && !@@handler_options[:post_user].empty?
|
|
99 |
else
|
|
100 |
@user = User.find_by_mail(sender_email) if sender_email.present?
|
|
101 |
end
|
| 98 |
102 |
if @user && !@user.active?
|
| 99 |
103 |
if logger
|
| 100 |
104 |
logger.info "MailHandler: ignoring email from non-active user [#{@user.login}]"
|
| ... | ... | |
| 106 |
110 |
case @@handler_options[:unknown_user]
|
| 107 |
111 |
when 'accept'
|
| 108 |
112 |
@user = User.anonymous
|
|
113 |
if @@handler_options[:post_user]
|
|
114 |
post_user = User.find_by_mail(@@handler_options[:post_user])
|
|
115 |
if post_user
|
|
116 |
if post_user.active?
|
|
117 |
logger.info "MailHandler: e-mail from unknown users are to be processed as user [#{post_user}]"
|
|
118 |
@user = post_user
|
|
119 |
else
|
|
120 |
logger.info "MailHandler: user [#{post_user}] was inactive, falling back to anonymous"
|
|
121 |
end
|
|
122 |
end
|
|
123 |
end
|
| 109 |
124 |
when 'create'
|
| 110 |
125 |
@user = create_user_from_email
|
| 111 |
126 |
if @user
|
| ... | ... | |
| 428 |
443 |
end
|
| 429 |
444 |
|
| 430 |
445 |
def cleaned_up_text_body
|
| 431 |
|
cleanup_body(plain_text_body)
|
|
446 |
header = ""
|
|
447 |
footer = ""
|
|
448 |
header = @@handler_options[:email_header] + "\n" if @@handler_options[:email_header]
|
|
449 |
footer = @@handler_options[:email_footer] + "\n" if @@handler_options[:email_footer]
|
|
450 |
header + cleanup_body(plain_text_body) + footer
|
| 432 |
451 |
end
|
| 433 |
452 |
|
| 434 |
453 |
def cleaned_up_subject
|