Changeset 713

Show
Ignore:
Timestamp:
12/19/07 23:06:44 (1 year ago)
Author:
laurentj
Message:

fixed bug #374: jMailer, bad encoding of characters in the subject

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/jelix/utils/jMailer.class.php

    r705 r713  
    2222 * @package jelix 
    2323 * @subpackage  utils 
    24  * @author Brent R. Matzelle 
     24 * @author Brent R. Matzelle, Andy Prevost 
    2525 * @contributor Laurent Jouanneau 
    2626 * @copyright 2001 - 2003 Brent R. Matzelle,  2006 Laurent Jouanneau 
     27 * @copyright 2004 - 2007 Andy Prevost 
    2728 * @since 1.0b1 
    2829 */ 
     
    629630     * automatically perform wrapping and for quoted-printable. 
    630631     * Original written by philippe. 
     632     * @internal the code of this method has been picked from version 2.0.0 og PHPMailer 
    631633     * @return string 
    632634     */ 
     
    635637 
    636638        $message = $this->FixEOL($message); 
    637         if (substr($message, -1) == $this->LE) 
     639        if (substr($message, -1) == $this->LE) { 
    638640            $message = substr($message, 0, -1); 
    639  
    640         return wordwrap ( $message, $length, $this->LE, 1 ); 
     641        } 
     642 
     643        $line = explode($this->LE, $message); 
     644        $message = ''; 
     645        for ($i=0 ;$i < count($line); $i++) { 
     646            $line_part = explode(' ', $line[$i]); 
     647            $buf = ''; 
     648            for ($e = 0; $e<count($line_part); $e++) { 
     649                $word = $line_part[$e]; 
     650                if ($qp_mode and (strlen($word) > $length)) { 
     651                    $space_left = $length - strlen($buf) - 1; 
     652                    if ($e != 0) { 
     653                        if ($space_left > 20) { 
     654                            $len = $space_left; 
     655                            if (substr($word, $len - 1, 1) == '=') { 
     656                                $len--; 
     657                            } elseif (substr($word, $len - 2, 1) == '=') { 
     658                                $len -= 2; 
     659                            } 
     660                            $part = substr($word, 0, $len); 
     661                            $word = substr($word, $len); 
     662                            $buf .= ' ' . $part; 
     663                            $message .= $buf . sprintf("=%s", $this->LE); 
     664                        } else { 
     665                            $message .= $buf . $soft_break; 
     666                        } 
     667                        $buf = ''; 
     668                    } 
     669                    while (strlen($word) > 0) { 
     670                        $len = $length; 
     671                        if (substr($word, $len - 1, 1) == '=') { 
     672                            $len--; 
     673                        } elseif (substr($word, $len - 2, 1) == '=') { 
     674                            $len -= 2; 
     675                        } 
     676                        $part = substr($word, 0, $len); 
     677                        $word = substr($word, $len); 
     678 
     679                        if (strlen($word) > 0) { 
     680                            $message .= $part . sprintf("=%s", $this->LE); 
     681                        } else { 
     682                            $buf = $part; 
     683                        } 
     684                    } 
     685                } else { 
     686                    $buf_o = $buf; 
     687                    $buf .= ($e == 0) ? $word : (' ' . $word); 
     688 
     689                    if (strlen($buf) > $length and $buf_o != '') { 
     690                        $message .= $buf_o . $soft_break; 
     691                        $buf = $word; 
     692                    } 
     693                } 
     694            } 
     695            $message .= $buf . $this->LE; 
     696        } 
     697 
     698        return $message; 
    641699    } 
    642700 
  • trunk/lib/jelix/utils/jMailer.class.php

    r705 r713  
    2222 * @package jelix 
    2323 * @subpackage  utils 
    24  * @author Brent R. Matzelle 
     24 * @author Brent R. Matzelle, Andy Prevost 
    2525 * @contributor Laurent Jouanneau 
    2626 * @copyright 2001 - 2003 Brent R. Matzelle,  2006 Laurent Jouanneau 
     27 * @copyright 2004 - 2007 Andy Prevost 
    2728 * @since 1.0b1 
    2829 */ 
     
    629630     * automatically perform wrapping and for quoted-printable. 
    630631     * Original written by philippe. 
     632     * @internal the code of this method has been picked from version 2.0.0 og PHPMailer 
    631633     * @return string 
    632634     */ 
     
    635637 
    636638        $message = $this->FixEOL($message); 
    637         if (substr($message, -1) == $this->LE) 
     639        if (substr($message, -1) == $this->LE) { 
    638640            $message = substr($message, 0, -1); 
    639  
    640         return wordwrap ( $message, $length, $this->LE, 1 ); 
     641        } 
     642 
     643        $line = explode($this->LE, $message); 
     644        $message = ''; 
     645        for ($i=0 ;$i < count($line); $i++) { 
     646            $line_part = explode(' ', $line[$i]); 
     647            $buf = ''; 
     648            for ($e = 0; $e<count($line_part); $e++) { 
     649                $word = $line_part[$e]; 
     650                if ($qp_mode and (strlen($word) > $length)) { 
     651                    $space_left = $length - strlen($buf) - 1; 
     652                    if ($e != 0) { 
     653                        if ($space_left > 20) { 
     654                            $len = $space_left; 
     655                            if (substr($word, $len - 1, 1) == '=') { 
     656                                $len--; 
     657                            } elseif (substr($word, $len - 2, 1) == '=') { 
     658                                $len -= 2; 
     659                            } 
     660                            $part = substr($word, 0, $len); 
     661                            $word = substr($word, $len); 
     662                            $buf .= ' ' . $part; 
     663                            $message .= $buf . sprintf("=%s", $this->LE); 
     664                        } else { 
     665                            $message .= $buf . $soft_break; 
     666                        } 
     667                        $buf = ''; 
     668                    } 
     669                    while (strlen($word) > 0) { 
     670                        $len = $length; 
     671                        if (substr($word, $len - 1, 1) == '=') { 
     672                            $len--; 
     673                        } elseif (substr($word, $len - 2, 1) == '=') { 
     674                            $len -= 2; 
     675                        } 
     676                        $part = substr($word, 0, $len); 
     677                        $word = substr($word, $len); 
     678 
     679                        if (strlen($word) > 0) { 
     680                            $message .= $part . sprintf("=%s", $this->LE); 
     681                        } else { 
     682                            $buf = $part; 
     683                        } 
     684                    } 
     685                } else { 
     686                    $buf_o = $buf; 
     687                    $buf .= ($e == 0) ? $word : (' ' . $word); 
     688 
     689                    if (strlen($buf) > $length and $buf_o != '') { 
     690                        $message .= $buf_o . $soft_break; 
     691                        $buf = $word; 
     692                    } 
     693                } 
     694            } 
     695            $message .= $buf . $this->LE; 
     696        } 
     697 
     698        return $message; 
    641699    } 
    642700 
Download in other formats: Unified Diff Zip Archive