Advertisement
Guest User

Untitled

a guest
Oct 11th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #! /usr/bin/env python2.7
  2.  
  3. import imaplib,re
  4.  
  5. class pygmail:
  6.  
  7. GMAIL_IMAP_SERVER = 'imap.gmail.com'
  8. GMAIL_IMAP_PORT = '993'
  9. GMAIL_USERNAME = 'username'
  10. GMAIL_PASSWORD = 'password'
  11.  
  12.  
  13. def __init__(self):
  14. self.conn = imaplib.IMAP4_SSL(self.GMAIL_IMAP_SERVER,self.GMAIL_IMAP_PORT)
  15.  
  16. def login(self):
  17. rc,self.response = self.conn.login(self.GMAIL_USERNAME,self.GMAIL_PASSWORD)
  18.  
  19. def logout(self):
  20. self.conn.logout()
  21.  
  22. def get_mail_count(self,folder='Inbox'):
  23. rc,count = self.M.select(folder)
  24. return count[0]
  25.  
  26. def get_unread_count(self):
  27. unreadCount = re.search("UNSEEN (\d+)", self.conn.status("INBOX", "(UNSEEN)")[1][0]).group(1)
  28. return unreadCount
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement