Example #1
0
    def get_thread(self, _id):
        thread = Thread(_id)
        thread.title = 'Mail for %s' % _id
        thread.flags = thread.IS_DISCUSSION

        self._get_messages_thread(_id, thread)
        return thread
Example #2
0
 def iter_threads(self):
     for thread in self.browser.get_threads():
         t = Thread(thread['id'])
         t.flags = Thread.IS_DISCUSSION
         t.title = u'Discussion with %s' % thread['name']
         t.date = local2utc(datetime.datetime.fromtimestamp(thread['last_message']['utc_timestamp']))
         yield t
Example #3
0
 def iter_threads(self):
     for thread in self.browser.get_threads():
         t = Thread(thread['id'])
         t.flags = Thread.IS_DISCUSSION
         t.title = u'Discussion with %s' % thread['name']
         t.date = local2utc(datetime.datetime.fromtimestamp(thread['last_message']['utc_timestamp']))
         yield t
Example #4
0
    def get_thread(self, _id):
        thread = Thread(_id)
        thread.title = 'Mail for %s' % _id
        thread.flags = thread.IS_DISCUSSION

        self._get_messages_thread(_id, thread)
        return thread
Example #5
0
    def iter_threads(self):
        for thread in self.browser.get_threads():
            if not "person" in thread:
                # The account has been removed, probably because it was a
                # spammer.
                continue

            t = Thread(thread["_id"])
            t.flags = Thread.IS_DISCUSSION
            t.title = u"Discussion with %s" % thread["person"]["name"]
            contact = self.storage.get("contacts", t.id, default={"lastmsg": 0})

            birthday = parse_date(thread["person"]["birth_date"]).date()
            signature = u"Age: %d (%s)" % ((datetime.date.today() - birthday).days / 365.25, birthday)
            signature += u"\nLast ping: %s" % parse_date(thread["person"]["ping_time"]).strftime("%Y-%m-%d %H:%M:%S")
            signature += u"\nPhotos:\n\t%s" % "\n\t".join([photo["url"] for photo in thread["person"]["photos"]])
            signature += u"\n\n%s" % thread["person"]["bio"]

            t.root = Message(
                thread=t,
                id=1,
                title=t.title,
                sender=unicode(thread["person"]["name"]),
                receivers=[self.browser.my_name],
                date=parse_date(thread["created_date"]),
                content=u"Match!",
                children=[],
                signature=signature,
                flags=Message.IS_UNREAD if int(contact["lastmsg"]) < 1 else 0,
            )
            parent = t.root

            for msg in thread["messages"]:
                flags = 0
                if int(contact["lastmsg"]) < msg["timestamp"]:
                    flags = Message.IS_UNREAD

                msg = Message(
                    thread=t,
                    id=msg["timestamp"],
                    title=t.title,
                    sender=unicode(
                        self.browser.my_name if msg["from"] == self.browser.my_id else thread["person"]["name"]
                    ),
                    receivers=[
                        unicode(self.browser.my_name if msg["to"] == self.browser.my_id else thread["person"]["name"])
                    ],
                    date=parse_date(msg["sent_date"]),
                    content=unicode(msg["message"]),
                    children=[],
                    parent=parent,
                    signature=signature if msg["to"] == self.browser.my_id else u"",
                    flags=flags,
                )
                parent.children.append(msg)
                parent = msg

            yield t
Example #6
0
 def iter_threads(self):
     for thread in self.browser.get_threads():
         t = Thread(thread['id'])
         t.flags = Thread.IS_DISCUSSION
         for user in thread['participants']:
             if user['user']['id'] != self.browser.my_id:
                 t.title = u'Discussion with %s' % user['user']['display_name']
         t.date = parse_date(thread['modification_date'])
         yield t
Example #7
0
 def iter_threads(self):
     for thread in self.browser.get_threads():
         t = Thread(thread['id'])
         t.flags = Thread.IS_DISCUSSION
         for user in thread['participants']:
             if user['user']['id'] != self.browser.my_id:
                 t.title = u'Discussion with %s' % user['user']['first_name']
         t.date = parse_date(thread['modification_date'])
         yield t
Example #8
0
    def iter_threads(self):
        threads = self.browser.get_threads_list()

        for thread in threads:
            t = Thread(thread['userid'])
            t.flags = Thread.IS_DISCUSSION
            t.title = u'Discussion with %s' % thread['user']['username']
            t.date = datetime.fromtimestamp(thread['timestamp'])
            yield t
Example #9
0
    def iter_threads(self):
        threads = self.browser.get_threads_list()

        for thread in threads:
            t = Thread(thread['userid'])
            t.flags = Thread.IS_DISCUSSION
            t.title = u'Discussion with %s' % thread['user']['username']
            t.date = datetime.fromtimestamp(thread['timestamp'])
            yield t
Example #10
0
    def get_thread(self, thread):
        if not isinstance(thread, Thread):
            thread = Thread(thread)
            thread.flags = Thread.IS_DISCUSSION

        info = self.browser.get_thread(thread.id)
        for user in info['participants']:
            if user['user']['fb_id'] is not None:
                user['user']['fb'] = self.browser.get_facebook(
                    user['user']['fb_id'])
            if user['user']['id'] == self.browser.my_id:
                me = HappnContact(user['user'])
            else:
                other = HappnContact(user['user'])

        thread.title = u'Discussion with %s' % other.name

        contact = self.storage.get(
            'contacts',
            thread.id,
            default={'lastmsg_date': '1970-01-01T01:01:01+00:00'})

        child = None

        for msg in info['messages']:
            flags = 0
            if parse_date(contact['lastmsg_date']) < parse_date(
                    msg['creation_date']):
                flags = Message.IS_UNREAD

            if msg['sender']['id'] == me.id:
                sender = me
                receiver = other
            else:
                sender = other
                receiver = me

            msg = Message(thread=thread,
                          id=msg['id'],
                          title=thread.title,
                          sender=sender.name,
                          receivers=[receiver.name],
                          date=parse_date(msg['creation_date']),
                          content=msg['message'],
                          children=[],
                          parent=None,
                          signature=sender.get_text(),
                          flags=flags)

            if child:
                msg.children.append(child)
                child.parent = msg
            child = msg
        thread.root = child

        return thread
Example #11
0
    def get_thread(self, thread):
        if not isinstance(thread, Thread):
            thread = Thread(thread)
            thread.flags = Thread.IS_DISCUSSION

        user = self.browser.get_user(thread.id)
        thread.title = u'Discussion with %s' % user['name']

        contact = self.storage.get('contacts', thread.id, default={'lastmsg': 0})

        signature = u'Age: %s' % user['age']
        signature += u'\nLast online: %s' % user['last_online']
        signature += u'\nPhotos:\n\t%s' % '\n\t'.join([user['photo_host'] + photo['large'] for photo in user['photos']])

        child = None

        for msg in self.browser.get_thread_messages(thread.id):
            flags = 0
            if int(contact['lastmsg']) < msg['utc_timestamp']:
                flags = Message.IS_UNREAD

            if msg['type'] == 'msg':
                content = unicode(msg['msg'])
            elif msg['type'] == 'new_challenge':
                content = u'A new challenge has been proposed!'
            elif msg['type'] == 'serie':
                content = u"I've played"
            elif msg['type'] == 'end_game':
                content = u'%s is the winner! (%s VS %s)' % (self.browser.my_name if msg['score']['w'] == self.browser.my_id else user['name'], msg['score']['s'][0], msg['score']['s'][1])
            else:
                content = u'Unknown action: %s' % msg['type']

            msg = Message(thread=thread,
                          id=msg['utc_timestamp'],
                          title=thread.title,
                          sender=unicode(self.browser.my_name if msg['from'] == self.browser.my_id else user['name']),
                          receivers=[unicode(self.browser.my_name if msg['from'] != self.browser.my_id else user['name'])],
                          date=local2utc(datetime.datetime.fromtimestamp(msg['utc_timestamp'])),
                          content=content,
                          children=[],
                          parent=None,
                          signature=signature if msg['from'] != self.browser.my_id else u'',
                          flags=flags)

            if child:
                msg.children.append(child)
                child.parent = msg
            child = msg
        thread.root = child

        return thread
Example #12
0
    def get_thread(self, thread):
        if not isinstance(thread, Thread):
            thread = Thread(thread)
            thread.flags = Thread.IS_DISCUSSION

        user = self.browser.get_user(thread.id)
        thread.title = u'Discussion with %s' % user['name']

        contact = self.storage.get('contacts', thread.id, default={'lastmsg': 0})

        signature = u'Age: %s' % user['age']
        signature += u'\nLast online: %s' % user['last_online']
        signature += u'\nPhotos:\n\t%s' % '\n\t'.join([user['photo_host'] + photo['large'] for photo in user['photos']])

        child = None

        for msg in self.browser.get_thread_messages(thread.id):
            flags = 0
            if int(contact['lastmsg']) < msg['utc_timestamp']:
                flags = Message.IS_UNREAD

            if msg['type'] == 'msg':
                content = unicode(msg['msg'])
            elif msg['type'] == 'new_challenge':
                content = u'A new challenge has been proposed!'
            elif msg['type'] == 'serie':
                content = u"I've played"
            elif msg['type'] == 'end_game':
                content = u'%s is the winner! (%s VS %s)' % (self.browser.my_name if msg['score']['w'] == self.browser.my_id else user['name'], msg['score']['s'][0], msg['score']['s'][1])
            else:
                content = u'Unknown action: %s' % msg['type']

            msg = Message(thread=thread,
                          id=msg['utc_timestamp'],
                          title=thread.title,
                          sender=unicode(self.browser.my_name if msg['from'] == self.browser.my_id else user['name']),
                          receivers=[unicode(self.browser.my_name if msg['from'] != self.browser.my_id else user['name'])],
                          date=local2utc(datetime.datetime.fromtimestamp(msg['utc_timestamp'])),
                          content=content,
                          children=[],
                          parent=None,
                          signature=signature if msg['from'] != self.browser.my_id else u'',
                          flags=flags)

            if child:
                msg.children.append(child)
                child.parent = msg
            child = msg
        thread.root = child

        return thread
Example #13
0
    def get_thread(self, thread):
        if not isinstance(thread, Thread):
            thread = Thread(thread)
            thread.flags = Thread.IS_DISCUSSION

        info = self.browser.get_thread(thread.id)
        for user in info['participants']:
            if user['user']['fb_id'] is not None:
                user['user']['fb'] = self.browser.get_facebook(user['user']['fb_id'])
            if user['user']['id'] == self.browser.my_id:
                me = HappnContact(user['user'])
            else:
                other = HappnContact(user['user'])

        thread.title = u'Discussion with %s' % other.name

        contact = self.storage.get('contacts', thread.id, default={'lastmsg_date': '1970-01-01T01:01:01+00:00'})

        child = None

        for msg in info['messages']:
            flags = 0
            if parse_date(contact['lastmsg_date']) < parse_date(msg['creation_date']):
                flags = Message.IS_UNREAD

            if msg['sender']['id'] == me.id:
                sender = me
                receiver = other
            else:
                sender = other
                receiver = me

            msg = Message(thread=thread,
                          id=msg['id'],
                          title=thread.title,
                          sender=sender.name,
                          receivers=[receiver.name],
                          date=parse_date(msg['creation_date']),
                          content=msg['message'],
                          children=[],
                          parent=None,
                          signature=sender.get_text(),
                          flags=flags)

            if child:
                msg.children.append(child)
                child.parent = msg
            child = msg
        thread.root = child

        return thread
Example #14
0
    def iter_threads(self):
        with self.browser:
            threads = self.browser.get_threads_list()

        for thread in threads:
            # Remove messages from user that quit
            #if thread['member'].get('isBan', thread['member'].get('dead', False)):
            #    with self.browser:
            #        self.browser.delete_thread(thread['member']['id'])
            #    continue
            t = Thread(int(thread['id']))
            t.flags = Thread.IS_DISCUSSION
            t.title = u'Discussion with %s' % thread['username']
            yield t
Example #15
0
    def iter_threads(self):
        with self.browser:
            threads = self.browser.get_threads_list()

        for thread in threads:
            # Remove messages from user that quit
            # if thread['member'].get('isBan', thread['member'].get('dead', False)):
            #    with self.browser:
            #        self.browser.delete_thread(thread['member']['id'])
            #    continue
            t = Thread(int(thread["id"]))
            t.flags = Thread.IS_DISCUSSION
            t.title = u"Discussion with %s" % thread["username"]
            yield t
Example #16
0
    def _iter_threads(self, root_link=None):
        links = list(self.browser.iter_links(root_link.url if root_link else None))

        for link in links:
            if link.type == link.FORUM:
                link.title = '%s[%s]' % (root_link.title if root_link else '', link.title)
                for thread in self._iter_threads(link):
                    yield thread
            if link.type == link.TOPIC:
                thread = Thread(url2id(link.url))
                thread.title = ('%s ' % root_link.title if root_link else '') + link.title
                thread.date = link.date
                thread.flags = thread.IS_DISCUSSION
                yield thread
Example #17
0
    def _iter_threads(self, root_link=None):
        links = list(self.browser.iter_links(root_link.url if root_link else None))

        for link in links:
            if link.type == link.FORUM:
                link.title = '%s[%s]' % (root_link.title if root_link else '', link.title)
                for thread in self._iter_threads(link):
                    yield thread
            if link.type == link.TOPIC:
                thread = Thread(url2id(link.url))
                thread.title = ('%s ' % root_link.title if root_link else '') + link.title
                thread.date = link.date
                thread.flags = thread.IS_DISCUSSION
                yield thread
Example #18
0
    def get_thread(self, thread):
        if not isinstance(thread, Thread):
            thread = Thread(thread)
            thread.flags = Thread.IS_DISCUSSION

        messages = self.browser.get_thread_messages(thread.id)

        contact = self.storage.get('s***s',
                                   thread.id,
                                   default={'lastmsg': datetime(1970, 1, 1)})
        thread.title = u'Discussion with %s' % messages['fields']['username']

        me = OkcContact(self.browser.get_profile(self.browser.me['userid']))
        other = OkcContact(self.browser.get_profile(thread.id))

        parent = None
        for message in messages['messages']['messages']:
            date = datetime.fromtimestamp(message['timestamp'])

            flags = 0
            if contact['lastmsg'] < date:
                flags = Message.IS_UNREAD

            if message['from'] == thread.id:
                sender = other
                receiver = me
            else:
                receiver = other
                sender = me

            msg = Message(thread=thread,
                          id=message['id'],
                          title=thread.title,
                          sender=sender.name,
                          receivers=[receiver.name],
                          date=date,
                          content=to_unicode(unescape(message['body'])),
                          children=[],
                          parent=parent,
                          signature=sender.get_text(),
                          flags=flags)

            if parent:
                parent.children = [msg]
            else:
                thread.root = msg

            parent = msg

        return thread
Example #19
0
    def iter_threads(self):
        threads = self.browser.get_threads_list()

        for thread in threads:
            #if thread['member'].get('isBan', thread['member'].get('dead', False)):
            #    self.browser.delete_thread(thread['member']['id'])
            #    continue
            if self.antispam and not self.antispam.check_thread(thread):
                self.logger.info('Skipped a spam-thread from %s' % thread['pseudo'])
                self.report_spam(thread['who']['id'])
                continue
            t = Thread(int(thread['who']['id']))
            t.flags = Thread.IS_DISCUSSION
            t.title = u'Discussion with %s' % to_unicode(thread['who']['pseudo'])
            yield t
Example #20
0
    def iter_threads(self):
        for thread in self.browser.get_threads():
            if 'person' not in thread:
                # The account has been removed, probably because it was a
                # spammer.
                continue

            t = Thread(thread['_id'])
            t.flags = Thread.IS_DISCUSSION
            t.title = u'Discussion with %s' % thread['person']['name']
            contact = self.storage.get('contacts', t.id, default={'lastmsg': 0})

            birthday = parse_date(thread['person']['birth_date']).date()
            signature = u'Age: %d (%s)' % ((datetime.date.today() - birthday).days / 365.25, birthday)
            signature += u'\nLast ping: %s' % parse_date(thread['person']['ping_time']).strftime('%Y-%m-%d %H:%M:%S')
            signature += u'\nPhotos:\n\t%s' % '\n\t'.join([photo['url'] for photo in thread['person']['photos']])
            signature += u'\n\n%s' % thread['person']['bio']

            t.root = Message(thread=t, id=1, title=t.title,
                             sender=unicode(thread['person']['name']),
                             receivers=[self.browser.my_name],
                             date=parse_date(thread['created_date']),
                             content=u'Match!',
                             children=[],
                             signature=signature,
                             flags=Message.IS_UNREAD if int(contact['lastmsg']) < 1 else 0)
            parent = t.root

            for msg in thread['messages']:
                flags = 0
                if int(contact['lastmsg']) < msg['timestamp']:
                    flags = Message.IS_UNREAD

                msg = Message(thread=t,
                              id=msg['timestamp'],
                              title=t.title,
                              sender=unicode(self.browser.my_name if msg['from'] == self.browser.my_id else thread['person']['name']),
                              receivers=[unicode(self.browser.my_name if msg['to'] == self.browser.my_id else thread['person']['name'])],
                              date=parse_date(msg['sent_date']),
                              content=unicode(msg['message']),
                              children=[],
                              parent=parent,
                              signature=signature if msg['to'] == self.browser.my_id else u'',
                              flags=flags)
                parent.children.append(msg)
                parent = msg

            yield t
Example #21
0
    def get_thread(self, thread):
        if not isinstance(thread, Thread):
            thread = Thread(thread)
            thread.flags = Thread.IS_DISCUSSION

        messages = self.browser.get_thread_messages(thread.id)

        contact = self.storage.get('s***s', thread.id, default={'lastmsg': datetime(1970,1,1)})
        thread.title = u'Discussion with %s' % messages['fields']['username']

        me = OkcContact(self.browser.get_profile(self.browser.me['userid']))
        other = OkcContact(self.browser.get_profile(thread.id))

        parent = None
        for message in messages['messages']['messages']:
            date = datetime.fromtimestamp(message['timestamp'])

            flags = 0
            if contact['lastmsg'] < date:
                flags = Message.IS_UNREAD

            if message['from'] == thread.id:
                sender = other
                receiver = me
            else:
                receiver = other
                sender = me

            msg = Message(thread=thread,
                          id=message['id'],
                          title=thread.title,
                          sender=sender.name,
                          receivers=[receiver.name],
                          date=date,
                          content=to_unicode(unescape(message['body'])),
                          children=[],
                          parent=parent,
                          signature=sender.get_text(),
                          flags=flags)

            if parent:
                parent.children = [msg]
            else:
                thread.root = msg

            parent = msg

        return thread
Example #22
0
    def iter_threads(self):
        for thread in self.browser.get_threads():
            if 'person' not in thread:
                # The account has been removed, probably because it was a
                # spammer.
                continue

            t = Thread(thread['_id'])
            t.flags = Thread.IS_DISCUSSION
            t.title = u'Discussion with %s' % thread['person']['name']
            contact = self.storage.get('contacts', t.id, default={'lastmsg': 0})

            birthday = parse_date(thread['person']['birth_date']).date()
            signature = u'Age: %d (%s)' % ((datetime.date.today() - birthday).days / 365.25, birthday)
            signature += u'\nLast ping: %s' % parse_date(thread['person']['ping_time']).strftime('%Y-%m-%d %H:%M:%S')
            signature += u'\nPhotos:\n\t%s' % '\n\t'.join([photo['url'] for photo in thread['person']['photos']])
            signature += u'\n\n%s' % thread['person'].get('bio', '')

            t.root = Message(thread=t, id=1, title=t.title,
                             sender=unicode(thread['person']['name']),
                             receivers=[self.browser.my_name],
                             date=parse_date(thread['created_date']),
                             content=u'Match!',
                             children=[],
                             signature=signature,
                             flags=Message.IS_UNREAD if int(contact['lastmsg']) < 1 else 0)
            parent = t.root

            for msg in thread['messages']:
                flags = 0
                if int(contact['lastmsg']) < msg['timestamp']:
                    flags = Message.IS_UNREAD

                msg = Message(thread=t,
                              id=msg['timestamp'],
                              title=t.title,
                              sender=unicode(self.browser.my_name if msg['from'] == self.browser.my_id else thread['person']['name']),
                              receivers=[unicode(self.browser.my_name if msg['to'] == self.browser.my_id else thread['person']['name'])],
                              date=parse_date(msg['sent_date']),
                              content=unicode(msg['message']),
                              children=[],
                              parent=parent,
                              signature=signature if msg['to'] == self.browser.my_id else u'',
                              flags=flags)
                parent.children.append(msg)
                parent = msg

            yield t
Example #23
0
    def iter_threads(self):
        inbox = self.config['inbox'].get()
        if not inbox:
            raise NotImplementedError()
        else:
            for d in self.browser.get_mails(inbox):
                thread = Thread(d['id'])
                thread.title = d['subject']
                thread.flags = thread.IS_DISCUSSION

                msg = self.make_message(d, thread)
                if not msg.content:
                    msg.content = self.browser.get_mail_content(msg.id)

                thread.root = msg
                yield thread
Example #24
0
    def iter_threads_list(self):
        # site is sorted from latest to oldest
        for message_a in reversed(self.document.findAll('a', href=re.compile(r'message_read.php\?'))):
            ovs_id = re.search(r'Id=(\d+)', message_a["href"]).group(1)
            id_ = ovs_id

            thread = Thread(id_)
            thread.title = ovsparse.all_text_recursive(message_a)
            thread.flags = Thread.IS_DISCUSSION

            #~ parent_tr = message_a.findParent('tr')
            #~ username = all_text_recursive(parent_tr.find('a', href=re.compile(r'profil_read.php\?.*')))
            #~ notread_self = (parent_tr.get('class') == 'newmails')
            #~ notread_other = (parent_tr.find('span', **{'class': 'new_sortiepartenaire'}) is not None)

            yield thread
Example #25
0
    def iter_threads(self):
        inbox = self.config['inbox'].get()
        if not inbox:
            raise NotImplementedError()
        else:
            for d in self.browser.get_mails(inbox):
                thread = Thread(d['id'])
                thread.title = d['subject']
                thread.flags = thread.IS_DISCUSSION

                msg = self.make_message(d, thread)
                if not msg.content:
                    self._fetch_content(msg)

                thread.root = msg
                yield thread
Example #26
0
    def iter_threads(self):
        threads = self.browser.get_threads_list()

        for thread in threads:
            #if thread['member'].get('isBan', thread['member'].get('dead', False)):
            #    self.browser.delete_thread(thread['member']['id'])
            #    continue
            if self.antispam and not self.antispam.check_thread(thread):
                self.logger.info('Skipped a spam-thread from %s' %
                                 thread['pseudo'])
                self.report_spam(thread['who']['id'])
                continue
            t = Thread(int(thread['who']['id']))
            t.flags = Thread.IS_DISCUSSION
            t.title = u'Discussion with %s' % to_unicode(
                thread['who']['pseudo'])
            yield t
Example #27
0
    def get_thread(self, _id):
        t = Thread(_id)
        t.title = 'Mail for %s' % _id
        t.flags = t.IS_DISCUSSION

        first = True
        for d in self.browser.get_mails(_id):
            m = self.make_message(d, t)
            if not m.content:
                m.content = self.browser.get_mail_content(m.id)

            if first:
                first = False
                t.root = m
            else:
                m.parent = t.root
                m.parent.children.append(m)

        return t
Example #28
0
    def get_thread(self, _id):
        t = Thread(_id)
        t.title = 'Mail for %s' % _id
        t.flags = t.IS_DISCUSSION

        first = True
        for d in self.browser.get_mails(_id):
            m = self.make_message(d, t)
            if not m.content:
                m.content = self.browser.get_mail_content(m.id)

            if first:
                first = False
                t.root = m
            else:
                m.parent = t.root
                m.parent.children.append(m)

        return t
Example #29
0
    def get_thread(self, _id):
        thread = Thread(_id)

        thread.title = self.document.find('div', 'PADtitreBlanc_txt').find('center').string
        thread.flags = Thread.IS_DISCUSSION
        root = True

        for message in self._get_messages(thread):
            if root:
                message.children = []
                thread.root = message
                thread.date = message.date
                message.title = thread.title
                root = False
            else:
                message.title = 'Re: %s' % thread.title
                message.children = []
                message.parent = thread.root
                thread.root.children.append(message)

        return thread
Example #30
0
    def get_thread(self, id, contacts=None, get_profiles=False):
        """
        Get a thread and its messages.

        The 'contacts' parameters is only used for internal calls.
        """
        thread = None
        if isinstance(id, Thread):
            thread = id
            id = thread.id

        if not thread and isinstance(id, basestring) and not id.isdigit():
            for t in self.browser.get_threads_list():
                if t['username'] == id:
                    id = t['id']
                    break
            else:
                return None

        if not thread:
            thread = Thread(int(id))
            thread.flags = Thread.IS_DISCUSSION

        with self.browser:
            mails = self.browser.get_thread_mails(id)
            my_name = self.browser.get_my_name()

        child = None
        msg = None
        s**t = self._get_slut(thread.id)
        if contacts is None:
            contacts = {}

        if not thread.title:
            thread.title = u'Discussion with %s' % mails['member']['pseudo']

        for mail in mails['messages']:
            flags = 0
            if mail['date'] > s**t['lastmsg']:
                flags |= Message.IS_UNREAD

                if get_profiles:
                    if not mail['id_from'] in contacts:
                        with self.browser:
                            contacts[mail['id_from']] = self.get_contact(mail['id_from'])

            signature = u''
            if mail.get('src', None):
                signature += u'Sent from my %s\n\n' % mail['src']
            if contacts.get(mail['id_from'], None) is not None:
                signature += contacts[mail['id_from']].get_text()

            msg = Message(thread=thread,
                          id=int(time.strftime('%Y%m%d%H%M%S', mail['date'].timetuple())),
                          title=thread.title,
                          sender=mail['id_from'],
                          receivers=[my_name if mail['id_from'] != my_name else mails['member']['pseudo']],
                          date=mail['date'],
                          content=mail['message'],
                          signature=signature,
                          children=[],
                          flags=flags)
            if child:
                msg.children.append(child)
                child.parent = msg

            child = msg

        if msg:
            msg.parent = None

        thread.root = msg

        return thread
Example #31
0
    def get_thread(self, id, contacts=None, get_profiles=False):
        """
        Get a thread and its messages.

        The 'contacts' parameters is only used for internal calls.
        """
        thread = None
        if isinstance(id, Thread):
            thread = id
            id = thread.id

        if not thread:
            thread = Thread(int(id))
            thread.flags = Thread.IS_DISCUSSION
            full = False
        else:
            full = True

        with self.browser:
            mails = self.browser.get_thread_mails(id, 100)
            my_name = self.browser.get_my_name()

        child = None
        msg = None
        s**t = self._get_slut(id)
        if contacts is None:
            contacts = {}

        if not thread.title:
            thread.title = u'Discussion with %s' % mails['who']['pseudo']

        self.storage.set('s***s', int(thread.id), 'status', mails['status'])
        self.storage.save()

        for mail in mails['results']:
            flags = 0
            if self.antispam and not self.antispam.check_mail(mail):
                self.logger.info('Skipped a spam-mail from %s' %
                                 mails['who']['pseudo'])
                self.report_spam(thread.id)
                break

            if parse_dt(mail['date']) > s**t['lastmsg']:
                flags |= Message.IS_UNREAD

                if get_profiles:
                    if not mail['from'] in contacts:
                        try:
                            with self.browser:
                                contacts[mail['from']] = self.get_contact(
                                    mail['from'])
                        except BrowserHTTPNotFound:
                            pass
                    if self.antispam and mail[
                            'from'] in contacts and not self.antispam.check_contact(
                                contacts[mail['from']]):
                        self.logger.info(
                            'Skipped a spam-mail-profile from %s' %
                            mails['who']['pseudo'])
                        self.report_spam(thread.id)
                        break

            if int(mail['from']) == self.browser.my_id:
                if mails['remote_status'] == 'new' and msg is None:
                    flags |= Message.IS_NOT_RECEIVED
                else:
                    flags |= Message.IS_RECEIVED

            signature = u''
            #if mail.get('src', None):
            #    signature += u'Sent from my %s\n\n' % mail['src']
            if mail['from'] in contacts:
                signature += contacts[mail['from']].get_text()

            msg = Message(
                thread=thread,
                id=int(
                    time.strftime('%Y%m%d%H%M%S',
                                  parse_dt(mail['date']).timetuple())),
                title=thread.title,
                sender=to_unicode(my_name if int(mail['from']) == self.browser.
                                  my_id else mails['who']['pseudo']),
                receivers=[
                    to_unicode(my_name if int(mail['from']) != self.browser.
                               my_id else mails['who']['pseudo'])
                ],
                date=parse_dt(mail['date']),
                content=to_unicode(unescape(mail['message'] or '').strip()),
                signature=signature,
                children=[],
                flags=flags)
            if child:
                msg.children.append(child)
                child.parent = msg

            child = msg

        if full and msg:
            # If we have get all the messages, replace NotLoaded with None as
            # parent.
            msg.parent = None
        if not full and not msg:
            # Perhaps there are hidden messages
            msg = NotLoaded

        thread.root = msg

        return thread
Example #32
0
    def get_thread(self, id, contacts=None, get_profiles=False):
        """
        Get a thread and its messages.

        The 'contacts' parameters is only used for internal calls.
        """
        thread = None
        if isinstance(id, Thread):
            thread = id
            id = thread.id

        if not thread:
            thread = Thread(int(id))
            thread.flags = Thread.IS_DISCUSSION
            full = False
        else:
            full = True

        with self.browser:
            mails = self.browser.get_thread_mails(id, 100)
            my_name = self.browser.get_my_name()

        child = None
        msg = None
        s**t = self._get_slut(id)
        if contacts is None:
            contacts = {}

        if not thread.title:
            thread.title = u'Discussion with %s' % mails['who']['pseudo']

        self.storage.set('s***s', int(thread.id), 'status', mails['status'])
        self.storage.save()

        for mail in mails['results']:
            flags = 0
            if self.antispam and not self.antispam.check_mail(mail):
                self.logger.info('Skipped a spam-mail from %s' % mails['who']['pseudo'])
                self.report_spam(thread.id)
                break

            if parse_dt(mail['date']) > s**t['lastmsg']:
                flags |= Message.IS_UNREAD

                if get_profiles:
                    if not mail['from'] in contacts:
                        try:
                            with self.browser:
                                contacts[mail['from']] = self.get_contact(mail['from'])
                        except BrowserHTTPNotFound:
                            pass
                    if self.antispam and mail['from'] in contacts and not self.antispam.check_contact(contacts[mail['from']]):
                        self.logger.info('Skipped a spam-mail-profile from %s' % mails['who']['pseudo'])
                        self.report_spam(thread.id)
                        break

            if int(mail['from']) == self.browser.my_id:
                if mails['remote_status'] == 'new' and msg is None:
                    flags |= Message.IS_NOT_RECEIVED
                else:
                    flags |= Message.IS_RECEIVED

            signature = u''
            #if mail.get('src', None):
            #    signature += u'Sent from my %s\n\n' % mail['src']
            if mail['from'] in contacts:
                signature += contacts[mail['from']].get_text()

            msg = Message(thread=thread,
                          id=int(time.strftime('%Y%m%d%H%M%S', parse_dt(mail['date']).timetuple())),
                          title=thread.title,
                          sender=to_unicode(my_name if int(mail['from']) == self.browser.my_id else mails['who']['pseudo']),
                          receivers=[to_unicode(my_name if int(mail['from']) != self.browser.my_id else mails['who']['pseudo'])],
                          date=parse_dt(mail['date']),
                          content=to_unicode(unescape(mail['message'] or '').strip()),
                          signature=signature,
                          children=[],
                          flags=flags)
            if child:
                msg.children.append(child)
                child.parent = msg

            child = msg

        if full and msg:
            # If we have get all the messages, replace NotLoaded with None as
            # parent.
            msg.parent = None
        if not full and not msg:
            # Perhaps there are hidden messages
            msg = NotLoaded

        thread.root = msg

        return thread
Example #33
0
    def get_thread(self, id, contacts=None, get_profiles=False):
        """
        Get a thread and its messages.

        The 'contacts' parameters is only used for internal calls.
        """
        thread = None
        if isinstance(id, Thread):
            thread = id
            id = thread.id

        if not thread:
            thread = Thread(int(id))
            thread.flags = Thread.IS_DISCUSSION
            full = False
        else:
            full = True

        with self.browser:
            mails = self.browser.get_thread_mails(id, 100)
            my_name = self.browser.get_my_name()

        child = None
        msg = None
        s**t = self._get_slut(mails["member"]["pseudo"])
        if contacts is None:
            contacts = {}

        if not thread.title:
            thread.title = u"Discussion with %s" % mails["member"]["pseudo"]

        for mail in mails["messages"]:
            flags = Message.IS_HTML
            if parse_dt(mail["date"]) > s**t["lastmsg"] and mail["id_from"] != self.browser.get_my_name():
                flags |= Message.IS_UNREAD

                if get_profiles:
                    if not mail["id_from"] in contacts:
                        with self.browser:
                            contacts[mail["id_from"]] = self.get_contact(mail["id_from"])

            signature = u""
            if mail.get("src", None):
                signature += u"Sent from my %s\n\n" % mail["src"]
            if mail["id_from"] in contacts:
                signature += contacts[mail["id_from"]].get_text()

            msg = Message(
                thread=thread,
                id=int(time.strftime("%Y%m%d%H%M%S", parse_dt(mail["date"]).timetuple())),
                title=thread.title,
                sender=mail["id_from"],
                receivers=[my_name if mail["id_from"] != my_name else mails["member"]["pseudo"]],
                date=parse_dt(mail["date"]),
                content=unescape(mail["message"]).strip(),
                signature=signature,
                children=[],
                flags=flags,
            )
            if child:
                msg.children.append(child)
                child.parent = msg

            child = msg

        if full and msg:
            # If we have get all the messages, replace NotLoaded with None as
            # parent.
            msg.parent = None
        if not full and not msg:
            # Perhaps there are hidden messages
            msg = NotLoaded

        thread.root = msg

        return thread
Example #34
0
    def get_thread(self, id, contacts=None, get_profiles=False):
        """
        Get a thread and its messages.

        The 'contacts' parameters is only used for internal calls.
        """
        thread = None
        if isinstance(id, Thread):
            thread = id
            id = thread.id

        if not thread:
            thread = Thread(int(id))
            thread.flags = Thread.IS_DISCUSSION
            full = False
        else:
            full = True

        with self.browser:
            mails = self.browser.get_thread_mails(id, 100)
            my_name = self.browser.get_my_name()

        child = None
        msg = None
        s**t = self._get_slut(mails['member']['pseudo'])
        if contacts is None:
            contacts = {}

        if not thread.title:
            thread.title = u'Discussion with %s' % mails['member']['pseudo']

        for mail in mails['messages']:
            flags = Message.IS_HTML
            if parse_dt(mail['date']) > s**t['lastmsg'] and mail[
                    'id_from'] != self.browser.get_my_name():
                flags |= Message.IS_UNREAD

                if get_profiles:
                    if not mail['id_from'] in contacts:
                        with self.browser:
                            contacts[mail['id_from']] = self.get_contact(
                                mail['id_from'])

            signature = u''
            if mail.get('src', None):
                signature += u'Sent from my %s\n\n' % mail['src']
            if mail['id_from'] in contacts:
                signature += contacts[mail['id_from']].get_text()

            msg = Message(thread=thread,
                          id=int(
                              time.strftime('%Y%m%d%H%M%S',
                                            parse_dt(
                                                mail['date']).timetuple())),
                          title=thread.title,
                          sender=mail['id_from'],
                          receivers=[
                              my_name if mail['id_from'] != my_name else
                              mails['member']['pseudo']
                          ],
                          date=parse_dt(mail['date']),
                          content=unescape(mail['message']).strip(),
                          signature=signature,
                          children=[],
                          flags=flags)
            if child:
                msg.children.append(child)
                child.parent = msg

            child = msg

        if full and msg:
            # If we have get all the messages, replace NotLoaded with None as
            # parent.
            msg.parent = None
        if not full and not msg:
            # Perhaps there are hidden messages
            msg = NotLoaded

        thread.root = msg

        return thread
Example #35
0
    def get_thread(self, id, contacts=None, get_profiles=False):
        """
        Get a thread and its messages.

        The 'contacts' parameters is only used for internal calls.
        """
        thread = None
        if isinstance(id, Thread):
            thread = id
            id = thread.id

        if not thread and isinstance(id, basestring) and not id.isdigit():
            for t in self.browser.get_threads_list():
                if t['username'] == id:
                    id = t['id']
                    break
            else:
                return None

        if not thread:
            thread = Thread(int(id))
            thread.flags = Thread.IS_DISCUSSION

        with self.browser:
            mails = self.browser.get_thread_mails(id)
            my_name = self.browser.get_my_name()

        child = None
        msg = None
        s**t = self._get_slut(thread.id)
        if contacts is None:
            contacts = {}

        if not thread.title:
            thread.title = u'Discussion with %s' % mails['member']['pseudo']

        for mail in mails['messages']:
            flags = 0
            if mail['date'] > s**t['lastmsg']:
                flags |= Message.IS_UNREAD

                if get_profiles:
                    if mail['id_from'] not in contacts:
                        with self.browser:
                            contacts[mail['id_from']] = self.get_contact(
                                mail['id_from'])

            signature = u''
            if mail.get('src', None):
                signature += u'Sent from my %s\n\n' % mail['src']
            if contacts.get(mail['id_from'], None) is not None:
                signature += contacts[mail['id_from']].get_text()

            msg = Message(thread=thread,
                          id=int(
                              time.strftime('%Y%m%d%H%M%S',
                                            mail['date'].timetuple())),
                          title=thread.title,
                          sender=mail['id_from'],
                          receivers=[
                              my_name if mail['id_from'] != my_name else
                              mails['member']['pseudo']
                          ],
                          date=mail['date'],
                          content=mail['message'],
                          signature=signature,
                          children=[],
                          flags=flags)
            if child:
                msg.children.append(child)
                child.parent = msg

            child = msg

        if msg:
            msg.parent = None

        thread.root = msg

        return thread
Example #36
0
    def get_thread(self, thread):
        if not isinstance(thread, Thread):
            thread = Thread(thread)
            thread.flags = Thread.IS_DISCUSSION

        messages = self.browser.get_thread_messages(thread.id)

        contact = self.storage.get('s***s',
                                   thread.id,
                                   default={'lastmsg': datetime(1970, 1, 1)})
        thread.title = u'Discussion with %s' % messages['fields']['username']

        me = OkcContact(self.browser.get_profile(self.browser.me['userid']))
        other = OkcContact(self.browser.get_profile(thread.id))

        parent = None
        for message in messages['messages']:
            date = datetime.fromtimestamp(message['timestamp'])

            flags = 0
            if contact['lastmsg'] < date:
                flags = Message.IS_UNREAD

            if message['from'] == thread.id:
                sender = other
                receiver = me
            else:
                receiver = other
                sender = me
                if message.get('read', False):
                    flags |= Message.IS_RECEIVED
                    # Apply that flag on all previous messages as the 'read'
                    # attribute is only set on the last read message.
                    pmsg = parent
                    while pmsg:
                        if pmsg.flags & Message.IS_NOT_RECEIVED:
                            pmsg.flags |= Message.IS_RECEIVED
                            pmsg.flags &= ~Message.IS_NOT_RECEIVED
                        pmsg = pmsg.parent
                else:
                    flags |= Message.IS_NOT_RECEIVED

            msg = Message(thread=thread,
                          id=message['id'],
                          title=thread.title,
                          sender=sender.name,
                          receivers=[receiver.name],
                          date=date,
                          content=to_unicode(HTMLParser().unescape(
                              message['body'])),
                          children=[],
                          parent=parent,
                          signature=sender.get_text(),
                          flags=flags)

            if parent:
                parent.children = [msg]
            else:
                thread.root = msg

            parent = msg

        return thread