welcome: please sign in

The following 142 words could not be found in the dictionary of 7 words (including 7 LocalSpellingWords) and are highlighted below:
addresses   all   All   and   any   are   argv   below   big   bog   can   case   catch   change   character   checked   classes   Client   com   compile   data   domain   dompattern   easy   email   emails   ever   exist   explicitly   extend   fetch   find   flags   folder   for   forwarding   from   getpass   Gmail   gmail   have   haven   having   if   If   imap   imapclient   import   in   inbox   info   install   installed   is   issues   it   It   iteritems   keys   know   Let   line   login   logout   long   lower   luna   Mail   mainly   may   me   messages   migrate   msgid   my   need   not   of   off   on   one   or   particular   people   pip   print   purpose   py   python   re   reasonably   replace   replacing   response   Run   run   script   search   select   server   set   situation   small   smaller   so   ssl   strip   sub   sys   take   test   that   The   the   there   these   they   This   this   time   to   To   True   true   uid   Uncomment   upgrade   use   used   variables   very   want   well   which   who   will   with   works   You   you   your   z0  

Clear message
Edit

FindAllAddresses

This is a script which will find all To-addresses for a particular domain that exist in your email.

The purpose is mainly so that people who want to migrate off of having a catch-all for forwarding to Gmail can explicitly set all the addresses they have ever used.

You need python with IMAPClient installed (I haven't checked if this is true or not on bog).

pip install imapclient             # install
pip install --upgrade imapclient   # upgrade

or

easy_install IMAPClient            # install
easy_install --upgrade IMAPClient  # upgrade

Run the script with

python addresses.py $DOMAIN $GMAIL_USERNAME

replacing the variables with your particular situation. It can take a very long time to run. If you want to test that it works reasonably well for your situation, you can find a folder that is small and run the script on that folder (in my case, that's the inbox). Uncomment the line with 'INBOX' below (and change folder to a smaller one if your inbox is big).

Let me know if there are any issues. //luna

# Written by Daniel Luna <daniel@lunas.se>
from imapclient import IMAPClient
import sys
import re
from getpass import getpass

domain = sys.argv[1]
HOST = 'imap.gmail.com'
USERNAME = sys.argv[2]
PASSWORD = getpass()
server = IMAPClient(HOST, use_uid=True, ssl=True)
server.login(USERNAME, PASSWORD)
select_info = server.select_folder('[Gmail]/All Mail')
#select_info = server.select_folder('INBOX')
messages = server.search()
response = server.fetch(messages, ['BODY[HEADER.FIELDS (TO)]'])
dompattern = re.compile('@' + domain, flags=re.IGNORECASE)
emails = {}
for msgid, data in response.iteritems():
    x = data['BODY[HEADER.FIELDS (TO)]'].replace('\n', '').replace('\r', '').strip().lower()
    if dompattern.search(x):
        # You may want to extend these character classes
        emails[re.sub('.*[^-a-z0-9_.+]([-a-z0-9_.+]*@' + domain + ').*', '\\1', x)] = True
server.logout()
for email in emails.keys():
    print '%s' % email

FindAllAddresses (last edited 2013-01-16 19:20:33 by RobinTempleton)