def _process_post(self, thread, post, is_root): # Tapatalk app seems to have hardcoded this construction... I don't think we can do better :( url = u'%s/index.php?/topic/%s-%s#entry%s' % ( self.config["url"].get().rstrip('/'), thread.id, re.sub(r'[^a-zA-Z0-9-]', '', re.sub(r'\s+', '-', thread.title)), post['post_id'] ) message = Message( id = is_root and "0" or str(post['post_id']), thread = thread, sender = unicode(str(post.get('post_author_name', 'Anonymous')), 'utf-8'), title = is_root and thread.title or u"Re: %s"%thread.title, url = url, receivers = None, date = self._get_time(post), content = self._format_content(post),#bbcode(), signature = None, parent = thread.root or None, children = [], flags = Message.IS_HTML) if thread.root: thread.root.children.append(message) elif is_root: thread.root = message else: # First message in the thread is not the root message, # because we asked only for unread messages. Create a non-loaded root # message to allow monboob to fill correctly the References: header thread.root = Message(id="0", parent=None, children=[message], thread=thread) message.parent = thread.root return message
def _process_post(self, thread, post, is_root): # Tapatalk app seems to have hardcoded this construction... I don't think we can do better :( url = u'%s/index.php?/topic/%s-%s#entry%s' % ( self.config["url"].get().rstrip('/'), thread.id, re.sub(r'[^a-zA-Z0-9-]', '', re.sub( r'\s+', '-', thread.title)), post['post_id']) message = Message( id=is_root and "0" or str(post['post_id']), thread=thread, sender=unicode(str(post.get('post_author_name', 'Anonymous')), 'utf-8'), title=is_root and thread.title or u"Re: %s" % thread.title, url=url, receivers=None, date=self._get_time(post), content=self._format_content(post), #bbcode(), signature=None, parent=thread.root or None, children=[], flags=Message.IS_HTML) if thread.root: thread.root.children.append(message) elif is_root: thread.root = message else: # First message in the thread is not the root message, # because we asked only for unread messages. Create a non-loaded root # message to allow monboob to fill correctly the References: header thread.root = Message(id="0", parent=None, children=[message], thread=thread) message.parent = thread.root return message
def _process_post(self, thread, post, is_root): message_id = is_root and u'0' or xmlrpc_str(post['post_id']) message_title = is_root and thread.title or u'Re: %s' % thread.title # Tapatalk app seems to have hardcoded this construction... I don't think we can do better :( rel_url = self.config['message_url_format'].get().format( thread_id = urllib.parse.quote(thread.id.encode('utf-8')), thread_title = urllib.parse.quote(thread.title.encode('utf-8')), message_id = urllib.parse.quote(message_id.encode('utf-8')), message_title = urllib.parse.quote(message_title.encode('utf-8'))) message = Message( id = message_id, thread = thread, sender = xmlrpc_str(post.get('post_author_name', u'Anonymous')), title = message_title, url = urllib.parse.urljoin(self.config['url'].get(), rel_url), receivers = None, date = self._get_time(post), content = self._format_content(post), signature = None, parent = thread.root or None, children = [], flags = Message.IS_HTML) if thread.root: thread.root.children.append(message) elif is_root: thread.root = message else: # First message in the thread is not the root message, # because we asked only for unread messages. Create a non-loaded root # message to allow monboob to fill correctly the References: header thread.root = Message(id=u'0', parent=None, children=[message], thread=thread) message.parent = thread.root return message
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
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
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
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
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
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