/* Set the default charset & encoding.
* $charset - charset to use when sending messages
- * $encoding - best guessed charset offered to the user as the default value in
- * the charset dropdown list. */
-if ($prefs->isLocked('sending_charset')) {
- $charset = NLS::getEmailCharset();
-} else {
- $charset = Util::getFormData('charset');
-}
+ * $encoding - best guessed charset offered to the user as the default value
+ * in the charset dropdown list. */
+$charset = $prefs->isLocked('sending_charset') ? NLS::getEmailCharset() : Util::getFormData('charset');
$encoding = empty($charset) ? NLS::getEmailCharset() : $charset;
/* Is this a popup window? */
}
$title .= ' ' . $header['subject'];
- $encoding = empty($charset) ? $header['encoding'] : $charset;
+ $encoding = empty($charset) ? $reply_msg['encoding'] : $charset;
$reply_index = $index;
break;
$format = $fwd_msg['format'];
$rtemode = ($rtemode || (!is_null($rtemode) && ($format == 'html')));
$title = $header['title'];
- $encoding = empty($charset) ? $header['encoding'] : $charset;
+ $encoding = empty($charset) ? $reply_msg['encoding'] : $charset;
break;
case 'redirect_compose':
return $contents;
}
- $msg_text = $this->getMessageText($contents);
+ $msg_text = $this->_getMessageText($contents);
if (empty($msg_text)) {
$message = '';
$mode = 'text';
* @return array An array with the following keys:
* <pre>
* 'body' - The text of the body part
+ * 'encoding' - The guessed charset to use for the reply
* 'headers' - The headers of the message to use for the reply
* 'format' - The format of the body message
* 'identity' - The identity to use for the reply based on the original
$compose_html = $GLOBALS['prefs']->getValue('compose_html');
- $msg_text = $this->getMessageText($contents, array(
+ $msg_text = $this->_getMessageText($contents, array(
'html' => ($GLOBALS['prefs']->getValue('reply_format') || $compose_html),
'replylimit' => true,
'toflowed' => true
return array(
'body' => $msg . "\n",
+ 'encoding' => $msg_text['encoding'],
'headers' => $header,
'format' => $msg_text['mode'],
'identity' => $match_identity
* @return array An array with the following keys:
* <pre>
* 'body' - The text of the body part
+ * 'encoding' - The guessed charset to use for the reply
* 'headers' - The headers of the message to use for the reply
* 'format' - The format of the body message
* 'identity' - The identity to use for the reply based on the original
$compose_html = $GLOBALS['prefs']->getValue('compose_html');
- $msg_text = $this->getMessageText($contents, array(
+ $msg_text = $this->_getMessageText($contents, array(
'html' => ($GLOBALS['prefs']->getValue('reply_format') || $compose_html)
));
return array(
'body' => $msg,
+ 'encoding' => $msg_text['encoding'],
'format' => $format,
'headers' => $header,
'identity' => $this->_getMatchingIdentity($h)
* @return mixed Null if bodypart not found, or array with the following
* keys:
* <pre>
+ * 'encoding' - (string) The guessed encoding to use.
* 'id' - (string) The MIME ID of the bodypart.
* 'mode' - (string)
* 'text' - (string)
* </pre>
*/
- public function getMessageText($contents, $options = array())
+ protected function _getMessageText($contents, $options = array())
{
$body_id = null;
$mode = 'text';
$part = $contents->getMIMEPart($body_id);
$type = $part->getType();
- $msg = String::convertCharset($part->getContents(), $part->getCharset());
+ $part_charset = $part->getCharset();
+ $charset = NLS::getCharset();
+ $msg = String::convertCharset($part->getContents(), $part_charset);
/* Enforce reply limits. */
if (!empty($options['replylimit']) &&
if (($mode == 'html)' &&
($tidy_config = IMP::getTidyConfig($part->getBytes())))) {
$tidy_config['show-body-only'] = true;
- $tidy = tidy_parse_string(String::convertCharset($msg, NLS::getCharset(), 'UTF-8'), $tidy_config, 'UTF8');
+ $tidy = tidy_parse_string(String::convertCharset($msg, $charset, 'UTF-8'), $tidy_config, 'UTF8');
$tidy->cleanRepair();
- $msg = String::convertCharset(tidy_get_output($tidy), 'UTF-8', NLS::getCharset());
+ $msg = String::convertCharset(tidy_get_output($tidy), 'UTF-8', $charset);
}
if ($mode == 'html') {
$msg = Text_Filter::filter($msg, 'xss', array('body_only' => true, 'strip_styles' => true, 'strip_style_attributes' => false));
} elseif ($type == 'text/html') {
require_once 'Horde/Text/Filter.php';
- $msg = Text_Filter::filter($msg, 'html2text', array('charset' => NLS::getCharset()));
+ $msg = Text_Filter::filter($msg, 'html2text', array('charset' => $charset));
$type = 'text/plain';
}
}
}
+ /* Determine default encoding. */
+ $encoding = NLS::getEmailCharset();
+ if (($charset == 'UTF-8') &&
+ (strcasecmp($part_charset, 'US-ASCII') !== 0) &&
+ (strcasecmp($part_charset, $encoding) !== 0)) {
+ $encoding = 'UTF-8';
+ }
+
return array(
+ 'encoding' => $encoding,
'id' => $body_id,
'mode' => $mode,
'text' => $msg