2.3.2-forum_message_creation_by_mail.patch

Christian Burger, 2013-07-24 10:32

Download (2.18 KB)

View differences:

mail_handler.rb 2013-07-21 08:58:21.471607222 +0200
126 126
  MESSAGE_ID_RE = %r{^<?redmine\.([a-z0-9_]+)\-(\d+)\.\d+@}
127 127
  ISSUE_REPLY_SUBJECT_RE = %r{\[[^\]]*#(\d+)\]}
128 128
  MESSAGE_REPLY_SUBJECT_RE = %r{\[[^\]]*msg(\d+)\]}
129
  MESSAGE_CREATE_SUBJECT = %r{^\[([^\]]+ - )?([^\]]+)\] ?(.*)}
129 130

  
130 131
  def dispatch
131 132
    headers = [email.in_reply_to, email.references].flatten.compact
......
142 143
      receive_issue_reply(m[1].to_i)
143 144
    elsif m = subject.match(MESSAGE_REPLY_SUBJECT_RE)
144 145
      receive_message_reply(m[1].to_i)
146
    elsif m = subject.match(MESSAGE_CREATE_SUBJECT)
147
      receive_message(m[1], m[2], m[3])
145 148
    else
146 149
      dispatch_to_default
147 150
    end
......
186 189
    issue
187 190
  end
188 191

  
192
  # Creates a new forum message
193
  def receive_message(project, board, subject)
194
    project &&= Project.find_by_name(project[0..-4])
195
    project ||= target_project
196
    board = Board.find_by_name_and_project_id(board, project.id)
197

  
198
    # check permission
199
    unless @@handler_options[:no_permission_check]
200
      raise UnauthorizedAction unless user.allowed_to?(:add_messages, project)
201
    end
202

  
203
    message = Message.new(:author => user, :board => board)
204
    message.subject = subject
205
    message.content = cleaned_up_text_body
206
    add_watchers(message)
207
    message.save!
208
    add_attachments(message)
209

  
210
    logger.info "MailHandler: message #{message.id} - \"#{message.subject}\" created by #{user}" if logger && logger.info
211
    message
212
  end
213

  
189 214
  # Adds a note to an existing issue
190 215
  def receive_issue_reply(issue_id, from_journal=nil)
191 216
    issue = Issue.find_by_id(issue_id)
......
266 291
  # Adds To and Cc as watchers of the given object if the sender has the
267 292
  # appropriate permission
268 293
  def add_watchers(obj)
269
    if user.allowed_to?("add_#{obj.class.name.underscore}_watchers".to_sym, obj.project)
294
    if user.allowed_to?("add_#{obj.class.name.underscore}_watchers".to_sym, obj.project) \
295
        || obj.is_a?(Message)
270 296
      addresses = [email.to, email.cc].flatten.compact.uniq.collect {|a| a.strip.downcase}
271 297
      unless addresses.empty?
272 298
        watchers = User.active.where('LOWER(mail) IN (?)', addresses).all