Skip to content

Commit

Permalink
fix email_formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rooterkyberian committed Feb 25, 2024
1 parent 35c93a3 commit a1d9a1c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pyproject_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os.path
import pathlib
import typing
from email.utils import formataddr


if typing.TYPE_CHECKING:
Expand Down Expand Up @@ -319,11 +320,11 @@ def _name_list(self, people: list[tuple[str, str]]) -> str:
)

def _email_list(self, people: list[tuple[str, str]]) -> str:
return ', '.join([
'{}{}'.format(name, f' <{_email}>' if _email else '')
return ', '.join(
formataddr((name, _email))
for name, _email in people
if _email
])
)

def _build_extra_req(
self,
Expand Down
25 changes: 25 additions & 0 deletions tests/test_rfc822.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,28 @@ def test_convert_optional_dependencies():
'foo; (os_name == "nt" or sys_platform == "win32") and extra == "test"',
'bar; os_name == "posix" and sys_platform == "linux" and extra == "test"',
]


def test_convert_author_email():
metadata = pyproject_metadata.StandardMetadata.from_pyproject(
{
'project': {
'name': 'example',
'version': '0.1.0',
'authors': [
{
'name': 'John Doe, Inc.',
'email': '[email protected]',
},
{
'name': 'Kate Doe, LLC.',
'email': '[email protected]',
}
],
},
}
)
message = metadata.as_rfc822()
assert message.headers['Author-Email'] == [
'"John Doe, Inc." <[email protected]>, "Kate Doe, LLC." <[email protected]>'
]

0 comments on commit a1d9a1c

Please sign in to comment.