Fix. get text part of email message with single part email.
This commit is contained in:
parent
0080578811
commit
c9ba145f1d
|
|
@ -181,7 +181,7 @@ if (sizeof($result) != 0) {
|
||||||
|
|
||||||
//get email body (if any) for cover page
|
//get email body (if any) for cover page
|
||||||
$fax_message = parse_message($connection, $email_id, FT_UID);
|
$fax_message = parse_message($connection, $email_id, FT_UID);
|
||||||
if ($fax_message == '') {
|
if ($fax_message != '') {
|
||||||
$fax_message = strip_tags($fax_message);
|
$fax_message = strip_tags($fax_message);
|
||||||
$fax_message = str_replace("\r\n\r\n","\r\n", $fax_message);
|
$fax_message = str_replace("\r\n\r\n","\r\n", $fax_message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,38 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
function parse_message($connection, $message_number, $option = '', $to_charset = 'UTF-8') {
|
function parse_message($connection, $message_number, $option = null, $to_charset = 'UTF-8') {
|
||||||
$structure = imap_fetchstructure($connection, $message_number, $option);
|
$structure = imap_fetchstructure($connection, $message_number, $option);
|
||||||
if(isset($structure->parts) && count($structure->parts)) {
|
if(isset($structure->parts)) {
|
||||||
|
return parse_message_parts($connection, $structure, false, $message_number, $option, $to_charset);
|
||||||
|
}
|
||||||
|
return parse_message_part($connection, $structure, '1', $message_number, $option, $to_charset);
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_message_parts($connection, $structure, $level, $message_number, $option, $to_charset) {
|
||||||
|
if(isset($structure->parts)) {
|
||||||
for($i = 0; $i < count($structure->parts); $i++) {
|
for($i = 0; $i < count($structure->parts); $i++) {
|
||||||
$msg = '';
|
|
||||||
$part = $structure->parts[$i];
|
$part = $structure->parts[$i];
|
||||||
|
if($part->type != TYPEMULTIPART){
|
||||||
|
$id = $i + 1;
|
||||||
|
if($level) $id = $level . '.' . $id;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$id = $level;
|
||||||
|
}
|
||||||
|
|
||||||
|
$msg = parse_message_part($connection, $part, $id, $message_number, $option, $to_charset);
|
||||||
|
if($msg){
|
||||||
|
return $msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_message_part($connection, $part, $id, $message_number, $option, $to_charset){
|
||||||
|
$msg = false;
|
||||||
|
|
||||||
if($part->type == TYPETEXT){
|
if($part->type == TYPETEXT){
|
||||||
$msg = imap_fetchbody($connection, $message_number, $i+1, $option);
|
$msg = imap_fetchbody($connection, $message_number, $id, $option);
|
||||||
if($part->encoding == ENCBASE64){
|
if($part->encoding == ENCBASE64){
|
||||||
$msg = base64_decode($msg);
|
$msg = base64_decode($msg);
|
||||||
}
|
}
|
||||||
|
|
@ -27,12 +52,13 @@ function parse_message($connection, $message_number, $option = '', $to_charset =
|
||||||
if($charset){
|
if($charset){
|
||||||
$msg = mb_convert_encoding($msg, $to_charset, $charset);
|
$msg = mb_convert_encoding($msg, $to_charset, $charset);
|
||||||
}
|
}
|
||||||
|
$msg = trim($msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(($part->type == TYPEMULTIPART) || ($part->type == TYPEMESSAGE)){
|
||||||
|
$msg = parse_message_parts($connection, $part, $id, $message_number, $option, $to_charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($msg){
|
|
||||||
return $msg;
|
return $msg;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue