Changeset 5825 in subversion for branches/devel-framework/roundcubemail


Ignore:
Timestamp:
Jan 26, 2012 6:05:23 AM (17 months ago)
Author:
alec
Message:
  • Add lost functions, some improvements and migration bugfixes
Location:
branches/devel-framework/roundcubemail/program/include
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-framework/roundcubemail/program/include/main.inc

    r5822 r5825  
    341341    return rcube_request_header($name); 
    342342} 
     343 
     344function rc_mime_content_type($path, $name, $failover = 'application/octet-stream', $is_stream=false) 
     345{ 
     346    return rcube_mime::file_content_type($path, $name, $failover, $is_stream); 
     347} 
     348 
     349function rc_image_content_type($data) 
     350{ 
     351    return rcube_mime::image_content_type($data); 
     352} 
  • branches/devel-framework/roundcubemail/program/include/rcube_imap.php

    r5822 r5825  
    183183            if ($pass && $user) { 
    184184                $message = sprintf("Login failed for %s from %s. %s", 
    185                     $user, rcmail::rcmail_remote_ip(), $this->conn->error); 
     185                    $user, rcmail::remote_ip(), $this->conn->error); 
    186186 
    187187                raise_error(array('code' => 403, 'type' => 'imap', 
     
    830830     * depth, has_children and unread_children 
    831831     * 
    832      * @param  array             $headers Reference to headers array indexed by message UID 
    833      * @param  rcube_imap_result $threads Threads data object 
     832     * @param  array               $headers Reference to headers array indexed by message UID 
     833     * @param  rcube_result_thread $threads Threads data object 
    834834     * 
    835835     * @return array Message headers array indexed by message UID 
  • branches/devel-framework/roundcubemail/program/include/rcube_message.php

    r5822 r5825  
    651651                $uupart->mime_id  = 'uu.' . $part->mime_id . '.' . $pid; 
    652652 
    653                 $ctype = rc_mime_content_type($uupart->body, $uupart->filename, 'application/octet-stream', true); 
     653                $ctype = rcube_mime::content_type($uupart->body, $uupart->filename, 'application/octet-stream', true); 
    654654                $uupart->mimetype = $ctype; 
    655655                list($uupart->ctype_primary, $uupart->ctype_secondary) = explode('/', $ctype); 
  • branches/devel-framework/roundcubemail/program/include/rcube_mime.php

    r5822 r5825  
    552552    } 
    553553 
     554 
     555    /** 
     556     * A method to guess the mime_type of an attachment. 
     557     * 
     558     * @param string $path      Path to the file. 
     559     * @param string $name      File name (with suffix) 
     560     * @param string $failover  Mime type supplied for failover. 
     561     * @param string $is_stream Set to True if $path contains file body 
     562     * 
     563     * @return string 
     564     * @author Till Klampaeckel <till@php.net> 
     565     * @see    http://de2.php.net/manual/en/ref.fileinfo.php 
     566     * @see    http://de2.php.net/mime_content_type 
     567     */ 
     568    public static function file_content_type($path, $name, $failover = 'application/octet-stream', $is_stream = false) 
     569    { 
     570        $mime_type = null; 
     571        $mime_magic = rcmail::get_instance()->config->get('mime_magic'); 
     572        $mime_ext = @include RCMAIL_CONFIG_DIR . '/mimetypes.php'; 
     573 
     574        // use file name suffix with hard-coded mime-type map 
     575        if (is_array($mime_ext) && $name) { 
     576            if ($suffix = substr($name, strrpos($name, '.')+1)) { 
     577                $mime_type = $mime_ext[strtolower($suffix)]; 
     578            } 
     579        } 
     580 
     581        // try fileinfo extension if available 
     582        if (!$mime_type && function_exists('finfo_open')) { 
     583            if ($finfo = finfo_open(FILEINFO_MIME, $mime_magic)) { 
     584                if ($is_stream) 
     585                    $mime_type = finfo_buffer($finfo, $path); 
     586                else 
     587                    $mime_type = finfo_file($finfo, $path); 
     588                finfo_close($finfo); 
     589            } 
     590        } 
     591 
     592        // try PHP's mime_content_type 
     593        if (!$mime_type && !$is_stream && function_exists('mime_content_type')) { 
     594            $mime_type = @mime_content_type($path); 
     595        } 
     596 
     597        // fall back to user-submitted string 
     598        if (!$mime_type) { 
     599            $mime_type = $failover; 
     600        } 
     601        else { 
     602            // Sometimes (PHP-5.3?) content-type contains charset definition, 
     603            // Remove it (#1487122) also "charset=binary" is useless 
     604            $mime_type = array_shift(preg_split('/[; ]/', $mime_type)); 
     605        } 
     606 
     607        return $mime_type; 
     608    } 
     609 
     610 
     611    /** 
     612     * Detect image type of the given binary data by checking magic numbers. 
     613     * 
     614     * @param string $data  Binary file content 
     615     * 
     616     * @return string Detected mime-type or jpeg as fallback 
     617     */ 
     618    public static function image_content_type($data) 
     619    { 
     620        $type = 'jpeg'; 
     621        if      (preg_match('/^\x89\x50\x4E\x47/', $data)) $type = 'png'; 
     622        else if (preg_match('/^\x47\x49\x46\x38/', $data)) $type = 'gif'; 
     623        else if (preg_match('/^\x00\x00\x01\x00/', $data)) $type = 'ico'; 
     624    //  else if (preg_match('/^\xFF\xD8\xFF\xE0/', $data)) $type = 'jpeg'; 
     625 
     626        return 'image/' . $type; 
     627    } 
     628 
    554629} 
Note: See TracChangeset for help on using the changeset viewer.