UUDecode mail attachments
Posted by davidnewcomb on 02 May 2008 in Techie
We run Horde Webmail which runs from a PHP back end. A problem we hit occasionally is that some one will send a mail with a large attachment. Horde (via PHP) will try to extract the file to deliver it to the client but will hit a maximum memory constraint placed on it by the PHP engine and fail.
This is a problem with several solutions. The first is a quick fix, simply change the maximum amount of memory that a PHP process can consume. This is quick and easy but that limit is there to protect our web server (and ultimately our machine) from all the baddies on the internet and all the bugs in our code. It shouldn’t really be used.
The second approach involves some hacker’ry on the server. We can find the mail file and strip out the attachment by hand and decode it. After decoding the attachment, the file can be placed under the web server’s document root and downloaded as a regular static file with no restrictions.
- Locate the file with your mail attachment in it; the file’s location may vary depending on the mail server software you are using.
- Take a copy of the mail file, for editing, and call it
mail.b64
- Open the copy in your favourite editor (which had better be Vim) and strip out the base64 attachment
- At the top of the file, add the headers for the decoder
begin-base64 permission filename
egbegin-base64 0644 My Long file name.doc
- At the end of the file add the trailer, then save
====
- You file should look something like
begin-base64 0644 My Long file name.doc UmFyIRoHAM+QcwAADQAAAAAAAABKcXSggC4A2toXANraFwACeWsUbIJlpjYd MA4AIAAAAHBcRFNDMDE0MjMuSlBH/9j/4VI7RXhpZgAASUkqAAgAAAALAA4B AgAgAAAAkgAAAA8BAgAFAAAAsgAAABABAgAHAAAAuAAAABIBAwABAAAAAQAA ABoBBQABAAAAwAAAABsBBQABAAAAyAAAACgBAwABAAAAAgAAADIBAgAUAAAA 0AAAABMCAwABAAAAAgAAAGmHBAABAAAAAAEAAKXEBwAcAAAA5AAAAMgIAAAg [..snip..] SLS3LtIk04eQrKls4cPnv1AwD0qRnjuFdl3JLtZJSQp3Y4Ut7Y964ubEyZNa lOoyGNpHJjKh9tvl1dwB1xkgZ4x0P4UAhS6L+9iVeEM20yZI2jKkYJPNdeNr OxdOrQcD/9nz13TggCEAAAAAAAAAAAACAAAAAI9FbDgUMAEAEAAAAHDEPXsA QAcA ====
- Run the decoder
uudecode mail.b64
- A file called
My Long file name.doc
should appear in the current directory with permissions 0644 - Move the file to your web server’s document root and hay presto it is visible to the world.
No feedback yet
Form is loading...