2013-06-30 2 views
3

부품 번호를 일관되게 참조하는 방법을 결정하는 데 어려움이 있습니다 (2.0, 2.1, 2.2 등의 부품 번호는 일반/텍스트 메시지, 이미지/jpeg 등). 아래에서 주어진 메시지의 객체를 참조하기 위해 '1.'.$i'2.'.$j을 사용하고 있습니다. 나는 가까운 뭔가가 생각 해요처럼 나는 PHP의 imap_fetchbody 올바른 부품 번호/색인 본문 부분 목록 얻기

$ MBOX = imap_open ('{mail.example.com:143/novalidate-cert}INBOX','someone+example.com'... 느낌, '암호');

if ($ mbox) {$ structure = imap_fetchstructure ($ mbox, $ message_id);

$ i = 0; $ j = 0;

foreach ($ structure-> parts $ k1 => $ d1) {// 다음 줄, 어떻게하면 이 올바른 부분을 나타내는가? " '1.

if (isset($d1->parts)) 
{ 
foreach ($d1->parts as $j2 => $d2) 
{//Next line, how do we refer to the part correct, e.g. "'2.'.$j"? 
    $a = print_r(imap_fetchbody($mbox,$cms->page2,'2.'.$j),1); 
    echo '<div><img alt="" src="data:image/jpeg;base64,'.$a.'" /></div>'; 
}}}} 

이 또한 내가 어떤 프레임 워크를 사용하는 데 관심이 아니에요, 나는이 나 자신을 수행하는 방법을 알아 내려고합니다. 관련 설명을 요청할 때 제 질문을 수정 해 드리겠습니다.

+0

[여기] (http://php.net/manual/en/function.imap-fetchstructure.php)를 보면 필요한 모든 설명이 있습니다. – DevZer0

+0

당신은 대답을 찾았습니까? 나도 필요합니다. –

+0

@Wasim 나는 당신을 위해 몇 분 안에 발견 한 것을 게시 할 것입니다. – John

답변

-1

전자 메일을 데이터베이스로 마이그레이션하기 전에 모든 것을 $email 배열에 추가합니다.

다음은 이메일의 여러 부분에 걸쳐 반복되는 방식입니다. 여기에 더 이상 사용하지 않는 몇 가지 오래된 비트가 있을지도 모르지만 이것이 정상적으로 작동합니다. 누락 된 기능은 데이터베이스에 쓰여지기 전에 여러 부분을 준비하는 데 사용하는 기능입니다.

$message = imap_body($mbox,$i); 
    $structure = imap_fetchstructure($mbox,$i); 

    $f = array('!'); 
    $r = array(''); 
    $message = str_ireplace($f,$r,$message); 
    $find = array('=00'); 
    $replace = array(''); 
    $message = str_ireplace($find,$replace,$message); 
    $message = mb_convert_encoding($message,'us-ascii','UTF-8'); 
    $message = utf8_encode($message); 

    $dontattach = array('alternative','html','plain','related'); 
    $ii = 1; 
    $j = 1; 
    $k = 1; 
    $fallback = 0; 

    if (isset($structure->parts)) 
    { 
    foreach ($structure->parts as $k1 => $d1) 
    { 
    if ($d1->subtype=='GIF') 
    { 
     if (!isset($email['attachments'])) {$email['attachments'] = array();} 
     if (isset($d1->id)) {$id = $d1->id;} else {$id = '';} 
     $a = mail_service_attachment($mbox,$i,$ii,$j,$d1->parameters[0]->value,'image/gif',$id); 
     array_push($email['attachments'],$a); 
    } 
    else if ($d1->subtype=='HTML') 
    { 
     $a = mail_service_html($mbox,$i,$d1->encoding,$d1->parameters[0]->value,$ii,$j); 
     if (isset($a['css'])) {$email['css'] = $a['css'];} 
     $email['body_xml'] = $a['xml']; 
     $fallback++; 
    } 
    else if ($d1->subtype=='JPEG') 
    { 
     if (!isset($email['attachments'])) {$email['attachments'] = array();} 
     if (isset($d1->id)) {$id = $d1->id;} else {$id = '';} 
     $a = mail_service_attachment($mbox,$i,$ii,$j,$d1->parameters[0]->value,'image/jpeg',$id); 
     array_push($email['attachments'],$a); 
    } 
    else if ($d1->subtype=='PLAIN') 
    { 
     $a = mail_service_plain($mbox,$i,$d1->encoding,$d1->parameters[0]->value,$ii,$j,$k); 
     $email['body_clean'] = $a['xml']; 
     $email['body_text'] = $a['plain']; 
     $fallback++; 
    } 
    else if ($d1->subtype=='PNG') 
    { 
     if (!isset($email['attachments'])) {$email['attachments'] = array();} 
     if (isset($d1->id)) {$id = $d1->id;} else {$id = '';} 
     $a = mail_service_attachment($mbox,$i,$ii,$j,$d1->parameters[0]->value,'image/png',$id); 
     array_push($email['attachments'],$a); 
    } 
    else if (!in_array(strtolower($d1->subtype),$dontattach)) 
    { 
     if (!isset($email['attachments'])) {$email['attachments'] = array();} 
     if (isset($d1->id)) {$id = $d1->id;} else {$id = '';} 
     $a = mail_service_attachment($mbox,$i,$ii,$j,$d1->parameters[0]->value,strtolower($d1->subtype),$id); 
     array_push($email['attachments'],$a); 
    } 

    if (isset($d1->parts)) 
    { 
     foreach ($d1->parts as $j2 => $d2) 
     { 
     if ($d2->subtype=='GIF') 
     { 
     if (!isset($email['attachments'])) {$email['attachments'] = array();} 
     if (isset($d2->id)) {$id = $d2->id;} else {$id = '';} 
     $a = mail_service_attachment($mbox,$i,$ii,$j,$d2->parameters[0]->value,'image/gif',$id); 
     array_push($email['attachments'],$a); 
     } 
     else if ($d2->subtype=='HTML') 
     { 
     $a = mail_service_html($mbox,$i,$d2->encoding,$d2->parameters[0]->value,$ii,$j); 
     if (isset($a['css'])) {$email['css'] = $a['css'];} 
     $email['body_xml'] = $a['xml']; 
     $fallback++; 
     } 
     else if ($d2->subtype=='JPEG') 
     { 
     if (!isset($email['attachments'])) {$email['attachments'] = array();} 
     if (isset($d2->id)) {$id = $d2->id;} else {$id = '';} 
     $a = mail_service_attachment($mbox,$i,$ii,$j,$d2->parameters[0]->value,'image/jpeg',$id); 
     array_push($email['attachments'],$a); 
     } 
     else if ($d2->subtype=='PLAIN') 
     { 
     $a = mail_service_plain($mbox,$i,$d2->encoding,$d2->parameters[0]->value,$ii,$j,$k); 
     $email['body_clean'] = $a['xml']; 
     $email['body_text'] = $a['plain']; 
     $fallback++; 
     } 
     else if ($d2->subtype=='PNG') 
     { 
     if (!isset($email['attachments'])) {$email['attachments'] = array();} 
     if (isset($d2->id)) {$id = $d2->id;} else {$id = '';} 
     $a = mail_service_attachment($mbox,$i,$ii,$j,$d2->parameters[0]->value,'image/png',$id); 
     array_push($email['attachments'],$a); 
     } 
     else if (!in_array(strtolower($d2->subtype),$dontattach)) 
     { 
     if (!isset($email['attachments'])) {$email['attachments'] = array();} 
     if (isset($d2->id)) {$id = $d2->id;} else {$id = '';} 
     $a = mail_service_attachment($mbox,$i,$ii,$j,$d2->parameters[0]->value,strtolower($d2->subtype),$id); 
     array_push($email['attachments'],$a); 
     } 
     $j++; 
     $k = 1; 
     } 
    } 

    $ii++; 
    $j = 1; 
    $k = 1; 
    } 
    }