diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 3c98578..e6fb98d 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -50,7 +50,7 @@ class MailHandler < ActionMailer::Base # Use when receiving emails with rake tasks def self.extract_options_from_env(env) options = {:issue => {}} - %w(project status tracker category priority).each do |option| + %w(project status tracker category priority board).each do |option| options[:issue][option.to_sym] = env[option] if env[option] end %w(allow_override unknown_user no_permission_check no_account_notice default_group).each do |option| @@ -170,8 +170,32 @@ class MailHandler < ActionMailer::Base false end + # If a board number is provided in the environment, new emails are messages to that + # board, rather than a new issue def dispatch_to_default - receive_issue + if get_keyword(:board) + receive_message + else + receive_issue + end + end + + # Creates a new issue + def receive_message + board = target_board + # check permission + unless @@handler_options[:no_permission_check] + raise UnauthorizedAction unless user.allowed_to?(:add_messages, board.project) + end + + message = Message.new(:subject => cleaned_up_subject.gsub(%r{^.*msg\d+\]}, '').strip, + :content => cleaned_up_text_body) + message.author = user + message.board = board + message.save! + add_attachments(message) + logger.info "MailHandler: message ##{message.id} created by #{user}" if logger + message end # Creates a new issue @@ -342,6 +366,19 @@ class MailHandler < ActionMailer::Base keyword end + def target_board + target = Board.find_by_id(get_keyword(:board)) + if target.nil? + # Invalid board keyword, use the board specified as the default one + default_board = @@handler_options[:issue][:board] + if default_board.present? + target = Board.find_by_id(default_board) + end + end + raise MissingInformation.new('Unable to determine target board') if target.nil? + target + end + def target_project # TODO: other ways to specify project: # * parse the email To field diff --git a/app/views/mailer/message_posted.text.erb b/app/views/mailer/message_posted.text.erb index ef6a3b3..af48c2c 100644 --- a/app/views/mailer/message_posted.text.erb +++ b/app/views/mailer/message_posted.text.erb @@ -1,4 +1 @@ -<%= @message_url %> -<%= @message.author %> - <%= @message.content %> diff --git a/lib/tasks/email.rake b/lib/tasks/email.rake index 596b086..3faff22 100644 --- a/lib/tasks/email.rake +++ b/lib/tasks/email.rake @@ -82,6 +82,7 @@ Available IMAP options: Issue attributes control options: project=PROJECT identifier of the target project + board=BOARD_ID identifier of the board unknown input goes to status=STATUS name of the target status tracker=TRACKER name of the target tracker category=CATEGORY name of the target category