-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop'
- Loading branch information
Showing
10 changed files
with
218 additions
and
37 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
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 |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
description="A simple, command line mail merge tool", | ||
long_description=LONG_DESCRIPTION, | ||
long_description_content_type="text/markdown", | ||
version="2.2.1", | ||
version="2.2.2", | ||
author="Andrew DeOrio", | ||
author_email="[email protected]", | ||
url="https://github.com/awdeorio/mailmerge/", | ||
|
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 |
---|---|---|
|
@@ -859,3 +859,109 @@ def test_database_bom(tmpdir): | |
>>> Limit was 1 message. To remove the limit, use the --no-limit option. | ||
>>> This was a dry run. To send messages, use the --no-dry-run option. | ||
""") # noqa: E501 | ||
|
||
|
||
def test_database_tsv(tmpdir): | ||
"""Automatically detect TSV database format.""" | ||
# Simple template | ||
template_path = Path(tmpdir/"mailmerge_template.txt") | ||
template_path.write_text(textwrap.dedent("""\ | ||
TO: {{email}} | ||
FROM: My Self <[email protected]> | ||
Hello {{name}} | ||
"""), encoding="utf8") | ||
|
||
# Tab-separated format database | ||
database_path = Path(tmpdir/"mailmerge_database.csv") | ||
database_path.write_text(textwrap.dedent("""\ | ||
email\tname | ||
[email protected]\tMy Name | ||
"""), encoding="utf8") | ||
|
||
# Simple unsecure server config | ||
config_path = Path(tmpdir/"mailmerge_server.conf") | ||
config_path.write_text(textwrap.dedent("""\ | ||
[smtp_server] | ||
host = open-smtp.example.com | ||
port = 25 | ||
"""), encoding="utf8") | ||
|
||
# Run mailmerge | ||
runner = click.testing.CliRunner() | ||
with tmpdir.as_cwd(): | ||
result = runner.invoke(main, ["--output-format", "text"]) | ||
assert not result.exception | ||
assert result.exit_code == 0 | ||
|
||
# Verify output | ||
stdout = copy.deepcopy(result.output) | ||
stdout = re.sub(r"Date:.+", "Date: REDACTED", stdout, re.MULTILINE) | ||
assert stdout == textwrap.dedent("""\ | ||
>>> message 1 | ||
TO: [email protected] | ||
FROM: My Self <[email protected]> | ||
MIME-Version: 1.0 | ||
Content-Type: text/plain; charset="us-ascii" | ||
Content-Transfer-Encoding: 7bit | ||
Date: REDACTED | ||
Hello My Name | ||
>>> message 1 sent | ||
>>> Limit was 1 message. To remove the limit, use the --no-limit option. | ||
>>> This was a dry run. To send messages, use the --no-dry-run option. | ||
""") # noqa: E501 | ||
|
||
|
||
def test_database_semicolon(tmpdir): | ||
"""Automatically detect semicolon-delimited database format.""" | ||
# Simple template | ||
template_path = Path(tmpdir/"mailmerge_template.txt") | ||
template_path.write_text(textwrap.dedent("""\ | ||
TO: {{email}} | ||
FROM: My Self <[email protected]> | ||
Hello {{name}} | ||
"""), encoding="utf8") | ||
|
||
# Semicolon-separated format database | ||
database_path = Path(tmpdir/"mailmerge_database.csv") | ||
database_path.write_text(textwrap.dedent("""\ | ||
email;name | ||
[email protected];My Name | ||
"""), encoding="utf8") | ||
|
||
# Simple unsecure server config | ||
config_path = Path(tmpdir/"mailmerge_server.conf") | ||
config_path.write_text(textwrap.dedent("""\ | ||
[smtp_server] | ||
host = open-smtp.example.com | ||
port = 25 | ||
"""), encoding="utf8") | ||
|
||
# Run mailmerge | ||
runner = click.testing.CliRunner() | ||
with tmpdir.as_cwd(): | ||
result = runner.invoke(main, ["--output-format", "text"]) | ||
assert not result.exception | ||
assert result.exit_code == 0 | ||
|
||
# Verify output | ||
stdout = copy.deepcopy(result.output) | ||
stdout = re.sub(r"Date:.+", "Date: REDACTED", stdout, re.MULTILINE) | ||
assert stdout == textwrap.dedent("""\ | ||
>>> message 1 | ||
TO: [email protected] | ||
FROM: My Self <[email protected]> | ||
MIME-Version: 1.0 | ||
Content-Type: text/plain; charset="us-ascii" | ||
Content-Transfer-Encoding: 7bit | ||
Date: REDACTED | ||
Hello My Name | ||
>>> message 1 sent | ||
>>> Limit was 1 message. To remove the limit, use the --no-limit option. | ||
>>> This was a dry run. To send messages, use the --no-dry-run option. | ||
""") # noqa: E501 |
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 |
---|---|---|
|
@@ -250,6 +250,48 @@ def test_security_starttls(mocker, tmp_path): | |
assert smtp.sendmail.call_count == 1 | ||
|
||
|
||
def test_security_plain(mocker, tmp_path): | ||
"""Verify plain security configuration.""" | ||
# Config for Plain SMTP server | ||
config_path = tmp_path/"server.conf" | ||
config_path.write_text(textwrap.dedent("""\ | ||
[smtp_server] | ||
host = newman.eecs.umich.edu | ||
port = 25 | ||
security = PLAIN | ||
username = YOUR_USERNAME_HERE | ||
""")) | ||
|
||
# Simple template | ||
sendmail_client = SendmailClient(config_path, dry_run=False) | ||
message = email.message_from_string("Hello world") | ||
|
||
# Mock SMTP | ||
mock_smtp = mocker.patch('smtplib.SMTP') | ||
mock_smtp_ssl = mocker.patch('smtplib.SMTP_SSL') | ||
|
||
# Mock the password entry | ||
mock_getpass = mocker.patch('getpass.getpass') | ||
mock_getpass.return_value = "password" | ||
|
||
# Send a message | ||
sendmail_client.sendmail( | ||
sender="[email protected]", | ||
recipients=["[email protected]"], | ||
message=message, | ||
) | ||
|
||
# Verify SMTP library calls | ||
assert mock_getpass.call_count == 1 | ||
assert mock_smtp.call_count == 1 | ||
assert mock_smtp_ssl.call_count == 0 | ||
smtp = mock_smtp.return_value.__enter__.return_value | ||
assert smtp.ehlo.call_count == 0 | ||
assert smtp.starttls.call_count == 0 | ||
assert smtp.login.call_count == 1 | ||
assert smtp.sendmail.call_count == 1 | ||
|
||
|
||
def test_security_ssl(mocker, tmp_path): | ||
"""Verify open (Never) security configuration.""" | ||
# Config for SSL SMTP server | ||
|
Oops, something went wrong.