Changeset 4295 in subversion


Ignore:
Timestamp:
Dec 1, 2010 5:49:20 AM (2 years ago)
Author:
alec
Message:
  • Fix setting charset of attachment filenames (#1487122)
Location:
trunk/roundcubemail
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r4293 r4295  
    77- Fix window is blur'ed in IE when selecting a message (#1487316) 
    88- Fix cursor position on compose form in Webkit browsers (#1486674) 
     9- Fix setting charset of attachment filenames (#1487122) 
    910 
    1011RELEASE 0.5-BETA 
  • trunk/roundcubemail/INSTALL

    r4282 r4295  
    1818* PEAR packages distributed with Roundcube or external: 
    1919   - MDB2 2.5.0 or newer 
    20    - Mail_Mime 1.7.0 or newer 
     20   - Mail_Mime 1.8.1 or newer 
    2121   - Net_SMTP 1.4.2 or newer 
    2222   - Auth_SASL 1.0.3 or newer 
  • trunk/roundcubemail/program/lib/Mail/mime.php

    r3837 r4295  
    366366     * 
    367367     * @param string $file        The file name of the file to attach 
    368      *                            OR the file contents itself 
     368     *                            or the file contents itself 
    369369     * @param string $c_type      The content type 
    370370     * @param string $name        The filename of the attachment 
    371371     *                            Only use if $file is the contents 
    372      * @param bool   $isfile      Whether $file is a filename or not 
    373      *                            Defaults to true 
    374      * @param string $encoding    The type of encoding to use. 
    375      *                            Defaults to base64. 
    376      *                            Possible values: 7bit, 8bit, base64,  
    377      *                            or quoted-printable. 
     372     * @param bool   $isfile      Whether $file is a filename or not. Defaults to true 
     373     * @param string $encoding    The type of encoding to use. Defaults to base64. 
     374     *                            Possible values: 7bit, 8bit, base64 or quoted-printable. 
    378375     * @param string $disposition The content-disposition of this file 
    379376     *                            Defaults to attachment. 
    380377     *                            Possible values: attachment, inline. 
    381      * @param string $charset     The character set used in the filename 
    382      *                            of this attachment. 
     378     * @param string $charset     The character set of attachment's content. 
    383379     * @param string $language    The language of the attachment 
    384380     * @param string $location    The RFC 2557.4 location of the attachment 
    385      * @param string $n_encoding  Encoding for attachment name (Content-Type) 
     381     * @param string $n_encoding  Encoding of the attachment's name in Content-Type 
    386382     *                            By default filenames are encoded using RFC2231 method 
    387383     *                            Here you can set RFC2047 encoding (quoted-printable 
    388384     *                            or base64) instead 
    389      * @param string $f_encoding  Encoding for attachment filename (Content-Disposition) 
    390      *                            See $n_encoding description 
     385     * @param string $f_encoding  Encoding of the attachment's filename 
     386     *                            in Content-Disposition header. 
    391387     * @param string $description Content-Description header 
     388     * @param string $h_charset   The character set of the headers e.g. filename 
     389     *                            If not specified, $charset will be used 
    392390     * 
    393391     * @return mixed              True on success or PEAR_Error object 
     
    405403        $n_encoding  = null, 
    406404        $f_encoding  = null, 
    407         $description = '' 
     405        $description = '', 
     406        $h_charset   = null 
    408407    ) { 
    409408        $bodyfile = null; 
     
    438437            'name'        => $filename, 
    439438            'c_type'      => $c_type, 
     439            'charset'     => $charset, 
    440440            'encoding'    => $encoding, 
    441             'charset'     => $charset, 
    442441            'language'    => $language, 
    443442            'location'    => $location, 
     
    445444            'description' => $description, 
    446445            'name_encoding'     => $n_encoding, 
    447             'filename_encoding' => $f_encoding 
     446            'filename_encoding' => $f_encoding, 
     447            'headers_charset'   => $h_charset, 
    448448        ); 
    449449 
     
    622622        $params['encoding']     = 'base64'; 
    623623        $params['disposition']  = 'inline'; 
    624         $params['dfilename']    = $value['name']; 
     624        $params['filename']     = $value['name']; 
    625625        $params['cid']          = $value['cid']; 
    626626        $params['body_file']    = $value['body_file']; 
     
    651651    { 
    652652        $params['eol']          = $this->_build_params['eol']; 
    653         $params['dfilename']    = $value['name']; 
     653        $params['filename']     = $value['name']; 
    654654        $params['encoding']     = $value['encoding']; 
    655655        $params['content_type'] = $value['c_type']; 
     
    657657        $params['disposition']  = isset($value['disposition']) ?  
    658658                                  $value['disposition'] : 'attachment'; 
    659         if ($value['charset']) { 
     659 
     660        // content charset 
     661        if (!empty($value['charset'])) { 
    660662            $params['charset'] = $value['charset']; 
    661663        } 
    662         if ($value['language']) { 
     664        // headers charset (filename, description) 
     665        if (!empty($value['headers_charset'])) { 
     666            $params['headers_charset'] = $value['headers_charset']; 
     667        } 
     668        if (!empty($value['language'])) { 
    663669            $params['language'] = $value['language']; 
    664670        } 
    665         if ($value['location']) { 
     671        if (!empty($value['location'])) { 
    666672            $params['location'] = $value['location']; 
    667673        } 
     
    13881394        if ($headers['Content-Type'] == 'text/plain') { 
    13891395            // single-part message: add charset and encoding 
     1396            $charset = 'charset=' . $this->_build_params['text_charset']; 
     1397            // place charset parameter in the same line, if possible 
     1398            // 26 = strlen("Content-Type: text/plain; ") 
    13901399            $headers['Content-Type'] 
    1391                 .= ";$eol charset=" . $this->_build_params['text_charset']; 
     1400                .= (strlen($charset) + 26 <= 76) ? "; $charset" : ";$eol $charset"; 
    13921401            $headers['Content-Transfer-Encoding'] 
    13931402                = $this->_build_params['text_encoding']; 
    13941403        } else if ($headers['Content-Type'] == 'text/html') { 
    13951404            // single-part message: add charset and encoding 
     1405            $charset = 'charset=' . $this->_build_params['html_charset']; 
     1406            // place charset parameter in the same line, if possible 
    13961407            $headers['Content-Type'] 
    1397                 .= ";$eol charset=" . $this->_build_params['html_charset']; 
     1408                .= (strlen($charset) + 25 <= 76) ? "; $charset" : ";$eol $charset"; 
    13981409            $headers['Content-Transfer-Encoding'] 
    13991410                = $this->_build_params['html_encoding']; 
    14001411        } else { 
    1401             // multipart message: add charset and boundary 
     1412            // multipart message: and boundary 
    14021413            if (!empty($this->_build_params['boundary'])) { 
    14031414                $boundary = $this->_build_params['boundary']; 
  • trunk/roundcubemail/program/lib/Mail/mimePart.php

    r3837 r4295  
    142142    *     encoding          - The encoding to use, 7bit, 8bit, 
    143143    *                         base64, or quoted-printable 
     144    *     charset           - Content character set 
    144145    *     cid               - Content ID to apply 
    145146    *     disposition       - Content disposition, inline or attachment 
    146147    *     dfilename         - Filename parameter for content disposition 
    147148    *     description       - Content description 
    148     *     charset           - Character set to use 
    149     *     name_encoding     - Encoding for attachment name (Content-Type) 
     149    *     name_encoding     - Encoding of the attachment name (Content-Type) 
    150150    *                         By default filenames are encoded using RFC2231 
    151151    *                         Here you can set RFC2047 encoding (quoted-printable 
    152152    *                         or base64) instead 
    153     *     filename_encoding - Encoding for attachment filename (Content-Disposition) 
     153    *     filename_encoding - Encoding of the attachment filename (Content-Disposition) 
    154154    *                         See 'name_encoding' 
     155    *     headers_charset   - Charset of the headers e.g. filename, description. 
     156    *                         If not set, 'charset' will be used 
    155157    *     eol               - End of line sequence. Default: "\r\n" 
    156158    *     body_file         - Location of file with part's body (instead of $body) 
     
    166168        } 
    167169 
    168         $c_type = array(); 
    169         $c_disp = array(); 
    170170        foreach ($params as $key => $value) { 
    171171            switch ($key) { 
    172             case 'content_type': 
    173                 $c_type['type'] = $value; 
    174                 break; 
    175  
    176172            case 'encoding': 
    177173                $this->_encoding = $value; 
     
    183179                break; 
    184180 
    185             case 'disposition': 
    186                 $c_disp['disp'] = $value; 
    187                 break; 
    188  
    189             case 'dfilename': 
    190                 $c_disp['filename'] = $value; 
    191                 $c_type['name'] = $value; 
    192                 break; 
    193  
    194             case 'description': 
    195                 $headers['Content-Description'] = $value; 
    196                 break; 
    197  
    198             case 'charset': 
    199                 $c_type['charset'] = $value; 
    200                 $c_disp['charset'] = $value; 
    201                 break; 
    202  
    203             case 'language': 
    204                 $c_type['language'] = $value; 
    205                 $c_disp['language'] = $value; 
    206                 break; 
    207  
    208181            case 'location': 
    209182                $headers['Content-Location'] = $value; 
     
    217190 
    218191        // Default content-type 
    219         if (empty($c_type['type'])) { 
    220             $c_type['type'] = 'text/plain'; 
     192        if (empty($params['content_type'])) { 
     193            $params['content_type'] = 'text/plain'; 
    221194        } 
    222195 
    223196        // Content-Type 
    224         if (!empty($c_type['type'])) { 
    225             $headers['Content-Type'] = $c_type['type']; 
    226             if (!empty($c_type['charset'])) { 
    227                 $charset = "charset={$c_type['charset']}"; 
    228                 // place charset parameter in the same line, if possible 
    229                 if ((strlen($headers['Content-Type']) + strlen($charset) + 16) <= 76) { 
    230                     $headers['Content-Type'] .= '; '; 
    231                 } else { 
    232                     $headers['Content-Type'] .= ';' . $this->_eol . ' '; 
    233                 } 
    234                 $headers['Content-Type'] .= $charset; 
    235             } 
    236             if (!empty($c_type['name'])) { 
    237                 $headers['Content-Type'] .= ';' . $this->_eol; 
    238                 $headers['Content-Type'] .= $this->_buildHeaderParam( 
    239                     'name', $c_type['name'], 
    240                     isset($c_type['charset']) ? $c_type['charset'] : 'US-ASCII', 
    241                     isset($c_type['language']) ? $c_type['language'] : null, 
    242                     isset($params['name_encoding']) ?  $params['name_encoding'] : null 
    243                 ); 
    244             } 
     197        $headers['Content-Type'] = $params['content_type']; 
     198        if (!empty($params['charset'])) { 
     199            $charset = "charset={$params['charset']}"; 
     200            // place charset parameter in the same line, if possible 
     201            if ((strlen($headers['Content-Type']) + strlen($charset) + 16) <= 76) { 
     202                $headers['Content-Type'] .= '; '; 
     203            } else { 
     204                $headers['Content-Type'] .= ';' . $this->_eol . ' '; 
     205            } 
     206            $headers['Content-Type'] .= $charset; 
     207 
     208            // Default headers charset 
     209            if (!isset($params['headers_charset'])) { 
     210                $params['headers_charset'] = $params['charset']; 
     211            } 
     212        } 
     213        if (!empty($params['filename'])) { 
     214            $headers['Content-Type'] .= ';' . $this->_eol; 
     215            $headers['Content-Type'] .= $this->_buildHeaderParam( 
     216                'name', $params['filename'], 
     217                !empty($params['headers_charset']) ? $params['headers_charset'] : 'US-ASCII', 
     218                !empty($params['language']) ? $params['language'] : null, 
     219                !empty($params['name_encoding']) ? $params['name_encoding'] : null 
     220            ); 
    245221        } 
    246222 
    247223        // Content-Disposition 
    248         if (!empty($c_disp['disp'])) { 
    249             $headers['Content-Disposition'] = $c_disp['disp']; 
    250             if (!empty($c_disp['filename'])) { 
     224        if (!empty($params['disposition'])) { 
     225            $headers['Content-Disposition'] = $params['disposition']; 
     226            if (!empty($params['filename'])) { 
    251227                $headers['Content-Disposition'] .= ';' . $this->_eol; 
    252228                $headers['Content-Disposition'] .= $this->_buildHeaderParam( 
    253                     'filename', $c_disp['filename'], 
    254                     isset($c_disp['charset']) ? $c_disp['charset'] : 'US-ASCII', 
    255                     isset($c_disp['language']) ? $c_disp['language'] : null, 
    256                     isset($params['filename_encoding']) ? $params['filename_encoding'] : null 
     229                    'filename', $params['filename'], 
     230                    !empty($params['headers_charset']) ? $params['headers_charset'] : 'US-ASCII', 
     231                    !empty($params['language']) ? $params['language'] : null, 
     232                    !empty($params['filename_encoding']) ? $params['filename_encoding'] : null 
    257233                ); 
    258234            } 
    259235        } 
    260236 
    261         if (!empty($headers['Content-Description'])) { 
     237        if (!empty($params['description'])) { 
    262238            $headers['Content-Description'] = $this->encodeHeader( 
    263                 'Content-Description', $headers['Content-Description'], 
    264                 isset($c_type['charset']) ? $c_type['charset'] : 'US-ASCII', 
    265                 isset($params['name_encoding']) ? $params['name_encoding'] : 'quoted-printable', 
     239                'Content-Description', $params['description'], 
     240                !empty($params['headers_charset']) ? $params['headers_charset'] : 'US-ASCII', 
     241                !empty($params['name_encoding']) ? $params['name_encoding'] : 'quoted-printable', 
    266242                $this->_eol 
    267243            ); 
  • trunk/roundcubemail/program/steps/mail/sendmail.inc

    r4249 r4295  
    514514        ($ctype == 'message/rfc822' ? '8bit' : 'base64'), 
    515515        ($ctype == 'message/rfc822' ? 'inline' : 'attachment'), 
    516         $message_charset, '', '', 
     516        '', '', '', 
    517517        $CONFIG['mime_param_folding'] ? 'quoted-printable' : NULL, 
    518         $CONFIG['mime_param_folding'] == 2 ? 'quoted-printable' : NULL 
     518        $CONFIG['mime_param_folding'] == 2 ? 'quoted-printable' : NULL, 
     519        '', RCMAIL_CHARSET 
    519520      ); 
    520521    } 
Note: See TracChangeset for help on using the changeset viewer.