mysociety / alaveteli

Provide a Freedom of Information request system for your jurisdiction
https://alaveteli.org
Other
385 stars 195 forks source link

Mail sent To team@ with Cc pro_team@ does not get delivered to team@ #5649

Closed sagepe closed 2 years ago

sagepe commented 4 years ago

When an email is received that was sent both to a regular support address and a Pro support address (as per the example in the title), the mail handling code will override the regular support address with the pro support address defined in PRO_CONTACT_EMAIL.

See these lines in reply_handler.rb:

def self.get_forward_to_address(message)
  forward_to = AlaveteliConfiguration.forward_nonbounce_responses_to
  if AlaveteliConfiguration.enable_alaveteli_pro
    pro_contact_email = AlaveteliConfiguration.pro_contact_email
    original_to = message ? MailHandler.get_all_addresses(message) : []
    if original_to.include?(pro_contact_email)
      forward_to = AlaveteliConfiguration.forward_pro_nonbounce_responses_to
    end
  end
  forward_to
end

The call to MailHandler.get_all_addresses(message) in mail_backend.rbreturns an array that includes things in CC:

def get_all_addresses(mail, include_invalid: false)
  addrs = []
  addrs << mail.to
  addrs << mail[:to].try(:value) if mail.to.nil? && include_invalid
  addrs << mail.cc
  addrs << mail[:cc].try(:value) if mail.cc.nil? && include_invalid
  addrs << (mail['envelope-to'] ? mail['envelope-to'].value.to_s : nil)
  addrs.flatten.compact.uniq
end

The first snippet then resets forward_to to AlaveteliConfiguration.forward_pro_nonbounce_responses_to if AlaveteliConfiguration.pro_contact_email is found in the original_to array - which it will be in this case.

More details available in this internal ticket.

garethrees commented 3 years ago

Just noting that this was recorded as an issue in https://github.com/mysociety/alaveteli-professional/issues/138, implemented in https://github.com/mysociety/alaveteli/pull/3706 and similar issue fixed in https://github.com/mysociety/alaveteli/pull/4948