mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-26 01:43:47 +01:00
fix problem with possible json_encode problem (removing all initial data from mailbody) on reply/forward
This commit is contained in:
parent
35ef38e040
commit
397d5a6d36
@ -1118,28 +1118,7 @@ class mail_compose
|
|||||||
|
|
||||||
// prepare body
|
// prepare body
|
||||||
// in a way, this tests if we are having real utf-8 (the displayCharset) by now; we should if charsets reported (or detected) are correct
|
// in a way, this tests if we are having real utf-8 (the displayCharset) by now; we should if charsets reported (or detected) are correct
|
||||||
if (strtoupper($this->displayCharset) == 'UTF-8')
|
$content['body'] = translation::convert_jsonsafe($content['body'],'utf-8');
|
||||||
{
|
|
||||||
$test = @json_encode($content['body']);
|
|
||||||
//error_log(__METHOD__.__LINE__.' ->'.strlen($singleBodyPart['body']).' Error:'.json_last_error().'<- BodyPart:#'.$test.'#');
|
|
||||||
//if (json_last_error() != JSON_ERROR_NONE && strlen($singleBodyPart['body'])>0)
|
|
||||||
if ($test=="null" && strlen($content['body'])>0)
|
|
||||||
{
|
|
||||||
// try to fix broken utf8
|
|
||||||
$x = (function_exists('mb_convert_encoding')?mb_convert_encoding($content['body'],'UTF-8','UTF-8'):(function_exists('iconv')?@iconv("UTF-8","UTF-8//IGNORE",$content['body']):$content['body']));
|
|
||||||
$test = @json_encode($x);
|
|
||||||
if ($test=="null" && strlen($content['body'])>0)
|
|
||||||
{
|
|
||||||
// this should not be needed, unless something fails with charset detection/ wrong charset passed
|
|
||||||
error_log(__METHOD__.__LINE__.' Charset problem detected; Charset Detected:'.mail_bo::detect_encoding($content['body']));
|
|
||||||
$content['body'] = utf8_encode($content['body']);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$content['body'] = $x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//error_log(__METHOD__.__LINE__.array2string($content));
|
//error_log(__METHOD__.__LINE__.array2string($content));
|
||||||
|
|
||||||
// get identities of all accounts as "$acc_id:$ident_id" => $identity
|
// get identities of all accounts as "$acc_id:$ident_id" => $identity
|
||||||
@ -1630,7 +1609,7 @@ class mail_compose
|
|||||||
$bodyParts[$i]['body'] = "<pre>".$bodyParts[$i]['body']."</pre>";
|
$bodyParts[$i]['body'] = "<pre>".$bodyParts[$i]['body']."</pre>";
|
||||||
}
|
}
|
||||||
if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = mail_bo::detect_encoding($bodyParts[$i]['body']);
|
if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = mail_bo::detect_encoding($bodyParts[$i]['body']);
|
||||||
$bodyParts[$i]['body'] = translation::convert($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
|
$bodyParts[$i]['body'] = translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
|
||||||
#error_log( "GetDraftData (HTML) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
|
#error_log( "GetDraftData (HTML) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
|
||||||
$this->sessionData['body'] .= ($i>0?"<br>":""). $bodyParts[$i]['body'] ;
|
$this->sessionData['body'] .= ($i>0?"<br>":""). $bodyParts[$i]['body'] ;
|
||||||
}
|
}
|
||||||
@ -1644,7 +1623,7 @@ class mail_compose
|
|||||||
$this->sessionData['body'] .= "<hr>";
|
$this->sessionData['body'] .= "<hr>";
|
||||||
}
|
}
|
||||||
if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = mail_bo::detect_encoding($bodyParts[$i]['body']);
|
if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = mail_bo::detect_encoding($bodyParts[$i]['body']);
|
||||||
$bodyParts[$i]['body'] = translation::convert($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
|
$bodyParts[$i]['body'] = translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
|
||||||
#error_log( "GetDraftData (Plain) CharSet".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
|
#error_log( "GetDraftData (Plain) CharSet".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
|
||||||
$this->sessionData['body'] .= ($i>0?"\r\n":""). $bodyParts[$i]['body'] ;
|
$this->sessionData['body'] .= ($i>0?"\r\n":""). $bodyParts[$i]['body'] ;
|
||||||
}
|
}
|
||||||
@ -2094,7 +2073,7 @@ class mail_compose
|
|||||||
$_htmlConfig = mail_bo::$htmLawed_config;
|
$_htmlConfig = mail_bo::$htmLawed_config;
|
||||||
mail_bo::$htmLawed_config['comment'] = 2;
|
mail_bo::$htmLawed_config['comment'] = 2;
|
||||||
mail_bo::$htmLawed_config['transform_anchor'] = false;
|
mail_bo::$htmLawed_config['transform_anchor'] = false;
|
||||||
$this->sessionData['body'] .= "<br>".self::_getCleanHTML(translation::convert($bodyParts[$i]['body'], $bodyParts[$i]['charSet']));
|
$this->sessionData['body'] .= "<br>".self::_getCleanHTML(translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']));
|
||||||
mail_bo::$htmLawed_config = $_htmlConfig;
|
mail_bo::$htmLawed_config = $_htmlConfig;
|
||||||
#error_log( "GetReplyData (HTML) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
|
#error_log( "GetReplyData (HTML) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
|
||||||
}
|
}
|
||||||
@ -2117,8 +2096,7 @@ class mail_compose
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add line breaks to $bodyParts
|
// add line breaks to $bodyParts
|
||||||
if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = mail_bo::detect_encoding($bodyParts[$i]['body']);
|
$newBody = translation::convert_jsonsafe($bodyParts[$i]['body'],$bodyParts[$i]['charSet']);
|
||||||
$newBody = translation::convert($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
|
|
||||||
#error_log( "GetReplyData (Plain) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
|
#error_log( "GetReplyData (Plain) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
|
||||||
$newBody = mail_ui::resolve_inline_images($newBody, $_folder, $_uid, $_partID, 'plain');
|
$newBody = mail_ui::resolve_inline_images($newBody, $_folder, $_uid, $_partID, 'plain');
|
||||||
$this->sessionData['body'] .= "\r\n";
|
$this->sessionData['body'] .= "\r\n";
|
||||||
|
@ -1961,23 +1961,7 @@ class mail_ui
|
|||||||
foreach ($attachments as $key => $value)
|
foreach ($attachments as $key => $value)
|
||||||
{
|
{
|
||||||
$attachmentHTML[$key]['filename']= ($value['name'] ? ( $value['filename'] ? $value['filename'] : $value['name'] ) : lang('(no subject)'));
|
$attachmentHTML[$key]['filename']= ($value['name'] ? ( $value['filename'] ? $value['filename'] : $value['name'] ) : lang('(no subject)'));
|
||||||
$test = @json_encode($attachmentHTML[$key]['filename']);
|
$attachmentHTML[$key]['filename'] = translation::convert_jsonsafe($attachmentHTML[$key]['filename'],'utf-8');
|
||||||
//error_log(__METHOD__.__LINE__.' ->'.strlen($singleBodyPart['body']).' Error:'.json_last_error().'<- BodyPart:#'.$test.'#');
|
|
||||||
if (($test=="null" || $test === false || is_null($test)) && strlen($attachmentHTML[$key]['filename'])>0)
|
|
||||||
{
|
|
||||||
// try to fix broken utf8
|
|
||||||
$x = utf8_encode($attachmentHTML[$key]['filename']);
|
|
||||||
$test = @json_encode($x);
|
|
||||||
if (($test=="null" || $test === false || is_null($test)) && strlen($attachmentHTML[$key]['filename'])>0)
|
|
||||||
{
|
|
||||||
// this should not be needed, unless something fails with charset detection/ wrong charset passed
|
|
||||||
$attachmentHTML[$key]['filename'] = (function_exists('mb_convert_encoding')?mb_convert_encoding($attachmentHTML[$key]['filename'],'UTF-8','UTF-8'):(function_exists('iconv')?@iconv("UTF-8","UTF-8//IGNORE",$attachmentHTML[$key]['filename']):$attachmentHTML[$key]['filename']));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$attachmentHTML[$key]['filename'] = $x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//error_log(array2string($value));
|
//error_log(array2string($value));
|
||||||
//error_log(strtoupper($value['mimeType']) .'<->'. mime_magic::filename2mime($attachmentHTML[$key]['filename']));
|
//error_log(strtoupper($value['mimeType']) .'<->'. mime_magic::filename2mime($attachmentHTML[$key]['filename']));
|
||||||
if (strtoupper($value['mimeType']=='APPLICATION/OCTET-STREAM')) $value['mimeType'] = mime_magic::filename2mime($attachmentHTML[$key]['filename']);
|
if (strtoupper($value['mimeType']=='APPLICATION/OCTET-STREAM')) $value['mimeType'] = mime_magic::filename2mime($attachmentHTML[$key]['filename']);
|
||||||
@ -2749,33 +2733,7 @@ class mail_ui
|
|||||||
{
|
{
|
||||||
$singleBodyPart['body'] = preg_replace($sar,$rar,$singleBodyPart['body']);
|
$singleBodyPart['body'] = preg_replace($sar,$rar,$singleBodyPart['body']);
|
||||||
}
|
}
|
||||||
if ($singleBodyPart['charSet']===false) $singleBodyPart['charSet'] = translation::detect_encoding($singleBodyPart['body']);
|
$singleBodyPart['body'] = translation::convert_jsonsafe($singleBodyPart['body'],$singleBodyPart['charSet']);
|
||||||
$singleBodyPart['body'] = $GLOBALS['egw']->translation->convert(
|
|
||||||
$singleBodyPart['body'],
|
|
||||||
strtolower($singleBodyPart['charSet'])
|
|
||||||
);
|
|
||||||
// in a way, this tests if we are having real utf-8 (the displayCharset) by now; we should if charsets reported (or detected) are correct
|
|
||||||
if (strtoupper(mail_bo::$displayCharset) == 'UTF-8')
|
|
||||||
{
|
|
||||||
$test = @json_encode($singleBodyPart['body']);
|
|
||||||
//error_log(__METHOD__.__LINE__.' ->'.strlen($singleBodyPart['body']).' Error:'.json_last_error().'<- BodyPart:#'.$test.'#');
|
|
||||||
if (($test=="null" || $test === false || is_null($test)) && strlen($singleBodyPart['body'])>0)
|
|
||||||
{
|
|
||||||
// try to fix broken utf8
|
|
||||||
$x = (function_exists('mb_convert_encoding')?mb_convert_encoding($singleBodyPart['body'],'UTF-8','UTF-8'):(function_exists('iconv')?@iconv("UTF-8","UTF-8//IGNORE",$singleBodyPart['body']):$singleBodyPart['body']));
|
|
||||||
$test = @json_encode($x);
|
|
||||||
if (($test=="null" || $test === false || is_null($test)) && strlen($singleBodyPart['body'])>0)
|
|
||||||
{
|
|
||||||
// this should not be needed, unless something fails with charset detection/ wrong charset passed
|
|
||||||
error_log(__METHOD__.__LINE__.' Charset Reported:'.$singleBodyPart['charSet'].' Charset Detected:'.translation::detect_encoding($singleBodyPart['body']));
|
|
||||||
$singleBodyPart['body'] = utf8_encode($singleBodyPart['body']);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$singleBodyPart['body'] = $x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//error_log(__METHOD__.__LINE__.array2string($singleBodyPart));
|
//error_log(__METHOD__.__LINE__.array2string($singleBodyPart));
|
||||||
if($singleBodyPart['mimeType'] == 'text/plain')
|
if($singleBodyPart['mimeType'] == 'text/plain')
|
||||||
{
|
{
|
||||||
|
@ -921,6 +921,42 @@ class translation
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* converts a string $data from charset $from to something that is json_encode tested
|
||||||
|
*
|
||||||
|
* @param string/array $data string(s) to convert
|
||||||
|
* @param string/boolean $from charset $data is in or False if it should be detected
|
||||||
|
* @return string/array converted string(s) from $data
|
||||||
|
*/
|
||||||
|
static function convert_jsonsafe($data,$from=False)
|
||||||
|
{
|
||||||
|
if ($from===false) $from = self::detect_encoding($data);
|
||||||
|
$data = self::convert($data,strtolower($from));
|
||||||
|
// in a way, this tests if we are having real utf-8 (the displayCharset) by now; we should if charsets reported (or detected) are correct
|
||||||
|
if (strtoupper(self::charset()) == 'UTF-8')
|
||||||
|
{
|
||||||
|
$test = @json_encode($data);
|
||||||
|
//error_log(__METHOD__.__LINE__.' ->'.strlen($data).' Error:'.json_last_error().'<- data:#'.$test.'#');
|
||||||
|
if (($test=="null" || $test === false || is_null($test)) && strlen($data)>0)
|
||||||
|
{
|
||||||
|
// try to fix broken utf8
|
||||||
|
$x = (function_exists('mb_convert_encoding')?mb_convert_encoding($data,'UTF-8','UTF-8'):(function_exists('iconv')?@iconv("UTF-8","UTF-8//IGNORE",$data):$data));
|
||||||
|
$test = @json_encode($x);
|
||||||
|
if (($test=="null" || $test === false || is_null($test)) && strlen($data)>0)
|
||||||
|
{
|
||||||
|
// this should not be needed, unless something fails with charset detection/ wrong charset passed
|
||||||
|
error_log(__METHOD__.__LINE__.' Charset Reported:'.$from.' Charset Detected:'.translation::detect_encoding($data));
|
||||||
|
$data = utf8_encode($data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$data = $x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* insert/update/delete one phrase in the lang-table
|
* insert/update/delete one phrase in the lang-table
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user