If i understand the script correctly this one is for gmail only however similar checks could be implemented for other services also.

that will be i think 2-3 more steps.

1) extract the domain...