Feature #15141 ยป listserv.patch
app/models/mail_handler.rb | ||
---|---|---|
50 | 50 |
# Use when receiving emails with rake tasks |
51 | 51 |
def self.extract_options_from_env(env) |
52 | 52 |
options = {:issue => {}} |
53 |
%w(project status tracker category priority).each do |option| |
|
53 |
%w(project status tracker category priority board).each do |option|
|
|
54 | 54 |
options[:issue][option.to_sym] = env[option] if env[option] |
55 | 55 |
end |
56 | 56 |
%w(allow_override unknown_user no_permission_check no_account_notice default_group).each do |option| |
... | ... | |
170 | 170 |
false |
171 | 171 |
end |
172 | 172 | |
173 |
# If a board number is provided in the environment, new emails are messages to that |
|
174 |
# board, rather than a new issue |
|
173 | 175 |
def dispatch_to_default |
174 |
receive_issue |
|
176 |
if get_keyword(:board) |
|
177 |
receive_message |
|
178 |
else |
|
179 |
receive_issue |
|
180 |
end |
|
181 |
end |
|
182 | ||
183 |
# Creates a new issue |
|
184 |
def receive_message |
|
185 |
board = target_board |
|
186 |
# check permission |
|
187 |
unless @@handler_options[:no_permission_check] |
|
188 |
raise UnauthorizedAction unless user.allowed_to?(:add_messages, board.project) |
|
189 |
end |
|
190 | ||
191 |
message = Message.new(:subject => cleaned_up_subject.gsub(%r{^.*msg\d+\]}, '').strip, |
|
192 |
:content => cleaned_up_text_body) |
|
193 |
message.author = user |
|
194 |
message.board = board |
|
195 |
message.save! |
|
196 |
add_attachments(message) |
|
197 |
logger.info "MailHandler: message ##{message.id} created by #{user}" if logger |
|
198 |
message |
|
175 | 199 |
end |
176 | 200 | |
177 | 201 |
# Creates a new issue |
... | ... | |
342 | 366 |
keyword |
343 | 367 |
end |
344 | 368 | |
369 |
def target_board |
|
370 |
target = Board.find_by_id(get_keyword(:board)) |
|
371 |
if target.nil? |
|
372 |
# Invalid board keyword, use the board specified as the default one |
|
373 |
default_board = @@handler_options[:issue][:board] |
|
374 |
if default_board.present? |
|
375 |
target = Board.find_by_id(default_board) |
|
376 |
end |
|
377 |
end |
|
378 |
raise MissingInformation.new('Unable to determine target board') if target.nil? |
|
379 |
target |
|
380 |
end |
|
381 | ||
345 | 382 |
def target_project |
346 | 383 |
# TODO: other ways to specify project: |
347 | 384 |
# * parse the email To field |
app/views/mailer/message_posted.text.erb | ||
---|---|---|
1 |
<%= @message_url %> |
|
2 |
<%= @message.author %> |
|
3 | ||
4 | 1 |
<%= @message.content %> |
lib/tasks/email.rake | ||
---|---|---|
82 | 82 | |
83 | 83 |
Issue attributes control options: |
84 | 84 |
project=PROJECT identifier of the target project |
85 |
board=BOARD_ID identifier of the board unknown input goes to |
|
85 | 86 |
status=STATUS name of the target status |
86 | 87 |
tracker=TRACKER name of the target tracker |
87 | 88 |
category=CATEGORY name of the target category |