Changeset 45

Show
Ignore:
Timestamp:
05/15/2007 02:13:05 PM (19 months ago)
Author:
JAAulde
Message:

fixed newline problem from #23

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/1.0/system/libraries/Email.php

    r24 r45  
    7171        var     $_base_charsets = array('iso-8859-1', 'us-ascii'); 
    7272        var     $_bit_depths    = array('7bit', '8bit'); 
    73         var     $_priorities    = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)');       
     73        var     $_priorities    = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)'); 
    7474 
    7575 
     
    7878         * 
    7979         * The constructor can be passed an array of config values 
    80          */      
     80         */ 
    8181        function CI_Email($config = array()) 
    82         {                
     82        { 
    8383                if (count($config) > 0) 
    8484                { 
    8585                        $this->initialize($config); 
    86                 }        
     86                } 
    8787 
    8888                log_message('debug', "Email Class Initialized"); 
     
    9797         * @param       array 
    9898         * @return      void 
    99          */      
     99         */ 
    100100        function initialize($config = array()) 
    101101        { 
     
    106106                        { 
    107107                                $method = 'set_'.$key; 
    108                                  
     108 
    109109                                if (method_exists($this, $method)) 
    110110                                { 
     
    114114                                { 
    115115                                        $this->$key = $val; 
    116                                 }                        
     116                                } 
    117117                        } 
    118118                } 
    119                 $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE;                  
     119                $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; 
    120120                $this->_safe_mode = (@ini_get("safe_mode") == 0) ? FALSE : TRUE; 
    121121        } 
    122          
     122 
    123123        // -------------------------------------------------------------------- 
    124124 
     
    128128         * @access      public 
    129129         * @return      void 
    130          */      
     130         */ 
    131131        function clear($clear_attachments = FALSE) 
    132132        { 
     
    139139                $this->_headers         = array(); 
    140140                $this->_debug_msg       = array(); 
    141                  
    142                 $this->_set_header('User-Agent', $this->useragent);                              
     141 
     142                $this->_set_header('User-Agent', $this->useragent); 
    143143                $this->_set_header('Date', $this->_set_date()); 
    144                  
     144 
    145145                if ($clear_attachments !== FALSE) 
    146146                { 
     
    148148                        $this->_attach_type = array(); 
    149149                        $this->_attach_disp = array(); 
    150                 }                
    151         } 
    152          
     150                } 
     151        } 
     152 
    153153        // -------------------------------------------------------------------- 
    154154 
     
    160160         * @param       string 
    161161         * @return      void 
    162          */      
     162         */ 
    163163        function from($from, $name = '') 
    164164        { 
     
    168168                if ($this->validate) 
    169169                        $this->validate_email($this->_str_to_array($from)); 
    170                          
     170 
    171171                if ($name != '' && substr($name, 0, 1) != '"') 
    172172                { 
    173173                        $name = '"'.$name.'"'; 
    174174                } 
    175          
     175 
    176176                $this->_set_header('From', $name.' <'.$from.'>'); 
    177177                $this->_set_header('Return-Path', '<'.$from.'>'); 
    178178        } 
    179          
     179 
    180180        // -------------------------------------------------------------------- 
    181181 
     
    187187         * @param       string 
    188188         * @return      void 
    189          */      
     189         */ 
    190190        function reply_to($replyto, $name = '') 
    191191        { 
     
    194194 
    195195                if ($this->validate) 
    196                         $this->validate_email($this->_str_to_array($replyto));   
     196                        $this->validate_email($this->_str_to_array($replyto)); 
    197197 
    198198                if ($name == '') 
     
    209209                $this->_replyto_flag = TRUE; 
    210210        } 
    211          
     211 
    212212        // -------------------------------------------------------------------- 
    213213 
     
    218218         * @param       string 
    219219         * @return      void 
    220          */      
     220         */ 
    221221        function to($to) 
    222222        { 
    223223                $to = $this->_str_to_array($to); 
    224224                $to = $this->clean_email($to); 
    225          
     225 
    226226                if ($this->validate) 
    227227                        $this->validate_email($to); 
    228                          
     228 
    229229                if ($this->_get_protocol() != 'mail') 
    230230                        $this->_set_header('To', implode(", ", $to)); 
     
    238238                        case 'mail'             : $this->_recipients = implode(", ", $to); 
    239239                        break; 
    240                 }        
    241         } 
    242          
     240                } 
     241        } 
     242 
    243243        // -------------------------------------------------------------------- 
    244244 
     
    249249         * @param       string 
    250250         * @return      void 
    251          */      
     251         */ 
    252252        function cc($cc) 
    253         {        
     253        { 
    254254                $cc = $this->_str_to_array($cc); 
    255255                $cc = $this->clean_email($cc); 
     
    259259 
    260260                $this->_set_header('Cc', implode(", ", $cc)); 
    261                  
     261 
    262262                if ($this->_get_protocol() == "smtp") 
    263263                        $this->_cc_array = $cc; 
    264264        } 
    265          
     265 
    266266        // -------------------------------------------------------------------- 
    267267 
     
    273273         * @param       string 
    274274         * @return      void 
    275          */      
     275         */ 
    276276        function bcc($bcc, $limit = '') 
    277277        { 
     
    284284                $bcc = $this->_str_to_array($bcc); 
    285285                $bcc = $this->clean_email($bcc); 
    286                  
     286 
    287287                if ($this->validate) 
    288288                        $this->validate_email($bcc); 
     
    293293                        $this->_set_header('Bcc', implode(", ", $bcc)); 
    294294        } 
    295          
     295 
    296296        // -------------------------------------------------------------------- 
    297297 
     
    302302         * @param       string 
    303303         * @return      void 
    304          */      
     304         */ 
    305305        function subject($subject) 
    306306        { 
    307307                $subject = preg_replace("/(\r\n)|(\r)|(\n)/", "", $subject); 
    308308                $subject = preg_replace("/(\t)/", " ", $subject); 
    309                  
    310                 $this->_set_header('Subject', trim($subject));           
    311         } 
    312          
     309 
     310                $this->_set_header('Subject', trim($subject)); 
     311        } 
     312 
    313313        // -------------------------------------------------------------------- 
    314314 
     
    319319         * @param       string 
    320320         * @return      void 
    321          */      
     321         */ 
    322322        function message($body) 
    323323        { 
    324                 $this->_body = stripslashes(rtrim(str_replace("\r", "", $body)));        
    325         }        
    326          
     324                $this->_body = stripslashes(rtrim(str_replace("\r", "", $body))); 
     325        } 
     326 
    327327        // -------------------------------------------------------------------- 
    328328 
     
    333333         * @param       string 
    334334         * @return      string 
    335          */              
     335         */ 
    336336        function attach($filename, $disposition = 'attachment') 
    337         {                        
     337        { 
    338338                $this->_attach_name[] = $filename; 
    339339                $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); 
     
    350350         * @param       string 
    351351         * @return      void 
    352          */      
     352         */ 
    353353        function _set_header($header, $value) 
    354354        { 
    355355                $this->_headers[$header] = $value; 
    356356        } 
    357          
     357 
    358358        // -------------------------------------------------------------------- 
    359359 
     
    364364         * @param       string 
    365365         * @return      array 
    366          */      
     366         */ 
    367367        function _str_to_array($email) 
    368368        { 
    369369                if ( ! is_array($email)) 
    370                 {        
     370                { 
    371371                        if (ereg(',$', $email)) 
    372372                                $email = substr($email, 0, -1); 
    373                          
     373 
    374374                        if (ereg('^,', $email)) 
    375                                 $email = substr($email, 1);      
    376                                          
     375                                $email = substr($email, 1); 
     376 
    377377                        if (ereg(',', $email)) 
    378                         {                                        
     378                        { 
    379379                                $x = explode(',', $email); 
    380380                                $email = array(); 
    381                                  
     381 
    382382                                for ($i = 0; $i < count($x); $i ++) 
    383383                                        $email[] = trim($x[$i]); 
    384384                        } 
    385385                        else 
    386                         {                                
     386                        { 
    387387                                $email = trim($email); 
    388388                                settype($email, "array"); 
     
    391391                return $email; 
    392392        } 
    393          
     393 
    394394        // -------------------------------------------------------------------- 
    395395 
     
    400400         * @param       string 
    401401         * @return      void 
    402          */      
     402         */ 
    403403        function set_alt_message($str = '') 
    404404        { 
    405405                $this->alt_message = ($str == '') ? '' : $str; 
    406406        } 
    407          
     407 
    408408        // -------------------------------------------------------------------- 
    409409 
     
    414414         * @param       string 
    415415         * @return      void 
    416          */      
     416         */ 
    417417        function set_mailtype($type = 'text') 
    418418        { 
    419419                $this->mailtype = ($type == 'html') ? 'html' : 'text'; 
    420420        } 
    421          
     421 
    422422        // -------------------------------------------------------------------- 
    423423 
     
    428428         * @param       string 
    429429         * @return      void 
    430          */      
     430         */ 
    431431        function set_wordwrap($wordwrap = TRUE) 
    432432        { 
    433433                $this->wordwrap = ($wordwrap === FALSE) ? FALSE : TRUE; 
    434434        } 
    435          
     435 
    436436        // -------------------------------------------------------------------- 
    437437 
     
    442442         * @param       string 
    443443         * @return      void 
    444          */      
     444         */ 
    445445        function set_protocol($protocol = 'mail') 
    446446        { 
    447447                $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); 
    448448        } 
    449          
     449 
    450450        // -------------------------------------------------------------------- 
    451451 
     
    456456         * @param       integer 
    457457         * @return      void 
    458          */      
     458         */ 
    459459        function set_priority($n = 3) 
    460460        { 
     
    464464                        return; 
    465465                } 
    466          
     466 
    467467                if ($n < 1 OR $n > 5) 
    468468                { 
     
    470470                        return; 
    471471                } 
    472          
     472 
    473473                $this->priority = $n; 
    474474        } 
    475          
     475 
    476476        // -------------------------------------------------------------------- 
    477477 
     
    482482         * @param       string 
    483483         * @return      void 
    484          */      
     484         */ 
    485485        function set_newline($newline = "\n") 
    486486        { 
    487                 if ($newline != "\n" OR $newline != "\r\n" OR $newline != "\r") 
    488                 { 
    489                         $this->newline  = "\n";  
    490                         return; 
    491                 } 
    492          
    493                 $this->newline  = $newline;      
    494         } 
    495          
     487                $this->newline = 
     488                        ($newline == "\n" OR $newline == "\r\n" OR $newline == "\r") ? 
     489                                $newline: 
     490                                "\n"; 
     491        } 
     492 
    496493        // -------------------------------------------------------------------- 
    497494 
     
    501498         * @access      private 
    502499         * @return      void 
    503          */      
     500         */ 
    504501        function _set_boundaries() 
    505502        { 
     
    507504                $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary 
    508505        } 
    509          
     506 
    510507        // -------------------------------------------------------------------- 
    511508 
     
    515512         * @access      private 
    516513         * @return      string 
    517          */      
     514         */ 
    518515        function _get_message_id() 
    519516        { 
     
    521518                $from = str_replace(">", "", $from); 
    522519                $from = str_replace("<", "", $from); 
    523          
    524                 return  "<".uniqid('').strstr($from, '@').">";   
    525         } 
    526          
     520 
     521                return  "<".uniqid('').strstr($from, '@').">"; 
     522        } 
     523 
    527524        // -------------------------------------------------------------------- 
    528525 
     
    533530         * @param       bool 
    534531         * @return      string 
    535          */      
     532         */ 
    536533        function _get_protocol($return = true) 
    537534        { 
    538535                $this->protocol = strtolower($this->protocol); 
    539536                $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; 
    540                  
     537 
    541538                if ($return == true) 
    542539                        return $this->protocol; 
    543540        } 
    544          
     541 
    545542        // -------------------------------------------------------------------- 
    546543 
     
    551548         * @param       bool 
    552549         * @return      string 
    553          */      
     550         */ 
    554551        function _get_encoding($return = true) 
    555         {                
     552        { 
    556553                $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '7bit' : $this->_encoding; 
    557                  
     554 
    558555                if ( ! in_array($this->charset, $this->_base_charsets, TRUE)) 
    559556                        $this->_encoding = "8bit"; 
    560                          
     557 
    561558                if ($return == true) 
    562559                        return $this->_encoding; 
     
    570567         * @access      private 
    571568         * @return      string 
    572          */      
     569         */ 
    573570        function _get_content_type() 
    574         {        
     571        { 
    575572                        if      ($this->mailtype == 'html' &&  count($this->_attach_name) == 0) 
    576573                                return 'html'; 
    577          
     574 
    578575                elseif  ($this->mailtype == 'html' &&  count($this->_attach_name)  > 0) 
    579                                 return 'html-attach';                            
    580                                  
     576                                return 'html-attach'; 
     577 
    581578                elseif  ($this->mailtype == 'text' &&  count($this->_attach_name)  > 0) 
    582579                                return 'plain-attach'; 
    583                                  
     580 
    584581                  else  return 'plain'; 
    585582        } 
    586          
     583 
    587584        // -------------------------------------------------------------------- 
    588585 
     
    592589         * @access      public 
    593590         * @return      string 
    594          */      
     591         */ 
    595592        function _set_date() 
    596593        { 
     
    599596                $timezone = abs($timezone); 
    600597                $timezone = ($timezone/3600) * 100 + ($timezone % 3600) /60; 
    601                  
     598 
    602599                return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone); 
    603600        } 
    604          
     601 
    605602        // -------------------------------------------------------------------- 
    606603 
     
    610607         * @access      private 
    611608         * @return      string 
    612          */      
     609         */ 
    613610        function _get_mime_message() 
    614611        { 
    615612                return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format."; 
    616613        } 
    617          
     614 
    618615        // -------------------------------------------------------------------- 
    619616 
     
    624621         * @param       string 
    625622         * @return      bool 
    626          */      
     623         */ 
    627624        function validate_email($email) 
    628         {        
     625        { 
    629626                if ( ! is_array($email)) 
    630627                { 
    631                         $this->_set_error_message('email_must_be_array');                
     628                        $this->_set_error_message('email_must_be_array'); 
    632629                        return FALSE; 
    633630                } 
     
    637634                        if ( ! $this->valid_email($val)) 
    638635                        { 
    639                                 $this->_set_error_message('email_invalid_address', $val);                                
     636