Patch #3123 ยป mail_handler.rb.patch
| app/models/mail_handler.rb (working copy) | ||
|---|---|---|
| 40 | 40 |
# Processes incoming emails |
| 41 | 41 |
def receive(email) |
| 42 | 42 |
@email = email |
| 43 |
@user = User.active.find_by_mail(email.from.to_a.first.to_s.strip)
|
|
| 43 |
find_user_from_email_header(email['return-path']) || find_user_from_email_header(email['sender']) || find_user_from_email_header(email['from'])
|
|
| 44 | 44 |
unless @user |
| 45 | 45 |
# Unknown user => the email is ignored |
| 46 | 46 |
# TODO: ability to create the user's account |
| 47 |
logger.info "MailHandler: email submitted by unknown user [#{email.from.first}]" if logger && logger.info
|
|
| 47 |
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
|
|
| 48 | 48 |
return false |
| 49 | 49 |
end |
| 50 | 50 |
User.current = @user |
| ... | ... | |
| 53 | 53 | |
| 54 | 54 |
private |
| 55 | 55 | |
| 56 |
def find_user_from_email_header(address_header) |
|
| 57 |
address_spec = first_address_spec(address_header) |
|
| 58 |
@user = User.active.find_by_mail(address_spec.strip) if address_spec |
|
| 59 |
end |
|
| 60 |
|
|
| 61 |
def first_address_spec(address_header) |
|
| 62 |
return nil unless address_header && address_header.addrs |
|
| 63 |
list = address_header.addrs.map {|addr|
|
|
| 64 |
if addr.address_group? |
|
| 65 |
then addr.map {|a| a.spec }
|
|
| 66 |
else addr.spec |
|
| 67 |
end |
|
| 68 |
}.flatten |
|
| 69 |
list.first |
|
| 70 |
end |
|
| 71 |
|
|
| 56 | 72 |
MESSAGE_ID_RE = %r{^<redmine\.([a-z0-9_]+)\-(\d+)\.\d+@}
|
| 57 | 73 |
ISSUE_REPLY_SUBJECT_RE = %r{\[[^\]]+#(\d+)\]}
|
| 58 | 74 |
MESSAGE_REPLY_SUBJECT_RE = %r{\[[^\]]+msg(\d+)\]}
|