1<?php 2 3/** 4 * Swift Mailer mail() connection component 5 * Please read the LICENSE file 6 * @author Chris Corbyn <chris@w3style.co.uk> 7 * @package Swift_Connection 8 * @license GNU Lesser General Public License 9 */ 10 11require_once dirname(__FILE__) . "/../ClassLoader.php"; 12Swift_ClassLoader::load("Swift_ConnectionBase"); 13Swift_ClassLoader::load("Swift_Plugin_MailSend"); 14 15/** 16 * Swift mail() Connection 17 * NOTE: This class is nothing more than a stub. The MailSend plugin does the actual sending. 18 * @package Swift_Connection 19 * @author Chris Corbyn <chris@w3style.co.uk> 20 */ 21class Swift_Connection_NativeMail extends Swift_ConnectionBase 22{ 23 /** 24 * The response the stub will be giving next 25 * @var string Response 26 */ 27 protected $response = "220 Stubbed"; 28 /** 29 * The 5th parameter in mail() is a sprintf() formatted string. 30 * @var string 31 */ 32 protected $pluginParams; 33 /** 34 * An instance of the MailSend plugin. 35 * @var Swift_Plugin_MailSend 36 */ 37 protected $plugin = null; 38 39 /** 40 * Ctor. 41 * @param string The 5th parameter in mail() as a sprintf() formatted string where %s is the sender address. This only comes into effect if safe_mode is OFF. 42 */ 43 public function __construct($additional_params="-oi -f %s") 44 { 45 $this->setAdditionalMailParams($additional_params); 46 } 47 /** 48 * Sets the MailSend plugin in Swift once Swift has connected 49 * @param Swift The current instance of Swift 50 */ 51 public function postConnect(Swift $instance) 52 { 53 $this->plugin = new Swift_Plugin_MailSend($this->getAdditionalMailParams()); 54 $instance->attachPlugin($this->plugin, "_MAIL_SEND"); 55 } 56 /** 57 * Set the 5th parameter in mail() as a sprintf() formatted string. Only used if safe_mode is off. 58 * @param string 59 */ 60 public function setAdditionalMailParams($params) 61 { 62 $this->pluginParams = $params; 63 if ($this->plugin !== null) 64 { 65 $this->plugin->setAdditionalParams($params); 66 } 67 } 68 /** 69 * Get the 5th parameter in mail() as a sprintf() formatted string. 70 * @return string 71 */ 72 public function getAdditionalMailParams() 73 { 74 return $this->pluginParams; 75 } 76 /** 77 * Read a full response from the buffer (this is spoofed if running in -t mode) 78 * @return string 79 * @throws Swift_ConnectionException Upon failure to read 80 */ 81 public function read() 82 { 83 return $this->response; 84 } 85 /** 86 * Set the response this stub will return 87 * @param string The response to send 88 */ 89 public function setResponse($int) 90 { 91 $this->response = $int . " Stubbed"; 92 } 93 /** 94 * Write a command to the process (leave off trailing CRLF) 95 * @param string The command to send 96 * @throws Swift_ConnectionException Upon failure to write 97 */ 98 public function write($command, $end="\r\n") 99 { 100 $command = strtoupper($command); 101 if (strpos($command, " ")) $command = substr($command, 0, strpos($command, " ")); 102 switch ($command) 103 { 104 case "DATA": 105 $this->setResponse(354); 106 break; 107 case "EHLO": case "MAIL": case "RCPT": case "QUIT": case "RSET": default: 108 $this->setResponse(250); 109 break; 110 } 111 } 112 /** 113 * Try to start the connection 114 * @throws Swift_ConnectionException Upon failure to start 115 */ 116 public function start() 117 { 118 $this->response = "220 Stubbed"; 119 } 120 /** 121 * Try to close the connection 122 * @throws Swift_ConnectionException Upon failure to close 123 */ 124 public function stop() 125 { 126 $this->response = "220 Stubbed"; 127 } 128 /** 129 * Check if the process is still alive 130 * @return boolean 131 */ 132 public function isAlive() 133 { 134 return function_exists("mail"); 135 } 136} 137