· 7 years ago · Oct 09, 2018, 01:16 AM
1"""
2I ran into this issue when trying to bot a site with emails. I tried to mass send with an address like 'hello@gmail.com' but after some sends they banned hello from sending mail. My first instinct was to use a +str alias onto the email which usually works but this site prevented special characters from being inputted.
3
4The idea after this point was to encode dots into the gmail username. Personal gmail accounts ignore dots in email usernames so the emails 'alias@gmail.com' and 'a.lias@gmail.com' point to the same person. By exploiting this trick we can encode in binary, any integer. So, the number '5' is '101' in binary, and encoded into 'alias@gmail.com' becomes 'a.li.as@gmail.com' where 1's are dots.
5
6This allows me to bot the contact form with the same email with the maximum integer allowed inside being equal to 2^len(username). Any integer larger than that will just wrap to the beginning. Please note that this DOES NOT work with non-gmail accounts; even gSuite accounts will be invalid. Only mail going to `gmail.com` will allow for this method.
7"""
8import itertools
9
10def dot_encode_email_username(username: str, member_id: int):
11 stripped_username = username.replace('.', '').rstrip('+')
12
13 max_id = pow(2, len(stripped_username)) - 1
14 bounded_id = member_id % max_id
15 bin_id = bin(bounded_id)[2:]
16
17 i_username = [c for c in stripped_username]
18 i_bin_id = ['.' if bool(int(n)) else '' for n in bin_id] #remove b0 from binary string
19
20 i_encoded_username = [x for x in itertools.chain.from_iterable(itertools.zip_longest(i_username,i_bin_id)) if x]
21 return ''.join(i_encoded_username).rstrip('.')
22
23for member in members:
24 username = dot_encode_email_username(member['name'], member['id'])
25 encoded_email = f'{username}@gmail.com'
26 # do something with encoded_email