How to decode base64-encoded inline attachments in email files saved from Thunderbird or Gmail?
Although base64 [--decode]
works well when encoding and decoding files locally, I can’t decode a base64-encoded inline attachment in an eml file saved from Thunderbird or Gmail.
I observed that base64-encoded blocks in all eml files are similar to what base64
generates, but lines are of different length: the lines in base64-encoded blocks of text in eml files consist of 72 characters, while the locally generated base64-encoded files consist of 76-character-long lines. I suspect this discrepancy is why I cannot successfully use base64 --decode
on snippets of eml files.
Is my hypothesis true? How can I decode these attachments?
The command base64
performs encoding by wrapping text at default column width of 76 characters, unless another value is specified with the option --wrap=COLS
.
The command base64 --decode
is expected to work regardless of column width, e.g. the text block might consist of a single line (it doesn’t matter how long), or multiple lines wrapped at any fixed column width.
The problem with "Internet Message Format" (*.eml) files saved from Thunderbird or a web mail like GMail actually is that they use DOS/Windows ("CRLF" / "rn") – and not Unix/Linux ("LF" / "n") – line endings, while both base64
and base64 --decode
use the latter.
This means, "Internet Message Format" (*.eml) files (or base64-encoded text blocks retrieved from them) should first be converted using the dos2unix
command before executing the base64 --decode
command.