Patch #1616 » forum_message_creation_by_mail.patch
| app/models/mail_handler_with_forum_messages_creation_by_email.rb 2011-04-07 10:16:25.796713000 +0200 | ||
|---|---|---|
|
|
||
|
private
|
||
|
MESSAGE_ID_RE = %r{^<redmine\.([a-z0-9_]+)\-(\d+)\.\d+@}
|
||
|
ISSUE_REPLY_SUBJECT_RE = %r{\[[^\]]*#(\d+)\]}
|
||
|
MESSAGE_ID_RE = %r{^<redmine\.([a-z0-9_]+)\-(\d+)\.\d+@}
|
||
|
MESSAGE_REPLY_SUBJECT_RE = %r{\[[^\]]*msg(\d+)\]}
|
||
|
|
||
|
MESSAGE_SUBJECT = %r{(\[.* - .*\])}
|
||
|
MESSAGE_SUBJECT_SPLIT = %r{(\[)(.*)( - )(.*)(\])}
|
||
|
def dispatch
|
||
|
headers = [email.in_reply_to, email.references].flatten.compact
|
||
|
if headers.detect {|h| h.to_s =~ MESSAGE_ID_RE}
|
||
| ... | ... | |
|
receive_issue_reply(m[1].to_i)
|
||
|
elsif m = email.subject.match(MESSAGE_REPLY_SUBJECT_RE)
|
||
|
receive_message_reply(m[1].to_i)
|
||
|
elsif email.subject.match(MESSAGE_SUBJECT)
|
||
|
receive_forum_message
|
||
|
else
|
||
|
dispatch_to_default
|
||
|
end
|
||
| ... | ... | |
|
def dispatch_to_default
|
||
|
receive_issue
|
||
|
end
|
||
|
|
||
|
# Creates a new forum message
|
||
|
def receive_forum_message
|
||
|
project = target_project
|
||
|
board = target_board
|
||
|
# check permission
|
||
|
unless @@handler_options[:no_permission_check]
|
||
|
raise UnauthorizedAction unless user.allowed_to?(:edit_messages, project)
|
||
|
end
|
||
|
message = Message.new(:author => user, :board => board)
|
||
|
message.subject = email.subject.split(MESSAGE_SUBJECT_SPLIT)[6].strip
|
||
|
message.content = cleaned_up_text_body
|
||
|
message.save!
|
||
|
add_attachments(message)
|
||
|
logger.info "MailHandler: message ##{message.id} - #{message.subject} created by #{user}" if logger && logger.info
|
||
|
message
|
||
|
end
|
||
|
# Creates a new issue
|
||
|
def receive_issue
|
||
|
project = target_project
|
||
| ... | ... | |
|
# TODO: other ways to specify project:
|
||
|
# * parse the email To field
|
||
|
# * specific project (eg. Setting.mail_handler_target_project)
|
||
|
target = Project.find_by_identifier(get_keyword(:project))
|
||
|
unless target = Project.find_by_identifier(get_keyword(:project))
|
||
|
target = Project.find_by_name(email.subject.split(MESSAGE_SUBJECT_SPLIT)[2])
|
||
|
end
|
||
|
raise MissingInformation.new('Unable to determine target project') if target.nil?
|
||
|
target
|
||
|
end
|
||
|
|
||
|
def target_board
|
||
|
target = Board.find_by_name(email.subject.split(MESSAGE_SUBJECT_SPLIT)[4].strip)
|
||
|
raise MissingInformation.new('Unable to determine target board/forum') if target.nil?
|
||
|
target
|
||
|
end
|
||
|
# Returns a Hash of issue attributes extracted from keywords in the email body
|
||
|
def issue_attributes_from_keywords(issue)
|
||
|
assigned_to = (k = get_keyword(:assigned_to, :override => true)) && find_user_from_keyword(k)
|
||