Changeset 1903

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

Cleaning up email helper.

Location:
trunk/system
Files:
2 modified

Legend:

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

    r1893 r1903  
    11<?php defined('SYSPATH') or die('No direct script access.'); 
    22/** 
    3  * Mail connection DSN, used with the email helper. 
     3 * SwiftMailer driver, used with the email helper. 
    44 * 
    5  * PHP mail function - native://mail 
    6  * Server sendmail   - sendmail:///path/to/sendmail 
    7  * External SMTP     - smtp://user:password@host:port 
     5 * @see http://www.swiftmailer.org/wikidocs/v3/connections/nativemail 
     6 * @see http://www.swiftmailer.org/wikidocs/v3/connections/sendmail 
     7 * @see http://www.swiftmailer.org/wikidocs/v3/connections/smtp 
     8 * 
     9 * Valid drivers are: native, sendmail, smtp 
    810 */ 
    9 $config['dsn'] = 'native://mail'; 
     11$config['driver'] = 'native'; 
     12 
     13/** 
     14 * Driver options: 
     15 * @param   null    native: no options 
     16 * @param   string  sendmail: executable path, with -bs or equivalent attached 
     17 * @param   array   smtp: hostname, (username), (password), (port) 
     18 */ 
     19$config['options'] = NULL; 
  • 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