List GMail big size messages
a guest Oct 9th, 2011 508 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- from imapclient import IMAPClient
- HOST = 'imap.gmail.com'
- USERNAME = '***yourGMAILusername***'
- PASSWORD = '***yourGMAILpassword***'
- ssl = True
- FOLDER = 'INBOX'
- ### The default is to scan your Inbox. Uncomment the line below if you want
- ### to scan all of your mail. It could take >5min to scan all of your email.
- # FOLDER = '[Gmail]/All Mail'
- SIZETHRESHOLD = 10000000
- ### Scan for files larger than the number above (in bytes; 10Mb is reasonable to start with)
- server = IMAPClient(HOST, use_uid=True, ssl=ssl)
- server.login(USERNAME, PASSWORD)
- select_info = server.select_folder(FOLDER)
- print '%d messages in %s' % (select_info['EXISTS'], FOLDER)
- print "Messages:"
- criteria='LARGER %d' %SIZETHRESHOLD
- messages = server.search([criteria])
- response = server.fetch(messages, ['RFC822.SIZE', 'ENVELOPE'])
- for msgid, data in response.iteritems():
- if data['RFC822.SIZE'] > SIZETHRESHOLD :
- envelope = list(data['ENVELOPE'])
- sender = list(envelope)
- print ' ID %d: ' % msgid
- print ' From: %s <%s@%s>' % (sender, sender, sender)
- print ' Subject: %s ' % envelope
- print ' Size: %i' % data['RFC822.SIZE']
RAW Paste Data