summaryrefslogtreecommitdiff
path: root/program/lib
diff options
context:
space:
mode:
authorThomas Bruederli <thomas@roundcube.net>2012-11-19 11:02:13 +0100
committerThomas Bruederli <thomas@roundcube.net>2012-11-19 11:02:13 +0100
commitc72a96144de1e5674159f4010ec0e44c9d946a5b (patch)
tree8385fbd77ce12e30613bec7ecf2ccaeb8fb5520f /program/lib
parent6fa61759e2369f4702ecebe584c133f9d79e0d93 (diff)
Improve line wrapping behavior where message charset is changed by plugins (including html2plaintext conversion)
Diffstat (limited to 'program/lib')
-rw-r--r--program/lib/html2text.php17
1 files changed, 13 insertions, 4 deletions
diff --git a/program/lib/html2text.php b/program/lib/html2text.php
index dd413e0d6..34c719302 100644
--- a/program/lib/html2text.php
+++ b/program/lib/html2text.php
@@ -135,6 +135,14 @@ class html2text
var $width = 70;
/**
+ * Target character encoding for output text
+ *
+ * @var string $charset
+ * @access public
+ */
+ var $charset = 'UTF-8';
+
+ /**
* List of preg* regular expression patterns to search for,
* used in conjunction with $replace.
*
@@ -347,7 +355,7 @@ class html2text
* @access public
* @return void
*/
- function html2text( $source = '', $from_file = false, $do_links = true, $width = 75 )
+ function html2text( $source = '', $from_file = false, $do_links = true, $width = 75, $charset = 'UTF-8' )
{
if ( !empty($source) ) {
$this->set_html($source, $from_file);
@@ -356,6 +364,7 @@ class html2text
$this->set_base_url();
$this->_do_links = $do_links;
$this->width = $width;
+ $this->charset = $charset;
}
/**
@@ -517,7 +526,7 @@ class html2text
$text = preg_replace($this->ent_search, $this->ent_replace, $text);
// Replace known html entities
- $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
+ $text = html_entity_decode($text, ENT_QUOTES, $this->charset);
// Remove unknown/unhandled entities (this cannot be done in search-and-replace block)
$text = preg_replace('/&([a-zA-Z0-9]{2,6}|#[0-9]{2,4});/', '', $text);
@@ -732,14 +741,14 @@ class html2text
*/
private function _strtoupper($str)
{
- $str = html_entity_decode($str, ENT_COMPAT, RCMAIL_CHARSET);
+ $str = html_entity_decode($str, ENT_COMPAT, $this->charset);
if (function_exists('mb_strtoupper'))
$str = mb_strtoupper($str);
else
$str = strtoupper($str);
- $str = htmlspecialchars($str, ENT_COMPAT, RCMAIL_CHARSET);
+ $str = htmlspecialchars($str, ENT_COMPAT, $this->charset);
return $str;
}