diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index e87a2fde2..492c782f1 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -1371,6 +1371,9 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, except: HAS_IDLE = False + self.gmail_last_tid = None + self.gmail_last_time = None + def build_http_auth_answer(self, iq_obj, answer): if answer == 'yes': self.connection.send(iq_obj.buildReply('result')) @@ -1582,9 +1585,14 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, jid = gajim.get_jid_from_account(self.name) gajim.log.debug('Got notification of new gmail e-mail on %s. Asking the server for more info.' % jid) iq = common.xmpp.Iq(typ = 'get') - iq.setAttr('id', '13') + iq.setID(self.connection.getAnID()) query = iq.setTag('query') query.setNamespace(common.xmpp.NS_GMAILNOTIFY) + # we want only be notified about newer mails + if self.gmail_last_tid: + query.setAttr('newer-than-tid', self.gmail_last_tid) + if self.gmail_last_time: + query.setAttr('newer-than-time', self.gmail_last_time) self.connection.send(iq) raise common.xmpp.NodeProcessed @@ -1601,16 +1609,34 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, if gm.getTag('mailbox').getTag('mail-thread-info'): gmail_messages = gm.getTag('mailbox').getTags('mail-thread-info') for gmessage in gmail_messages: - sender = gmessage.getTag('senders').getTag('sender') - if not sender: + unread_senders = [] + for sender in gmessage.getTag('senders').getTags('sender'): + if sender.getAttr('unread') != '1': + continue + if sender.getAttr('name'): + unread_senders.append(sender.getAttr('name') + '< ' + \ + sender.getAttr('address') + '>') + else: + unread_senders.append(sender.getAttr('address')) + + if not unread_senders: continue - gmail_from = sender.getAttr('address') gmail_subject = gmessage.getTag('subject').getData() gmail_snippet = gmessage.getTag('snippet').getData() + tid = int(gmessage.getAttr('tid')) + if not self.gmail_last_tid or tid > self.gmail_last_tid: + self.gmail_last_tid = tid gmail_messages_list.append({ \ - 'From': gmail_from, \ + 'From': unread_senders, \ 'Subject': gmail_subject, \ - 'Snippet': gmail_snippet}) + 'Snippet': gmail_snippet, \ + 'url': gmessage.getAttr('url'), \ + 'participation': gmessage.getAttr('participation'), \ + 'messages': gmessage.getAttr('messages'), \ + 'date': gmessage.getAttr('date')}) + self.gmail_last_time = int(gm.getTag('mailbox').getAttr( + 'result-time')) + jid = gajim.get_jid_from_account(self.name) gajim.log.debug(('You have %s new gmail e-mails on %s.') % (newmsgs, jid)) self.dispatch('GMAIL_NOTIFY', (jid, newmsgs, gmail_messages_list)) diff --git a/src/gajim.py b/src/gajim.py index 86f763bad..a9e6a62b0 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -1648,18 +1648,26 @@ class Interface: gmail_new_messages, gmail_new_messages) if gajim.config.get('notify_on_new_gmail_email_extra'): + cnt = 0 for gmessage in gmail_messages_list: - #FIXME: emulate Gtalk client popups. find out what they parse and how - #they decide what to show - # each message has a 'From', 'Subject' and 'Snippet' field - text += _('\nFrom: %(from_address)s') % \ - {'from_address': gmessage['From']} + #FIXME: emulate Gtalk client popups. find out what they parse and + # how they decide what to show each message has a 'From', + # 'Subject' and 'Snippet' field + if cnt >=5: + break + senders = reduce(lambda b, a: a + ',\n ' + b, + gmessage['From']) + text += _('\n\nFrom: %(from_address)s\nSubject: %(subject)s\n%(snippet)s') % \ + {'from_address': senders, 'subject': gmessage['Subject'], + 'snippet': gmessage['Snippet']} + cnt += 1 if gajim.config.get_per('soundevents', 'gmail_received', 'enabled'): helpers.play_sound('gmail_received') path = gtkgui_helpers.get_path_to_generic_or_avatar(img) notify.popup(_('New E-mail'), jid, account, 'gmail', - path_to_image = path, title = title, text = text) + path_to_image=path, title=title, + text=gobject.markup_escape_text(text)) if self.remote_ctrl: self.remote_ctrl.raise_signal('NewGmail', (account, array))