Subversion Repositories HomeAutomation

Rev

Blame | Last modification | View Log | SVN | RSS feed

  1. ############################################################################
  2. #    Copyright (C) 2008 by Mattias Runge   #
  3. #    mattias@runge.se   #
  4. #                                                                          #
  5. #    This program is free software; you can redistribute it and#or modify  #
  6. #    it under the terms of the GNU General Public License as published by  #
  7. #    the Free Software Foundation; either version 2 of the License, or     #
  8. #    (at your option) any later version.                                   #
  9. #                                                                          #
  10. #    This program is distributed in the hope that it will be useful,       #
  11. #    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
  12. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
  13. #    GNU General Public License for more details.                          #
  14. #                                                                          #
  15. #    You should have received a copy of the GNU General Public License     #
  16. #    along with this program; if not, write to the                         #
  17. #    Free Software Foundation, Inc.,                                       #
  18. #    59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             #
  19. ############################################################################
  20.  
  21. import ServiceBase
  22. import Util
  23. from imaplib import *
  24.  
  25. class Service (ServiceBase.ServiceBase):
  26.     Values = {}
  27.    
  28.     def __init__(self, id):
  29.         ServiceBase.ServiceBase.__init__(self, id, "Imap")
  30.        
  31.         self.events = {"onMailStatusUpdate":[]}
  32.  
  33.     #   self.CreateInterval(20, "CheckNewEmail", self.CheckNewEmail)
  34.  
  35.     def CheckNewEmail(self, server, username, password, mailbox):
  36.  
  37.         server = IMAP4(server)
  38.  
  39.         server.login(username, password)
  40.  
  41.         r = server.select(mailbox)
  42.  
  43.         r, data = server.search(None, "(NEW)")
  44.  
  45.         if r == "OK":
  46.             return len(data)
  47.  
  48.         return -1
  49.  
  50.  
  51.  
  52.  
  53.