Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3797364
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:23:31+00:00 2026-05-19T13:23:31+00:00

I have a file containing an email in plain text MIME message format. I

  • 0

I have a file containing an email in “plain text MIME message format”. I am not sure if this is the EML format. The email contains an attachment and I want to extract the attachment and create those files again. This is how the attachment part looks like –

...
...
Receive, deliver details
...
...
From: sac ascsac <sacsac@sacascsac.ascsac>

Date: Thu, 20 Jan 2011 18:05:16 +0530

Message-ID: <AANLkTimmSL0iGW4rA3tvSJ9M3eT5yZLTGsqvCvf2fFC3@mail.gmail.com>

Subject: Test attachments

To: ascsacsa@ascsac.com

Content-Type: multipart/mixed; boundary=20cf3054ac85d97721049a465e12



--20cf3054ac85d97721049a465e12

Content-Type: multipart/alternative; boundary=20cf3054ac85d97717049a465e10



--20cf3054ac85d97717049a465e10

Content-Type: text/plain; charset=ISO-8859-1



hello this is a test mail. It contains two attachments



--20cf3054ac85d97717049a465e10

Content-Type: text/html; charset=ISO-8859-1



hello this is a test mail. It contains two attachments<br>


--20cf3054ac85d97717049a465e10--

--20cf3054ac85d97721049a465e12

Content-Type: text/plain; charset=US-ASCII; name="simple_test.txt"

Content-Disposition: attachment; filename="simple_test.txt"

Content-Transfer-Encoding: base64

X-Attachment-Id: f_gj5n2yx60



aGVsbG8gd29ybGQKYWMgYXNj
...
encoded things here
...
ZyBmZyAKCjIKNDIzCnQ2Mwo=

--20cf3054ac85d97721049a465e12

Content-Type: application/x-httpd-php; name="oscomm_backup_code.php"

Content-Disposition: attachment; filename="oscomm_backup_code.php"

Content-Transfer-Encoding: base64

X-Attachment-Id: f_gj5n5gxn1



PD9waHAKCg ...
...
encoded things here
...
X2xpbmsoRklMRU5BTUVfQkFDS1VQKSk7Cgo/Pgo=
--20cf3054ac85d97721049a465e12--

I can see that the part between X-Attachment-Id: f_gj5n2yx60 and ZyBmZyAKCjIKNDIzCnQ2Mwo=, both including
is the content of the first attachment. I want to parse those attachments (file names and contents and create those files).

I got this file after parsing a dbx format file using a DBX Parser class available in PHP classes.

I searched in many places and did not find much discussion regarding this here in SO other than Script to parse emails for attachments. May be I missed some terms while searching. In that answer it is mentioned –

you can use the boundries to extract
the base64 encoded information

But I am not sure which are the boundaries and how exactly to use the boundaries? There already must be some libraries or some well defined method of doing this. I guess I will commit many mistakes if I try reinventing the wheel here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T13:23:32+00:00Added an answer on May 19, 2026 at 1:23 pm

    There’s an PHP Mailparse extension, have you tried it?

    The manual way would be, process the mail line by line. When you hit your first Content-Type header (this one in your example):
    Content-Type: multipart/mixed; boundary=20cf3054ac85d97721049a465e12

    You have the boundary. This string is used as the boundary between your multiple parts (that’s why they call it multipart).
    Everytime a line starts with the dashes and this string, a new part begin. In your example:
    –20cf3054ac85d97721049a465e12

    Every part will start with headers, a blank line, and content. By looking at the content-type of the headers you can determine which are attachments, what their type is and their filename.
    Read the whole content, strip the spaces, base64_decode it, and you’ve got the binary contents of the file. Does this help?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a plain text file looking like this: some text containing line breaks
I have a c++ header file containing a class. I want to use this
I have a text file containing ~300k rows. Each row has a varying number
hey say I have a file containing something like this name1 lastname1 email1 date1
I have a contact form in my flash file with name/email/message fields which a
I have a file containing data in the format: 0.0 x1 0.1 x2 0.2
I have a text file containing the first 1000 prime numbers and I have
I have a text file containing the following string: --jonesj (release 00) some sql
I have a .xib file containing a UIView and 2 UILabel subviews linked to
I have a ListView containing file names. These file names need to be draggable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.