创建 MIME 边界的规则(对于邮件附件)

发布于 2024-11-10 05:27:59 字数 487 浏览 0 评论 0原文

我正在使用 PHP mail() 函数发送带有附件的邮件。 因此,PHP 源内容包含一个边界来定义附件的开始和结束位置。

所以问题是:创建这个 MIME 边界有什么规则吗(例如只允许使用字母和数字) 我仍然知道这个问题 -> 哪些规则适用于 MIME 边界? 是否有必要为 HASH 创建边界? 因为以下内容也适用:

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

是否有原因,为什么 MIME 边界应该是唯一的值?

..我在互联网上没有找到任何信息。

谢谢你!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

动次打次papapa 2024-11-17 05:27:59

没有什么规定边界标记必须是哈希值,但它们必须是唯一的。想象一下,如果您插入的实际电子邮件文本在某处自然包含单词 --abc-- ,会发生什么。

您的电子邮件看起来像这样:

--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

那么...邮件客户端如何知道电子邮件的一部分以及“开销”是什么?这就是为什么你使用独特的边界。

哈希是最简单的方法。在极端情况下,电子邮件文本不太可能在可以被视为边界标记的确切位置包含自己的哈希值。

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.

强者自强 2024-11-17 05:27:59

MIME 边界应该是不可能出现在用户的实际消息中的东西。哈希是一个不错的选择,因为它们很长且唯一。独特性还使得其他人很难通过弄清楚您使用的边界并将其包含在他们的消息中来搞乱他们的消息。但是,我找不到边界唯一的任何要求,只是整行少于 70 个字符。

MIME boundaries should be something impossibly unlikely to appear in the user's actual message. Hashes are a good option because they are long and unique. Uniqueness also makes it difficult for someone to mess up their messages by figuring out what boundary you use and including it in their message. However, I can't find any requirement that boundaries be unique, just that the entire line be under 70 characters.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文