ymail.py 582 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. import sys, imaplib
  4. port = 993
  5. server = 'imap.yandex.ru'
  6. username = 'user@home.com'
  7. passwd = ''
  8. imap_server = imaplib.IMAP4_SSL(server, port)
  9. try:
  10. imap_server.login(username, passwd)
  11. except:
  12. print('?? new')
  13. sys.exit( 1 )
  14. typ, data = imap_server.select ('Inbox', True)
  15. if typ == 'OK':
  16. total = int(data[0])
  17. typ, data = imap_server.search (None, 'SEEN')
  18. if typ == 'OK':
  19. seen = len(data[0].split())
  20. print('{} new'.format(total - seen))
  21. if typ != 'OK':
  22. print('?? new')
  23. imap_server.logout()