From bd705bf9f602d63ed24d17834b5eccabe664e774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandra=20Alb=C3=B3nico?= Date: Tue, 13 Jul 2021 11:58:37 -0300 Subject: [PATCH 1/6] testing change to error [skip ci] --- mailparser/utils.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/mailparser/utils.py b/mailparser/utils.py index 3fd4a3c..b607bd3 100644 --- a/mailparser/utils.py +++ b/mailparser/utils.py @@ -219,21 +219,15 @@ def msgconvert(email): temph, temp = tempfile.mkstemp(prefix="outlook_") command = ["msgconvert", "--outfile", temp, email] - try: - if six.PY2: - with open(os.devnull, "w") as devnull: - out = subprocess.Popen( - command, stdin=subprocess.PIPE, - stdout=subprocess.PIPE, stderr=devnull) - elif six.PY3: + if six.PY2: + with open(os.devnull, "w") as devnull: out = subprocess.Popen( command, stdin=subprocess.PIPE, - stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) - - except OSError: - message = "To use this function you must install 'msgconvert' tool" - log.exception(message) - raise MailParserOSError(message) + stdout=subprocess.PIPE, stderr=devnull) + elif six.PY3: + out = subprocess.Popen( + command, stdin=subprocess.PIPE, + stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) else: stdoutdata, _ = out.communicate() From c7efde2bd48b5ef84664fa5b08a3f23231fd3442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandra=20Alb=C3=B3nico?= Date: Tue, 13 Jul 2021 14:39:56 -0300 Subject: [PATCH 2/6] more changes --- mailparser/utils.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/mailparser/utils.py b/mailparser/utils.py index b607bd3..453f2b7 100644 --- a/mailparser/utils.py +++ b/mailparser/utils.py @@ -219,15 +219,19 @@ def msgconvert(email): temph, temp = tempfile.mkstemp(prefix="outlook_") command = ["msgconvert", "--outfile", temp, email] - if six.PY2: - with open(os.devnull, "w") as devnull: + try: + if six.PY2: + with open(os.devnull, "w") as devnull: + out = subprocess.Popen( + command, stdin=subprocess.PIPE, + stdout=subprocess.PIPE, stderr=devnull) + elif six.PY3: out = subprocess.Popen( command, stdin=subprocess.PIPE, - stdout=subprocess.PIPE, stderr=devnull) - elif six.PY3: - out = subprocess.Popen( - command, stdin=subprocess.PIPE, - stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) + stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) + + except OSError: + raise ValueError else: stdoutdata, _ = out.communicate() From 2e82c5d1246599bfdd0a83ca69067fc1f5b58a0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandra=20Alb=C3=B3nico?= Date: Tue, 13 Jul 2021 17:48:47 -0300 Subject: [PATCH 3/6] third try [skip ci] --- mailparser/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mailparser/utils.py b/mailparser/utils.py index 453f2b7..2dd9c38 100644 --- a/mailparser/utils.py +++ b/mailparser/utils.py @@ -230,8 +230,8 @@ def msgconvert(email): command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) - except OSError: - raise ValueError + except Exception as e: + print(e) else: stdoutdata, _ = out.communicate() From 482303746d4c7fdc68ef1d77086191f0454c81e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandra=20Alb=C3=B3nico?= Date: Fri, 16 Jul 2021 19:30:34 -0300 Subject: [PATCH 4/6] testing better way to show error --- mailparser/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mailparser/utils.py b/mailparser/utils.py index 2dd9c38..fe90184 100644 --- a/mailparser/utils.py +++ b/mailparser/utils.py @@ -230,8 +230,11 @@ def msgconvert(email): command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) - except Exception as e: + except OSError as e: print(e) + message = "Check if 'msgconvert' tool is installed" + log.exception(message) + raise MailParserOSError(message) else: stdoutdata, _ = out.communicate() From 80ccd5a3bdfee3cfa477ece11d350613e0fc728b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandra=20Alb=C3=B3nico?= Date: Fri, 16 Jul 2021 22:28:46 -0300 Subject: [PATCH 5/6] update code --- mailparser/utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mailparser/utils.py b/mailparser/utils.py index fe90184..2d27a3e 100644 --- a/mailparser/utils.py +++ b/mailparser/utils.py @@ -231,8 +231,7 @@ def msgconvert(email): stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) except OSError as e: - print(e) - message = "Check if 'msgconvert' tool is installed" + message = "Check if 'msgconvert' tool is installed / %s" % e log.exception(message) raise MailParserOSError(message) From 04630cf53c9575c91f86629ea1cd1a8d20e00f76 Mon Sep 17 00:00:00 2001 From: Fedele Mantuano Date: Tue, 20 Jul 2021 09:43:02 +0200 Subject: [PATCH 6/6] Update utils.py --- mailparser/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mailparser/utils.py b/mailparser/utils.py index 2d27a3e..b25fa34 100644 --- a/mailparser/utils.py +++ b/mailparser/utils.py @@ -231,7 +231,7 @@ def msgconvert(email): stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) except OSError as e: - message = "Check if 'msgconvert' tool is installed / %s" % e + message = "Check if 'msgconvert' tool is installed / {!r}".format(e) log.exception(message) raise MailParserOSError(message)