Patch #3123 ยป mail_handler.rb.patch
| app/models/mail_handler.rb (working copy) | ||
|---|---|---|
|
# Processes incoming emails
|
||
|
def receive(email)
|
||
|
@email = email
|
||
|
@user = User.active.find_by_mail(email.from.to_a.first.to_s.strip)
|
||
|
find_user_from_email_header(email['return-path']) || find_user_from_email_header(email['sender']) || find_user_from_email_header(email['from'])
|
||
|
unless @user
|
||
|
# Unknown user => the email is ignored
|
||
|
# TODO: ability to create the user's account
|
||
|
logger.info "MailHandler: email submitted by unknown user [#{email.from.first}]" if logger && logger.info
|
||
|
logger.info "MailHandler: email submitted by unknown user, Return-Path: #{email.header_string('return-path')}, Sender: #{email.header_string('sender')}, From: #{email.header_string('from')}" if logger && logger.info
|
||
|
return false
|
||
|
end
|
||
|
User.current = @user
|
||
| ... | ... | |
|
private
|
||
|
def find_user_from_email_header(address_header)
|
||
|
address_spec = first_address_spec(address_header)
|
||
|
@user = User.active.find_by_mail(address_spec.strip) if address_spec
|
||
|
end
|
||
|
|
||
|
def first_address_spec(address_header)
|
||
|
return nil unless address_header && address_header.addrs
|
||
|
list = address_header.addrs.map {|addr|
|
||
|
if addr.address_group?
|
||
|
then addr.map {|a| a.spec }
|
||
|
else addr.spec
|
||
|
end
|
||
|
}.flatten
|
||
|
list.first
|
||
|
end
|
||
|
|
||
|
MESSAGE_ID_RE = %r{^<redmine\.([a-z0-9_]+)\-(\d+)\.\d+@}
|
||
|
ISSUE_REPLY_SUBJECT_RE = %r{\[[^\]]+#(\d+)\]}
|
||
|
MESSAGE_REPLY_SUBJECT_RE = %r{\[[^\]]+msg(\d+)\]}
|
||