sspreitzer

gmap.py

Aug 19th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. import imaplib
  2. import re
  3.  
  4. class g(object):
  5.     def __init__(self, user, password):
  6.         self._M = imaplib.IMAP4_SSL("imap.googlemail.com")
  7.         self._M.login(user, password)
  8.         self._M.select("[Gmail]/Alle Nachrichten")
  9.        
  10.     def getFilterByYear(self, year="2012"):
  11.         return "(SINCE 01-Jan-" + str(year) + " BEFORE 31-Dec-" + str(year) + ")"
  12.    
  13.     def getList(self, filter="ALL"):
  14.         return self._M.search(None, filter)[1][0].split()
  15.    
  16.     def getCount(self, filter="ALL"):
  17.         return len(self.getList(filter))
  18.    
  19.     def fetchRFC822(self, num):
  20.         return self._M.fetch(num, "(RFC822)")[1][0][1]
  21.    
  22.     def getSubject(self, message):
  23.         try:
  24.             subj = re.search("^[Ss]ubject:\ (.*)$", message, re.M).group(1)
  25.         except:
  26.             return ""
  27.         return subj[:len(subj)-1]
  28.  
  29.     def __getitem__(self, num):
  30.         return self.fetchRFC822(num)
  31.    
  32.     def __len__(self):
  33.         return self.getCount()
Advertisement
Add Comment
Please, Sign In to add comment