From 50b0bbd7aef436a34410826a4a6c6e17079e5c46 Mon Sep 17 00:00:00 2001 From: Andrew Engelbrecht Date: Mon, 20 Jul 2015 15:27:18 -0400 Subject: [PATCH] update test suite to compare mime-decoded messages --- run-tests | 3 +-- tests/flatten-mime | 38 ++++++++++++++++++++++++++++++++++++++ tests/out1.txt | 29 ++++++++++++----------------- 3 files changed, 51 insertions(+), 19 deletions(-) create mode 100755 tests/flatten-mime diff --git a/run-tests b/run-tests index 5cbdb27..48570f1 100755 --- a/run-tests +++ b/run-tests @@ -19,11 +19,10 @@ G_HOME=./tests/testgnupghome -OUT_DIFF_1="$(./edward < ./tests/test1.eml | GNUPGHOME="$G_HOME" gpg 2> /dev/null | diff -Z -u ./tests/out1.txt - )" +OUT_DIFF_1="$(time ./edward < ./tests/test1.eml | GNUPGHOME="$G_HOME" gpg 2> /dev/null | ./tests/flatten-mime | diff -Z -u ./tests/out1.txt - )" if [ -n "$OUT_DIFF_1" ] ; then echo "*** test 1 failed! difference:" >&2 echo "$OUT_DIFF_1" >&2 fi - diff --git a/tests/flatten-mime b/tests/flatten-mime new file mode 100755 index 0000000..9406eae --- /dev/null +++ b/tests/flatten-mime @@ -0,0 +1,38 @@ +#! /usr/bin/env python3 +# -*- coding: utf-8 -*- + +"""*********************************************************************** +* "flatten-mime" is free software: you can redistribute it and/or modify * +* it under the terms of the GNU Affero Public License as published by * +* the Free Software Foundation, either version 3 of the License, or * +* (at your option) any later version. * +* * +* "flatten-mime" is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU Affero Public License for more details. * +* * +* You should have received a copy of the GNU Affero Public License * +* along with Edward. If not, see . * +* * +* Copyright (C) 2015 Andrew Engelbrecht (AGPLv3+) * +************************************************************************** + +""" + +import sys +import email.parser + + +mime_text = sys.stdin.read() + +email_struct = email.parser.Parser().parsestr(mime_text) + +for subpart in email_struct.walk(): + payload_b = subpart.get_payload(decode=True) + + if payload_b: + payload = payload_b.decode("utf-8") + + print(payload) + diff --git a/tests/out1.txt b/tests/out1.txt index 265c9d2..6a7350b 100644 --- a/tests/out1.txt +++ b/tests/out1.txt @@ -1,23 +1,18 @@ -MIME-Version: 1.0 -Content-Type: text/plain; charset="utf-8" -Content-Transfer-Encoding: quoted-printable - thanks for the message! > thanks for the message! ->=20 -> > =C3=9Cber Spa=C3=9F. -> >=20 -> > qual =C3=A8 il suono di una mano sola? -> >=20 -> > =E3=81=93=E3=82=93=E3=81=AB=E3=81=A1=E3=81=AF=E3=80=81=E3=81=8A=E5=85= -=83=E6=B0=97=E3=81=A7=E3=81=99=E3=81=8B=EF=BC=9F -> >=20 ->=20 +> +> > Über Spaß. +> > +> > qual è il suono di una mano sola? +> > +> > こんにちは、お元気ですか? +> > +> > test. ->=20 +> > -andrew ->=20 ->=20 ->=20 +> +> +> -- 2.25.1