WHAT IS IT
Mail users, especially in non-English countries, often find that mail messages arrived in different formats, with different content types, in different encodings and charsets. Usually this is good because it allows us to use appropriate format/encoding/whatever. Sometimes, though, some unification is desirable. For example, one may want to put mail messages into an archive, make HTML indices, run search indexer, etc. In such situations converting messages to text in one character set and skipping some binary attachments is much desirable.
Here is the solution - mimedecode.
This is a program to decode MIME messages. The program expects one input file (either on command line or on stdin) which is treated as an RFC822 message, and decodes to stdout or an output file. If the file is not an RFC822 message it is just copied to the output one-to-one. If the file is a simple RFC822 message it is decoded as one part. If it is a MIME message with multiple parts ("attachments") all parts are decoded. Decoding can be controlled by command-line options.
Think about said mail archive; for example, its maintainer wants to put there only texts, convert PDF/Postscript to text, pass HTML and images decoding base64 to html but leaving images encoded, and ignore everything else. This is how it could be done:
mimedecode -t application/pdf -t application/postscript -t text/plain -b text/html -B 'image/*' -i '*/*'
Version 3.1.0 (2021-05-23)
Convert mimedecode.docbook to reST. Generate html/man/text using Sphinx.
Replaced outdated and insecure `mktemp` with `NamedTemporaryFile`.
Python 3.8, 3.9.
WHERE TO GET Home page: https://phdru.name/Software/Python/#mimedecode git clone https://github.com/phdru/mimedecode.git git clone https://git.phdru.name/mimedecode.git git clone git://git.phdru.name/mimedecode.git
Requires: Python 2.7 or Python 3.4+, m_lib.defenc 1.0+. Tests require: tox, m_lib 3.1+.
Recommends: configured mailcap database.
Documentation: https://phdru.name/Software/Python/mimedecode.html (also included in the package in html, man and txt formats).
AUTHOR Oleg Broytman email@example.com
COPYRIGHT Copyright (C) 2001-2021 PhiloSoft Design.