def process(self, user_id, message_id):
        """Process a message for an user."""
        user = User.get(user_id)
        msg = RawMessage.get(user, message_id)
        # XXX should use raw message type to use correct message formatter
        mail = MailMessage(msg.data)

        message = mail.to_parameter()
        message.recipients = self._get_recipients(user, mail)

        # compute tags
        message.tags = self._get_tags(user, mail)

        # lookup by external references
        lookup_sequence = mail.lookup_sequence()
        lookup = self.lookup(user, lookup_sequence)
        # Create or update existing thread thread
        if lookup:
            log.debug('Found thread %r' % lookup.thread_id)
            thread = Thread.get(user, lookup.thread_id)
            thread.update_from_message(message)
        else:
            log.debug('Creating new thread')
            thread = Thread.create_from_message(user, message)

        msg = Message.create(user, message, thread, lookup)
        # XXX Init lookup
        if not lookup:
            self.__init_lookups(lookup_sequence, msg)
        else:
            if msg.external_message_id:
                params = {
                    'user_id': msg.user_id,
                    'external_message_id': msg.external_message_id,
                    'thread_id': msg.thread_id,
                    'message_id': msg.message_id,
                }
                new_lookup = ThreadMessageLookup.create(**params)
                log.debug('Created message lookup %r' % new_lookup)
        return msg
Beispiel #2
0
 def text(self):
     """Return text from message."""
     # XXX do not use RawMail lookup
     raw = RawMessage.get(self.user, str(self.external_message_id))
     msg = raw.parse()
     return msg.text
 def text(self):
     """Return text from message."""
     # XXX do not use RawMail lookup
     raw = RawMessage.get(self.user, str(self.external_message_id))
     msg = raw.parse()
     return msg.text