-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test exotic email addresses for v3.11+ Added method to import cryptography library. Keep current address parsing behaviour for Python3.12 Properly encrypt and sign to multiple recipients - will fix #41 (#42) Refactor envelope.py to support multiple recipient certificates and to use binary PKCS7 options for encryption --------- Co-authored-by: G22147 <[email protected]> Co-authored-by: zfydryn <[email protected]>
- Loading branch information
1 parent
a8946be
commit 87a5711
Showing
5 changed files
with
42 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,10 +57,12 @@ def __new__(cls, displayed_email=None, name=None, address=None): | |
if displayed_email: | ||
v = _parseaddr(cls.remedy(displayed_email)) | ||
name, address = v[0] or name, v[1] or address | ||
|
||
if name: | ||
displayed_email = f"{name} <{address}>" | ||
else: | ||
displayed_email = address | ||
|
||
instance = super().__new__(cls, displayed_email or "") | ||
instance._name, instance._address = name or "", address or "" | ||
return instance | ||
|
@@ -171,6 +173,8 @@ def parse(cls, email_or_list, single=False, allow_false=False): | |
return addresses[0] | ||
# if len(addresses) == 0: | ||
# raise ValueError(f"E-mail address cannot be parsed: {email_or_list}") | ||
# if len(addresses) == 0: | ||
# return email_or_list | ||
return addresses | ||
|
||
@classmethod | ||
|
@@ -180,6 +184,12 @@ def remedy(s): | |
parsed as two distinguish addresses with getaddresses. Rename the at-sign in the display name | ||
to "person--AT--example.com <[email protected]>" so that the result of getaddresses is less wrong. | ||
""" | ||
|
||
""" | ||
What happens when the string have more addresses? | ||
It also needs to get the address from string like "[email protected], <[email protected]>" so we need to | ||
take care of the comma and semicolon as well. | ||
""" | ||
if s.group(1).strip() == s.group(2).strip(): | ||
# Display name is the same as the e-mail in angle brackets | ||
# Ex: "[email protected] <[email protected]>" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -538,7 +538,7 @@ def test_smime_decrypt_attachments(self): | |
cd_string = 'Content-Disposition: attachment; filename="generic.txt"' | ||
pos = decrypted_data.index(cd_string) | ||
data_temp = decrypted_data[pos:] | ||
d = data_temp.split('\r\n\r\n')[1].strip() + "==" | ||
d = data_temp.split('\n\n')[1].strip() + "==" | ||
attachment_content = b64decode(d).decode('utf-8') | ||
|
||
with open(self.text_attachment, 'r') as f: | ||
|
@@ -1242,6 +1242,10 @@ def test_disguised_addresses(self): | |
# If any of these tests fails, it's a good message the underlying Python libraries are better | ||
# and we may stop remedying. | ||
# https://github.com/python/cpython/issues/40889#issuecomment-1094001067 | ||
|
||
if sys.version_info < (3, 11): | ||
return | ||
|
||
disguise_addr = "[email protected] <[email protected]>" | ||
same = "[email protected] <[email protected]>" | ||
self.assertEqual(('', '[email protected]'), _parseaddr(disguise_addr)) | ||
|
@@ -1526,14 +1530,17 @@ def test_email_addresses(self): | |
def test_invalid_email_addresses(self): | ||
""" If we discard silently every invalid e-mail address received, | ||
the user would not know their recipients are not valid. """ | ||
|
||
if sys.version_info < (3, 11): | ||
return | ||
|
||
e = (Envelope().to('[email protected], [invalid!email], [email protected]')) | ||
self.assertEqual(3, len(e.to())) | ||
self.assertFalse(e.check(check_mx=False, check_smtp=False)) | ||
|
||
e = (Envelope().to('[email protected], [email protected]')) | ||
self.assertTrue(e.check(check_mx=False, check_smtp=False)) | ||
|
||
|
||
class TestSupportive(TestAbstract): | ||
def test_copy(self): | ||
factory = Envelope().cc("[email protected]").copy | ||
|