Пример #1
0
    def find_by_email(self, email):
        """Find for a given email an openpgp key in its DNS zone."""
        clean = clean_email_address(email)
        local_part, domain = clean[0].split('@', 2)
        qname = compute_qname(local_part, domain)
        ns = resolver.ns_for(domain)
        if not ns:
            log.warn('No nameservers found for domain {}'.format(domain))
            return []

        # XXX use a random one
        use_ns = ns[0]
        resolv = resolver.Resolver(timeout=self.resolve_timeout)
        # XXX use of dnssec validation
        query = resolv.query_at(qname, 'OPENPGPKEY', use_ns)
        response = query.get()
        if not response:
            log.warn('No response for OPENPGPKEY dns query')
            return []
        rrsets = response.rrset
        if not rrsets:
            log.warn('No rrsets for OPENPGPKEY dns query')
            return []
        # XXX many rrset, key and signature, must be considered
        key = self._extract_key(rrsets[0])
        return self._parse_key(key)
Пример #2
0
    def external_references(self):
        """Return mail references to be used as external references.

         making use of RFC5322 headers :
            message-id
            in-reply-to
            references
        headers' strings are pruned to extract email addresses only.
        """
        ext_id = self.mail.get('Message-Id')
        parent_id = self.mail.get('In-Reply-To')
        ref = self.mail.get_all("References")
        ref_addr = getaddresses(ref) if ref else None
        ref_ids = [address[1] for address in ref_addr] if ref_addr else []
        mid = clean_email_address(ext_id)[1] if ext_id else None
        pid = clean_email_address(parent_id)[1] if parent_id else None
        return {'message_id': mid, 'parent_id': pid, 'ancestors_ids': ref_ids}
Пример #3
0
 def test_multiple(self):
     emails = '"Ceci est, une virgule" <*****@*****.**>, ' \
              '"Est une, autre virgule" <*****@*****.**>'
     parts = emails.split('>,')
     self.assertEqual(len(parts), 2)
     for part in parts:
         res = clean_email_address(part)
         self.assertTrue('@' in res[0])
Пример #4
0
    def external_references(self):
        """Return mail references to be used as external references.

         making use of RFC5322 headers :
            message-id
            in-reply-to
            references
        headers' strings are pruned to extract email addresses only.
        """
        ext_id = self.mail.get('Message-Id')
        parent_id = self.mail.get('In-Reply-To')
        ref = self.mail.get_all("References")
        ref_addr = getaddresses(ref) if ref else None
        ref_ids = [address[1] for address in ref_addr] if ref_addr else []
        mid = clean_email_address(ext_id)[1] if ext_id else None
        pid = clean_email_address(parent_id)[1] if parent_id else None
        return {
            'message_id': mid,
            'parent_id': pid,
            'ancestors_ids': ref_ids}
Пример #5
0
 def __init__(self, type, addr):
     """Parse an email address and create a participant."""
     self.type = type
     parts = clean_email_address(addr)
     self.address = parts[0]
     self.label = parts[1]
Пример #6
0
 def __init__(self, type, addr):
     """Parse an email address and create a participant."""
     self.type = type
     parts = clean_email_address(addr)
     self.address = parts[0]
     self.label = parts[1]
Пример #7
0
 def test_strange_1(self):
     email = 'ideascube/ideascube <*****@*****.**>'
     res = clean_email_address(email)
     self.assertEqual('*****@*****.**', res[0])
Пример #8
0
 def test_invalid_but_valid(self):
     email = 'Ceci [lamentable.ment] <*****@*****.**>'
     res = clean_email_address(email)
     self.assertEqual('*****@*****.**', res[0])
Пример #9
0
 def test_with_name_1(self):
     email = '"Ceci est, une virgule" <*****@*****.**>'
     res = clean_email_address(email)
     self.assertEqual('*****@*****.**', res[0])
     self.assertEqual('*****@*****.**', res[1])
Пример #10
0
 def test_simple_1(self):
     email = '*****@*****.**'
     res = clean_email_address(email)
     self.assertEqual(email, res[0])
     self.assertEqual(email, res[1])