Extract a Base64 attachment from a MIME email
Read the headers and boundaries of a small MIME part, select the two body lines and verify that they restore exactly five attachment bytes.
Locate the correct MIME part
In the raw source of a multipart email, a boundary separates the message parts. The example below is one part from a message whose boundary parameter is sample. Check the transfer encoding of that part and locate the blank line following its headers.
Copy only the attachment body
Select AAEC and /v8= from the example. The combined value AAEC/v8= restores 00 01 02 FE FF. MIME Base64 lines have a maximum length of 76 characters and can be shorter. These formatting line breaks do not become bytes in the restored attachment.
--sample
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
AAEC
/v8=
--sample--Use a MIME parser for multiple attachments
Removing whitespace from an entire email mixes letters from headers into the payload. For an .eml file, use a MIME parser to walk the parts. In Python, call get_payload(decode=True) on the leaf attachment part to obtain its transfer-decoded bytes.