SHARE
TWEET

List GMail big size messages

a guest Oct 9th, 2011 330 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from imapclient import IMAPClient
  2.  
  3. HOST = 'imap.gmail.com'
  4. USERNAME = '***yourGMAILusername***'
  5. PASSWORD = '***yourGMAILpassword***'
  6. ssl = True
  7.  
  8. FOLDER = 'INBOX'
  9. ### The default is to scan your Inbox. Uncomment the line below if you want
  10. ### to scan all of your mail. It could take >5min to scan all of your email.
  11. # FOLDER = '[Gmail]/All Mail'
  12.  
  13. SIZETHRESHOLD = 10000000
  14. ### Scan for files larger than the number above (in bytes; 10Mb is reasonable to start with)
  15.  
  16.  
  17.  
  18. server = IMAPClient(HOST, use_uid=True, ssl=ssl)
  19. server.login(USERNAME, PASSWORD)
  20.  
  21.  
  22. select_info = server.select_folder(FOLDER)
  23. print '%d messages in %s' % (select_info['EXISTS'], FOLDER)
  24.  
  25.  
  26. print
  27. print "Messages:"
  28.  
  29. criteria='LARGER %d' %SIZETHRESHOLD
  30. messages = server.search([criteria])
  31.  
  32. response = server.fetch(messages, ['RFC822.SIZE', 'ENVELOPE'])
  33. for msgid, data in response.iteritems():
  34.     if data['RFC822.SIZE'] > SIZETHRESHOLD :
  35.  
  36.         envelope = list(data['ENVELOPE'])
  37.         sender = list(envelope[2][0])
  38.  
  39.         print '   ID %d: ' % msgid
  40.         print '     From: %s <%s@%s>' % (sender[0], sender[2], sender[3])
  41.         print '     Subject: %s ' % envelope[1]
  42.         print '     Size: %i' % data['RFC822.SIZE']
  43.  
  44.  
RAW Paste Data
Top