2014-07-11 61 views
1

我使用php imap,遇到了麻煩。我需要獲取正文和身體HTML,但它並不像它必須是,我的代碼是:PHP IMAP解析正文文本

$this->email['bodyHTML'] = quoted_printable_decode(imap_fetchbody($imap, $i, 2.2,FT_PEEK)); 
     if(trim($this->email['bodyHTML']) == ''){ 
      $this->email['bodyHTML'] = imap_fetchbody($imap, $i, 1.2,FT_PEEK); 
     } 
     $this->email['bodyText'] = quoted_printable_decode(imap_fetchbody($imap,$i,1.1,FT_PEEK)); 
     if(trim($this->email['bodyText']) == ''){ 
      $this->email['bodyText'] = quoted_printable_decode(imap_fetchbody($imap,$i,1,FT_PEEK)); 
     } 

時做的var_dump是下面的文本輸出。但它不是電子郵件文本是什麼:

[bodyHTML] => [bodyText的] => UGVyIGNvbXBldGVuemEuIEdyYXppZQ0KDQogDQoNCkRhOiBFbWFudWVsZSBQZXJzaWNvIFttYWls dG86ZS5wZXJzaWNvQGJsdXNlcnZpY2UuaXRdIA0KSW52aWF0bzogZ2lvdmVkw6wgMTAgbHVnbGlv IDIwMTQgMTc6NDQNCkE6IENyaW5pdGkgU29uaWENCkNjOiBOYXN0YSBFbWlsaWENCk9nZ2V0dG86 IEZ3ZDogSTogUml2aXN0YSBkaSBkaXJpdHRvIHByb2Nlc3N1YWxlIC0gY29kaWNlIGNsaWVudGUg MDAwMTY1NDc3Mw0KDQogDQoNCkNpYW8gU29uaWEsDQoNCmNvbiBsYSBwcmVzZW50ZSByZXN0aXR1 aWFtbyBsYSBwcmF0aWNhIGluZXJlbnRlIGlsIGNsaWVudGUgYy8xNjU0NzczIGRpIGNvbXBldGVu emEgSXBzb2EuDQoNCkdyYXppZSBFbWFudWVsZQ0KDQoNCg0KLS0tLS0tLS0gTWVzc2FnZ2lvIG9y aWdpbmFsZSAtLS0tLS0tLSANCg0KT2dnZXR0bzogDQoNCkk6IFJpdmlzdGEgZGkgZGlyaXR0byBw cm9jZXNzdWFsZSAtIGNvZGljZSBjbGllbnRlIDAwMDE2NTQ3NzMNCg0KRGF0YTogDQoNCk1vbiwg MTYgSnVuIDIwMTQgMTE6NTQ6MDEgKzAyMDANCg0KTWl0dGVudGU6IA0KDQpDcmluaXRpIFNvbmlh IDxTb25pYS5Dcml uaXRpQHdraS5pdD4gPG1haWx0bzpTb25pYS5DcmluaXRpQHdraS5pdD4gDQoN CkE6IA0KDQo8Y2xpZW50aWdpdXJpZGljYUB3a2ltYWlsLml0PiA8bWFpbHRvOmNsaWVudGlnaXVy aWRpY2FAd2tpbWFpbC5pdD4gDQoNCg0KDQoNCg0KDQogIA0KDQogIA0KDQpEYTogTGlhIENhcm9s aW5hIEJhdGlzdGEgQ2ludHJhIFttYWlsdG86bGlhLmJhdGlzdGFAZ21haWwuY29tXSANCkludmlh dG86IG1lcmNvbGVkw6wgMTEgZ2l1Z25vIDIwMTQgMTQ6MjANCkE6IFNob3BXS0k7IEluZm8gQ29t bWVyY2lhbGkgV29sdGVyc0tsdXdlciBJdGFsaWE7IFNlcnZpemlvIENsaWVudGkgVXRldCBHaXVy aWRpY2ENCk9nZ2V0dG86IFJlOiBSaXZpc3RhIGRpIGRpcml0dG8gcHJvY2Vzc3VhbGUgLSBjb2Rp Y2UgY2xpZW50ZSAwMDAxNjU0NzczIA0KDQogIA0KDQpOb24gcmllc2NvIGEgY2FwaXJlIHBlc

回答

4

即數據是base64編碼。您需要檢查Content-Transfer-Encoding標題:如果它是quoted-printable,請將數據解碼爲quoted-printable,如上面的代碼所示,但如果它說base64,則將數據解碼爲base64。