Show
Ignore:
Timestamp:
02/02/2008 09:37:18 PM (11 months ago)
Author:
Shadowhand
Message:

Cleaning up email helper.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/helpers/email.php

    r1893 r1903  
    2121         * @return  void 
    2222         */ 
    23         public static function connect($dsn = NULL) 
     23        public static function connect($config = NULL) 
    2424        { 
    2525                // Load default configuration 
    26                 ($dsn === NULL) and $dsn = Config::item('email.dsn'); 
     26                ($config === NULL) and $config = Config::item('email'); 
    2727 
    2828                if ( ! class_exists('Swift', FALSE)) 
     
    3535                } 
    3636 
    37                 if (substr($dsn, 0, 4) === 'smtp') 
     37                switch ($config['driver']) 
    3838                { 
    39                         $dsn = parse_url($dsn); 
     39                        case 'smtp': 
     40                                // Create a SMTP connection 
     41                                $connection = new Swift_Connection_SMTP 
     42                                ( 
     43                                        $config['hostname'],  
     44                                        empty($config['options']['port']) ? 25 : $config['options']['port'] 
     45                                ); 
    4046 
    41                         // Create the connection 
    42                         $connection = new Swift_Connection_SMTP($dsn['host'], empty($dsn['port']) ? 25 : (int) $dsn['port']); 
     47                                // Do authentication, if part of the DSN 
     48                                empty($config['options']['username']) or $connection->setUsername($config['options']['username']); 
     49                                empty($config['options']['password']) or $connection->setPassword($config['options']['password']); 
    4350 
    44                         // Do authentication, if part of the DSN 
    45                         empty($dsn['user']) or $connection->setUsername($dsn['user']); 
    46                         empty($dsn['pass']) or $connection->setPassword($dsn['pass']); 
     51                                // Set the timeout to 5 seconds 
     52                                $connection->setTimeout(5); 
     53                        break; 
     54                        case 'sendmail': 
     55                                // Create a sendmail connection 
     56                                $connection = new Swift_Connection_Sendmail 
     57                                ( 
     58                                        empty($config['options']) ? Swift_Connection_Sendmail::AUTO_DETECT : $config['options'] 
     59                                ); 
    4760 
    48                         // Set the timeout to 5 seconds 
    49                         $connection->setTimeout(5); 
    50                 } 
    51                 elseif (substr($dsn, 0, 8) === 'sendmail') 
    52                 { 
    53                         if (($dsn = substr($dsn, 11)) === '') 
    54                         { 
    55                                 // Auto-detect the paths 
    56                                 $dsn = Swift_Connection_Sendmail::AUTO_DETECT; 
    57                         } 
    58                         else 
    59                         { 
    60                                 // Add the sendmail flags 
    61                                 $dsn.= ' -bs'; 
    62                         } 
    63  
    64                         // Use the sendmail connection 
    65                         $connection = new Swift_Connection_Sendmail($dsn); 
    66  
    67                         // Set the timeout to 5 seconds 
    68                         $connection->setTimeout(5); 
    69                 } 
    70                 else 
    71                 { 
    72                         // Use the native connection 
    73                         $connection = new Swift_Connection_NativeMail; 
     61                                // Set the timeout to 5 seconds 
     62                                $connection->setTimeout(5); 
     63                        break; 
     64                        default: 
     65                                // Use the native connection 
     66                                $connection = new Swift_Connection_NativeMail; 
     67                        break; 
    7468                } 
    7569