From f64ff2feea21c11865fd9345de41e602d60f085b Mon Sep 17 00:00:00 2001 From: Brian Read Date: Thu, 30 May 2024 21:47:57 +0100 Subject: [PATCH] Add in check for version of html2text --- root/usr/bin/mailstats.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/root/usr/bin/mailstats.py b/root/usr/bin/mailstats.py index 820c87b..46e08ae 100644 --- a/root/usr/bin/mailstats.py +++ b/root/usr/bin/mailstats.py @@ -227,6 +227,15 @@ def html_to_text(input_file, output_file): print(f"Error occurred: {e.stderr.decode('utf-8')}", file=sys.stderr) sys.exit(e.returncode) +def get_html2text_version(): + try: + result = subprocess.run(['html2text', '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + # Ensure the result is treated as a string in Python 3.6+ + return result.stdout.strip() + except subprocess.CalledProcessError as e: + print(f"Error occurred while checking html2text version: {e}", file=sys.stderr) + return None + if __name__ == "__main__": try: chameleon_version = pkg_resources.get_distribution("Chameleon").version @@ -419,7 +428,8 @@ if __name__ == "__main__": output_path = output_path.replace(' ','_') with open(output_path+'.html', 'w') as output_file: output_file.write(rendered_html) - #and create a text version - html_to_text(output_path+'.html',output_path+'.txt') + #and create a text version if the local version is suffiicent + if get_html2text_version() == '2019.9.26': + html_to_text(output_path+'.html',output_path+'.txt') print(f"Rendered HTML saved to {output_path}.html/txt")