Ramin Hossaini (blog)

15Mar/11

Extracting attachments from .EML files

Note: If you're only interested in the download, scroll down to the bottom of the post.

An inconsiderate friend sent me a couple of .eml files with attachments that I had to look through. I downloaded the files and found that I had no associated application to open them. So instead of finding an application to open them, I thought I'd take a closer look at the files:

The top portion had a whole bunch of stuff I had no interest in whatsoever:

After all the HTML, I found the code for the attachment:

So I figured I just had to decode the Base64-encoded data and save it as the filename (in this case, a PDF)

The most logical thing at this point was to write my own application to do it. Just made a simple C# form with a textbox for the Base64-encoded data, a textbox for the filename to write to and a Decode button to get things going:

The Decode function is pretty simple:

1
2
3
4
5
public byte[] decode(string data)
{
    byte[] output = Convert.FromBase64String( data );
    return output;
}

So feed the function the Base64 part and it spits out the good stuff that you just write to a file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
FileStream fs = new FileStream(txtFilename.Text, FileMode.Create, FileAccess.Write);
BinaryWriter writer = new BinaryWriter(fs);
try
{
    for (int i = 0; i < decodedData.Length; i++)
    {
        writer.Write(decodedData[i]);
    }
}
finally
{
    writer.Close();
    fs.Close();
}

You can also just download the latest version of the app here: Base64 Decoder

The open file function is a bit experimental and does some .EML file clean-up.

It requires the .NET framework and no, it doesn't come supported, and I can't promise that I'll continue working on it.

13Oct/08

Packer – Javascript compressor

I tried 'packing' an already minimized version of JQuery (which was about 55KB) and this compressed it to about 30KB (almost 50% less). My advice - don't publish any javascript without pumping it through this first!


http://dean.edwards.name/packer/

Some tips:

  • Packer obfuscates code, so it makes things very difficult to debug. If you end up having problems with compressing the code, try compressing sections at a time to find out what's causing the problem.
  • Write code so that it doesn't rely on whitespace or line-breaks. Use braces instead.
  • Don't forget your semi-colons. (Especially when declaring anonymous functions for example)
30Mar/08

Gravatars

Gravatar: Derived from 'avatar' - Globally Recognized Avatar, is basically an avatar image that follows you across the web when you comment on gravatar-enabled blogs using a unique e-mail address.

Interesting, because this would imply that anyone could use your gravatar if they knew the e-mail address you used to sign-up for the account. So if you're going to sign up for one, I'd suggest using an e-mail address not known to anyone else.

If you have a blog of your own, take a look at the full implementation guide.

If you already have a wordpress blog, the easiest is to upgrade your installation to the latest available version (Version 2.5 comes with the functionality built-in - this only means gravatars will get more popular). Blogger hasn't implemented it yet - although it should only be a matter of time before they do.

You might have to do some tweaking if you developed your own wordpress theme:

The syntax is:

function get_avatar( $id_or_email, $size = '64',$default = 'http://url-to-default-avatar' )

This example uses the user's e-mail address to retrieve the gravatar at 80x80 pixels (add to comments.php):

<?php echo get_avatar( get_comment_author_email(), '80' ); ?>;

Click here to sign-up and set up a gravatar of your own.

Tagged as: , , 5 Comments
Private
Page 1 of 11
Bear