From 7cc9808b47ba766091070fa1540170c2705023b6 Mon Sep 17 00:00:00 2001 From: Andrew Engelbrecht Date: Tue, 19 Jul 2016 14:48:01 -0400 Subject: [PATCH] basic testing for auto-reply messages this should prevent some auto-response feedback loops. --- edward | 32 ++++++++++++++++++++++++++++++-- tests/flatten-9.eml | 11 +++++++++++ tests/flatten-9.out | 1 + 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 tests/flatten-9.eml create mode 100644 tests/flatten-9.out diff --git a/edward b/edward index ed47182..fc099d8 100755 --- a/edward +++ b/edward @@ -267,11 +267,13 @@ def main (): print_reply_only = handle_args() + email_bytes = sys.stdin.buffer.read() + + test_auto_reply(email_bytes) + gpgme_ctx = get_gpg_context(edward_config.gnupghome, edward_config.sign_with_key) - email_bytes = sys.stdin.buffer.read() - # do this twice so sigs can be verified with newly imported keys parse_pgp_mime(email_bytes, gpgme_ctx) email_struct = parse_pgp_mime(email_bytes, gpgme_ctx) @@ -1243,6 +1245,32 @@ def is_key_usable (key_obj): return False +def test_auto_reply (email_bytes): + """Test whether email is auto-generated + + If the email is autogenerated, edward quits without sending a response. + This is not a perfect test. Some auto-responses will go undetected. + + Args: + email_bytes: the byte string from of the email + + Returns: + Nothing, or exits the program + """ + + email_struct = email.parser.BytesHeaderParser().parsebytes(email_bytes) + + auto_submitted = email_struct['Auto-Submitted'] + + if auto_submitted == None or auto_submitted == "no" \ + or auto_submitted == "No": + + return + + debug("autoreply") + exit(0) + + def email_to_reply_to_subject (email_bytes): """Returns the email's To:, Reply-To: (or From:), and Subject: fields diff --git a/tests/flatten-9.eml b/tests/flatten-9.eml new file mode 100644 index 0000000..bbc8963 --- /dev/null +++ b/tests/flatten-9.eml @@ -0,0 +1,11 @@ +From - Tue Jul 19 14:09:15 2016 +To: noone@localhost +Subject: auto-response test +Auto-Submitted: auto-replied +From: No One +Date: Tue, 19 Jul 2016 14:09:14 -0400 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 7bit + +test + diff --git a/tests/flatten-9.out b/tests/flatten-9.out new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/flatten-9.out @@ -0,0 +1 @@ + -- 2.25.1