~mitya57/unity-mail/unity-mail

« back to all changes in this revision

Viewing changes to UnityMail/application.py

  • Committer: Dmitry Shachnev
  • Date: 2015-02-18 10:11:39 UTC
  • mfrom: (470.1.2 unity-mail)
  • Revision ID: mitya57@ubuntu.com-20150218101139-8ic6vnps8vhh1vh7
Add support for GMail thread URLs (contributed by Alexander Botev).

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import subprocess
19
19
import sys
20
20
import time
 
21
import re
21
22
 
22
23
from os.path import exists, join
23
24
from socket import error as socketerror
39
40
logger.addHandler(handler)
40
41
logger.propagate = False
41
42
 
 
43
thrid_re = re.compile(b'THRID (\\d+)')
 
44
 
42
45
def print_error(error, text=None):
43
46
        msg = text + ': exception occured: ' if text else 'Exception occured: '
44
47
        logger.error(msg + str(error))
85
88
class Message(object):
86
89
        """Message object"""
87
90
        def __init__(self, account_id, account_position, title, folder, message_id,
88
 
                         timestamp):
 
91
                     timestamp, thread_id=None):
89
92
                self.is_active = True
90
93
                self.account_id = account_id
91
94
                self.account_position = account_position
93
96
                self.folder = folder
94
97
                self.message_id = message_id
95
98
                self.timestamp = timestamp
 
99
                self.thread_id = thread_id      
96
100
 
97
101
class UnityMail(object):
98
102
        """Main Unity Mail Application"""
165
169
                        if message.message_id == sourceid:
166
170
                                urlid = self.get_urlid(message.account_id)
167
171
                                if urlid:
168
 
                                        open_url_or_command(urlid)
 
172
                                        open_url_or_command(name=urlid, thread=message.thread_id)
169
173
                                else:
170
174
                                        self.mark_message_as_read(message)
171
175
                                if message.is_active and with_unity:
377
381
                for m in ui:
378
382
                        signal.alarm(3)
379
383
                        typ, msg_data = self.mail_client[cn].fetch(m, '(BODY.PEEK[HEADER])')
 
384
                        try:
 
385
                                thread_id = self.mail_client[cn].fetch(m, '(X-GM-THRID)')[1][0]
 
386
                                thread_id = hex(int(thrid_re.search(thread_id).group(1)))
 
387
                        except imaplib.IMAP4.error:
 
388
                                thread_id = None
380
389
                        msg = None
381
390
                        for response_part in msg_data:
382
391
                                if isinstance(response_part, tuple):
416
425
                                                sender = sender[1:pos+1]+sender[pos+2:]
417
426
                                ilabel = subj if subj else _('No subject')
418
427
                                message = Message(account_id=cn, account_position=m, title=ilabel,
419
 
                                        folder=folder_name, message_id=message_id, timestamp=timestamp)
 
428
                                        folder=folder_name, message_id=message_id, timestamp=timestamp,
 
429
                                        thread_id=thread_id)
420
430
                                self.unread_messages.append(message)
421
431
                                if self.enable_notifications:
422
432
                                        self.notifications_queue.append((sender, subj, cn))