Files
dotfiles/mutt/filter.py
2022-10-11 08:30:13 +02:00

34 lines
1.1 KiB
Python
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
import re
import sys
# Read data from stdin
data = sys.stdin.read()
# Remove unwanted text
data = re.sub(r'\[-- Autoview.*--\]', '', data)
data = re.sub(r'\[-- Attachment #[0-9] --\]', '', data)
data = re.sub(r'\[cid\]', '', data)
data = re.sub(r'\[-- application.*unsupported.*--\]', '', data)
data = re.sub(r'\[-- image.*unsupported.*--\]', '', data)
data = re.sub(r'\[-- Type.*--\]', '', data)
# replace text for signed and encrypted email
data = re.sub(r'\[-- OpenSSL.*\nVerification successful\n.*',
'[-- Signed Email: Verification successful --]', data)
data = re.sub(r'\[-- The following data is S/MIME encrypted --\]',
'[-- Encrypted Email: S/MIME --]', data)
data = re.sub(r'\[-- The following data is signed --\]', '', data)
data = re.sub(r'\[-- End of signed data --\]', '', data)
data = re.sub(r'\[-- End of S/MIME encrypted data. --\]', '', data)
# Add line for quoted email
data = re.sub(r'(?<=\n)(From:.*)', '_'*80 + r'\n\1', data)
# clean up multiple blanks lines
data = re.sub(r'.*\n', '', data)
data = re.sub(r'\n\s*\n', r'\n\n', data)
# Output filtered text to stdout
sys.stdout.write(data)