【发布时间】:2022-01-09 16:27:41
【问题描述】:
我正在使用我的 PHP 来提取我将电子邮件标头存储在 mysql 数据库中的二进制数据。我需要一些帮助来提取二进制数据以获取附件二进制数据。
例子:
UEsDBBQAAAAIAEpZrEjPyoXURw....etc
如果您要查找文件名,我不知道如何提取二进制数据,例如:email_example1.zip。
这是标题:
Return-Path: <sender@domain.com>
Delivered-To: chris@domain.com
Received: from domain.com
------=_Part_4094373_1508330616.1564422111167
Content-Type: application/zip
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="email_example1.zip"
Content-ID: <05063d19-5033-af14-87e2-d2fbf22d5857@yahoo.com>
UEsDBBQAAAAIAEpZrEjPyoXURw....etc
------=_Part_4094373_1508330616.1564422111167
Content-Type: application/zip
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="example2.zip"
Content-ID: <3b2c4fee-2b28-778b-b27f-c63881d64e17@domain.com>
UEsDBBQAAAAIALtk6U5W+XzU7iM....etc
这里是 PHP:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
//Connect to the database
include('config.php');
$id = $_GET['id'];
$attid = $_GET['attid'];
$message_id = $_GET['msgid'];
$mailbox_sql = 'SELECT * FROM ' . $mailfolder . ' WHERE email_id = ? AND message_id = ?';
$mailbox = $link->prepare($mailbox_sql);
$mailbox->execute([$id,$message_id]);
// set the resulting array to associative
$row = $mailbox->fetch(PDO::FETCH_ASSOC);
if (is_array($row)) {
$attached = $row['attached_files'];
$attached_arr = explode("\n", $attached);
}
foreach ($attached_arr as $files) {
$attached_file = 'attid: ' . $attid . ' filename:';
$attached = '';
if (strpos($files, ' attid: ') !== false) {
$filename = trim(strrchr($files, ':'), ': ');
$files = 'attid: ' . $attid . ' filename: ' . $filename;
}
if (strpos($files, $attached_file) !== false) {
$attached = trim(strrchr($files, ':'), ': ');
}
mailbox = null;
?>
你知道我如何搜索电子邮件标题中的文件名来提取二进制数据吗?
任何建议都会非常感激。
【问题讨论】:
-
那是某种编码,也许是base64?
-
@user3783243 是的,我想提取编码数据。你知道怎么做吗??
-
@bumperbox 我知道如何使用 base64_decode 但我正在谈论如何搜索 base64 编码字符串,例如:
UEsDBBQAAAAIAEpZrEjPyoXURw....etc。你知道我在搜索文件名时如何获取base64编码字符串吗?? -
二进制数据在您的正文中
Content-Type: application/zip。文件名通过 Content-Disposition HeaderContent-Disposition: attachment; filename="email_example1.zip"公开,您只需解析文件名即可。如果这不能回答您的问题,请更好地解释您想要实现的目标。
标签: php email-attachments