FIX: Correct the forwarded by user small post for group inbox (PR #14252)

When 2ac9fd9dff5a2a9210e2b1b765e1a324bbb4f421 was done, this affected the small post that is created when forwarding an email into the group inbox. Instead of using the name and the email of the user who forwarded the email, it used the original from email and name to create the small post. So instead of something like “Discourse Team forwarded the above email” we ended up with “John Smith forwarded the above email” which is incorrect.

This fixes the issue by creating a staged user for the forwarding email address (if such a user does not yet exist) and uses that for the “forwarded” small post instead.

GitHub

I am not sure if @forwarded_by_address and @forwarded_by_name should be instance variables as they are quite specific to 2 methods.

You already have instance variable @mail which makes sens because whole class is using it. What would you say for some helper method like

def fowarded_by_address_and_forwarded_by_name
  @fowarded_by_address_and_forwarded_by_name ||= extract_from_fields_from_header(@mail, :from)
end
def fowarded_by_address
  @forwarded_by_address ||= fowarded_by_address_and_forwarded_by_name&.first
end
def fowarded_by_name
  @forwarded_by_name ||= fowarded_by_address_and_forwarded_by_name&.last
end

# This instance variables are just to memoize, not to be used

Yes I think this is a good call, will change

Do we need to pass @mail?

I found just one reference to that method, so maybe lets just use @mail inside?

Ah yes sorry this was a change from the other fix I have to do in this error that snuck into the diff, I will get rid of it for now.