From cb7d32ebdd1c783f201e2f3fa6c52f1fafdc6fcf Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Fri, 22 Oct 2010 11:24:39 -0400
Subject: [PATCH] List groups in address detail view and allow to subscribe/unsubscribe from there (#1486753)

---
 program/lib/Mail/mime.php |   82 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 77 insertions(+), 5 deletions(-)

diff --git a/program/lib/Mail/mime.php b/program/lib/Mail/mime.php
index c08c7cf..481764a 100644
--- a/program/lib/Mail/mime.php
+++ b/program/lib/Mail/mime.php
@@ -842,14 +842,16 @@
 
         if (isset($this->_headers['From'])) {
             // Bug #11381: Illegal characters in domain ID
-            if (preg_match("|(@[0-9a-zA-Z\-\.]+)|", $this->_headers['From'], $matches)) {
+            if (preg_match('#(@[0-9a-zA-Z\-\.]+)#', $this->_headers['From'], $matches)) {
                 $domainID = $matches[1];
             } else {
-                $domainID = "@localhost";
+                $domainID = '@localhost';
             }
             foreach ($this->_html_images as $i => $img) {
-                $this->_html_images[$i]['cid']
-                    = $this->_html_images[$i]['cid'] . $domainID;
+                $cid = $this->_html_images[$i]['cid']; 
+                if (!preg_match('#'.preg_quote($domainID).'$#', $cid)) {
+                    $this->_html_images[$i]['cid'] = $cid . $domainID;
+                }
             }
         }
 
@@ -993,7 +995,7 @@
             $ret = null;
             return $ret;
         }
-        
+
         // Use saved boundary
         if (!empty($this->_build_params['boundary'])) {
             $boundary = $this->_build_params['boundary'];
@@ -1028,6 +1030,7 @@
      * $array['header-name'] = 'header-value';
      *
      * @param array $xtra_headers Assoc array with any extra headers (optional)
+     *                            (Don't set Content-Type for multipart messages here!)
      * @param bool  $overwrite    Overwrite already existing headers.
      * @param bool  $skip_content Don't return content headers: Content-Type,
      *                            Content-Disposition and Content-Transfer-Encoding
@@ -1064,6 +1067,8 @@
             unset($headers['Content-Type']);
             unset($headers['Content-Transfer-Encoding']);
             unset($headers['Content-Disposition']);
+        } else if (!empty($this->_build_params['ctype'])) {
+            $headers['Content-Type'] = $this->_build_params['ctype'];
         }
 
         $encodedHeaders = $this->_encodeHeaders($headers);
@@ -1075,6 +1080,7 @@
      * (usefull if you want to use the PHP mail() function)
      *
      * @param array $xtra_headers Assoc array with any extra headers (optional)
+     *                            (Don't set Content-Type for multipart messages here!)
      * @param bool  $overwrite    Overwrite the existing headers with new.
      * @param bool  $skip_content Don't return content headers: Content-Type,
      *                            Content-Disposition and Content-Transfer-Encoding
@@ -1111,6 +1117,54 @@
     }
 
     /**
+     * Sets message Content-Type header.
+     * Use it to build messages with various content-types e.g. miltipart/raport
+     * not supported by _contentHeaders() function.
+     *
+     * @param string $type   Type name
+     * @param array  $params Hash array of header parameters
+     *
+     * @return void
+     * @access public
+     * @since 1.7.0
+     */
+    function setContentType($type, $params = array())
+    {
+        $header = $type;
+
+        $eol = !empty($this->_build_params['eol'])
+            ? $this->_build_params['eol'] : "\r\n";
+
+        // add parameters
+        $token_regexp = '#([^\x21,\x23-\x27,\x2A,\x2B,\x2D'
+            . ',\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])#';
+        if (is_array($params)) {
+            foreach ($params as $name => $value) {
+                if ($name == 'boundary') {
+                    $this->_build_params['boundary'] = $value;
+                }
+                if (!preg_match($token_regexp, $value)) {
+                    $header .= ";$eol $name=$value";
+                } else {
+                    $value = addcslashes($value, '\\"');
+                    $header .= ";$eol $name=\"$value\"";
+                }
+            }
+        }
+
+        // add required boundary parameter if not defined
+        if (preg_match('/^multipart\//i', $type)) {
+            if (empty($this->_build_params['boundary'])) {
+                $this->_build_params['boundary'] = '=_' . md5(rand() . microtime());
+            }
+
+            $header .= ";$eol boundary=\"".$this->_build_params['boundary']."\"";
+        }
+
+        $this->_build_params['ctype'] = $header;
+    }
+
+    /**
      * Sets the Subject header
      *
      * @param string $subject String to set the subject to.
@@ -1137,6 +1191,24 @@
     }
 
     /**
+     * Add an email to the To header
+     * (multiple calls to this method are allowed)
+     *
+     * @param string $email The email direction to add
+     *
+     * @return void
+     * @access public
+     */
+    function addTo($email)
+    {
+        if (isset($this->_headers['To'])) {
+            $this->_headers['To'] .= ", $email";
+        } else {
+            $this->_headers['To'] = $email;
+        }
+    }
+
+    /**
      * Add an email to the Cc (carbon copy) header
      * (multiple calls to this method are allowed)
      *

--
Gitblit v1.9.1