Sometimes you are unable to download an attachment from Gmail due to the following message:
Anti-virus warning - 1 attachment contains a virus or blocked file. Downloading this attachment is disabled.
Now what ?
One particular one cought my interest: Show original
Clicking this option opened a text file with the original, MIME encoded message. The interesting thing of course was
------=_NextPart_000_004F_01CA0AED.E63C2A30
Content-Type: application/octet-stream;
name="phdstuff.rar"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="phdstuff.rar"
UmFyIRoHAM+QcwAADQAAAAAAAAB0f3TAgCwANAMAAFQEAAACRbXCx8lr9TodMwwAIAAAAG5ld2Zp
bmFsLnR4dA3dEQzM082BF7sB+D3q6QPUNEfwG7vHQgNkiQDTkGvfhOE4mNltIJJlBFMOCQPzPeKD
...
So the whole attachment was contained in that text file, encoded in base64! Now I just needed to extract it from the email and convert it back to binary.
Here’s a simple program that gets an email in text/mime format as input and dumps all attachments:
Save this to a file named get_attachments.py and, after saving the original message to a file named 0.txt run python get_attachments.py 0.txt and you’ll see the attachments of your email in the same folder!