전자 메일 계정에서 새 메시지를 확인하고 각 전자 메일에서 .zip 및 .pdf 첨부 파일을 다운로드하려고 시도합니다.전자 메일에서 첨부 파일 추출 - 첨부 파일 이름을 얻을 수 없습니다.
[1] => stdClass Object
(
[type] => 3
[encoding] => 3
[ifsubtype] => 1
[subtype] => PDF
[ifdescription] => 0
[ifid] => 0
[bytes] => 132780
[ifdisposition] => 1
[disposition] => attachment
[ifdparameters] => 1
[dparameters] => Array
(
[0] => stdClass Object
(
[attribute] => filename
[value] => some_filename.pdf
)
)
[ifparameters] => 1
[parameters] => Array
(
[0] => stdClass Object
(
[attribute] => name
[value] => some_filename.pdf
)
)
)
[2] => stdClass Object
(
[type] => 3
[encoding] => 3
[ifsubtype] => 1
[subtype] => ZIP
[ifdescription] => 0
[ifid] => 0
[bytes] => 43170
[ifdisposition] => 1
[disposition] => attachment
[ifdparameters] => 1
[dparameters] => Array
(
[0] => stdClass Object
(
[attribute] => filename
[value] => another_filename.zip
)
)
[ifparameters] => 1
[parameters] => Array
(
[0] => stdClass Object
(
[attribute] => name
[value] => another_filename.zip
)
)
)
당신이 각각의 확장자와 파일 이름을 알아 내기 위해 쉽게 볼 수 있듯이 : $structure->parts
는 다음과 같이 보이는, 대부분의 이메일에 대한
/* try to connect */
$inbox = imap_open($hostname, $username, $password) or die ('Cannot connect to domain:' . imap_last_error());
/* grab emails */
$emails = imap_search($inbox, 'ALL');
/* put the newest emails on top */
rsort($emails);
foreach ($emails as $email_number) {
$overview = imap_fetch_overview($inbox, $email_number, 0);
if ($overview [0]->seen) {
continue;
}
$structure = imap_fetchstructure($inbox, $email_number);
if (!property_exists($structure, 'parts')) {
continue;
}
//print_r($structure->parts);
//get attachments
}
: 나는이 작업을 수행하려면 다음 코드를 사용하고 있습니다 부착.
[1] => stdClass Object
(
[type] => 3
[encoding] => 3
[ifsubtype] => 1
[subtype] => OCTET-STREAM
[ifdescription] => 1
[description] => =?utf-8?B?Q1RHIFF1ZXLDqXRhcm8gIC0gIC0gMTJfOF8xNi5wZGY=?=
[ifid] => 1
[id] => <[email protected]>
[bytes] => 44592
[ifdisposition] => 1
[disposition] => attachment
[ifdparameters] => 1
[dparameters] => Array
(
[0] => stdClass Object
(
[attribute] => filename
[value] => =?utf-8?B?Q1RHIFF1ZXLDqXRhcm8gIC0gIC0gMTJfOF8xNi5wZGY=?=
)
[1] => stdClass Object
(
[attribute] => size
[value] => 32586
)
[2] => stdClass Object
(
[attribute] => creation-date
[value] => Thu, 08 Dec 2016 22:16:31 GMT
)
[3] => stdClass Object
(
[attribute] => modification-date
[value] => Thu, 08 Dec 2016 22:16:31 GMT
)
)
[ifparameters] => 1
[parameters] => Array
(
[0] => stdClass Object
(
[attribute] => name
[value] => =?utf-8?B?Q1RHIFF1ZXLDqXRhcm8gIC0gIC0gMTJfOF8xNi5wZGY=?=
)
)
)
[2] => stdClass Object
(
[type] => 3
[encoding] => 3
[ifsubtype] => 1
[subtype] => OCTET-STREAM
[ifdescription] => 1
[description] => =?utf-8?B?Q1RHIFF1ZXLDqXRhcm8gIC0gIC0gMTJfOF8xNi56aXA=?=
[ifid] => 1
[id] => <[email protected]>
[bytes] => 10966
[ifdisposition] => 1
[disposition] => attachment
[ifdparameters] => 1
[dparameters] => Array
(
[0] => stdClass Object
(
[attribute] => filename
[value] => =?utf-8?B?Q1RHIFF1ZXLDqXRhcm8gIC0gIC0gMTJfOF8xNi56aXA=?=
)
[1] => stdClass Object
(
[attribute] => size
[value] => 8011
)
[2] => stdClass Object
(
[attribute] => creation-date
[value] => Thu, 08 Dec 2016 22:16:31 GMT
)
[3] => stdClass Object
(
[attribute] => modification-date
[value] => Thu, 08 Dec 2016 22:16:31 GMT
)
)
[ifparameters] => 1
[parameters] => Array
(
[0] => stdClass Object
(
[attribute] => name
[value] => =?utf-8?B?Q1RHIFF1ZXLDqXRhcm8gIC0gIC0gMTJfOF8xNi56aXA=?=
)
)
)
이 첨부 파일을 다시 PDF와 ZIP하고 이메일 클라이언트를 사용하는 경우가 첨부 파일과 같은 모양 그러나, 최근에 나는 $ 구조 -> 부품 대신 다음과 같습니다 일부 이메일을 받았는데 다른 이메일. 그러나 위에서 볼 수 있듯이 파일 이름 대신 blahblah.zip 및 blahblah.pdf 대신 "=? utf-8? B? Q1RHIFF1ZXLDqXRhcm8gIC0gIC0gMTJfOF8xNi56aXA =? ="와 같은 내용이 표시됩니다. 또한 둘 모두의 하위 유형은 '우편'또는 'pdf'대신 'OCTET-STREAM'입니다. 따라서 각 유형의 첨부 파일이 무엇인지 알지 못하고 이메일을 통해 아무 것도 할 수 없습니다.
도움을 주시면 감사하겠습니다. 요약하면, 나는 다르게 행동하는 전자 메일의이 특정 세그먼트에서 첨부 파일 정보를 올바르게 추출하는 방법을 알아 내려고 노력하고 있습니다.
감사합니다. @HawkHogan. 내 하루를 구했다. '$ resp = iconv_mime_decode ($ string_encoded, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, "ISO-8859-15"),' 'echo $ resp = utf8_encode ($ resp);' – Duque