Project

General

Profile

Patch #1616 » 2.3.2-forum_message_creation_by_mail.patch

Christian Burger, 2013-07-24 10:32

View differences:

mail_handler.rb 2013-07-21 08:58:21.471607222 +0200
MESSAGE_ID_RE = %r{^<?redmine\.([a-z0-9_]+)\-(\d+)\.\d+@}
ISSUE_REPLY_SUBJECT_RE = %r{\[[^\]]*#(\d+)\]}
MESSAGE_REPLY_SUBJECT_RE = %r{\[[^\]]*msg(\d+)\]}
MESSAGE_CREATE_SUBJECT = %r{^\[([^\]]+ - )?([^\]]+)\] ?(.*)}
def dispatch
headers = [email.in_reply_to, email.references].flatten.compact
......
receive_issue_reply(m[1].to_i)
elsif m = subject.match(MESSAGE_REPLY_SUBJECT_RE)
receive_message_reply(m[1].to_i)
elsif m = subject.match(MESSAGE_CREATE_SUBJECT)
receive_message(m[1], m[2], m[3])
else
dispatch_to_default
end
......
issue
end
# Creates a new forum message
def receive_message(project, board, subject)
project &&= Project.find_by_name(project[0..-4])
project ||= target_project
board = Board.find_by_name_and_project_id(board, project.id)
# check permission
unless @@handler_options[:no_permission_check]
raise UnauthorizedAction unless user.allowed_to?(:add_messages, project)
end
message = Message.new(:author => user, :board => board)
message.subject = subject
message.content = cleaned_up_text_body
add_watchers(message)
message.save!
add_attachments(message)
logger.info "MailHandler: message #{message.id} - \"#{message.subject}\" created by #{user}" if logger && logger.info
message
end
# Adds a note to an existing issue
def receive_issue_reply(issue_id, from_journal=nil)
issue = Issue.find_by_id(issue_id)
......
# Adds To and Cc as watchers of the given object if the sender has the
# appropriate permission
def add_watchers(obj)
if user.allowed_to?("add_#{obj.class.name.underscore}_watchers".to_sym, obj.project)
if user.allowed_to?("add_#{obj.class.name.underscore}_watchers".to_sym, obj.project) \
|| obj.is_a?(Message)
addresses = [email.to, email.cc].flatten.compact.uniq.collect {|a| a.strip.downcase}
unless addresses.empty?
watchers = User.active.where('LOWER(mail) IN (?)', addresses).all
(4-4/4)