Welcome!‎ > ‎Science‎ > ‎Computer‎ > ‎

Decode base64 MIME multi-part email attachments

Imagine that someone wants to send you a big attachment by email and you receive the attachment as being split into multi-part attachments each sent in separate emails.

This can also happen if you use these all-in-one photocopier, scanner, and fax devices. Once a document is scanned, the machine emails the document as attachment (file format: PDF) to a specified email address. Unfortunately once the maximum size for its email attachment is reached, most machines split the document into multi-part attachments and send each in a separate email.

Hence, each attachment contains parts of the original file encoded using MIME encoding. 

Merging the attachments into one file
In order to merge all attachments into one file the munpack can be used.

Once munpack is installed the attachments at01.mime, at02.mime, ...
can be merged using:
cat at01.mime at02.mime <...> | munpack

<...> stands for all further the MIME attachments in the right order.

Note: Ubuntu users can install munpack by using apt:
sudo apt-get install mpack

Another method would be using GNU base64 decoder

First, check if the first of the attachments has any headers. If you find headers, remove them completely.

Second, run the GNU base64 decoder and pipe your output into a file (output.pdf):

cat at01.mime at02.mime <...> | base64 -d -i > output.pdf

<...> stands for all further (header removed) MIME attachments in the right order.

Other methods for decoding base64 MIME multi-part email attachments can be found here.