Guest User

Untitled

a guest
Nov 20th, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # Simple i3blocks mail checker script
  3. #
  4. # Config; ~/.mailchecker.ini
  5. #
  6. #
  7. # Example config:
  8. #
  9. # [config]
  10. # username = foo
  11. # password = bar
  12. # server = qux.tld
  13.  
  14. import imaplib
  15. import ConfigParser
  16. import os
  17. import sys
  18.  
  19. # Parse configuration file
  20. configfile = os.getenv('HOME') + "/.mailchecker.ini"
  21. if os.path.isfile(configfile):
  22. try:
  23. config = ConfigParser.ConfigParser()
  24. config.read(configfile)
  25. myuser = config.get('config', 'username')
  26. mypassword = config.get('config', 'password')
  27. myserver = config.get('config', 'server')
  28. except Exception as e:
  29. print ""
  30. print "Error while parsing configuration file: " + str(e._Error__message)
  31. print ""
  32. sys.exit(200)
  33.  
  34.  
  35. mail = imaplib.IMAP4_SSL(myserver)
  36. (retcode, capabilities) = mail.login(myuser,mypassword)
  37. mail.list()
  38. mail.select('inbox')
  39.  
  40. n=0
  41. (retcode, messages) = mail.search(None, '(UNSEEN)')
  42. if retcode == 'OK':
  43. print "Mail: " + str(len(messages)) + " unread (" + myserver
Add Comment
Please, Sign In to add comment