2013-02-17 3 views
0

몇 시간 동안 붙어 있습니다. 하지만 기본적으로 내가 가지고 나가기를 원하는 일부 콘텐츠와 첨부 된 PDF가있는 전자 메일을받는받은 편지함이 있습니다. 내가 원하는 모든 HTML을 가져 오는 방법을 알아 냈지만 첨부 된 PDF는 어떻게 저장합니까? 전자 메일에서 첨부 된 PDF를 얻고 저장하려면 어떻게해야합니까?

는 지금까지이 대구이다 I가 print_r의 경우 I 메시지 구조를 가질

$strUser  = "email"; 
    $strPassword = "passwrd"; 
    $delete_emails=false; 

    // open 
    $hMail = imap_open ("{webmail.somethingsomething.com:143/notls}INBOX", "$strUser", "$strPassword") or die("can't connect: " . imap_last_error()); 
    // get headers 
    $aHeaders = imap_headers($hMail); 
    // get message count 
    $objMail = imap_mailboxmsginfo($hMail); 
    if($objMail != NULL) 
    {   
     // process messages 
     for($idxMsg = 1; $idxMsg <= $objMail->Nmsgs; $idxMsg++ ) 
     { 
      // get header info 
      $objHeader = imap_headerinfo($hMail, $idxMsg); 

      // get from object array 
      $aFrom = $objHeader->from; 

      // process headers 
      for($idx = 0; $idx < count($aFrom); $idx++) 
      { 
       // get object 
       $objData = $aFrom[ $idx ]; 
       // get email from 
       $strEmailFrom = $objData->mailbox . "@" . $objData->host; 
       //Get the subject 
       $message_subject = $objHeader->subject; 
       //Get the body of the message 
       $fullBody = imap_fetchbody($hMail,$idxMsg, 2);//displays full body including junk 
       $bodyMessage = quoted_printable_decode($fullBody); 
       //Get the msg structure 
       $message_structure = imap_fetchstructure($hMail, $idx); 
       //WHAT DO I DO HERE???? 
      } 

      // delete message 
      if($delete_emails == true){ 
       imap_delete($hMail, $idxMsg); 
      } 

     } 

     // expunge deleted messages 
     if($delete_emails == true){ 
      imap_expunge($hMail); 
     } 


     //Clears the cache 
     imap_gc($hMail, IMAP_GC_ELT); 

    } 
    // close 
    imap_close($hMail); 



} 

을 확인

공용 기능 read_emails() { // 사용자 설정 및 내가 수 부품 중 하나에 첨부 파일이 있다는 것을 확인하면 PDF라는 것을 알 수 있습니다. 다음에 무엇이 올지 확신 할 수 없습니다. 나는 노력했지만 좋은 해결책을 찾을 수없는 것 같습니다.

감사합니다.

편집 : 여기 imap_fetchstructure

stdClass 개체 ([형태] => 1 인코딩] => 0 [ifsubtype] => 1 아형] => MIXED [ifdescription] => 0 [의 함유량은 ([0] => stdClass 객체 ([attribute] => 경계 [value] => f46d044473ef81609f04d5f1997c)> 0 [ifdisposition] => 0 [ifdparameters]) [부품] => 배열 ([0] => 표준 클래스 => 1 [인코딩] => 0 [ifsubtype] => 1 [하위 유형] => 대체 [ifdescription] => 0 [ifid] => 0 [ifdisposition] => 0 [ifparameters] => 0 [ifparameters] => 1 매개 변수 => 배열 ([0] => stdClass 객체 ([attribute] => 경계 [value] => f46d044473ef81609b04d5f1997a)) [부품] => 배열 ([0] => stdClass 객체 ([type] => 0 [encoding] => 0 [ifsubtype] => 1 [subtype] => PLAIN [ifdescription] => 0 [ifid] => 0 [lines] => 1 [bytes] => 37 [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] 매개 변수] => 배열 ([0] => stdClass 객체 ([attribute] => charset [value] => ISO-8859-1))) [1] => stdClass 객체 ([type] => 0 [encoding] ifconfiguration] => 0 [ifid] => 0 [lines] => 1 [bytes] => 37 [ifdisposition] => 0 [ifdparameters] => 0 [ifsubtype] stdClass 객체 ([attribute] => charset [value] => ISO-8859-1))))))) [1] => stdClass 객체 0 [바이트] => 179876 [ifdisposition] => 1 [ifdescription] => 0 [ifidcription] => => 1 [dparameters] => 배열 ([0] => stdClass 객체 ([attribute] => 파일명 [value] => Statement of Account.pdf)) [ifparameters] => 1 [매개 변수] => 배열 ([0] => stdClass 객체 ([attribute] => name [value] => 계정 명세서). 이 배열을 통해 루프를 할 수 있었던 부분의 ->type->subtype는 PDF 문서에 해당하는 경우 중지 있도록 PDF)))))

답변

0

doc에 따르면, 당신은 $message_structure->parts에 신체 부위의 배열을 가지고있다. 예 :

foreach ($message_structure->parts as $idx => $part) { 
    if (TYPEAPPLICATION === $part->type && 'pdf' === strtolower($part->subtype)) { 
     $data = imap_fetchbody($hMail, $idxMsg, $idx); 
     // Then you should check the $part->encoding 
     // to decode data appropriately, e.g.: 
     if (ENCBASE64 === $part->encoding) { 
      $data = base64_decode($data); 
     } 
    } 
} 
+0

당신은 PDF 또는 뭔가를 다운로드하여 저장하지 않아도됩니까? 어떻게해야합니까? – Bill

+0

데이터를 가져 와서 어떻게 든 인코딩해야한다고 생각합니까? – Bill

+0

예, 업데이트 된 답변보기 – lazyhammer

관련 문제