Fixes; remove dependency on HTTP_Request
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 3 Dec 2008 11:58:10 +0000 (04:58 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 3 Dec 2008 18:27:09 +0000 (11:27 -0700)
Fixes to reply/forward/attachment handling.
Use Horde_Http_Client instead of HTTP_Request.

imp/docs/CHANGES
imp/docs/INSTALL
imp/lib/Compose.php
imp/lib/Views/Compose.php
imp/test.php

index 92cf6c4..a945122 100644 (file)
@@ -2,7 +2,9 @@
 v5.0-cvs
 --------
 
-[mms] MIMP has been absorbed into IMP.
+[mms] No longer need HTTP_Request - use Horde_Http_Client instead.
+[mms] Use Horde_Imap_Client as the IMAP library in IMP.
+[mms] DIMP and MIMP have been moved into IMP.
 [mms] Allow all parts in a message to be displayed (Bug #1866).
 [mms] Only support FCKeditor as GUI HTML editor.
 [mms] Strip extra 'Fwd' and 'Re' cruft from subject line when replying to or
index fa6a9ac..9cacb5e 100644 (file)
@@ -181,15 +181,6 @@ To function properly, IMP **requires** the following:
       Auth_SASL is required if your IMAP server uses CRAM-MD5 or DIGEST-MD5
       authentication.
 
-   b. HTTP_Request [OPTIONAL]
-
-      HTTP_Request is used in the HTML composition mode to download remote
-      images contained in the message and store them in the body of the
-      outgoing messages.  Without HTTP_Request, the message will be sent
-      with the images linked to the remote images, with no guarantee that
-      the remote images will still be accessible when the recipient of the
-      message views that message.
-
 4. The following PECL modules:
    (See `horde/docs/INSTALL`_ for instructions on installing PECL modules)
 
index a779aec..f5088f4 100644 (file)
@@ -1188,8 +1188,7 @@ class IMP_Compose
                 $reply = Horde_Mime_Address::addrArray2String($from_arr);
             }
 
-            $header['to'] = Horde_Mime_Address::addrArray2String(array_merge($to_arr, $from_arr));
-            $me[] = Horde_Mime_Address::bareAddress($header['to'], $_SESSION['imp']['maildomain']);
+            $header['to'] = Horde_Mime_Address::addrArray2String(array_merge($to_arr, $from_arr), $me);
 
             /* Build the Cc: header. */
             $cc_arr = $h->getOb('to');
@@ -1209,7 +1208,7 @@ class IMP_Compose
         }
 
         if (in_array($actionID, array('reply_list', '*'))) {
-            $imp_ui = new IMP_UI_Compose();
+            $imp_ui = new IMP_UI_Message();
             $list_info = $imp_ui->getListInformation($h);
             if ($list_info['exists']) {
                 $header['to'] = $list_info['reply_list'];
@@ -1400,13 +1399,9 @@ class IMP_Compose
                 $part = new Horde_Mime_Part();
                 $part->setCharset(NLS::getCharset());
                 $part->setType('message/rfc822');
-                if (!($name = $headerob->getValue('subject'))) {
-                    $name = _("[No Subject]");
-                } else {
-                    // Strip periods from name - see Ticket #4977
-                    $part->setName(_("Forwarded Message:") . ' ' . rtrim($name, '.'));
-                }
-                $part->setContents(preg_replace("/\r\n?/", "\n", $contents->fullMessageText()));
+                $part->setName(_("Forwarded Message"));
+                $part->setContents($contents->fullMessageText());
+
                 $result = $this->addMIMEPartAttachment($part);
                 if (is_a($result, 'PEAR_Error')) {
                     $GLOBALS['notification']->push($result);
@@ -1415,10 +1410,16 @@ class IMP_Compose
             }
         }
 
-        return ($attached == 1)
-            // $name is set inside the loop above.
-            ? 'Fwd: ' . Horde_Imap_Client::getBaseSubject($name, array('keepblob' => true))
-            : 'Fwd: ' . sprintf(_("%u Forwarded Messages"), $attached);
+        if ($attached == 1) {
+            if (!($name = $headerob->getValue('subject'))) {
+                $name = _("[No Subject]");
+            } elseif (String::length($name) > 80) {
+                $name = String::substr($name, 0, 80) . '...';
+            }
+            return 'Fwd: ' . Horde_Imap_Client::getBaseSubject($name, array('keepblob' => true));
+        } else {
+            return 'Fwd: ' . sprintf(_("%u Forwarded Messages"), $attached);
+        }
     }
 
     /**
@@ -1496,7 +1497,6 @@ class IMP_Compose
 
         /* Store the data in a Horde_Mime_Part. Some browsers do not send the
          * MIME type so try an educated guess. */
-        $part = new Horde_Mime_Part();
         if (!empty($_FILES[$name]['type']) &&
             ($_FILES[$name]['type'] != 'application/octet-stream')) {
             $type = $_FILES[$name]['type'];
@@ -1510,6 +1510,7 @@ class IMP_Compose
                 $type = Horde_Mime_Magic::filenameToMIME($filename, false);
             }
         }
+        $part = new Horde_Mime_Part();
         $part->setType($type);
         $part->setCharset(NLS::getCharset());
         $part->setName($filename);
@@ -1965,42 +1966,37 @@ class IMP_Compose
     {
         global $conf;
 
-        /* Return immediately if HTTP_Request is not available, if this is
-         * not a HTML part, or no 'img' tags are found (specifically searching
-         * for the 'src' parameter). */
-        if (!(include_once 'HTTP/Request.php') ||
-            ($mime_part->getType() != 'text/html') ||
+        /* Return immediately if this is not a HTML part, or no 'img' tags are
+         * found (specifically searching for the 'src' parameter). */
+        if (($mime_part->getType() != 'text/html') ||
             !preg_match_all('/<img[^>]+src\s*\=\s*([^\s]+)\s+/iU', $mime_part->getContents(), $results)) {
             return $mime_part;
         }
 
-        $img_data = $img_parts = array();
+        $client_opts = $img_data = $img_parts = array();
 
         /* Go through list of results, download the image, and create
          * Horde_Mime_Part objects with the data. */
-        $img_request_options = array('timeout' => 5);
-        if (isset($conf['http']['proxy']) &&
-            !empty($conf['http']['proxy']['proxy_host'])) {
-            $img_request_options = array_merge($img_request_options, $conf['http']['proxy']);
+        if (!empty($conf['http']['proxy']['proxy_host'])) {
+            $client_opts['proxyServer'] = $conf['http']['proxy']['proxy_host'] . ':' . $conf['http']['proxy']['proxy_port'];
+            if (!empty($conf['http']['proxy']['proxy_user'])) {
+                $client_opts['proxyUser'] = $conf['http']['proxy']['proxy_user'];
+                $client_opts['proxyPass'] = empty($conf['http']['proxy']['proxy_pass']) ? $conf['http']['proxy']['proxy_pass'] : '';
+            }
         }
+        $client = new Horde_Http_Client($client_opts);
 
         foreach ($results[1] as $url) {
-            /* Strip any quotation marks and convert '&amp;' to '&' (since
-             * HTTP_Request doesn't handle the former correctly). */
-            $img_url = str_replace('&amp;', '&', trim($url, '"\''));
-
             /* Attempt to download the image data. */
-            $request = new HTTP_Request($img_url, $img_request_options);
-            $request->sendRequest();
-
-            if ($request->getResponseCode() == '200') {
+            $response = $client->get(str_replace('&amp;', '&', trim($url, '"\'')));
+            if ($response->code == 200) {
                 /* We need to determine the image type.  Try getting
                  * that information from the returned HTTP
                  * content-type header.  TODO: Use Horde_Mime_Magic if this
                  * fails (?) */
                 $part = new Horde_Mime_Part();
-                $part->setType($request->getResponseHeader('content-type'));
-                $part->setContents($request->getResponseBody(), '8bit');
+                $part->setType($response->getHeader('content-type'));
+                $part->setContents($response->getBody(), '8bit');
                 $part->setDisposition('attachment');
                 $img_data[$url] = '"cid:' . $part->setContentID() . '"';
                 $img_parts[] = $part;
@@ -2014,9 +2010,7 @@ class IMP_Compose
         }
 
         /* Replace the URLs with with CID tags. */
-        $text = $mime_part->getContents();
-        $text = str_replace(array_keys($img_data), array_values($img_data), $text);
-        $mime_part->setContents($text);
+        $mime_part->setContents(str_replace(array_keys($img_data), array_values($img_data), $mime_part->getContents()));
 
         /* Create new multipart/related part. */
         $related = new Horde_Mime_Part();
index 8ba3e01..f681ef2 100644 (file)
@@ -74,7 +74,8 @@ class IMP_Views_Compose
             $composeCache = $args['composeCache'];
 
             if ($imp_compose->numberOfAttachments()) {
-                foreach ($imp_compose->getAttachments() as $num => $mime) {
+                foreach ($imp_compose->getAttachments() as $num => $atc) {
+                    $mime = $atc['part'];
                     $result['js_onload'][] = 'DimpCompose.addAttach(' . $num . ', \'' . addslashes($mime->getName(true)) . '\', \'' . addslashes($mime->getType()) . '\', \'' . addslashes($mime->getSize()) . "')";
                 }
             }
index 8eaf158..03d3c5f 100644 (file)
@@ -195,10 +195,6 @@ $pear_list = array(
     'Auth_SASL' => array(
         'path' => 'Auth/SASL.php',
         'error' => 'If your IMAP server uses CRAM-MD5 or DIGEST-MD5 authentication, this module is required.'
-    ),
-    'HTTP_Request' => array(
-        'path' => 'HTTP/Request.php',
-        'error' => 'The HTML composition mode requires HTTP_Request.'
     )
 );