summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/gmail_notify.py
diff options
context:
space:
mode:
authorNathan Fritz <fritzy@netflint.net>2009-06-03 22:56:51 +0000
committerNathan Fritz <fritzy@netflint.net>2009-06-03 22:56:51 +0000
commit96b103b27599e5af247c1e3b95d62c80c1e32a63 (patch)
tree0527b1607b16adb020759ee9a944e1b22e3e0e6b /sleekxmpp/plugins/gmail_notify.py
downloadslixmpp-96b103b27599e5af247c1e3b95d62c80c1e32a63.tar.gz
slixmpp-96b103b27599e5af247c1e3b95d62c80c1e32a63.tar.bz2
slixmpp-96b103b27599e5af247c1e3b95d62c80c1e32a63.tar.xz
slixmpp-96b103b27599e5af247c1e3b95d62c80c1e32a63.zip
moved seesmic branch to trunk
Diffstat (limited to 'sleekxmpp/plugins/gmail_notify.py')
-rw-r--r--sleekxmpp/plugins/gmail_notify.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/sleekxmpp/plugins/gmail_notify.py b/sleekxmpp/plugins/gmail_notify.py
new file mode 100644
index 00000000..8bc4423a
--- /dev/null
+++ b/sleekxmpp/plugins/gmail_notify.py
@@ -0,0 +1,57 @@
+"""
+ SleekXMPP: The Sleek XMPP Library
+ Copyright (C) 2007 Nathanael C. Fritz
+ This file is part of SleekXMPP.
+
+ SleekXMPP is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ SleekXMPP is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with SleekXMPP; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+"""
+from __future__ import with_statement
+import base
+import logging
+from xml.etree import cElementTree as ET
+import traceback
+import time
+
+class gmail_notify(base.base_plugin):
+
+ def plugin_init(self):
+ self.description = 'Google Talk Gmail Notification'
+ self.xmpp.add_event_handler('sent_presence', self.handler_gmailcheck, threaded=True)
+ self.emails = []
+
+ def handler_gmailcheck(self, payload):
+ #TODO XEP 30 should cache results and have getFeature
+ result = self.xmpp['xep_0030'].getInfo(self.xmpp.server)
+ features = []
+ for feature in result.findall('{http://jabber.org/protocol/disco#info}query/{http://jabber.org/protocol/disco#info}feature'):
+ features.append(feature.get('var'))
+ if 'google:mail:notify' in features:
+ logging.debug("Server supports Gmail Notify")
+ self.xmpp.add_handler("<iq type='set' xmlns='%s'><new-mail xmlns='google:mail:notify' /></iq>" % self.xmpp.default_ns, self.handler_notify)
+ self.getEmail()
+
+ def handler_notify(self, xml):
+ logging.info("New Gmail recieved!")
+ self.xmpp.event('gmail_notify')
+
+ def getEmail(self):
+ iq = self.xmpp.makeIqGet()
+ iq.attrib['from'] = self.xmpp.fulljid
+ iq.attrib['to'] = self.xmpp.jid
+ self.xmpp.makeIqQuery(iq, 'google:mail:notify')
+ emails = self.xmpp.send(iq, self.xmpp.makeIq(self.xmpp.id))
+ mailbox = emails.find('{google:mail:notify}mailbox')
+ total = int(mailbox.get('total-matched', 0))
+ logging.info("%s New Gmail Messages" % total)