Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what rule for creating an MIME boundary (for Mail attachments)

i'm using the PHP mail() function to send mails with attachment. Therefore the PHP source contents an boundary to define where the attachment begins and ends.

So the question is: are there any ruels for creating this MIME boundary (exampt that are only letters and numbres are allowed) i still know this SO question -> What rules apply to MIME boundary? Is it necessary to create an boundary form an HASH? Because the following also works:

$headers .= "Content-Type: multipart/related; boundary=\"abc\"";
[...]
$msg .="--abc\n";
[...]
$msg .= "--abc--\n\n"; 

Is there a reason, why a MIME boundary should be an unique value?

..i didn't found any information at the Internet.

Thank you!

like image 703
The Bndr Avatar asked May 30 '11 15:05

The Bndr


1 Answers

Nothing says the boundary markers have to be hashes, but they MUST be unique. Think of what would happen if the actual email text you're inserting naturally contains the words --abc-- somewhere.

Your email would look something like this:

--abc--    <--actual boundary
This is my email. There are many like it, but this one is mine.
Now for some reason I'm going to put in a line that shouldn't be there
--abc--    <--part of the email
There it was. Did you see it? No, you didn't, because the mail client saw a boundary
line and sliced it out. Because of this extra boundary, now the email has 2 sections,
instead of 1.
--abc--    <--actual boundary

So... How is a mail client to know what's part of the email and what's just "overhead"? That's why you use unique boundaries.

Hashes are simply the easiest method. It's unlikely in the extreme that an email text would happen to contain its own hash value in the exact spot where it could be seen as a boundary marker.

like image 87
Marc B Avatar answered Sep 27 '22 17:09

Marc B