Scripting de appartenance à un groupe

Let me give an example, because my question must not have been clear.

I have these three email address:
alice@example.com - Belongs to a forum member who is not a group member of SomeGroup
bob@foo.org - Belongs to a forum member who is a member of SomeGroup
carol@bar.edu - Does not belong to a forum member.

I’d like the script to add the user associated with alice@example.com to SomeGroup (and possibly send a welcome message), do nothing for the user bob@foo.org, and send an invite with the group enrolment flag to carol@bar.edu.