From 9e8a1756b7032fba21fec82efda57cf896a2735a Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Mon, 08 Dec 2008 14:42:31 -0500
Subject: [PATCH] #1485616: read content-id/content-location only for multipart/related type

---
 program/lib/html2text.php |   30 ++++++++++++++++++++++++------
 1 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/program/lib/html2text.php b/program/lib/html2text.php
index ee7b0dc..938dfec 100644
--- a/program/lib/html2text.php
+++ b/program/lib/html2text.php
@@ -232,7 +232,7 @@
         '--',
         '-',
         '*',
-        '�',
+        '£',
         'EUR',                                  // Euro sign. � ?
         '',                                     // Unknown/unhandled entities
         ' '                                     // Runs of spaces, post-handling
@@ -314,6 +314,15 @@
      */
     var $_link_count = 0;
 
+    /** 
+     * Boolean flag, true if a table of link URLs should be listed after the text. 
+     *  
+     * @var boolean $_do_links 
+     * @access private 
+     * @see html2text() 
+     */
+    var $_do_links = true;
+ 
     /**
      *  Constructor.
      *
@@ -323,15 +332,20 @@
      *
      *  @param string $source HTML content
      *  @param boolean $from_file Indicates $source is a file to pull content from
+     *  @param boolean $do_links Indicate whether a table of link URLs is desired
+     *  @param integer $width Maximum width of the formatted text, 0 for no limit
      *  @access public
      *  @return void
      */
-    function html2text( $source = '', $from_file = false )
+    function html2text( $source = '', $from_file = false, $do_links = true, $width = 75 )
     {
         if ( !empty($source) ) {
             $this->set_html($source, $from_file);
         }
+	
         $this->set_base_url();
+	$this->_do_links = $do_links;
+	$this->width = $width;
     }
 
     /**
@@ -349,7 +363,6 @@
         }
         else
 	    $this->html = $source;
-
 
         $this->_converted = false;
     }
@@ -452,7 +465,10 @@
 
 	// Convert <PRE>
         $this->_convert_pre($text);
-	
+
+	// Replace known html entities
+	$text = html_entity_decode($text, ENT_COMPAT, 'UTF-8');
+
         // Run our defined search-and-replace
         $text = preg_replace($this->search, $this->replace, $text);
 
@@ -495,7 +511,9 @@
      */
     function _build_link_list( $link, $display )
     {
-		if ( substr($link, 0, 7) == 'http://' || substr($link, 0, 8) == 'https://' ||
+	if ( !$this->_do_links ) return $display;
+	
+	if ( substr($link, 0, 7) == 'http://' || substr($link, 0, 8) == 'https://' ||
              substr($link, 0, 7) == 'mailto:' ) {
             $this->_link_count++;
             $this->_link_list .= "[" . $this->_link_count . "] $link\n";
@@ -528,7 +546,7 @@
 	while(preg_match('/<pre[^>]*>(.*)<\/pre>/ismU', $text, $matches))
 	{
 	    $result = preg_replace($this->pre_search, $this->pre_replace, $matches[1]);
-	    $text = preg_replace('/<pre[^>]*>.*<\/pre>/ismU', '<div><br>' . $result . '<br></div>', $text);
+	    $text = preg_replace('/<pre[^>]*>.*<\/pre>/ismU', '<div><br>' . $result . '<br></div>', $text, 1);
 	}
     }
 }

--
Gitblit v1.9.1