summaryrefslogtreecommitdiff
path: root/sleekxmpp
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2013-01-21 01:37:42 -0800
committerLance Stout <lancestout@gmail.com>2013-01-21 01:38:02 -0800
commitf34b9399cc3fa8bb87d0271293a891533c8dacfd (patch)
treef08751cf133fbce2251941a019347b38135272a5 /sleekxmpp
parent7d0d96f94053472202fb2ef8f3f915f5ad3a2286 (diff)
downloadslixmpp-f34b9399cc3fa8bb87d0271293a891533c8dacfd.tar.gz
slixmpp-f34b9399cc3fa8bb87d0271293a891533c8dacfd.tar.bz2
slixmpp-f34b9399cc3fa8bb87d0271293a891533c8dacfd.tar.xz
slixmpp-f34b9399cc3fa8bb87d0271293a891533c8dacfd.zip
Simplify Gmail notifications.
Diffstat (limited to 'sleekxmpp')
-rw-r--r--sleekxmpp/plugins/gmail/notifications.py27
-rw-r--r--sleekxmpp/plugins/gmail/stanza.py2
2 files changed, 7 insertions, 22 deletions
diff --git a/sleekxmpp/plugins/gmail/notifications.py b/sleekxmpp/plugins/gmail/notifications.py
index 6c8a4a02..dbc68162 100644
--- a/sleekxmpp/plugins/gmail/notifications.py
+++ b/sleekxmpp/plugins/gmail/notifications.py
@@ -38,14 +38,6 @@ class Gmail(BasePlugin):
register_stanza_plugin(Iq, stanza.NewMail)
self.xmpp.register_handler(
- Callback('Gmail Result',
- MatchXPath('{%s}iq/{%s}%s' % (
- self.xmpp.default_ns,
- stanza.MailBox.namespace,
- stanza.MailBox.name)),
- self._handle_gmail))
-
- self.xmpp.register_handler(
Callback('Gmail New Mail',
MatchXPath('{%s}iq/{%s}%s' % (
self.xmpp.default_ns,
@@ -56,24 +48,17 @@ class Gmail(BasePlugin):
self._last_result_time = None
def plugin_end(self):
- self.xmpp.remove_handler('Gmail Result')
self.xmpp.remove_handler('Gmail New Mail')
- def _handle_gmail(self, iq):
- mailbox = iq['gmail_results']
- log.info('Gmail: Received%s %s emails',
- ' approximately' if mailbox['estimated'] else '',
- mailbox['matched'])
- self._last_result_time = mailbox['result_time']
- self.xmpp.event('gmail_messages', iq)
-
def _handle_new_mail(self, iq):
- log.info("Gmail: New emails received!")
- self.xmpp.event('gmail_notify', iq)
- self.check(block=False)
+ log.info("Gmail: New email!")
+ iq.reply().send()
+ self.xmpp.event('gmail_notification')
def check(self, block=True, timeout=None, callback=None):
- return self.search(newer=self._last_result_time,
+ last_time = self._last_result_time
+ self._last_result_time = str(int(time.time() * 1000))
+ return self.search(newer=last_time,
block=block,
timeout=timeout,
callback=callback)
diff --git a/sleekxmpp/plugins/gmail/stanza.py b/sleekxmpp/plugins/gmail/stanza.py
index fe56177d..e7e308e1 100644
--- a/sleekxmpp/plugins/gmail/stanza.py
+++ b/sleekxmpp/plugins/gmail/stanza.py
@@ -46,7 +46,7 @@ class GmailQuery(ElementBase):
class MailBox(ElementBase):
namespace = 'google:mail:notify'
name = 'mailbox'
- plugin_attrib = 'gmail_results'
+ plugin_attrib = 'gmail_messages'
interfaces = set(['result_time', 'url', 'matched', 'estimate'])
def get_matched(self):