While playing around with IMAP sync a staged user was created for Group.email_username during import from the IMAP account.
Trying to understand what happened I noticed that Group.find_by_email does not take Group.email_username into account requiring to set Group.incoming_email to include this value at least.
enable IMAP sync
configure Email sync options on a group but leave Group.incoming_email unconfigured
Thanks @thoka , I had a look into this. I think you are right in that Group.find_by_email needs to have the email_username added to it, but it is not the cause of the group email user getting staged in this case. This actually happens later on in the receiver where we add other addresses to the newly created topic. The important part here is should_invite?
Which in turn compares the email against group_incoming_emails_regex:
I think we will need to make it so in this regex, or another, that we compare against the email_username as well. So far we have not found it a problem that the staged user for the group is made, though I can see that it looks a little messy/unnecessary. I will need to do some testing when I change this to make sure the staged user for the group is not being made for some important currently unknown (to me) reason.