How to Decode an Email in MIME Format

Most emails sent today are MIME (Multipupose Internet Mail Extensions) formatted. This allows emails to be sent with plain text and rich text/HTML versions, inline images, and attachments. MIME extensions can be added to a message in standard RFC/822 format so backward compatibility is achieved with older mail systems.

Things You'll Need

  • Knowledge of a computer language (i.e. C++, C#, VB, etc).
  • Basic knowledge of the format of an RFC/822 formatted email message.
Show More

Instructions

    • 1

      Load the contents of the email message.

    • 2

      Check the "Content-Type" header. If the content type is multipart (i.e. "multipart/mixed", "multipart/alternative", etc) the message will have multiple sections to parse. If the content type is multipart, continue with below steps.

    • 3

      The Content-Type header should contain a unique string used by the code that generated the MIME message to designate MIME part boundaries. Example:

      Content-Type: multipart/mixed;
      boundary="part_c7161025_fe8a_45f4_83ef_6befcfa5d021"

      The boundary string in this case is "part_c7161025_fe8a_45f4_83ef_6befcfa5d021".

    • 4

      Each MIME part will be separated by the boundary string preceeded by two dashes ("--") on a blank line. You will need to scan the message line by line looking for the part boundaries. All text in between the boundaries *except the final CR/LF* is part of that MIME part.

      Important: The last MIME part will end with the boundary string followed by two more dashes.

      Example:

      --part_c7161025_fe8a_45f4_83ef_6befcfa5d021
      First MIME part.

      --part_c7161025_fe8a_45f4_83ef_6befcfa5d021
      Second MIME part

      --part_c7161025_fe8a_45f4_83ef_6befcfa5d021
      Last MIME part.

      --part_c7161025_fe8a_45f4_83ef_6befcfa5d021--

    • 5

      Each MIME part then needs to be parsed. The format of each MIME part is similar to the original RFC/822 formatted message. It will contain a series of headers, followed by a blank line, then the body data.

    • 6

      A MIME part can itself be multipart, with its own "Content-Type" header and boundary string. Your code must recursively parse MIME parts until it reaches the child nodes.

    • 7

      A MIME part can simply be a binary attachment. In this case a Filename header will usually be supplied, along with the transfer encoding. BASE64 is a popular encoding type. In this case the entire MIME part body must be BASE64 decoded. As an example here are the first few lines of an attached JPG image:

      ------_=_NextPart_003_01C755EF.43F2628D
      Content-Type: image/jpeg;
      name="testimage.jpg"
      Content-Transfer-Encoding: base64
      Content-Description: testimage.jpg
      Content-Disposition: attachment;
      filename="testimage.jpg"

      /9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
      HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIy
      MjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAQABQQDASIA
      AhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA

    • 8

      The HTML body of the message should be in a MIME section with ContentType: Text/Html, inside a ContentType: Multipart/Alternative MIME section.

    • 9

      The plaintext body of the message should be in a MIME section with ContentType: Text/plain, inside a ContentType: Multipart/Alternative MIME section.

Tips & Warnings

  • Consult RFC 822 http://www.ietf.org/rfc/rfc0822.txt?number=822 and RFC 1341 http://www.ietf.org/rfc/rfc1341.txt?number=1341 for more information.

  • If you are coding in C#, an excellent free library is available at http://www.codeproject.com/csharp/mime_project.asp.

Related Searches:

Comments

You May Also Like

  • How to Read MIME Format Emails

    In email terminology, MIME means "Multipurpose Internet Mail Extensions." MIME format emails use the Internet protocol to extend the ability of emails...

  • How do I Convert Mime to AVI?

    MIME is a file extension that allows the transfer of non-text documents, such as AVIs or JPEGs, through email. Most email clients...

  • Facts on MIME Format

    Sending e-mail is pretty much a fact of life for most people. Many are unaware of the limitations that the ASCII-based messages...

  • How to Update MIME Types

    Multipurpose Internet Mail Extensions (MIME) is a method used to determine what program is executed when the user opens a file in...

  • How Can I Read an Email in MIME Version 1.0?

    MIME (Multipurpose Internet Mail Extensions) is a standard that allows email messages to contain text with unlimited line length. MIME also allows...

  • How to Create Your Own Message Decoder Game

    Coded messages add an extra step to games and puzzles by disguising key instructions or clues. In these games, the words or...

  • Types of MIME Images

    Types of MIME Images. When you receive emails in your inbox, you could find some of them containing a variety of attachments...

  • How to Decode Email Attachments

    If running either a Windows or Mac operating system, your computer comes with its own "zip file" decoding program (like "WinZip" for...

  • How to Create Mime Email

    MIME email refers to "Multipurpose Internet Mail Extensions." To put it simply, MIME email consists of both an HTML email message plus...

  • How to Create Plain Text & Mime Formatted Email With PHP

    When sending emails, there are two different formats used: plain text and MIME format. MIME is short for Multipurpose Internet Mail Extensions....

Related Ads

Featured