Simplify Gmail notifications.
This commit is contained in:
parent
7d0d96f940
commit
f34b9399cc
@ -37,14 +37,6 @@ class Gmail(BasePlugin):
|
|||||||
register_stanza_plugin(Iq, stanza.MailBox)
|
register_stanza_plugin(Iq, stanza.MailBox)
|
||||||
register_stanza_plugin(Iq, stanza.NewMail)
|
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(
|
self.xmpp.register_handler(
|
||||||
Callback('Gmail New Mail',
|
Callback('Gmail New Mail',
|
||||||
MatchXPath('{%s}iq/{%s}%s' % (
|
MatchXPath('{%s}iq/{%s}%s' % (
|
||||||
@ -56,24 +48,17 @@ class Gmail(BasePlugin):
|
|||||||
self._last_result_time = None
|
self._last_result_time = None
|
||||||
|
|
||||||
def plugin_end(self):
|
def plugin_end(self):
|
||||||
self.xmpp.remove_handler('Gmail Result')
|
|
||||||
self.xmpp.remove_handler('Gmail New Mail')
|
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):
|
def _handle_new_mail(self, iq):
|
||||||
log.info("Gmail: New emails received!")
|
log.info("Gmail: New email!")
|
||||||
self.xmpp.event('gmail_notify', iq)
|
iq.reply().send()
|
||||||
self.check(block=False)
|
self.xmpp.event('gmail_notification')
|
||||||
|
|
||||||
def check(self, block=True, timeout=None, callback=None):
|
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,
|
block=block,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
callback=callback)
|
callback=callback)
|
||||||
|
@ -46,7 +46,7 @@ class GmailQuery(ElementBase):
|
|||||||
class MailBox(ElementBase):
|
class MailBox(ElementBase):
|
||||||
namespace = 'google:mail:notify'
|
namespace = 'google:mail:notify'
|
||||||
name = 'mailbox'
|
name = 'mailbox'
|
||||||
plugin_attrib = 'gmail_results'
|
plugin_attrib = 'gmail_messages'
|
||||||
interfaces = set(['result_time', 'url', 'matched', 'estimate'])
|
interfaces = set(['result_time', 'url', 'matched', 'estimate'])
|
||||||
|
|
||||||
def get_matched(self):
|
def get_matched(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user