Esempio n. 1
0
    def __init__(self, manager, name, email):
        self.email = ascii_text(stringify(email))
        self.name = stringify(name)
        if not registry.email.validate(self.email):
            self.email = None
        if registry.email.validate(self.name):
            self.email = self.email or ascii_text(self.name)
            self.name = None

        # This should be using formataddr, but I cannot figure out how
        # to use that without encoding the name.
        self.label = None
        if self.name is not None and self.email is not None:
            self.label = '%s <%s>' % (self.name, self.email)
        elif self.name is None and self.email is not None:
            self.label = self.email
        elif self.email is None and self.name is not None:
            self.label = self.name

        self.entity = None
        if self.email is not None:
            key = self.email.lower().strip()
            fragment = safe_fragment(self.label)
            self.entity = manager.make_entity('Person')
            self.entity.make_id(key)
            self.entity.add('name', self.name)
            self.entity.add('email', self.email)
            manager.emit_entity(self.entity, fragment=fragment)
Esempio n. 2
0
 def emit_text_fragment(self, entity, texts, fragment):
     texts = [t for t in ensure_list(texts) if filter_text(t)]
     if len(texts):
         doc = self.make_entity(entity.schema)
         doc.id = entity.id
         doc.add('indexText', texts)
         self.emit_entity(doc, fragment=safe_fragment(fragment))
Esempio n. 3
0
    def resolve_message_ids(self, entity):
        # https://cr.yp.to/immhf/thread.html
        ctx = self.manager.stage.job.dataset.name

        for message_id in entity.get('messageId'):
            key = self.cache_key('mid-ent', ctx, message_id)
            self.add_cache_set(key, entity.id)

            rev_key = self.cache_key('ent-mid', ctx, message_id)
            for response_id in self.get_cache_set(rev_key):
                if response_id == entity.id:
                    continue
                email = self.manager.make_entity('Email')
                email.id = response_id
                email.add('inReplyToEmail', entity.id)
                fragment = safe_fragment(message_id)
                self.manager.emit_entity(email, fragment=fragment)

        for message_id in entity.get('inReplyTo'):
            # forward linking: from message ID to entity ID
            key = self.cache_key('mid-ent', ctx, message_id)
            for email_id in self.get_cache_set(key):
                if email_id != entity.id:
                    entity.add('inReplyToEmail', email_id)

            # backward linking: prepare entity ID for message to come
            rev_key = self.cache_key('ent-mid', ctx, message_id)
            self.add_cache_set(rev_key, entity.id)
Esempio n. 4
0
    def resolve_message_ids(self, entity):
        ctx = self.manager.queue.dataset
        for message_id in entity.get('messageId'):
            message_id = self._clean_message_id(message_id)
            if message_id is None:
                continue
            key = self.cache_key('msid', ctx, message_id)
            self.set_cache_value(key, entity.id)
            rev_key = self.cache_key('mrid', ctx, message_id)
            for entity_id in self.get_cache_set(rev_key):
                email = self.manager.make_entity('Email')
                email.id = entity_id
                email.add('inReplyToEmail', message_id)
                fragment = safe_fragment(message_id)
                self.manager.emit_entity(email, fragment=fragment)

        for message_id in entity.get('inReplyTo'):
            message_id = self._clean_message_id(message_id)
            if message_id is None:
                continue
            key = self.cache_key('msid', ctx, message_id)
            entity.add('inReplyToEmail', self.get_cache_value(key))
            rev_key = self.cache_key('mrid', ctx, message_id)
            self.add_cache_set(rev_key, entity.id)