@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | * Callback function called by cURL for saving the response headers |
| 380 | 380 | * |
| 381 | 381 | * @param resource cURL handle |
| 382 | - * @param string response header (with trailing CRLF) |
|
| 382 | + * @param string string header (with trailing CRLF) |
|
| 383 | 383 | * @return integer number of bytes saved |
| 384 | 384 | * @see HTTP_Request2_Response::parseHeaderLine() |
| 385 | 385 | */ |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | * Callback function called by cURL for saving the response body |
| 441 | 441 | * |
| 442 | 442 | * @param resource cURL handle (not used) |
| 443 | - * @param string part of the response body |
|
| 443 | + * @param string string of the response body |
|
| 444 | 444 | * @return integer number of bytes saved |
| 445 | 445 | * @see HTTP_Request2_Response::appendBody() |
| 446 | 446 | */ |
@@ -60,55 +60,55 @@ discard block |
||
| 60 | 60 | * Mapping of header names to cURL options |
| 61 | 61 | * @var array |
| 62 | 62 | */ |
| 63 | - protected static $headerMap = array( |
|
| 64 | - 'accept-encoding' => CURLOPT_ENCODING, |
|
| 65 | - 'cookie' => CURLOPT_COOKIE, |
|
| 66 | - 'referer' => CURLOPT_REFERER, |
|
| 67 | - 'user-agent' => CURLOPT_USERAGENT |
|
| 68 | - ); |
|
| 63 | + protected static $headerMap = array( |
|
| 64 | + 'accept-encoding' => CURLOPT_ENCODING, |
|
| 65 | + 'cookie' => CURLOPT_COOKIE, |
|
| 66 | + 'referer' => CURLOPT_REFERER, |
|
| 67 | + 'user-agent' => CURLOPT_USERAGENT |
|
| 68 | + ); |
|
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * Mapping of SSL context options to cURL options |
| 72 | 72 | * @var array |
| 73 | 73 | */ |
| 74 | - protected static $sslContextMap = array( |
|
| 75 | - 'ssl_verify_peer' => CURLOPT_SSL_VERIFYPEER, |
|
| 76 | - 'ssl_cafile' => CURLOPT_CAINFO, |
|
| 77 | - 'ssl_capath' => CURLOPT_CAPATH, |
|
| 78 | - 'ssl_local_cert' => CURLOPT_SSLCERT, |
|
| 79 | - 'ssl_passphrase' => CURLOPT_SSLCERTPASSWD |
|
| 74 | + protected static $sslContextMap = array( |
|
| 75 | + 'ssl_verify_peer' => CURLOPT_SSL_VERIFYPEER, |
|
| 76 | + 'ssl_cafile' => CURLOPT_CAINFO, |
|
| 77 | + 'ssl_capath' => CURLOPT_CAPATH, |
|
| 78 | + 'ssl_local_cert' => CURLOPT_SSLCERT, |
|
| 79 | + 'ssl_passphrase' => CURLOPT_SSLCERTPASSWD |
|
| 80 | 80 | ); |
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | 83 | * Response being received |
| 84 | 84 | * @var HTTP_Request2_Response |
| 85 | 85 | */ |
| 86 | - protected $response; |
|
| 86 | + protected $response; |
|
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | 89 | * Whether 'sentHeaders' event was sent to observers |
| 90 | 90 | * @var boolean |
| 91 | 91 | */ |
| 92 | - protected $eventSentHeaders = false; |
|
| 92 | + protected $eventSentHeaders = false; |
|
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | 95 | * Whether 'receivedHeaders' event was sent to observers |
| 96 | 96 | * @var boolean |
| 97 | 97 | */ |
| 98 | - protected $eventReceivedHeaders = false; |
|
| 98 | + protected $eventReceivedHeaders = false; |
|
| 99 | 99 | |
| 100 | 100 | /** |
| 101 | 101 | * Position within request body |
| 102 | 102 | * @var integer |
| 103 | 103 | * @see callbackReadBody() |
| 104 | 104 | */ |
| 105 | - protected $position = 0; |
|
| 105 | + protected $position = 0; |
|
| 106 | 106 | |
| 107 | 107 | /** |
| 108 | 108 | * Information about last transfer, as returned by curl_getinfo() |
| 109 | 109 | * @var array |
| 110 | 110 | */ |
| 111 | - protected $lastInfo; |
|
| 111 | + protected $lastInfo; |
|
| 112 | 112 | |
| 113 | 113 | /** |
| 114 | 114 | * Sends request to the remote server and returns its response |
@@ -117,52 +117,52 @@ discard block |
||
| 117 | 117 | * @return HTTP_Request2_Response |
| 118 | 118 | * @throws HTTP_Request2_Exception |
| 119 | 119 | */ |
| 120 | - public function sendRequest(HTTP_Request2 $request) |
|
| 121 | - { |
|
| 122 | - if (!extension_loaded('curl')) { |
|
| 123 | - throw new HTTP_Request2_Exception('cURL extension not available'); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - $this->request = $request; |
|
| 127 | - $this->response = null; |
|
| 128 | - $this->position = 0; |
|
| 129 | - $this->eventSentHeaders = false; |
|
| 130 | - $this->eventReceivedHeaders = false; |
|
| 131 | - |
|
| 132 | - try { |
|
| 133 | - if (false === curl_exec($ch = $this->createCurlHandle())) { |
|
| 134 | - $errorMessage = 'Error sending request: #' . curl_errno($ch) . |
|
| 135 | - ' ' . curl_error($ch); |
|
| 136 | - } |
|
| 137 | - } catch (Exception $e) { |
|
| 138 | - } |
|
| 139 | - $this->lastInfo = curl_getinfo($ch); |
|
| 140 | - curl_close($ch); |
|
| 141 | - |
|
| 142 | - $response = $this->response; |
|
| 143 | - unset($this->request, $this->requestBody, $this->response); |
|
| 144 | - |
|
| 145 | - if (!empty($e)) { |
|
| 146 | - throw $e; |
|
| 147 | - } elseif (!empty($errorMessage)) { |
|
| 148 | - throw new HTTP_Request2_Exception($errorMessage); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - if (0 < $this->lastInfo['size_download']) { |
|
| 152 | - $request->setLastEvent('receivedBody', $response); |
|
| 153 | - } |
|
| 154 | - return $response; |
|
| 155 | - } |
|
| 120 | + public function sendRequest(HTTP_Request2 $request) |
|
| 121 | + { |
|
| 122 | + if (!extension_loaded('curl')) { |
|
| 123 | + throw new HTTP_Request2_Exception('cURL extension not available'); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + $this->request = $request; |
|
| 127 | + $this->response = null; |
|
| 128 | + $this->position = 0; |
|
| 129 | + $this->eventSentHeaders = false; |
|
| 130 | + $this->eventReceivedHeaders = false; |
|
| 131 | + |
|
| 132 | + try { |
|
| 133 | + if (false === curl_exec($ch = $this->createCurlHandle())) { |
|
| 134 | + $errorMessage = 'Error sending request: #' . curl_errno($ch) . |
|
| 135 | + ' ' . curl_error($ch); |
|
| 136 | + } |
|
| 137 | + } catch (Exception $e) { |
|
| 138 | + } |
|
| 139 | + $this->lastInfo = curl_getinfo($ch); |
|
| 140 | + curl_close($ch); |
|
| 141 | + |
|
| 142 | + $response = $this->response; |
|
| 143 | + unset($this->request, $this->requestBody, $this->response); |
|
| 144 | + |
|
| 145 | + if (!empty($e)) { |
|
| 146 | + throw $e; |
|
| 147 | + } elseif (!empty($errorMessage)) { |
|
| 148 | + throw new HTTP_Request2_Exception($errorMessage); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + if (0 < $this->lastInfo['size_download']) { |
|
| 152 | + $request->setLastEvent('receivedBody', $response); |
|
| 153 | + } |
|
| 154 | + return $response; |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | 157 | /** |
| 158 | 158 | * Returns information about last transfer |
| 159 | 159 | * |
| 160 | 160 | * @return array associative array as returned by curl_getinfo() |
| 161 | 161 | */ |
| 162 | - public function getInfo() |
|
| 163 | - { |
|
| 164 | - return $this->lastInfo; |
|
| 165 | - } |
|
| 162 | + public function getInfo() |
|
| 163 | + { |
|
| 164 | + return $this->lastInfo; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | 167 | /** |
| 168 | 168 | * Creates a new cURL handle and populates it with data from the request |
@@ -170,140 +170,140 @@ discard block |
||
| 170 | 170 | * @return resource a cURL handle, as created by curl_init() |
| 171 | 171 | * @throws HTTP_Request2_Exception |
| 172 | 172 | */ |
| 173 | - protected function createCurlHandle() |
|
| 174 | - { |
|
| 175 | - $ch = curl_init(); |
|
| 176 | - |
|
| 177 | - curl_setopt_array($ch, array( |
|
| 178 | - // setup write callbacks |
|
| 179 | - CURLOPT_HEADERFUNCTION => array($this, 'callbackWriteHeader'), |
|
| 180 | - CURLOPT_WRITEFUNCTION => array($this, 'callbackWriteBody'), |
|
| 181 | - // buffer size |
|
| 182 | - CURLOPT_BUFFERSIZE => $this->request->getConfig('buffer_size'), |
|
| 183 | - // connection timeout |
|
| 184 | - CURLOPT_CONNECTTIMEOUT => $this->request->getConfig('connect_timeout'), |
|
| 185 | - // save full outgoing headers, in case someone is interested |
|
| 186 | - CURLINFO_HEADER_OUT => true, |
|
| 187 | - // request url |
|
| 188 | - CURLOPT_URL => $this->request->getUrl()->getUrl() |
|
| 189 | - )); |
|
| 190 | - |
|
| 191 | - // set up redirects |
|
| 192 | - if (!$this->request->getConfig('follow_redirects')) { |
|
| 193 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); |
|
| 194 | - } else { |
|
| 195 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
|
| 196 | - curl_setopt($ch, CURLOPT_MAXREDIRS, $this->request->getConfig('max_redirects')); |
|
| 197 | - // limit redirects to http(s), works in 5.2.10+ |
|
| 198 | - if (defined('CURLOPT_REDIR_PROTOCOLS')) { |
|
| 199 | - curl_setopt($ch, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); |
|
| 200 | - } |
|
| 201 | - // works sometime after 5.3.0, http://bugs.php.net/bug.php?id=49571 |
|
| 202 | - if ($this->request->getConfig('strict_redirects') && defined('CURLOPT_POSTREDIR ')) { |
|
| 203 | - curl_setopt($ch, CURLOPT_POSTREDIR, 3); |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - // request timeout |
|
| 208 | - if ($timeout = $this->request->getConfig('timeout')) { |
|
| 209 | - curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - // set HTTP version |
|
| 213 | - switch ($this->request->getConfig('protocol_version')) { |
|
| 214 | - case '1.0': |
|
| 215 | - curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
|
| 216 | - break; |
|
| 217 | - case '1.1': |
|
| 218 | - curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - // set request method |
|
| 222 | - switch ($this->request->getMethod()) { |
|
| 223 | - case HTTP_Request2::METHOD_GET: |
|
| 224 | - curl_setopt($ch, CURLOPT_HTTPGET, true); |
|
| 225 | - break; |
|
| 226 | - case HTTP_Request2::METHOD_POST: |
|
| 227 | - curl_setopt($ch, CURLOPT_POST, true); |
|
| 228 | - break; |
|
| 229 | - case HTTP_Request2::METHOD_HEAD: |
|
| 230 | - curl_setopt($ch, CURLOPT_NOBODY, true); |
|
| 231 | - break; |
|
| 232 | - default: |
|
| 233 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->request->getMethod()); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - // set proxy, if needed |
|
| 237 | - if ($host = $this->request->getConfig('proxy_host')) { |
|
| 238 | - if (!($port = $this->request->getConfig('proxy_port'))) { |
|
| 239 | - throw new HTTP_Request2_Exception('Proxy port not provided'); |
|
| 240 | - } |
|
| 241 | - curl_setopt($ch, CURLOPT_PROXY, $host . ':' . $port); |
|
| 242 | - if ($user = $this->request->getConfig('proxy_user')) { |
|
| 243 | - curl_setopt($ch, CURLOPT_PROXYUSERPWD, $user . ':' . |
|
| 244 | - $this->request->getConfig('proxy_password')); |
|
| 245 | - switch ($this->request->getConfig('proxy_auth_scheme')) { |
|
| 246 | - case HTTP_Request2::AUTH_BASIC: |
|
| 247 | - curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); |
|
| 248 | - break; |
|
| 249 | - case HTTP_Request2::AUTH_DIGEST: |
|
| 250 | - curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_DIGEST); |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - // set authentication data |
|
| 256 | - if ($auth = $this->request->getAuth()) { |
|
| 257 | - curl_setopt($ch, CURLOPT_USERPWD, $auth['user'] . ':' . $auth['password']); |
|
| 258 | - switch ($auth['scheme']) { |
|
| 259 | - case HTTP_Request2::AUTH_BASIC: |
|
| 260 | - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); |
|
| 261 | - break; |
|
| 262 | - case HTTP_Request2::AUTH_DIGEST: |
|
| 263 | - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - // set SSL options |
|
| 268 | - if (0 == strcasecmp($this->request->getUrl()->getScheme(), 'https')) { |
|
| 269 | - foreach ($this->request->getConfig() as $name => $value) { |
|
| 270 | - if ('ssl_verify_host' == $name && null !== $value) { |
|
| 271 | - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $value? 2: 0); |
|
| 272 | - } elseif (isset(self::$sslContextMap[$name]) && null !== $value) { |
|
| 273 | - curl_setopt($ch, self::$sslContextMap[$name], $value); |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - $headers = $this->request->getHeaders(); |
|
| 279 | - // make cURL automagically send proper header |
|
| 280 | - if (!isset($headers['accept-encoding'])) { |
|
| 281 | - $headers['accept-encoding'] = ''; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - // set headers having special cURL keys |
|
| 285 | - foreach (self::$headerMap as $name => $option) { |
|
| 286 | - if (isset($headers[$name])) { |
|
| 287 | - curl_setopt($ch, $option, $headers[$name]); |
|
| 288 | - unset($headers[$name]); |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - $this->calculateRequestLength($headers); |
|
| 293 | - if (isset($headers['content-length'])) { |
|
| 294 | - $this->workaroundPhpBug47204($ch, $headers); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - // set headers not having special keys |
|
| 298 | - $headersFmt = array(); |
|
| 299 | - foreach ($headers as $name => $value) { |
|
| 300 | - $canonicalName = implode('-', array_map('ucfirst', explode('-', $name))); |
|
| 301 | - $headersFmt[] = $canonicalName . ': ' . $value; |
|
| 302 | - } |
|
| 303 | - curl_setopt($ch, CURLOPT_HTTPHEADER, $headersFmt); |
|
| 304 | - |
|
| 305 | - return $ch; |
|
| 306 | - } |
|
| 173 | + protected function createCurlHandle() |
|
| 174 | + { |
|
| 175 | + $ch = curl_init(); |
|
| 176 | + |
|
| 177 | + curl_setopt_array($ch, array( |
|
| 178 | + // setup write callbacks |
|
| 179 | + CURLOPT_HEADERFUNCTION => array($this, 'callbackWriteHeader'), |
|
| 180 | + CURLOPT_WRITEFUNCTION => array($this, 'callbackWriteBody'), |
|
| 181 | + // buffer size |
|
| 182 | + CURLOPT_BUFFERSIZE => $this->request->getConfig('buffer_size'), |
|
| 183 | + // connection timeout |
|
| 184 | + CURLOPT_CONNECTTIMEOUT => $this->request->getConfig('connect_timeout'), |
|
| 185 | + // save full outgoing headers, in case someone is interested |
|
| 186 | + CURLINFO_HEADER_OUT => true, |
|
| 187 | + // request url |
|
| 188 | + CURLOPT_URL => $this->request->getUrl()->getUrl() |
|
| 189 | + )); |
|
| 190 | + |
|
| 191 | + // set up redirects |
|
| 192 | + if (!$this->request->getConfig('follow_redirects')) { |
|
| 193 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); |
|
| 194 | + } else { |
|
| 195 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
|
| 196 | + curl_setopt($ch, CURLOPT_MAXREDIRS, $this->request->getConfig('max_redirects')); |
|
| 197 | + // limit redirects to http(s), works in 5.2.10+ |
|
| 198 | + if (defined('CURLOPT_REDIR_PROTOCOLS')) { |
|
| 199 | + curl_setopt($ch, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); |
|
| 200 | + } |
|
| 201 | + // works sometime after 5.3.0, http://bugs.php.net/bug.php?id=49571 |
|
| 202 | + if ($this->request->getConfig('strict_redirects') && defined('CURLOPT_POSTREDIR ')) { |
|
| 203 | + curl_setopt($ch, CURLOPT_POSTREDIR, 3); |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + // request timeout |
|
| 208 | + if ($timeout = $this->request->getConfig('timeout')) { |
|
| 209 | + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + // set HTTP version |
|
| 213 | + switch ($this->request->getConfig('protocol_version')) { |
|
| 214 | + case '1.0': |
|
| 215 | + curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
|
| 216 | + break; |
|
| 217 | + case '1.1': |
|
| 218 | + curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + // set request method |
|
| 222 | + switch ($this->request->getMethod()) { |
|
| 223 | + case HTTP_Request2::METHOD_GET: |
|
| 224 | + curl_setopt($ch, CURLOPT_HTTPGET, true); |
|
| 225 | + break; |
|
| 226 | + case HTTP_Request2::METHOD_POST: |
|
| 227 | + curl_setopt($ch, CURLOPT_POST, true); |
|
| 228 | + break; |
|
| 229 | + case HTTP_Request2::METHOD_HEAD: |
|
| 230 | + curl_setopt($ch, CURLOPT_NOBODY, true); |
|
| 231 | + break; |
|
| 232 | + default: |
|
| 233 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->request->getMethod()); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + // set proxy, if needed |
|
| 237 | + if ($host = $this->request->getConfig('proxy_host')) { |
|
| 238 | + if (!($port = $this->request->getConfig('proxy_port'))) { |
|
| 239 | + throw new HTTP_Request2_Exception('Proxy port not provided'); |
|
| 240 | + } |
|
| 241 | + curl_setopt($ch, CURLOPT_PROXY, $host . ':' . $port); |
|
| 242 | + if ($user = $this->request->getConfig('proxy_user')) { |
|
| 243 | + curl_setopt($ch, CURLOPT_PROXYUSERPWD, $user . ':' . |
|
| 244 | + $this->request->getConfig('proxy_password')); |
|
| 245 | + switch ($this->request->getConfig('proxy_auth_scheme')) { |
|
| 246 | + case HTTP_Request2::AUTH_BASIC: |
|
| 247 | + curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); |
|
| 248 | + break; |
|
| 249 | + case HTTP_Request2::AUTH_DIGEST: |
|
| 250 | + curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_DIGEST); |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + // set authentication data |
|
| 256 | + if ($auth = $this->request->getAuth()) { |
|
| 257 | + curl_setopt($ch, CURLOPT_USERPWD, $auth['user'] . ':' . $auth['password']); |
|
| 258 | + switch ($auth['scheme']) { |
|
| 259 | + case HTTP_Request2::AUTH_BASIC: |
|
| 260 | + curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); |
|
| 261 | + break; |
|
| 262 | + case HTTP_Request2::AUTH_DIGEST: |
|
| 263 | + curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + // set SSL options |
|
| 268 | + if (0 == strcasecmp($this->request->getUrl()->getScheme(), 'https')) { |
|
| 269 | + foreach ($this->request->getConfig() as $name => $value) { |
|
| 270 | + if ('ssl_verify_host' == $name && null !== $value) { |
|
| 271 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $value? 2: 0); |
|
| 272 | + } elseif (isset(self::$sslContextMap[$name]) && null !== $value) { |
|
| 273 | + curl_setopt($ch, self::$sslContextMap[$name], $value); |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + $headers = $this->request->getHeaders(); |
|
| 279 | + // make cURL automagically send proper header |
|
| 280 | + if (!isset($headers['accept-encoding'])) { |
|
| 281 | + $headers['accept-encoding'] = ''; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + // set headers having special cURL keys |
|
| 285 | + foreach (self::$headerMap as $name => $option) { |
|
| 286 | + if (isset($headers[$name])) { |
|
| 287 | + curl_setopt($ch, $option, $headers[$name]); |
|
| 288 | + unset($headers[$name]); |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + $this->calculateRequestLength($headers); |
|
| 293 | + if (isset($headers['content-length'])) { |
|
| 294 | + $this->workaroundPhpBug47204($ch, $headers); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + // set headers not having special keys |
|
| 298 | + $headersFmt = array(); |
|
| 299 | + foreach ($headers as $name => $value) { |
|
| 300 | + $canonicalName = implode('-', array_map('ucfirst', explode('-', $name))); |
|
| 301 | + $headersFmt[] = $canonicalName . ': ' . $value; |
|
| 302 | + } |
|
| 303 | + curl_setopt($ch, CURLOPT_HTTPHEADER, $headersFmt); |
|
| 304 | + |
|
| 305 | + return $ch; |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | 308 | /** |
| 309 | 309 | * Workaround for PHP bug #47204 that prevents rewinding request body |
@@ -315,32 +315,32 @@ discard block |
||
| 315 | 315 | * @param resource cURL handle |
| 316 | 316 | * @param array Request headers |
| 317 | 317 | */ |
| 318 | - protected function workaroundPhpBug47204($ch, &$headers) |
|
| 319 | - { |
|
| 320 | - // no redirects, no digest auth -> probably no rewind needed |
|
| 321 | - if (!$this->request->getConfig('follow_redirects') |
|
| 322 | - && (!($auth = $this->request->getAuth()) |
|
| 323 | - || HTTP_Request2::AUTH_DIGEST != $auth['scheme']) |
|
| 324 | - ) { |
|
| 325 | - curl_setopt($ch, CURLOPT_READFUNCTION, array($this, 'callbackReadBody')); |
|
| 326 | - |
|
| 327 | - // rewind may be needed, read the whole body into memory |
|
| 328 | - } else { |
|
| 329 | - if ($this->requestBody instanceof HTTP_Request2_MultipartBody) { |
|
| 330 | - $this->requestBody = $this->requestBody->__toString(); |
|
| 331 | - |
|
| 332 | - } elseif (is_resource($this->requestBody)) { |
|
| 333 | - $fp = $this->requestBody; |
|
| 334 | - $this->requestBody = ''; |
|
| 335 | - while (!feof($fp)) { |
|
| 336 | - $this->requestBody .= fread($fp, 16384); |
|
| 337 | - } |
|
| 338 | - } |
|
| 339 | - // curl hangs up if content-length is present |
|
| 340 | - unset($headers['content-length']); |
|
| 341 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $this->requestBody); |
|
| 342 | - } |
|
| 343 | - } |
|
| 318 | + protected function workaroundPhpBug47204($ch, &$headers) |
|
| 319 | + { |
|
| 320 | + // no redirects, no digest auth -> probably no rewind needed |
|
| 321 | + if (!$this->request->getConfig('follow_redirects') |
|
| 322 | + && (!($auth = $this->request->getAuth()) |
|
| 323 | + || HTTP_Request2::AUTH_DIGEST != $auth['scheme']) |
|
| 324 | + ) { |
|
| 325 | + curl_setopt($ch, CURLOPT_READFUNCTION, array($this, 'callbackReadBody')); |
|
| 326 | + |
|
| 327 | + // rewind may be needed, read the whole body into memory |
|
| 328 | + } else { |
|
| 329 | + if ($this->requestBody instanceof HTTP_Request2_MultipartBody) { |
|
| 330 | + $this->requestBody = $this->requestBody->__toString(); |
|
| 331 | + |
|
| 332 | + } elseif (is_resource($this->requestBody)) { |
|
| 333 | + $fp = $this->requestBody; |
|
| 334 | + $this->requestBody = ''; |
|
| 335 | + while (!feof($fp)) { |
|
| 336 | + $this->requestBody .= fread($fp, 16384); |
|
| 337 | + } |
|
| 338 | + } |
|
| 339 | + // curl hangs up if content-length is present |
|
| 340 | + unset($headers['content-length']); |
|
| 341 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $this->requestBody); |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | 345 | /** |
| 346 | 346 | * Callback function called by cURL for reading the request body |
@@ -350,30 +350,30 @@ discard block |
||
| 350 | 350 | * @param integer maximum length of data to return |
| 351 | 351 | * @return string part of the request body, up to $length bytes |
| 352 | 352 | */ |
| 353 | - protected function callbackReadBody($ch, $fd, $length) |
|
| 354 | - { |
|
| 355 | - if (!$this->eventSentHeaders) { |
|
| 356 | - $this->request->setLastEvent( |
|
| 357 | - 'sentHeaders', curl_getinfo($ch, CURLINFO_HEADER_OUT) |
|
| 358 | - ); |
|
| 359 | - $this->eventSentHeaders = true; |
|
| 360 | - } |
|
| 361 | - if (in_array($this->request->getMethod(), self::$bodyDisallowed) || |
|
| 362 | - 0 == $this->contentLength || $this->position >= $this->contentLength |
|
| 363 | - ) { |
|
| 364 | - return ''; |
|
| 365 | - } |
|
| 366 | - if (is_string($this->requestBody)) { |
|
| 367 | - $string = substr($this->requestBody, $this->position, $length); |
|
| 368 | - } elseif (is_resource($this->requestBody)) { |
|
| 369 | - $string = fread($this->requestBody, $length); |
|
| 370 | - } else { |
|
| 371 | - $string = $this->requestBody->read($length); |
|
| 372 | - } |
|
| 373 | - $this->request->setLastEvent('sentBodyPart', strlen($string)); |
|
| 374 | - $this->position += strlen($string); |
|
| 375 | - return $string; |
|
| 376 | - } |
|
| 353 | + protected function callbackReadBody($ch, $fd, $length) |
|
| 354 | + { |
|
| 355 | + if (!$this->eventSentHeaders) { |
|
| 356 | + $this->request->setLastEvent( |
|
| 357 | + 'sentHeaders', curl_getinfo($ch, CURLINFO_HEADER_OUT) |
|
| 358 | + ); |
|
| 359 | + $this->eventSentHeaders = true; |
|
| 360 | + } |
|
| 361 | + if (in_array($this->request->getMethod(), self::$bodyDisallowed) || |
|
| 362 | + 0 == $this->contentLength || $this->position >= $this->contentLength |
|
| 363 | + ) { |
|
| 364 | + return ''; |
|
| 365 | + } |
|
| 366 | + if (is_string($this->requestBody)) { |
|
| 367 | + $string = substr($this->requestBody, $this->position, $length); |
|
| 368 | + } elseif (is_resource($this->requestBody)) { |
|
| 369 | + $string = fread($this->requestBody, $length); |
|
| 370 | + } else { |
|
| 371 | + $string = $this->requestBody->read($length); |
|
| 372 | + } |
|
| 373 | + $this->request->setLastEvent('sentBodyPart', strlen($string)); |
|
| 374 | + $this->position += strlen($string); |
|
| 375 | + return $string; |
|
| 376 | + } |
|
| 377 | 377 | |
| 378 | 378 | /** |
| 379 | 379 | * Callback function called by cURL for saving the response headers |
@@ -383,58 +383,58 @@ discard block |
||
| 383 | 383 | * @return integer number of bytes saved |
| 384 | 384 | * @see HTTP_Request2_Response::parseHeaderLine() |
| 385 | 385 | */ |
| 386 | - protected function callbackWriteHeader($ch, $string) |
|
| 387 | - { |
|
| 388 | - // we may receive a second set of headers if doing e.g. digest auth |
|
| 389 | - if ($this->eventReceivedHeaders || !$this->eventSentHeaders) { |
|
| 390 | - // don't bother with 100-Continue responses (bug #15785) |
|
| 391 | - if (!$this->eventSentHeaders || |
|
| 392 | - $this->response->getStatus() >= 200 |
|
| 393 | - ) { |
|
| 394 | - $this->request->setLastEvent( |
|
| 395 | - 'sentHeaders', curl_getinfo($ch, CURLINFO_HEADER_OUT) |
|
| 396 | - ); |
|
| 397 | - } |
|
| 398 | - $upload = curl_getinfo($ch, CURLINFO_SIZE_UPLOAD); |
|
| 399 | - // if body wasn't read by a callback, send event with total body size |
|
| 400 | - if ($upload > $this->position) { |
|
| 401 | - $this->request->setLastEvent( |
|
| 402 | - 'sentBodyPart', $upload - $this->position |
|
| 403 | - ); |
|
| 404 | - $this->position = $upload; |
|
| 405 | - } |
|
| 406 | - $this->eventSentHeaders = true; |
|
| 407 | - // we'll need a new response object |
|
| 408 | - if ($this->eventReceivedHeaders) { |
|
| 409 | - $this->eventReceivedHeaders = false; |
|
| 410 | - $this->response = null; |
|
| 411 | - } |
|
| 412 | - } |
|
| 413 | - if (empty($this->response)) { |
|
| 414 | - $this->response = new HTTP_Request2_Response($string, false); |
|
| 415 | - } else { |
|
| 416 | - $this->response->parseHeaderLine($string); |
|
| 417 | - if ('' == trim($string)) { |
|
| 418 | - // don't bother with 100-Continue responses (bug #15785) |
|
| 419 | - if (200 <= $this->response->getStatus()) { |
|
| 420 | - $this->request->setLastEvent('receivedHeaders', $this->response); |
|
| 421 | - } |
|
| 422 | - // for versions lower than 5.2.10, check the redirection URL protocol |
|
| 423 | - if ($this->request->getConfig('follow_redirects') && !defined('CURLOPT_REDIR_PROTOCOLS') |
|
| 424 | - && $this->response->isRedirect() |
|
| 425 | - ) { |
|
| 426 | - $redirectUrl = new Net_URL2($this->response->getHeader('location')); |
|
| 427 | - if ($redirectUrl->isAbsolute() |
|
| 428 | - && !in_array($redirectUrl->getScheme(), array('http', 'https')) |
|
| 429 | - ) { |
|
| 430 | - return -1; |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - $this->eventReceivedHeaders = true; |
|
| 434 | - } |
|
| 435 | - } |
|
| 436 | - return strlen($string); |
|
| 437 | - } |
|
| 386 | + protected function callbackWriteHeader($ch, $string) |
|
| 387 | + { |
|
| 388 | + // we may receive a second set of headers if doing e.g. digest auth |
|
| 389 | + if ($this->eventReceivedHeaders || !$this->eventSentHeaders) { |
|
| 390 | + // don't bother with 100-Continue responses (bug #15785) |
|
| 391 | + if (!$this->eventSentHeaders || |
|
| 392 | + $this->response->getStatus() >= 200 |
|
| 393 | + ) { |
|
| 394 | + $this->request->setLastEvent( |
|
| 395 | + 'sentHeaders', curl_getinfo($ch, CURLINFO_HEADER_OUT) |
|
| 396 | + ); |
|
| 397 | + } |
|
| 398 | + $upload = curl_getinfo($ch, CURLINFO_SIZE_UPLOAD); |
|
| 399 | + // if body wasn't read by a callback, send event with total body size |
|
| 400 | + if ($upload > $this->position) { |
|
| 401 | + $this->request->setLastEvent( |
|
| 402 | + 'sentBodyPart', $upload - $this->position |
|
| 403 | + ); |
|
| 404 | + $this->position = $upload; |
|
| 405 | + } |
|
| 406 | + $this->eventSentHeaders = true; |
|
| 407 | + // we'll need a new response object |
|
| 408 | + if ($this->eventReceivedHeaders) { |
|
| 409 | + $this->eventReceivedHeaders = false; |
|
| 410 | + $this->response = null; |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | + if (empty($this->response)) { |
|
| 414 | + $this->response = new HTTP_Request2_Response($string, false); |
|
| 415 | + } else { |
|
| 416 | + $this->response->parseHeaderLine($string); |
|
| 417 | + if ('' == trim($string)) { |
|
| 418 | + // don't bother with 100-Continue responses (bug #15785) |
|
| 419 | + if (200 <= $this->response->getStatus()) { |
|
| 420 | + $this->request->setLastEvent('receivedHeaders', $this->response); |
|
| 421 | + } |
|
| 422 | + // for versions lower than 5.2.10, check the redirection URL protocol |
|
| 423 | + if ($this->request->getConfig('follow_redirects') && !defined('CURLOPT_REDIR_PROTOCOLS') |
|
| 424 | + && $this->response->isRedirect() |
|
| 425 | + ) { |
|
| 426 | + $redirectUrl = new Net_URL2($this->response->getHeader('location')); |
|
| 427 | + if ($redirectUrl->isAbsolute() |
|
| 428 | + && !in_array($redirectUrl->getScheme(), array('http', 'https')) |
|
| 429 | + ) { |
|
| 430 | + return -1; |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + $this->eventReceivedHeaders = true; |
|
| 434 | + } |
|
| 435 | + } |
|
| 436 | + return strlen($string); |
|
| 437 | + } |
|
| 438 | 438 | |
| 439 | 439 | /** |
| 440 | 440 | * Callback function called by cURL for saving the response body |
@@ -444,18 +444,18 @@ discard block |
||
| 444 | 444 | * @return integer number of bytes saved |
| 445 | 445 | * @see HTTP_Request2_Response::appendBody() |
| 446 | 446 | */ |
| 447 | - protected function callbackWriteBody($ch, $string) |
|
| 448 | - { |
|
| 449 | - // cURL calls WRITEFUNCTION callback without calling HEADERFUNCTION if |
|
| 450 | - // response doesn't start with proper HTTP status line (see bug #15716) |
|
| 451 | - if (empty($this->response)) { |
|
| 452 | - throw new HTTP_Request2_Exception("Malformed response: {$string}"); |
|
| 453 | - } |
|
| 454 | - if ($this->request->getConfig('store_body')) { |
|
| 455 | - $this->response->appendBody($string); |
|
| 456 | - } |
|
| 457 | - $this->request->setLastEvent('receivedBodyPart', $string); |
|
| 458 | - return strlen($string); |
|
| 459 | - } |
|
| 447 | + protected function callbackWriteBody($ch, $string) |
|
| 448 | + { |
|
| 449 | + // cURL calls WRITEFUNCTION callback without calling HEADERFUNCTION if |
|
| 450 | + // response doesn't start with proper HTTP status line (see bug #15716) |
|
| 451 | + if (empty($this->response)) { |
|
| 452 | + throw new HTTP_Request2_Exception("Malformed response: {$string}"); |
|
| 453 | + } |
|
| 454 | + if ($this->request->getConfig('store_body')) { |
|
| 455 | + $this->response->appendBody($string); |
|
| 456 | + } |
|
| 457 | + $this->request->setLastEvent('receivedBodyPart', $string); |
|
| 458 | + return strlen($string); |
|
| 459 | + } |
|
| 460 | 460 | } |
| 461 | 461 | ?> |
@@ -131,8 +131,8 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | try { |
| 133 | 133 | if (false === curl_exec($ch = $this->createCurlHandle())) { |
| 134 | - $errorMessage = 'Error sending request: #' . curl_errno($ch) . |
|
| 135 | - ' ' . curl_error($ch); |
|
| 134 | + $errorMessage = 'Error sending request: #'.curl_errno($ch). |
|
| 135 | + ' '.curl_error($ch); |
|
| 136 | 136 | } |
| 137 | 137 | } catch (Exception $e) { |
| 138 | 138 | } |
@@ -238,9 +238,9 @@ discard block |
||
| 238 | 238 | if (!($port = $this->request->getConfig('proxy_port'))) { |
| 239 | 239 | throw new HTTP_Request2_Exception('Proxy port not provided'); |
| 240 | 240 | } |
| 241 | - curl_setopt($ch, CURLOPT_PROXY, $host . ':' . $port); |
|
| 241 | + curl_setopt($ch, CURLOPT_PROXY, $host.':'.$port); |
|
| 242 | 242 | if ($user = $this->request->getConfig('proxy_user')) { |
| 243 | - curl_setopt($ch, CURLOPT_PROXYUSERPWD, $user . ':' . |
|
| 243 | + curl_setopt($ch, CURLOPT_PROXYUSERPWD, $user.':'. |
|
| 244 | 244 | $this->request->getConfig('proxy_password')); |
| 245 | 245 | switch ($this->request->getConfig('proxy_auth_scheme')) { |
| 246 | 246 | case HTTP_Request2::AUTH_BASIC: |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | |
| 255 | 255 | // set authentication data |
| 256 | 256 | if ($auth = $this->request->getAuth()) { |
| 257 | - curl_setopt($ch, CURLOPT_USERPWD, $auth['user'] . ':' . $auth['password']); |
|
| 257 | + curl_setopt($ch, CURLOPT_USERPWD, $auth['user'].':'.$auth['password']); |
|
| 258 | 258 | switch ($auth['scheme']) { |
| 259 | 259 | case HTTP_Request2::AUTH_BASIC: |
| 260 | 260 | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | if (0 == strcasecmp($this->request->getUrl()->getScheme(), 'https')) { |
| 269 | 269 | foreach ($this->request->getConfig() as $name => $value) { |
| 270 | 270 | if ('ssl_verify_host' == $name && null !== $value) { |
| 271 | - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $value? 2: 0); |
|
| 271 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $value ? 2 : 0); |
|
| 272 | 272 | } elseif (isset(self::$sslContextMap[$name]) && null !== $value) { |
| 273 | 273 | curl_setopt($ch, self::$sslContextMap[$name], $value); |
| 274 | 274 | } |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | $headersFmt = array(); |
| 299 | 299 | foreach ($headers as $name => $value) { |
| 300 | 300 | $canonicalName = implode('-', array_map('ucfirst', explode('-', $name))); |
| 301 | - $headersFmt[] = $canonicalName . ': ' . $value; |
|
| 301 | + $headersFmt[] = $canonicalName.': '.$value; |
|
| 302 | 302 | } |
| 303 | 303 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headersFmt); |
| 304 | 304 | |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | * Returns the user part of the userinfo part (the part preceding the first |
| 230 | 230 | * ":"), or false if there is no userinfo part. |
| 231 | 231 | * |
| 232 | - * @return string|bool |
|
| 232 | + * @return string|false |
|
| 233 | 233 | */ |
| 234 | 234 | public function getUser() |
| 235 | 235 | { |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | * contain "@" in front of the hostname) or the userinfo part does not |
| 245 | 245 | * contain ":". |
| 246 | 246 | * |
| 247 | - * @return string|bool |
|
| 247 | + * @return string|false |
|
| 248 | 248 | */ |
| 249 | 249 | public function getPassword() |
| 250 | 250 | { |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | * @param string|bool $userinfo userinfo or username |
| 272 | 272 | * @param string|bool $password optional password, or false |
| 273 | 273 | * |
| 274 | - * @return void |
|
| 274 | + * @return Net_URL2 |
|
| 275 | 275 | */ |
| 276 | 276 | public function setUserinfo($userinfo, $password = false) |
| 277 | 277 | { |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | * Returns the authority part, i.e. [ userinfo "@" ] host [ ":" port ], or |
| 334 | 334 | * false if there is no authority. |
| 335 | 335 | * |
| 336 | - * @return string|bool |
|
| 336 | + * @return false|string |
|
| 337 | 337 | */ |
| 338 | 338 | public function getAuthority() |
| 339 | 339 | { |
@@ -360,11 +360,11 @@ discard block |
||
| 360 | 360 | * Sets the authority part, i.e. [ userinfo "@" ] host [ ":" port ]. Specify |
| 361 | 361 | * false if there is no authority. |
| 362 | 362 | * |
| 363 | - * @param string|false $authority a hostname or an IP addresse, possibly |
|
| 363 | + * @param string|boolean $authority a hostname or an IP addresse, possibly |
|
| 364 | 364 | * with userinfo prefixed and port number |
| 365 | 365 | * appended, e.g. "foo:[email protected]:81". |
| 366 | 366 | * |
| 367 | - * @return void |
|
| 367 | + * @return Net_URL2 |
|
| 368 | 368 | */ |
| 369 | 369 | public function setAuthority($authority) |
| 370 | 370 | { |
@@ -517,7 +517,7 @@ discard block |
||
| 517 | 517 | * |
| 518 | 518 | * @param array $array (name => value) array |
| 519 | 519 | * |
| 520 | - * @return void |
|
| 520 | + * @return Net_URL2 |
|
| 521 | 521 | */ |
| 522 | 522 | public function setQueryVariables(array $array) |
| 523 | 523 | { |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | * @param string $name variable name |
| 553 | 553 | * @param mixed $value variable value |
| 554 | 554 | * |
| 555 | - * @return array |
|
| 555 | + * @return Net_URL2 |
|
| 556 | 556 | */ |
| 557 | 557 | public function setQueryVariable($name, $value) |
| 558 | 558 | { |
@@ -689,7 +689,7 @@ discard block |
||
| 689 | 689 | * Returns an Net_URL2 instance representing an absolute URL relative to |
| 690 | 690 | * this URL. |
| 691 | 691 | * |
| 692 | - * @param Net_URL2|string $reference relative URL |
|
| 692 | + * @param Net_URL2 $reference relative URL |
|
| 693 | 693 | * |
| 694 | 694 | * @return Net_URL2 |
| 695 | 695 | */ |
@@ -826,7 +826,7 @@ discard block |
||
| 826 | 826 | * Returns a Net_URL2 instance representing the canonical URL of the |
| 827 | 827 | * currently executing PHP script. |
| 828 | 828 | * |
| 829 | - * @return string |
|
| 829 | + * @return Net_URL2 |
|
| 830 | 830 | */ |
| 831 | 831 | public static function getCanonical() |
| 832 | 832 | { |
@@ -884,7 +884,7 @@ discard block |
||
| 884 | 884 | * |
| 885 | 885 | * @param string $optionName The name of the option to retrieve |
| 886 | 886 | * |
| 887 | - * @return mixed |
|
| 887 | + * @return string |
|
| 888 | 888 | */ |
| 889 | 889 | function getOption($optionName) |
| 890 | 890 | { |
@@ -56,839 +56,839 @@ |
||
| 56 | 56 | */ |
| 57 | 57 | class Net_URL2 |
| 58 | 58 | { |
| 59 | - /** |
|
| 60 | - * Do strict parsing in resolve() (see RFC 3986, section 5.2.2). Default |
|
| 61 | - * is true. |
|
| 62 | - */ |
|
| 63 | - const OPTION_STRICT = 'strict'; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Represent arrays in query using PHP's [] notation. Default is true. |
|
| 67 | - */ |
|
| 68 | - const OPTION_USE_BRACKETS = 'use_brackets'; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * URL-encode query variable keys. Default is true. |
|
| 72 | - */ |
|
| 73 | - const OPTION_ENCODE_KEYS = 'encode_keys'; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Query variable separators when parsing the query string. Every character |
|
| 77 | - * is considered a separator. Default is "&". |
|
| 78 | - */ |
|
| 79 | - const OPTION_SEPARATOR_INPUT = 'input_separator'; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Query variable separator used when generating the query string. Default |
|
| 83 | - * is "&". |
|
| 84 | - */ |
|
| 85 | - const OPTION_SEPARATOR_OUTPUT = 'output_separator'; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Default options corresponds to how PHP handles $_GET. |
|
| 89 | - */ |
|
| 90 | - private $_options = array( |
|
| 91 | - self::OPTION_STRICT => true, |
|
| 92 | - self::OPTION_USE_BRACKETS => true, |
|
| 93 | - self::OPTION_ENCODE_KEYS => true, |
|
| 94 | - self::OPTION_SEPARATOR_INPUT => '&', |
|
| 95 | - self::OPTION_SEPARATOR_OUTPUT => '&', |
|
| 96 | - ); |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @var string|bool |
|
| 100 | - */ |
|
| 101 | - private $_scheme = false; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @var string|bool |
|
| 105 | - */ |
|
| 106 | - private $_userinfo = false; |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @var string|bool |
|
| 110 | - */ |
|
| 111 | - private $_host = false; |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @var string|bool |
|
| 115 | - */ |
|
| 116 | - private $_port = false; |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @var string |
|
| 120 | - */ |
|
| 121 | - private $_path = ''; |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @var string|bool |
|
| 125 | - */ |
|
| 126 | - private $_query = false; |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @var string|bool |
|
| 130 | - */ |
|
| 131 | - private $_fragment = false; |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Constructor. |
|
| 135 | - * |
|
| 136 | - * @param string $url an absolute or relative URL |
|
| 137 | - * @param array $options an array of OPTION_xxx constants |
|
| 138 | - */ |
|
| 139 | - public function __construct($url, array $options = array()) |
|
| 140 | - { |
|
| 141 | - foreach ($options as $optionName => $value) { |
|
| 142 | - if (array_key_exists($optionName, $this->_options)) { |
|
| 143 | - $this->_options[$optionName] = $value; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - // The regular expression is copied verbatim from RFC 3986, appendix B. |
|
| 148 | - // The expression does not validate the URL but matches any string. |
|
| 149 | - preg_match('!^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?!', |
|
| 150 | - $url, |
|
| 151 | - $matches); |
|
| 152 | - |
|
| 153 | - // "path" is always present (possibly as an empty string); the rest |
|
| 154 | - // are optional. |
|
| 155 | - $this->_scheme = !empty($matches[1]) ? $matches[2] : false; |
|
| 156 | - $this->setAuthority(!empty($matches[3]) ? $matches[4] : false); |
|
| 157 | - $this->_path = $matches[5]; |
|
| 158 | - $this->_query = !empty($matches[6]) ? $matches[7] : false; |
|
| 159 | - $this->_fragment = !empty($matches[8]) ? $matches[9] : false; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Magic Setter. |
|
| 164 | - * |
|
| 165 | - * This method will magically set the value of a private variable ($var) |
|
| 166 | - * with the value passed as the args |
|
| 167 | - * |
|
| 168 | - * @param string $var The private variable to set. |
|
| 169 | - * @param mixed $arg An argument of any type. |
|
| 170 | - * @return void |
|
| 171 | - */ |
|
| 172 | - public function __set($var, $arg) |
|
| 173 | - { |
|
| 174 | - $method = 'set' . $var; |
|
| 175 | - if (method_exists($this, $method)) { |
|
| 176 | - $this->$method($arg); |
|
| 177 | - } |
|
| 178 | - } |
|
| 59 | + /** |
|
| 60 | + * Do strict parsing in resolve() (see RFC 3986, section 5.2.2). Default |
|
| 61 | + * is true. |
|
| 62 | + */ |
|
| 63 | + const OPTION_STRICT = 'strict'; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Represent arrays in query using PHP's [] notation. Default is true. |
|
| 67 | + */ |
|
| 68 | + const OPTION_USE_BRACKETS = 'use_brackets'; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * URL-encode query variable keys. Default is true. |
|
| 72 | + */ |
|
| 73 | + const OPTION_ENCODE_KEYS = 'encode_keys'; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Query variable separators when parsing the query string. Every character |
|
| 77 | + * is considered a separator. Default is "&". |
|
| 78 | + */ |
|
| 79 | + const OPTION_SEPARATOR_INPUT = 'input_separator'; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Query variable separator used when generating the query string. Default |
|
| 83 | + * is "&". |
|
| 84 | + */ |
|
| 85 | + const OPTION_SEPARATOR_OUTPUT = 'output_separator'; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Default options corresponds to how PHP handles $_GET. |
|
| 89 | + */ |
|
| 90 | + private $_options = array( |
|
| 91 | + self::OPTION_STRICT => true, |
|
| 92 | + self::OPTION_USE_BRACKETS => true, |
|
| 93 | + self::OPTION_ENCODE_KEYS => true, |
|
| 94 | + self::OPTION_SEPARATOR_INPUT => '&', |
|
| 95 | + self::OPTION_SEPARATOR_OUTPUT => '&', |
|
| 96 | + ); |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @var string|bool |
|
| 100 | + */ |
|
| 101 | + private $_scheme = false; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @var string|bool |
|
| 105 | + */ |
|
| 106 | + private $_userinfo = false; |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @var string|bool |
|
| 110 | + */ |
|
| 111 | + private $_host = false; |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @var string|bool |
|
| 115 | + */ |
|
| 116 | + private $_port = false; |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @var string |
|
| 120 | + */ |
|
| 121 | + private $_path = ''; |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @var string|bool |
|
| 125 | + */ |
|
| 126 | + private $_query = false; |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @var string|bool |
|
| 130 | + */ |
|
| 131 | + private $_fragment = false; |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Constructor. |
|
| 135 | + * |
|
| 136 | + * @param string $url an absolute or relative URL |
|
| 137 | + * @param array $options an array of OPTION_xxx constants |
|
| 138 | + */ |
|
| 139 | + public function __construct($url, array $options = array()) |
|
| 140 | + { |
|
| 141 | + foreach ($options as $optionName => $value) { |
|
| 142 | + if (array_key_exists($optionName, $this->_options)) { |
|
| 143 | + $this->_options[$optionName] = $value; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + // The regular expression is copied verbatim from RFC 3986, appendix B. |
|
| 148 | + // The expression does not validate the URL but matches any string. |
|
| 149 | + preg_match('!^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?!', |
|
| 150 | + $url, |
|
| 151 | + $matches); |
|
| 152 | + |
|
| 153 | + // "path" is always present (possibly as an empty string); the rest |
|
| 154 | + // are optional. |
|
| 155 | + $this->_scheme = !empty($matches[1]) ? $matches[2] : false; |
|
| 156 | + $this->setAuthority(!empty($matches[3]) ? $matches[4] : false); |
|
| 157 | + $this->_path = $matches[5]; |
|
| 158 | + $this->_query = !empty($matches[6]) ? $matches[7] : false; |
|
| 159 | + $this->_fragment = !empty($matches[8]) ? $matches[9] : false; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Magic Setter. |
|
| 164 | + * |
|
| 165 | + * This method will magically set the value of a private variable ($var) |
|
| 166 | + * with the value passed as the args |
|
| 167 | + * |
|
| 168 | + * @param string $var The private variable to set. |
|
| 169 | + * @param mixed $arg An argument of any type. |
|
| 170 | + * @return void |
|
| 171 | + */ |
|
| 172 | + public function __set($var, $arg) |
|
| 173 | + { |
|
| 174 | + $method = 'set' . $var; |
|
| 175 | + if (method_exists($this, $method)) { |
|
| 176 | + $this->$method($arg); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * Magic Getter. |
|
| 182 | - * |
|
| 183 | - * This is the magic get method to retrieve the private variable |
|
| 184 | - * that was set by either __set() or it's setter... |
|
| 185 | - * |
|
| 186 | - * @param string $var The property name to retrieve. |
|
| 187 | - * @return mixed $this->$var Either a boolean false if the |
|
| 188 | - * property is not set or the value |
|
| 189 | - * of the private property. |
|
| 190 | - */ |
|
| 191 | - public function __get($var) |
|
| 192 | - { |
|
| 193 | - $method = 'get' . $var; |
|
| 194 | - if (method_exists($this, $method)) { |
|
| 195 | - return $this->$method(); |
|
| 196 | - } |
|
| 180 | + /** |
|
| 181 | + * Magic Getter. |
|
| 182 | + * |
|
| 183 | + * This is the magic get method to retrieve the private variable |
|
| 184 | + * that was set by either __set() or it's setter... |
|
| 185 | + * |
|
| 186 | + * @param string $var The property name to retrieve. |
|
| 187 | + * @return mixed $this->$var Either a boolean false if the |
|
| 188 | + * property is not set or the value |
|
| 189 | + * of the private property. |
|
| 190 | + */ |
|
| 191 | + public function __get($var) |
|
| 192 | + { |
|
| 193 | + $method = 'get' . $var; |
|
| 194 | + if (method_exists($this, $method)) { |
|
| 195 | + return $this->$method(); |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - return false; |
|
| 199 | - } |
|
| 198 | + return false; |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * Returns the scheme, e.g. "http" or "urn", or false if there is no |
|
| 203 | - * scheme specified, i.e. if this is a relative URL. |
|
| 204 | - * |
|
| 205 | - * @return string|bool |
|
| 206 | - */ |
|
| 207 | - public function getScheme() |
|
| 208 | - { |
|
| 209 | - return $this->_scheme; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Sets the scheme, e.g. "http" or "urn". Specify false if there is no |
|
| 214 | - * scheme specified, i.e. if this is a relative URL. |
|
| 215 | - * |
|
| 216 | - * @param string|bool $scheme e.g. "http" or "urn", or false if there is no |
|
| 217 | - * scheme specified, i.e. if this is a relative |
|
| 218 | - * URL |
|
| 219 | - * |
|
| 220 | - * @return void |
|
| 221 | - * @see getScheme() |
|
| 222 | - */ |
|
| 223 | - public function setScheme($scheme) |
|
| 224 | - { |
|
| 225 | - $this->_scheme = $scheme; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Returns the user part of the userinfo part (the part preceding the first |
|
| 230 | - * ":"), or false if there is no userinfo part. |
|
| 231 | - * |
|
| 232 | - * @return string|bool |
|
| 233 | - */ |
|
| 234 | - public function getUser() |
|
| 235 | - { |
|
| 236 | - return $this->_userinfo !== false |
|
| 237 | - ? preg_replace('@:.*$@', '', $this->_userinfo) |
|
| 238 | - : false; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Returns the password part of the userinfo part (the part after the first |
|
| 243 | - * ":"), or false if there is no userinfo part (i.e. the URL does not |
|
| 244 | - * contain "@" in front of the hostname) or the userinfo part does not |
|
| 245 | - * contain ":". |
|
| 246 | - * |
|
| 247 | - * @return string|bool |
|
| 248 | - */ |
|
| 249 | - public function getPassword() |
|
| 250 | - { |
|
| 251 | - return $this->_userinfo !== false |
|
| 252 | - ? substr(strstr($this->_userinfo, ':'), 1) |
|
| 253 | - : false; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * Returns the userinfo part, or false if there is none, i.e. if the |
|
| 258 | - * authority part does not contain "@". |
|
| 259 | - * |
|
| 260 | - * @return string|bool |
|
| 261 | - */ |
|
| 262 | - public function getUserinfo() |
|
| 263 | - { |
|
| 264 | - return $this->_userinfo; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * Sets the userinfo part. If two arguments are passed, they are combined |
|
| 269 | - * in the userinfo part as username ":" password. |
|
| 270 | - * |
|
| 271 | - * @param string|bool $userinfo userinfo or username |
|
| 272 | - * @param string|bool $password optional password, or false |
|
| 273 | - * |
|
| 274 | - * @return void |
|
| 275 | - */ |
|
| 276 | - public function setUserinfo($userinfo, $password = false) |
|
| 277 | - { |
|
| 278 | - $this->_userinfo = $userinfo; |
|
| 279 | - if ($password !== false) { |
|
| 280 | - $this->_userinfo .= ':' . $password; |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * Returns the host part, or false if there is no authority part, e.g. |
|
| 286 | - * relative URLs. |
|
| 287 | - * |
|
| 288 | - * @return string|bool a hostname, an IP address, or false |
|
| 289 | - */ |
|
| 290 | - public function getHost() |
|
| 291 | - { |
|
| 292 | - return $this->_host; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * Sets the host part. Specify false if there is no authority part, e.g. |
|
| 297 | - * relative URLs. |
|
| 298 | - * |
|
| 299 | - * @param string|bool $host a hostname, an IP address, or false |
|
| 300 | - * |
|
| 301 | - * @return void |
|
| 302 | - */ |
|
| 303 | - public function setHost($host) |
|
| 304 | - { |
|
| 305 | - $this->_host = $host; |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * Returns the port number, or false if there is no port number specified, |
|
| 310 | - * i.e. if the default port is to be used. |
|
| 311 | - * |
|
| 312 | - * @return string|bool |
|
| 313 | - */ |
|
| 314 | - public function getPort() |
|
| 315 | - { |
|
| 316 | - return $this->_port; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Sets the port number. Specify false if there is no port number specified, |
|
| 321 | - * i.e. if the default port is to be used. |
|
| 322 | - * |
|
| 323 | - * @param string|bool $port a port number, or false |
|
| 324 | - * |
|
| 325 | - * @return void |
|
| 326 | - */ |
|
| 327 | - public function setPort($port) |
|
| 328 | - { |
|
| 329 | - $this->_port = $port; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * Returns the authority part, i.e. [ userinfo "@" ] host [ ":" port ], or |
|
| 334 | - * false if there is no authority. |
|
| 335 | - * |
|
| 336 | - * @return string|bool |
|
| 337 | - */ |
|
| 338 | - public function getAuthority() |
|
| 339 | - { |
|
| 340 | - if (!$this->_host) { |
|
| 341 | - return false; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - $authority = ''; |
|
| 345 | - |
|
| 346 | - if ($this->_userinfo !== false) { |
|
| 347 | - $authority .= $this->_userinfo . '@'; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - $authority .= $this->_host; |
|
| 351 | - |
|
| 352 | - if ($this->_port !== false) { |
|
| 353 | - $authority .= ':' . $this->_port; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - return $authority; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * Sets the authority part, i.e. [ userinfo "@" ] host [ ":" port ]. Specify |
|
| 361 | - * false if there is no authority. |
|
| 362 | - * |
|
| 363 | - * @param string|false $authority a hostname or an IP addresse, possibly |
|
| 364 | - * with userinfo prefixed and port number |
|
| 365 | - * appended, e.g. "foo:[email protected]:81". |
|
| 366 | - * |
|
| 367 | - * @return void |
|
| 368 | - */ |
|
| 369 | - public function setAuthority($authority) |
|
| 370 | - { |
|
| 371 | - $this->_userinfo = false; |
|
| 372 | - $this->_host = false; |
|
| 373 | - $this->_port = false; |
|
| 374 | - if (preg_match('@^(([^\@]*)\@)?([^:]+)(:(\d*))?$@', $authority, $reg)) { |
|
| 375 | - if ($reg[1]) { |
|
| 376 | - $this->_userinfo = $reg[2]; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - $this->_host = $reg[3]; |
|
| 380 | - if (isset($reg[5])) { |
|
| 381 | - $this->_port = $reg[5]; |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * Returns the path part (possibly an empty string). |
|
| 388 | - * |
|
| 389 | - * @return string |
|
| 390 | - */ |
|
| 391 | - public function getPath() |
|
| 392 | - { |
|
| 393 | - return $this->_path; |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * Sets the path part (possibly an empty string). |
|
| 398 | - * |
|
| 399 | - * @param string $path a path |
|
| 400 | - * |
|
| 401 | - * @return void |
|
| 402 | - */ |
|
| 403 | - public function setPath($path) |
|
| 404 | - { |
|
| 405 | - $this->_path = $path; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * Returns the query string (excluding the leading "?"), or false if "?" |
|
| 410 | - * is not present in the URL. |
|
| 411 | - * |
|
| 412 | - * @return string|bool |
|
| 413 | - * @see self::getQueryVariables() |
|
| 414 | - */ |
|
| 415 | - public function getQuery() |
|
| 416 | - { |
|
| 417 | - return $this->_query; |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - /** |
|
| 421 | - * Sets the query string (excluding the leading "?"). Specify false if "?" |
|
| 422 | - * is not present in the URL. |
|
| 423 | - * |
|
| 424 | - * @param string|bool $query a query string, e.g. "foo=1&bar=2" |
|
| 425 | - * |
|
| 426 | - * @return void |
|
| 427 | - * @see self::setQueryVariables() |
|
| 428 | - */ |
|
| 429 | - public function setQuery($query) |
|
| 430 | - { |
|
| 431 | - $this->_query = $query; |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Returns the fragment name, or false if "#" is not present in the URL. |
|
| 436 | - * |
|
| 437 | - * @return string|bool |
|
| 438 | - */ |
|
| 439 | - public function getFragment() |
|
| 440 | - { |
|
| 441 | - return $this->_fragment; |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * Sets the fragment name. Specify false if "#" is not present in the URL. |
|
| 446 | - * |
|
| 447 | - * @param string|bool $fragment a fragment excluding the leading "#", or |
|
| 448 | - * false |
|
| 449 | - * |
|
| 450 | - * @return void |
|
| 451 | - */ |
|
| 452 | - public function setFragment($fragment) |
|
| 453 | - { |
|
| 454 | - $this->_fragment = $fragment; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - /** |
|
| 458 | - * Returns the query string like an array as the variables would appear in |
|
| 459 | - * $_GET in a PHP script. If the URL does not contain a "?", an empty array |
|
| 460 | - * is returned. |
|
| 461 | - * |
|
| 462 | - * @return array |
|
| 463 | - */ |
|
| 464 | - public function getQueryVariables() |
|
| 465 | - { |
|
| 466 | - $pattern = '/[' . |
|
| 467 | - preg_quote($this->getOption(self::OPTION_SEPARATOR_INPUT), '/') . |
|
| 468 | - ']/'; |
|
| 469 | - $parts = preg_split($pattern, $this->_query, -1, PREG_SPLIT_NO_EMPTY); |
|
| 470 | - $return = array(); |
|
| 471 | - |
|
| 472 | - foreach ($parts as $part) { |
|
| 473 | - if (strpos($part, '=') !== false) { |
|
| 474 | - list($key, $value) = explode('=', $part, 2); |
|
| 475 | - } else { |
|
| 476 | - $key = $part; |
|
| 477 | - $value = null; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - if ($this->getOption(self::OPTION_ENCODE_KEYS)) { |
|
| 481 | - $key = rawurldecode($key); |
|
| 482 | - } |
|
| 483 | - $value = rawurldecode($value); |
|
| 484 | - |
|
| 485 | - if ($this->getOption(self::OPTION_USE_BRACKETS) && |
|
| 486 | - preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) { |
|
| 487 | - |
|
| 488 | - $key = $matches[1]; |
|
| 489 | - $idx = $matches[2]; |
|
| 490 | - |
|
| 491 | - // Ensure is an array |
|
| 492 | - if (empty($return[$key]) || !is_array($return[$key])) { |
|
| 493 | - $return[$key] = array(); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - // Add data |
|
| 497 | - if ($idx === '') { |
|
| 498 | - $return[$key][] = $value; |
|
| 499 | - } else { |
|
| 500 | - $return[$key][$idx] = $value; |
|
| 501 | - } |
|
| 502 | - } elseif (!$this->getOption(self::OPTION_USE_BRACKETS) |
|
| 503 | - && !empty($return[$key]) |
|
| 504 | - ) { |
|
| 505 | - $return[$key] = (array) $return[$key]; |
|
| 506 | - $return[$key][] = $value; |
|
| 507 | - } else { |
|
| 508 | - $return[$key] = $value; |
|
| 509 | - } |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - return $return; |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * Sets the query string to the specified variable in the query string. |
|
| 517 | - * |
|
| 518 | - * @param array $array (name => value) array |
|
| 519 | - * |
|
| 520 | - * @return void |
|
| 521 | - */ |
|
| 522 | - public function setQueryVariables(array $array) |
|
| 523 | - { |
|
| 524 | - if (!$array) { |
|
| 525 | - $this->_query = false; |
|
| 526 | - } else { |
|
| 527 | - foreach ($array as $name => $value) { |
|
| 528 | - if ($this->getOption(self::OPTION_ENCODE_KEYS)) { |
|
| 529 | - $name = self::urlencode($name); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - if (is_array($value)) { |
|
| 533 | - foreach ($value as $k => $v) { |
|
| 534 | - $parts[] = $this->getOption(self::OPTION_USE_BRACKETS) |
|
| 535 | - ? sprintf('%s[%s]=%s', $name, $k, $v) |
|
| 536 | - : ($name . '=' . $v); |
|
| 537 | - } |
|
| 538 | - } elseif (!is_null($value)) { |
|
| 539 | - $parts[] = $name . '=' . self::urlencode($value); |
|
| 540 | - } else { |
|
| 541 | - $parts[] = $name; |
|
| 542 | - } |
|
| 543 | - } |
|
| 544 | - $this->_query = implode($this->getOption(self::OPTION_SEPARATOR_OUTPUT), |
|
| 545 | - $parts); |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Sets the specified variable in the query string. |
|
| 551 | - * |
|
| 552 | - * @param string $name variable name |
|
| 553 | - * @param mixed $value variable value |
|
| 554 | - * |
|
| 555 | - * @return array |
|
| 556 | - */ |
|
| 557 | - public function setQueryVariable($name, $value) |
|
| 558 | - { |
|
| 559 | - $array = $this->getQueryVariables(); |
|
| 560 | - $array[$name] = $value; |
|
| 561 | - $this->setQueryVariables($array); |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - /** |
|
| 565 | - * Removes the specifed variable from the query string. |
|
| 566 | - * |
|
| 567 | - * @param string $name a query string variable, e.g. "foo" in "?foo=1" |
|
| 568 | - * |
|
| 569 | - * @return void |
|
| 570 | - */ |
|
| 571 | - public function unsetQueryVariable($name) |
|
| 572 | - { |
|
| 573 | - $array = $this->getQueryVariables(); |
|
| 574 | - unset($array[$name]); |
|
| 575 | - $this->setQueryVariables($array); |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * Returns a string representation of this URL. |
|
| 580 | - * |
|
| 581 | - * @return string |
|
| 582 | - */ |
|
| 583 | - public function getURL() |
|
| 584 | - { |
|
| 585 | - // See RFC 3986, section 5.3 |
|
| 586 | - $url = ""; |
|
| 587 | - |
|
| 588 | - if ($this->_scheme !== false) { |
|
| 589 | - $url .= $this->_scheme . ':'; |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - $authority = $this->getAuthority(); |
|
| 593 | - if ($authority !== false) { |
|
| 594 | - $url .= '//' . $authority; |
|
| 595 | - } |
|
| 596 | - $url .= $this->_path; |
|
| 597 | - |
|
| 598 | - if ($this->_query !== false) { |
|
| 599 | - $url .= '?' . $this->_query; |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - if ($this->_fragment !== false) { |
|
| 603 | - $url .= '#' . $this->_fragment; |
|
| 604 | - } |
|
| 201 | + /** |
|
| 202 | + * Returns the scheme, e.g. "http" or "urn", or false if there is no |
|
| 203 | + * scheme specified, i.e. if this is a relative URL. |
|
| 204 | + * |
|
| 205 | + * @return string|bool |
|
| 206 | + */ |
|
| 207 | + public function getScheme() |
|
| 208 | + { |
|
| 209 | + return $this->_scheme; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Sets the scheme, e.g. "http" or "urn". Specify false if there is no |
|
| 214 | + * scheme specified, i.e. if this is a relative URL. |
|
| 215 | + * |
|
| 216 | + * @param string|bool $scheme e.g. "http" or "urn", or false if there is no |
|
| 217 | + * scheme specified, i.e. if this is a relative |
|
| 218 | + * URL |
|
| 219 | + * |
|
| 220 | + * @return void |
|
| 221 | + * @see getScheme() |
|
| 222 | + */ |
|
| 223 | + public function setScheme($scheme) |
|
| 224 | + { |
|
| 225 | + $this->_scheme = $scheme; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Returns the user part of the userinfo part (the part preceding the first |
|
| 230 | + * ":"), or false if there is no userinfo part. |
|
| 231 | + * |
|
| 232 | + * @return string|bool |
|
| 233 | + */ |
|
| 234 | + public function getUser() |
|
| 235 | + { |
|
| 236 | + return $this->_userinfo !== false |
|
| 237 | + ? preg_replace('@:.*$@', '', $this->_userinfo) |
|
| 238 | + : false; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Returns the password part of the userinfo part (the part after the first |
|
| 243 | + * ":"), or false if there is no userinfo part (i.e. the URL does not |
|
| 244 | + * contain "@" in front of the hostname) or the userinfo part does not |
|
| 245 | + * contain ":". |
|
| 246 | + * |
|
| 247 | + * @return string|bool |
|
| 248 | + */ |
|
| 249 | + public function getPassword() |
|
| 250 | + { |
|
| 251 | + return $this->_userinfo !== false |
|
| 252 | + ? substr(strstr($this->_userinfo, ':'), 1) |
|
| 253 | + : false; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * Returns the userinfo part, or false if there is none, i.e. if the |
|
| 258 | + * authority part does not contain "@". |
|
| 259 | + * |
|
| 260 | + * @return string|bool |
|
| 261 | + */ |
|
| 262 | + public function getUserinfo() |
|
| 263 | + { |
|
| 264 | + return $this->_userinfo; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * Sets the userinfo part. If two arguments are passed, they are combined |
|
| 269 | + * in the userinfo part as username ":" password. |
|
| 270 | + * |
|
| 271 | + * @param string|bool $userinfo userinfo or username |
|
| 272 | + * @param string|bool $password optional password, or false |
|
| 273 | + * |
|
| 274 | + * @return void |
|
| 275 | + */ |
|
| 276 | + public function setUserinfo($userinfo, $password = false) |
|
| 277 | + { |
|
| 278 | + $this->_userinfo = $userinfo; |
|
| 279 | + if ($password !== false) { |
|
| 280 | + $this->_userinfo .= ':' . $password; |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * Returns the host part, or false if there is no authority part, e.g. |
|
| 286 | + * relative URLs. |
|
| 287 | + * |
|
| 288 | + * @return string|bool a hostname, an IP address, or false |
|
| 289 | + */ |
|
| 290 | + public function getHost() |
|
| 291 | + { |
|
| 292 | + return $this->_host; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * Sets the host part. Specify false if there is no authority part, e.g. |
|
| 297 | + * relative URLs. |
|
| 298 | + * |
|
| 299 | + * @param string|bool $host a hostname, an IP address, or false |
|
| 300 | + * |
|
| 301 | + * @return void |
|
| 302 | + */ |
|
| 303 | + public function setHost($host) |
|
| 304 | + { |
|
| 305 | + $this->_host = $host; |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * Returns the port number, or false if there is no port number specified, |
|
| 310 | + * i.e. if the default port is to be used. |
|
| 311 | + * |
|
| 312 | + * @return string|bool |
|
| 313 | + */ |
|
| 314 | + public function getPort() |
|
| 315 | + { |
|
| 316 | + return $this->_port; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Sets the port number. Specify false if there is no port number specified, |
|
| 321 | + * i.e. if the default port is to be used. |
|
| 322 | + * |
|
| 323 | + * @param string|bool $port a port number, or false |
|
| 324 | + * |
|
| 325 | + * @return void |
|
| 326 | + */ |
|
| 327 | + public function setPort($port) |
|
| 328 | + { |
|
| 329 | + $this->_port = $port; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * Returns the authority part, i.e. [ userinfo "@" ] host [ ":" port ], or |
|
| 334 | + * false if there is no authority. |
|
| 335 | + * |
|
| 336 | + * @return string|bool |
|
| 337 | + */ |
|
| 338 | + public function getAuthority() |
|
| 339 | + { |
|
| 340 | + if (!$this->_host) { |
|
| 341 | + return false; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + $authority = ''; |
|
| 345 | + |
|
| 346 | + if ($this->_userinfo !== false) { |
|
| 347 | + $authority .= $this->_userinfo . '@'; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + $authority .= $this->_host; |
|
| 351 | + |
|
| 352 | + if ($this->_port !== false) { |
|
| 353 | + $authority .= ':' . $this->_port; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + return $authority; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * Sets the authority part, i.e. [ userinfo "@" ] host [ ":" port ]. Specify |
|
| 361 | + * false if there is no authority. |
|
| 362 | + * |
|
| 363 | + * @param string|false $authority a hostname or an IP addresse, possibly |
|
| 364 | + * with userinfo prefixed and port number |
|
| 365 | + * appended, e.g. "foo:[email protected]:81". |
|
| 366 | + * |
|
| 367 | + * @return void |
|
| 368 | + */ |
|
| 369 | + public function setAuthority($authority) |
|
| 370 | + { |
|
| 371 | + $this->_userinfo = false; |
|
| 372 | + $this->_host = false; |
|
| 373 | + $this->_port = false; |
|
| 374 | + if (preg_match('@^(([^\@]*)\@)?([^:]+)(:(\d*))?$@', $authority, $reg)) { |
|
| 375 | + if ($reg[1]) { |
|
| 376 | + $this->_userinfo = $reg[2]; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + $this->_host = $reg[3]; |
|
| 380 | + if (isset($reg[5])) { |
|
| 381 | + $this->_port = $reg[5]; |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * Returns the path part (possibly an empty string). |
|
| 388 | + * |
|
| 389 | + * @return string |
|
| 390 | + */ |
|
| 391 | + public function getPath() |
|
| 392 | + { |
|
| 393 | + return $this->_path; |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * Sets the path part (possibly an empty string). |
|
| 398 | + * |
|
| 399 | + * @param string $path a path |
|
| 400 | + * |
|
| 401 | + * @return void |
|
| 402 | + */ |
|
| 403 | + public function setPath($path) |
|
| 404 | + { |
|
| 405 | + $this->_path = $path; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * Returns the query string (excluding the leading "?"), or false if "?" |
|
| 410 | + * is not present in the URL. |
|
| 411 | + * |
|
| 412 | + * @return string|bool |
|
| 413 | + * @see self::getQueryVariables() |
|
| 414 | + */ |
|
| 415 | + public function getQuery() |
|
| 416 | + { |
|
| 417 | + return $this->_query; |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + /** |
|
| 421 | + * Sets the query string (excluding the leading "?"). Specify false if "?" |
|
| 422 | + * is not present in the URL. |
|
| 423 | + * |
|
| 424 | + * @param string|bool $query a query string, e.g. "foo=1&bar=2" |
|
| 425 | + * |
|
| 426 | + * @return void |
|
| 427 | + * @see self::setQueryVariables() |
|
| 428 | + */ |
|
| 429 | + public function setQuery($query) |
|
| 430 | + { |
|
| 431 | + $this->_query = $query; |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Returns the fragment name, or false if "#" is not present in the URL. |
|
| 436 | + * |
|
| 437 | + * @return string|bool |
|
| 438 | + */ |
|
| 439 | + public function getFragment() |
|
| 440 | + { |
|
| 441 | + return $this->_fragment; |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * Sets the fragment name. Specify false if "#" is not present in the URL. |
|
| 446 | + * |
|
| 447 | + * @param string|bool $fragment a fragment excluding the leading "#", or |
|
| 448 | + * false |
|
| 449 | + * |
|
| 450 | + * @return void |
|
| 451 | + */ |
|
| 452 | + public function setFragment($fragment) |
|
| 453 | + { |
|
| 454 | + $this->_fragment = $fragment; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + /** |
|
| 458 | + * Returns the query string like an array as the variables would appear in |
|
| 459 | + * $_GET in a PHP script. If the URL does not contain a "?", an empty array |
|
| 460 | + * is returned. |
|
| 461 | + * |
|
| 462 | + * @return array |
|
| 463 | + */ |
|
| 464 | + public function getQueryVariables() |
|
| 465 | + { |
|
| 466 | + $pattern = '/[' . |
|
| 467 | + preg_quote($this->getOption(self::OPTION_SEPARATOR_INPUT), '/') . |
|
| 468 | + ']/'; |
|
| 469 | + $parts = preg_split($pattern, $this->_query, -1, PREG_SPLIT_NO_EMPTY); |
|
| 470 | + $return = array(); |
|
| 471 | + |
|
| 472 | + foreach ($parts as $part) { |
|
| 473 | + if (strpos($part, '=') !== false) { |
|
| 474 | + list($key, $value) = explode('=', $part, 2); |
|
| 475 | + } else { |
|
| 476 | + $key = $part; |
|
| 477 | + $value = null; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + if ($this->getOption(self::OPTION_ENCODE_KEYS)) { |
|
| 481 | + $key = rawurldecode($key); |
|
| 482 | + } |
|
| 483 | + $value = rawurldecode($value); |
|
| 484 | + |
|
| 485 | + if ($this->getOption(self::OPTION_USE_BRACKETS) && |
|
| 486 | + preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) { |
|
| 487 | + |
|
| 488 | + $key = $matches[1]; |
|
| 489 | + $idx = $matches[2]; |
|
| 490 | + |
|
| 491 | + // Ensure is an array |
|
| 492 | + if (empty($return[$key]) || !is_array($return[$key])) { |
|
| 493 | + $return[$key] = array(); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + // Add data |
|
| 497 | + if ($idx === '') { |
|
| 498 | + $return[$key][] = $value; |
|
| 499 | + } else { |
|
| 500 | + $return[$key][$idx] = $value; |
|
| 501 | + } |
|
| 502 | + } elseif (!$this->getOption(self::OPTION_USE_BRACKETS) |
|
| 503 | + && !empty($return[$key]) |
|
| 504 | + ) { |
|
| 505 | + $return[$key] = (array) $return[$key]; |
|
| 506 | + $return[$key][] = $value; |
|
| 507 | + } else { |
|
| 508 | + $return[$key] = $value; |
|
| 509 | + } |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + return $return; |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * Sets the query string to the specified variable in the query string. |
|
| 517 | + * |
|
| 518 | + * @param array $array (name => value) array |
|
| 519 | + * |
|
| 520 | + * @return void |
|
| 521 | + */ |
|
| 522 | + public function setQueryVariables(array $array) |
|
| 523 | + { |
|
| 524 | + if (!$array) { |
|
| 525 | + $this->_query = false; |
|
| 526 | + } else { |
|
| 527 | + foreach ($array as $name => $value) { |
|
| 528 | + if ($this->getOption(self::OPTION_ENCODE_KEYS)) { |
|
| 529 | + $name = self::urlencode($name); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + if (is_array($value)) { |
|
| 533 | + foreach ($value as $k => $v) { |
|
| 534 | + $parts[] = $this->getOption(self::OPTION_USE_BRACKETS) |
|
| 535 | + ? sprintf('%s[%s]=%s', $name, $k, $v) |
|
| 536 | + : ($name . '=' . $v); |
|
| 537 | + } |
|
| 538 | + } elseif (!is_null($value)) { |
|
| 539 | + $parts[] = $name . '=' . self::urlencode($value); |
|
| 540 | + } else { |
|
| 541 | + $parts[] = $name; |
|
| 542 | + } |
|
| 543 | + } |
|
| 544 | + $this->_query = implode($this->getOption(self::OPTION_SEPARATOR_OUTPUT), |
|
| 545 | + $parts); |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Sets the specified variable in the query string. |
|
| 551 | + * |
|
| 552 | + * @param string $name variable name |
|
| 553 | + * @param mixed $value variable value |
|
| 554 | + * |
|
| 555 | + * @return array |
|
| 556 | + */ |
|
| 557 | + public function setQueryVariable($name, $value) |
|
| 558 | + { |
|
| 559 | + $array = $this->getQueryVariables(); |
|
| 560 | + $array[$name] = $value; |
|
| 561 | + $this->setQueryVariables($array); |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + /** |
|
| 565 | + * Removes the specifed variable from the query string. |
|
| 566 | + * |
|
| 567 | + * @param string $name a query string variable, e.g. "foo" in "?foo=1" |
|
| 568 | + * |
|
| 569 | + * @return void |
|
| 570 | + */ |
|
| 571 | + public function unsetQueryVariable($name) |
|
| 572 | + { |
|
| 573 | + $array = $this->getQueryVariables(); |
|
| 574 | + unset($array[$name]); |
|
| 575 | + $this->setQueryVariables($array); |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * Returns a string representation of this URL. |
|
| 580 | + * |
|
| 581 | + * @return string |
|
| 582 | + */ |
|
| 583 | + public function getURL() |
|
| 584 | + { |
|
| 585 | + // See RFC 3986, section 5.3 |
|
| 586 | + $url = ""; |
|
| 587 | + |
|
| 588 | + if ($this->_scheme !== false) { |
|
| 589 | + $url .= $this->_scheme . ':'; |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + $authority = $this->getAuthority(); |
|
| 593 | + if ($authority !== false) { |
|
| 594 | + $url .= '//' . $authority; |
|
| 595 | + } |
|
| 596 | + $url .= $this->_path; |
|
| 597 | + |
|
| 598 | + if ($this->_query !== false) { |
|
| 599 | + $url .= '?' . $this->_query; |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + if ($this->_fragment !== false) { |
|
| 603 | + $url .= '#' . $this->_fragment; |
|
| 604 | + } |
|
| 605 | 605 | |
| 606 | - return $url; |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - /** |
|
| 610 | - * Returns a string representation of this URL. |
|
| 611 | - * |
|
| 612 | - * @return string |
|
| 613 | - * @see toString() |
|
| 614 | - */ |
|
| 615 | - public function __toString() |
|
| 616 | - { |
|
| 617 | - return $this->getURL(); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * Returns a normalized string representation of this URL. This is useful |
|
| 622 | - * for comparison of URLs. |
|
| 623 | - * |
|
| 624 | - * @return string |
|
| 625 | - */ |
|
| 626 | - public function getNormalizedURL() |
|
| 627 | - { |
|
| 628 | - $url = clone $this; |
|
| 629 | - $url->normalize(); |
|
| 630 | - return $url->getUrl(); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - /** |
|
| 634 | - * Returns a normalized Net_URL2 instance. |
|
| 635 | - * |
|
| 636 | - * @return Net_URL2 |
|
| 637 | - */ |
|
| 638 | - public function normalize() |
|
| 639 | - { |
|
| 640 | - // See RFC 3886, section 6 |
|
| 641 | - |
|
| 642 | - // Schemes are case-insensitive |
|
| 643 | - if ($this->_scheme) { |
|
| 644 | - $this->_scheme = strtolower($this->_scheme); |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - // Hostnames are case-insensitive |
|
| 648 | - if ($this->_host) { |
|
| 649 | - $this->_host = strtolower($this->_host); |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - // Remove default port number for known schemes (RFC 3986, section 6.2.3) |
|
| 653 | - if ($this->_port && |
|
| 654 | - $this->_scheme && |
|
| 655 | - $this->_port == getservbyname($this->_scheme, 'tcp')) { |
|
| 656 | - |
|
| 657 | - $this->_port = false; |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - // Normalize case of %XX percentage-encodings (RFC 3986, section 6.2.2.1) |
|
| 661 | - foreach (array('_userinfo', '_host', '_path') as $part) { |
|
| 662 | - if ($this->$part) { |
|
| 663 | - $this->$part = preg_replace('/%[0-9a-f]{2}/ie', |
|
| 664 | - 'strtoupper("\0")', |
|
| 665 | - $this->$part); |
|
| 666 | - } |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - // Path segment normalization (RFC 3986, section 6.2.2.3) |
|
| 670 | - $this->_path = self::removeDotSegments($this->_path); |
|
| 671 | - |
|
| 672 | - // Scheme based normalization (RFC 3986, section 6.2.3) |
|
| 673 | - if ($this->_host && !$this->_path) { |
|
| 674 | - $this->_path = '/'; |
|
| 675 | - } |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - /** |
|
| 679 | - * Returns whether this instance represents an absolute URL. |
|
| 680 | - * |
|
| 681 | - * @return bool |
|
| 682 | - */ |
|
| 683 | - public function isAbsolute() |
|
| 684 | - { |
|
| 685 | - return (bool) $this->_scheme; |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * Returns an Net_URL2 instance representing an absolute URL relative to |
|
| 690 | - * this URL. |
|
| 691 | - * |
|
| 692 | - * @param Net_URL2|string $reference relative URL |
|
| 693 | - * |
|
| 694 | - * @return Net_URL2 |
|
| 695 | - */ |
|
| 696 | - public function resolve($reference) |
|
| 697 | - { |
|
| 698 | - if (!$reference instanceof Net_URL2) { |
|
| 699 | - $reference = new self($reference); |
|
| 700 | - } |
|
| 701 | - if (!$this->isAbsolute()) { |
|
| 702 | - throw new Exception('Base-URL must be absolute'); |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - // A non-strict parser may ignore a scheme in the reference if it is |
|
| 706 | - // identical to the base URI's scheme. |
|
| 707 | - if (!$this->getOption(self::OPTION_STRICT) && $reference->_scheme == $this->_scheme) { |
|
| 708 | - $reference->_scheme = false; |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - $target = new self(''); |
|
| 712 | - if ($reference->_scheme !== false) { |
|
| 713 | - $target->_scheme = $reference->_scheme; |
|
| 714 | - $target->setAuthority($reference->getAuthority()); |
|
| 715 | - $target->_path = self::removeDotSegments($reference->_path); |
|
| 716 | - $target->_query = $reference->_query; |
|
| 717 | - } else { |
|
| 718 | - $authority = $reference->getAuthority(); |
|
| 719 | - if ($authority !== false) { |
|
| 720 | - $target->setAuthority($authority); |
|
| 721 | - $target->_path = self::removeDotSegments($reference->_path); |
|
| 722 | - $target->_query = $reference->_query; |
|
| 723 | - } else { |
|
| 724 | - if ($reference->_path == '') { |
|
| 725 | - $target->_path = $this->_path; |
|
| 726 | - if ($reference->_query !== false) { |
|
| 727 | - $target->_query = $reference->_query; |
|
| 728 | - } else { |
|
| 729 | - $target->_query = $this->_query; |
|
| 730 | - } |
|
| 731 | - } else { |
|
| 732 | - if (substr($reference->_path, 0, 1) == '/') { |
|
| 733 | - $target->_path = self::removeDotSegments($reference->_path); |
|
| 734 | - } else { |
|
| 735 | - // Merge paths (RFC 3986, section 5.2.3) |
|
| 736 | - if ($this->_host !== false && $this->_path == '') { |
|
| 737 | - $target->_path = '/' . $this->_path; |
|
| 738 | - } else { |
|
| 739 | - $i = strrpos($this->_path, '/'); |
|
| 740 | - if ($i !== false) { |
|
| 741 | - $target->_path = substr($this->_path, 0, $i + 1); |
|
| 742 | - } |
|
| 743 | - $target->_path .= $reference->_path; |
|
| 744 | - } |
|
| 745 | - $target->_path = self::removeDotSegments($target->_path); |
|
| 746 | - } |
|
| 747 | - $target->_query = $reference->_query; |
|
| 748 | - } |
|
| 749 | - $target->setAuthority($this->getAuthority()); |
|
| 750 | - } |
|
| 751 | - $target->_scheme = $this->_scheme; |
|
| 752 | - } |
|
| 753 | - |
|
| 754 | - $target->_fragment = $reference->_fragment; |
|
| 755 | - |
|
| 756 | - return $target; |
|
| 757 | - } |
|
| 758 | - |
|
| 759 | - /** |
|
| 760 | - * Removes dots as described in RFC 3986, section 5.2.4, e.g. |
|
| 761 | - * "/foo/../bar/baz" => "/bar/baz" |
|
| 762 | - * |
|
| 763 | - * @param string $path a path |
|
| 764 | - * |
|
| 765 | - * @return string a path |
|
| 766 | - */ |
|
| 767 | - public static function removeDotSegments($path) |
|
| 768 | - { |
|
| 769 | - $output = ''; |
|
| 770 | - |
|
| 771 | - // Make sure not to be trapped in an infinite loop due to a bug in this |
|
| 772 | - // method |
|
| 773 | - $j = 0; |
|
| 774 | - while ($path && $j++ < 100) { |
|
| 775 | - if (substr($path, 0, 2) == './') { |
|
| 776 | - // Step 2.A |
|
| 777 | - $path = substr($path, 2); |
|
| 778 | - } elseif (substr($path, 0, 3) == '../') { |
|
| 779 | - // Step 2.A |
|
| 780 | - $path = substr($path, 3); |
|
| 781 | - } elseif (substr($path, 0, 3) == '/./' || $path == '/.') { |
|
| 782 | - // Step 2.B |
|
| 783 | - $path = '/' . substr($path, 3); |
|
| 784 | - } elseif (substr($path, 0, 4) == '/../' || $path == '/..') { |
|
| 785 | - // Step 2.C |
|
| 786 | - $path = '/' . substr($path, 4); |
|
| 787 | - $i = strrpos($output, '/'); |
|
| 788 | - $output = $i === false ? '' : substr($output, 0, $i); |
|
| 789 | - } elseif ($path == '.' || $path == '..') { |
|
| 790 | - // Step 2.D |
|
| 791 | - $path = ''; |
|
| 792 | - } else { |
|
| 793 | - // Step 2.E |
|
| 794 | - $i = strpos($path, '/'); |
|
| 795 | - if ($i === 0) { |
|
| 796 | - $i = strpos($path, '/', 1); |
|
| 797 | - } |
|
| 798 | - if ($i === false) { |
|
| 799 | - $i = strlen($path); |
|
| 800 | - } |
|
| 801 | - $output .= substr($path, 0, $i); |
|
| 802 | - $path = substr($path, $i); |
|
| 803 | - } |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - return $output; |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - /** |
|
| 810 | - * Percent-encodes all non-alphanumeric characters except these: _ . - ~ |
|
| 811 | - * Similar to PHP's rawurlencode(), except that it also encodes ~ in PHP |
|
| 812 | - * 5.2.x and earlier. |
|
| 813 | - * |
|
| 814 | - * @param $raw the string to encode |
|
| 815 | - * @return string |
|
| 816 | - */ |
|
| 817 | - public static function urlencode($string) |
|
| 818 | - { |
|
| 819 | - $encoded = rawurlencode($string); |
|
| 606 | + return $url; |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + /** |
|
| 610 | + * Returns a string representation of this URL. |
|
| 611 | + * |
|
| 612 | + * @return string |
|
| 613 | + * @see toString() |
|
| 614 | + */ |
|
| 615 | + public function __toString() |
|
| 616 | + { |
|
| 617 | + return $this->getURL(); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + /** |
|
| 621 | + * Returns a normalized string representation of this URL. This is useful |
|
| 622 | + * for comparison of URLs. |
|
| 623 | + * |
|
| 624 | + * @return string |
|
| 625 | + */ |
|
| 626 | + public function getNormalizedURL() |
|
| 627 | + { |
|
| 628 | + $url = clone $this; |
|
| 629 | + $url->normalize(); |
|
| 630 | + return $url->getUrl(); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + /** |
|
| 634 | + * Returns a normalized Net_URL2 instance. |
|
| 635 | + * |
|
| 636 | + * @return Net_URL2 |
|
| 637 | + */ |
|
| 638 | + public function normalize() |
|
| 639 | + { |
|
| 640 | + // See RFC 3886, section 6 |
|
| 641 | + |
|
| 642 | + // Schemes are case-insensitive |
|
| 643 | + if ($this->_scheme) { |
|
| 644 | + $this->_scheme = strtolower($this->_scheme); |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + // Hostnames are case-insensitive |
|
| 648 | + if ($this->_host) { |
|
| 649 | + $this->_host = strtolower($this->_host); |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + // Remove default port number for known schemes (RFC 3986, section 6.2.3) |
|
| 653 | + if ($this->_port && |
|
| 654 | + $this->_scheme && |
|
| 655 | + $this->_port == getservbyname($this->_scheme, 'tcp')) { |
|
| 656 | + |
|
| 657 | + $this->_port = false; |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + // Normalize case of %XX percentage-encodings (RFC 3986, section 6.2.2.1) |
|
| 661 | + foreach (array('_userinfo', '_host', '_path') as $part) { |
|
| 662 | + if ($this->$part) { |
|
| 663 | + $this->$part = preg_replace('/%[0-9a-f]{2}/ie', |
|
| 664 | + 'strtoupper("\0")', |
|
| 665 | + $this->$part); |
|
| 666 | + } |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + // Path segment normalization (RFC 3986, section 6.2.2.3) |
|
| 670 | + $this->_path = self::removeDotSegments($this->_path); |
|
| 671 | + |
|
| 672 | + // Scheme based normalization (RFC 3986, section 6.2.3) |
|
| 673 | + if ($this->_host && !$this->_path) { |
|
| 674 | + $this->_path = '/'; |
|
| 675 | + } |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + /** |
|
| 679 | + * Returns whether this instance represents an absolute URL. |
|
| 680 | + * |
|
| 681 | + * @return bool |
|
| 682 | + */ |
|
| 683 | + public function isAbsolute() |
|
| 684 | + { |
|
| 685 | + return (bool) $this->_scheme; |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * Returns an Net_URL2 instance representing an absolute URL relative to |
|
| 690 | + * this URL. |
|
| 691 | + * |
|
| 692 | + * @param Net_URL2|string $reference relative URL |
|
| 693 | + * |
|
| 694 | + * @return Net_URL2 |
|
| 695 | + */ |
|
| 696 | + public function resolve($reference) |
|
| 697 | + { |
|
| 698 | + if (!$reference instanceof Net_URL2) { |
|
| 699 | + $reference = new self($reference); |
|
| 700 | + } |
|
| 701 | + if (!$this->isAbsolute()) { |
|
| 702 | + throw new Exception('Base-URL must be absolute'); |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + // A non-strict parser may ignore a scheme in the reference if it is |
|
| 706 | + // identical to the base URI's scheme. |
|
| 707 | + if (!$this->getOption(self::OPTION_STRICT) && $reference->_scheme == $this->_scheme) { |
|
| 708 | + $reference->_scheme = false; |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + $target = new self(''); |
|
| 712 | + if ($reference->_scheme !== false) { |
|
| 713 | + $target->_scheme = $reference->_scheme; |
|
| 714 | + $target->setAuthority($reference->getAuthority()); |
|
| 715 | + $target->_path = self::removeDotSegments($reference->_path); |
|
| 716 | + $target->_query = $reference->_query; |
|
| 717 | + } else { |
|
| 718 | + $authority = $reference->getAuthority(); |
|
| 719 | + if ($authority !== false) { |
|
| 720 | + $target->setAuthority($authority); |
|
| 721 | + $target->_path = self::removeDotSegments($reference->_path); |
|
| 722 | + $target->_query = $reference->_query; |
|
| 723 | + } else { |
|
| 724 | + if ($reference->_path == '') { |
|
| 725 | + $target->_path = $this->_path; |
|
| 726 | + if ($reference->_query !== false) { |
|
| 727 | + $target->_query = $reference->_query; |
|
| 728 | + } else { |
|
| 729 | + $target->_query = $this->_query; |
|
| 730 | + } |
|
| 731 | + } else { |
|
| 732 | + if (substr($reference->_path, 0, 1) == '/') { |
|
| 733 | + $target->_path = self::removeDotSegments($reference->_path); |
|
| 734 | + } else { |
|
| 735 | + // Merge paths (RFC 3986, section 5.2.3) |
|
| 736 | + if ($this->_host !== false && $this->_path == '') { |
|
| 737 | + $target->_path = '/' . $this->_path; |
|
| 738 | + } else { |
|
| 739 | + $i = strrpos($this->_path, '/'); |
|
| 740 | + if ($i !== false) { |
|
| 741 | + $target->_path = substr($this->_path, 0, $i + 1); |
|
| 742 | + } |
|
| 743 | + $target->_path .= $reference->_path; |
|
| 744 | + } |
|
| 745 | + $target->_path = self::removeDotSegments($target->_path); |
|
| 746 | + } |
|
| 747 | + $target->_query = $reference->_query; |
|
| 748 | + } |
|
| 749 | + $target->setAuthority($this->getAuthority()); |
|
| 750 | + } |
|
| 751 | + $target->_scheme = $this->_scheme; |
|
| 752 | + } |
|
| 753 | + |
|
| 754 | + $target->_fragment = $reference->_fragment; |
|
| 755 | + |
|
| 756 | + return $target; |
|
| 757 | + } |
|
| 758 | + |
|
| 759 | + /** |
|
| 760 | + * Removes dots as described in RFC 3986, section 5.2.4, e.g. |
|
| 761 | + * "/foo/../bar/baz" => "/bar/baz" |
|
| 762 | + * |
|
| 763 | + * @param string $path a path |
|
| 764 | + * |
|
| 765 | + * @return string a path |
|
| 766 | + */ |
|
| 767 | + public static function removeDotSegments($path) |
|
| 768 | + { |
|
| 769 | + $output = ''; |
|
| 770 | + |
|
| 771 | + // Make sure not to be trapped in an infinite loop due to a bug in this |
|
| 772 | + // method |
|
| 773 | + $j = 0; |
|
| 774 | + while ($path && $j++ < 100) { |
|
| 775 | + if (substr($path, 0, 2) == './') { |
|
| 776 | + // Step 2.A |
|
| 777 | + $path = substr($path, 2); |
|
| 778 | + } elseif (substr($path, 0, 3) == '../') { |
|
| 779 | + // Step 2.A |
|
| 780 | + $path = substr($path, 3); |
|
| 781 | + } elseif (substr($path, 0, 3) == '/./' || $path == '/.') { |
|
| 782 | + // Step 2.B |
|
| 783 | + $path = '/' . substr($path, 3); |
|
| 784 | + } elseif (substr($path, 0, 4) == '/../' || $path == '/..') { |
|
| 785 | + // Step 2.C |
|
| 786 | + $path = '/' . substr($path, 4); |
|
| 787 | + $i = strrpos($output, '/'); |
|
| 788 | + $output = $i === false ? '' : substr($output, 0, $i); |
|
| 789 | + } elseif ($path == '.' || $path == '..') { |
|
| 790 | + // Step 2.D |
|
| 791 | + $path = ''; |
|
| 792 | + } else { |
|
| 793 | + // Step 2.E |
|
| 794 | + $i = strpos($path, '/'); |
|
| 795 | + if ($i === 0) { |
|
| 796 | + $i = strpos($path, '/', 1); |
|
| 797 | + } |
|
| 798 | + if ($i === false) { |
|
| 799 | + $i = strlen($path); |
|
| 800 | + } |
|
| 801 | + $output .= substr($path, 0, $i); |
|
| 802 | + $path = substr($path, $i); |
|
| 803 | + } |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + return $output; |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + /** |
|
| 810 | + * Percent-encodes all non-alphanumeric characters except these: _ . - ~ |
|
| 811 | + * Similar to PHP's rawurlencode(), except that it also encodes ~ in PHP |
|
| 812 | + * 5.2.x and earlier. |
|
| 813 | + * |
|
| 814 | + * @param $raw the string to encode |
|
| 815 | + * @return string |
|
| 816 | + */ |
|
| 817 | + public static function urlencode($string) |
|
| 818 | + { |
|
| 819 | + $encoded = rawurlencode($string); |
|
| 820 | 820 | // This is only necessary in PHP < 5.3. |
| 821 | 821 | $encoded = str_replace('%7E', '~', $encoded); |
| 822 | 822 | return $encoded; |
| 823 | - } |
|
| 824 | - |
|
| 825 | - /** |
|
| 826 | - * Returns a Net_URL2 instance representing the canonical URL of the |
|
| 827 | - * currently executing PHP script. |
|
| 828 | - * |
|
| 829 | - * @return string |
|
| 830 | - */ |
|
| 831 | - public static function getCanonical() |
|
| 832 | - { |
|
| 833 | - if (!isset($_SERVER['REQUEST_METHOD'])) { |
|
| 834 | - // ALERT - no current URL |
|
| 835 | - throw new Exception('Script was not called through a webserver'); |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - // Begin with a relative URL |
|
| 839 | - $url = new self($_SERVER['PHP_SELF']); |
|
| 840 | - $url->_scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http'; |
|
| 841 | - $url->_host = $_SERVER['SERVER_NAME']; |
|
| 842 | - $port = $_SERVER['SERVER_PORT']; |
|
| 843 | - if ($url->_scheme == 'http' && $port != 80 || |
|
| 844 | - $url->_scheme == 'https' && $port != 443) { |
|
| 845 | - |
|
| 846 | - $url->_port = $port; |
|
| 847 | - } |
|
| 848 | - return $url; |
|
| 849 | - } |
|
| 850 | - |
|
| 851 | - /** |
|
| 852 | - * Returns the URL used to retrieve the current request. |
|
| 853 | - * |
|
| 854 | - * @return string |
|
| 855 | - */ |
|
| 856 | - public static function getRequestedURL() |
|
| 857 | - { |
|
| 858 | - return self::getRequested()->getUrl(); |
|
| 859 | - } |
|
| 860 | - |
|
| 861 | - /** |
|
| 862 | - * Returns a Net_URL2 instance representing the URL used to retrieve the |
|
| 863 | - * current request. |
|
| 864 | - * |
|
| 865 | - * @return Net_URL2 |
|
| 866 | - */ |
|
| 867 | - public static function getRequested() |
|
| 868 | - { |
|
| 869 | - if (!isset($_SERVER['REQUEST_METHOD'])) { |
|
| 870 | - // ALERT - no current URL |
|
| 871 | - throw new Exception('Script was not called through a webserver'); |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - // Begin with a relative URL |
|
| 875 | - $url = new self($_SERVER['REQUEST_URI']); |
|
| 876 | - $url->_scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http'; |
|
| 877 | - // Set host and possibly port |
|
| 878 | - $url->setAuthority($_SERVER['HTTP_HOST']); |
|
| 879 | - return $url; |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - /** |
|
| 883 | - * Returns the value of the specified option. |
|
| 884 | - * |
|
| 885 | - * @param string $optionName The name of the option to retrieve |
|
| 886 | - * |
|
| 887 | - * @return mixed |
|
| 888 | - */ |
|
| 889 | - function getOption($optionName) |
|
| 890 | - { |
|
| 891 | - return isset($this->_options[$optionName]) |
|
| 892 | - ? $this->_options[$optionName] : false; |
|
| 893 | - } |
|
| 823 | + } |
|
| 824 | + |
|
| 825 | + /** |
|
| 826 | + * Returns a Net_URL2 instance representing the canonical URL of the |
|
| 827 | + * currently executing PHP script. |
|
| 828 | + * |
|
| 829 | + * @return string |
|
| 830 | + */ |
|
| 831 | + public static function getCanonical() |
|
| 832 | + { |
|
| 833 | + if (!isset($_SERVER['REQUEST_METHOD'])) { |
|
| 834 | + // ALERT - no current URL |
|
| 835 | + throw new Exception('Script was not called through a webserver'); |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + // Begin with a relative URL |
|
| 839 | + $url = new self($_SERVER['PHP_SELF']); |
|
| 840 | + $url->_scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http'; |
|
| 841 | + $url->_host = $_SERVER['SERVER_NAME']; |
|
| 842 | + $port = $_SERVER['SERVER_PORT']; |
|
| 843 | + if ($url->_scheme == 'http' && $port != 80 || |
|
| 844 | + $url->_scheme == 'https' && $port != 443) { |
|
| 845 | + |
|
| 846 | + $url->_port = $port; |
|
| 847 | + } |
|
| 848 | + return $url; |
|
| 849 | + } |
|
| 850 | + |
|
| 851 | + /** |
|
| 852 | + * Returns the URL used to retrieve the current request. |
|
| 853 | + * |
|
| 854 | + * @return string |
|
| 855 | + */ |
|
| 856 | + public static function getRequestedURL() |
|
| 857 | + { |
|
| 858 | + return self::getRequested()->getUrl(); |
|
| 859 | + } |
|
| 860 | + |
|
| 861 | + /** |
|
| 862 | + * Returns a Net_URL2 instance representing the URL used to retrieve the |
|
| 863 | + * current request. |
|
| 864 | + * |
|
| 865 | + * @return Net_URL2 |
|
| 866 | + */ |
|
| 867 | + public static function getRequested() |
|
| 868 | + { |
|
| 869 | + if (!isset($_SERVER['REQUEST_METHOD'])) { |
|
| 870 | + // ALERT - no current URL |
|
| 871 | + throw new Exception('Script was not called through a webserver'); |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + // Begin with a relative URL |
|
| 875 | + $url = new self($_SERVER['REQUEST_URI']); |
|
| 876 | + $url->_scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http'; |
|
| 877 | + // Set host and possibly port |
|
| 878 | + $url->setAuthority($_SERVER['HTTP_HOST']); |
|
| 879 | + return $url; |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + /** |
|
| 883 | + * Returns the value of the specified option. |
|
| 884 | + * |
|
| 885 | + * @param string $optionName The name of the option to retrieve |
|
| 886 | + * |
|
| 887 | + * @return mixed |
|
| 888 | + */ |
|
| 889 | + function getOption($optionName) |
|
| 890 | + { |
|
| 891 | + return isset($this->_options[$optionName]) |
|
| 892 | + ? $this->_options[$optionName] : false; |
|
| 893 | + } |
|
| 894 | 894 | } |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | */ |
| 172 | 172 | public function __set($var, $arg) |
| 173 | 173 | { |
| 174 | - $method = 'set' . $var; |
|
| 174 | + $method = 'set'.$var; |
|
| 175 | 175 | if (method_exists($this, $method)) { |
| 176 | 176 | $this->$method($arg); |
| 177 | 177 | } |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | */ |
| 191 | 191 | public function __get($var) |
| 192 | 192 | { |
| 193 | - $method = 'get' . $var; |
|
| 193 | + $method = 'get'.$var; |
|
| 194 | 194 | if (method_exists($this, $method)) { |
| 195 | 195 | return $this->$method(); |
| 196 | 196 | } |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | { |
| 278 | 278 | $this->_userinfo = $userinfo; |
| 279 | 279 | if ($password !== false) { |
| 280 | - $this->_userinfo .= ':' . $password; |
|
| 280 | + $this->_userinfo .= ':'.$password; |
|
| 281 | 281 | } |
| 282 | 282 | } |
| 283 | 283 | |
@@ -344,13 +344,13 @@ discard block |
||
| 344 | 344 | $authority = ''; |
| 345 | 345 | |
| 346 | 346 | if ($this->_userinfo !== false) { |
| 347 | - $authority .= $this->_userinfo . '@'; |
|
| 347 | + $authority .= $this->_userinfo.'@'; |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | $authority .= $this->_host; |
| 351 | 351 | |
| 352 | 352 | if ($this->_port !== false) { |
| 353 | - $authority .= ':' . $this->_port; |
|
| 353 | + $authority .= ':'.$this->_port; |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | return $authority; |
@@ -463,8 +463,8 @@ discard block |
||
| 463 | 463 | */ |
| 464 | 464 | public function getQueryVariables() |
| 465 | 465 | { |
| 466 | - $pattern = '/[' . |
|
| 467 | - preg_quote($this->getOption(self::OPTION_SEPARATOR_INPUT), '/') . |
|
| 466 | + $pattern = '/['. |
|
| 467 | + preg_quote($this->getOption(self::OPTION_SEPARATOR_INPUT), '/'). |
|
| 468 | 468 | ']/'; |
| 469 | 469 | $parts = preg_split($pattern, $this->_query, -1, PREG_SPLIT_NO_EMPTY); |
| 470 | 470 | $return = array(); |
@@ -533,10 +533,10 @@ discard block |
||
| 533 | 533 | foreach ($value as $k => $v) { |
| 534 | 534 | $parts[] = $this->getOption(self::OPTION_USE_BRACKETS) |
| 535 | 535 | ? sprintf('%s[%s]=%s', $name, $k, $v) |
| 536 | - : ($name . '=' . $v); |
|
| 536 | + : ($name.'='.$v); |
|
| 537 | 537 | } |
| 538 | 538 | } elseif (!is_null($value)) { |
| 539 | - $parts[] = $name . '=' . self::urlencode($value); |
|
| 539 | + $parts[] = $name.'='.self::urlencode($value); |
|
| 540 | 540 | } else { |
| 541 | 541 | $parts[] = $name; |
| 542 | 542 | } |
@@ -586,21 +586,21 @@ discard block |
||
| 586 | 586 | $url = ""; |
| 587 | 587 | |
| 588 | 588 | if ($this->_scheme !== false) { |
| 589 | - $url .= $this->_scheme . ':'; |
|
| 589 | + $url .= $this->_scheme.':'; |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | $authority = $this->getAuthority(); |
| 593 | 593 | if ($authority !== false) { |
| 594 | - $url .= '//' . $authority; |
|
| 594 | + $url .= '//'.$authority; |
|
| 595 | 595 | } |
| 596 | 596 | $url .= $this->_path; |
| 597 | 597 | |
| 598 | 598 | if ($this->_query !== false) { |
| 599 | - $url .= '?' . $this->_query; |
|
| 599 | + $url .= '?'.$this->_query; |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | if ($this->_fragment !== false) { |
| 603 | - $url .= '#' . $this->_fragment; |
|
| 603 | + $url .= '#'.$this->_fragment; |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | return $url; |
@@ -734,7 +734,7 @@ discard block |
||
| 734 | 734 | } else { |
| 735 | 735 | // Merge paths (RFC 3986, section 5.2.3) |
| 736 | 736 | if ($this->_host !== false && $this->_path == '') { |
| 737 | - $target->_path = '/' . $this->_path; |
|
| 737 | + $target->_path = '/'.$this->_path; |
|
| 738 | 738 | } else { |
| 739 | 739 | $i = strrpos($this->_path, '/'); |
| 740 | 740 | if ($i !== false) { |
@@ -780,10 +780,10 @@ discard block |
||
| 780 | 780 | $path = substr($path, 3); |
| 781 | 781 | } elseif (substr($path, 0, 3) == '/./' || $path == '/.') { |
| 782 | 782 | // Step 2.B |
| 783 | - $path = '/' . substr($path, 3); |
|
| 783 | + $path = '/'.substr($path, 3); |
|
| 784 | 784 | } elseif (substr($path, 0, 4) == '/../' || $path == '/..') { |
| 785 | 785 | // Step 2.C |
| 786 | - $path = '/' . substr($path, 4); |
|
| 786 | + $path = '/'.substr($path, 4); |
|
| 787 | 787 | $i = strrpos($output, '/'); |
| 788 | 788 | $output = $i === false ? '' : substr($output, 0, $i); |
| 789 | 789 | } elseif ($path == '.' || $path == '..') { |
@@ -117,6 +117,8 @@ |
||
| 117 | 117 | * @param string exception message |
| 118 | 118 | * @param int|Exception|PEAR_Error|array|null exception cause |
| 119 | 119 | * @param int|null exception code or null |
| 120 | + * @param string|null $message |
|
| 121 | + * @param integer $p2 |
|
| 120 | 122 | */ |
| 121 | 123 | public function __construct($message, $p2 = null, $p3 = null) |
| 122 | 124 | { |
@@ -96,296 +96,296 @@ |
||
| 96 | 96 | */ |
| 97 | 97 | class PEAR_Exception extends Exception |
| 98 | 98 | { |
| 99 | - const OBSERVER_PRINT = -2; |
|
| 100 | - const OBSERVER_TRIGGER = -4; |
|
| 101 | - const OBSERVER_DIE = -8; |
|
| 102 | - protected $cause; |
|
| 103 | - private static $_observers = array(); |
|
| 104 | - private static $_uniqueid = 0; |
|
| 105 | - private $_trace; |
|
| 99 | + const OBSERVER_PRINT = -2; |
|
| 100 | + const OBSERVER_TRIGGER = -4; |
|
| 101 | + const OBSERVER_DIE = -8; |
|
| 102 | + protected $cause; |
|
| 103 | + private static $_observers = array(); |
|
| 104 | + private static $_uniqueid = 0; |
|
| 105 | + private $_trace; |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Supported signatures: |
|
| 109 | - * - PEAR_Exception(string $message); |
|
| 110 | - * - PEAR_Exception(string $message, int $code); |
|
| 111 | - * - PEAR_Exception(string $message, Exception $cause); |
|
| 112 | - * - PEAR_Exception(string $message, Exception $cause, int $code); |
|
| 113 | - * - PEAR_Exception(string $message, PEAR_Error $cause); |
|
| 114 | - * - PEAR_Exception(string $message, PEAR_Error $cause, int $code); |
|
| 115 | - * - PEAR_Exception(string $message, array $causes); |
|
| 116 | - * - PEAR_Exception(string $message, array $causes, int $code); |
|
| 117 | - * @param string exception message |
|
| 118 | - * @param int|Exception|PEAR_Error|array|null exception cause |
|
| 119 | - * @param int|null exception code or null |
|
| 120 | - */ |
|
| 121 | - public function __construct($message, $p2 = null, $p3 = null) |
|
| 122 | - { |
|
| 123 | - if (is_int($p2)) { |
|
| 124 | - $code = $p2; |
|
| 125 | - $this->cause = null; |
|
| 126 | - } elseif (is_object($p2) || is_array($p2)) { |
|
| 127 | - // using is_object allows both Exception and PEAR_Error |
|
| 128 | - if (is_object($p2) && !($p2 instanceof Exception)) { |
|
| 129 | - if (!class_exists('PEAR_Error') || !($p2 instanceof PEAR_Error)) { |
|
| 130 | - throw new PEAR_Exception('exception cause must be Exception, ' . |
|
| 131 | - 'array, or PEAR_Error'); |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - $code = $p3; |
|
| 135 | - if (is_array($p2) && isset($p2['message'])) { |
|
| 136 | - // fix potential problem of passing in a single warning |
|
| 137 | - $p2 = array($p2); |
|
| 138 | - } |
|
| 139 | - $this->cause = $p2; |
|
| 140 | - } else { |
|
| 141 | - $code = null; |
|
| 142 | - $this->cause = null; |
|
| 143 | - } |
|
| 144 | - parent::__construct($message, $code); |
|
| 145 | - $this->signal(); |
|
| 146 | - } |
|
| 107 | + /** |
|
| 108 | + * Supported signatures: |
|
| 109 | + * - PEAR_Exception(string $message); |
|
| 110 | + * - PEAR_Exception(string $message, int $code); |
|
| 111 | + * - PEAR_Exception(string $message, Exception $cause); |
|
| 112 | + * - PEAR_Exception(string $message, Exception $cause, int $code); |
|
| 113 | + * - PEAR_Exception(string $message, PEAR_Error $cause); |
|
| 114 | + * - PEAR_Exception(string $message, PEAR_Error $cause, int $code); |
|
| 115 | + * - PEAR_Exception(string $message, array $causes); |
|
| 116 | + * - PEAR_Exception(string $message, array $causes, int $code); |
|
| 117 | + * @param string exception message |
|
| 118 | + * @param int|Exception|PEAR_Error|array|null exception cause |
|
| 119 | + * @param int|null exception code or null |
|
| 120 | + */ |
|
| 121 | + public function __construct($message, $p2 = null, $p3 = null) |
|
| 122 | + { |
|
| 123 | + if (is_int($p2)) { |
|
| 124 | + $code = $p2; |
|
| 125 | + $this->cause = null; |
|
| 126 | + } elseif (is_object($p2) || is_array($p2)) { |
|
| 127 | + // using is_object allows both Exception and PEAR_Error |
|
| 128 | + if (is_object($p2) && !($p2 instanceof Exception)) { |
|
| 129 | + if (!class_exists('PEAR_Error') || !($p2 instanceof PEAR_Error)) { |
|
| 130 | + throw new PEAR_Exception('exception cause must be Exception, ' . |
|
| 131 | + 'array, or PEAR_Error'); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + $code = $p3; |
|
| 135 | + if (is_array($p2) && isset($p2['message'])) { |
|
| 136 | + // fix potential problem of passing in a single warning |
|
| 137 | + $p2 = array($p2); |
|
| 138 | + } |
|
| 139 | + $this->cause = $p2; |
|
| 140 | + } else { |
|
| 141 | + $code = null; |
|
| 142 | + $this->cause = null; |
|
| 143 | + } |
|
| 144 | + parent::__construct($message, $code); |
|
| 145 | + $this->signal(); |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * @param mixed $callback - A valid php callback, see php func is_callable() |
|
| 150 | - * - A PEAR_Exception::OBSERVER_* constant |
|
| 151 | - * - An array(const PEAR_Exception::OBSERVER_*, |
|
| 152 | - * mixed $options) |
|
| 153 | - * @param string $label The name of the observer. Use this if you want |
|
| 154 | - * to remove it later with removeObserver() |
|
| 155 | - */ |
|
| 156 | - public static function addObserver($callback, $label = 'default') |
|
| 157 | - { |
|
| 158 | - self::$_observers[$label] = $callback; |
|
| 159 | - } |
|
| 148 | + /** |
|
| 149 | + * @param mixed $callback - A valid php callback, see php func is_callable() |
|
| 150 | + * - A PEAR_Exception::OBSERVER_* constant |
|
| 151 | + * - An array(const PEAR_Exception::OBSERVER_*, |
|
| 152 | + * mixed $options) |
|
| 153 | + * @param string $label The name of the observer. Use this if you want |
|
| 154 | + * to remove it later with removeObserver() |
|
| 155 | + */ |
|
| 156 | + public static function addObserver($callback, $label = 'default') |
|
| 157 | + { |
|
| 158 | + self::$_observers[$label] = $callback; |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - public static function removeObserver($label = 'default') |
|
| 162 | - { |
|
| 163 | - unset(self::$_observers[$label]); |
|
| 164 | - } |
|
| 161 | + public static function removeObserver($label = 'default') |
|
| 162 | + { |
|
| 163 | + unset(self::$_observers[$label]); |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * @return int unique identifier for an observer |
|
| 168 | - */ |
|
| 169 | - public static function getUniqueId() |
|
| 170 | - { |
|
| 171 | - return self::$_uniqueid++; |
|
| 172 | - } |
|
| 166 | + /** |
|
| 167 | + * @return int unique identifier for an observer |
|
| 168 | + */ |
|
| 169 | + public static function getUniqueId() |
|
| 170 | + { |
|
| 171 | + return self::$_uniqueid++; |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - private function signal() |
|
| 175 | - { |
|
| 176 | - foreach (self::$_observers as $func) { |
|
| 177 | - if (is_callable($func)) { |
|
| 178 | - call_user_func($func, $this); |
|
| 179 | - continue; |
|
| 180 | - } |
|
| 181 | - settype($func, 'array'); |
|
| 182 | - switch ($func[0]) { |
|
| 183 | - case self::OBSERVER_PRINT : |
|
| 184 | - $f = (isset($func[1])) ? $func[1] : '%s'; |
|
| 185 | - printf($f, $this->getMessage()); |
|
| 186 | - break; |
|
| 187 | - case self::OBSERVER_TRIGGER : |
|
| 188 | - $f = (isset($func[1])) ? $func[1] : E_USER_NOTICE; |
|
| 189 | - trigger_error($this->getMessage(), $f); |
|
| 190 | - break; |
|
| 191 | - case self::OBSERVER_DIE : |
|
| 192 | - $f = (isset($func[1])) ? $func[1] : '%s'; |
|
| 193 | - die(printf($f, $this->getMessage())); |
|
| 194 | - break; |
|
| 195 | - default: |
|
| 196 | - trigger_error('invalid observer type', E_USER_WARNING); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } |
|
| 174 | + private function signal() |
|
| 175 | + { |
|
| 176 | + foreach (self::$_observers as $func) { |
|
| 177 | + if (is_callable($func)) { |
|
| 178 | + call_user_func($func, $this); |
|
| 179 | + continue; |
|
| 180 | + } |
|
| 181 | + settype($func, 'array'); |
|
| 182 | + switch ($func[0]) { |
|
| 183 | + case self::OBSERVER_PRINT : |
|
| 184 | + $f = (isset($func[1])) ? $func[1] : '%s'; |
|
| 185 | + printf($f, $this->getMessage()); |
|
| 186 | + break; |
|
| 187 | + case self::OBSERVER_TRIGGER : |
|
| 188 | + $f = (isset($func[1])) ? $func[1] : E_USER_NOTICE; |
|
| 189 | + trigger_error($this->getMessage(), $f); |
|
| 190 | + break; |
|
| 191 | + case self::OBSERVER_DIE : |
|
| 192 | + $f = (isset($func[1])) ? $func[1] : '%s'; |
|
| 193 | + die(printf($f, $this->getMessage())); |
|
| 194 | + break; |
|
| 195 | + default: |
|
| 196 | + trigger_error('invalid observer type', E_USER_WARNING); |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * Return specific error information that can be used for more detailed |
|
| 203 | - * error messages or translation. |
|
| 204 | - * |
|
| 205 | - * This method may be overridden in child exception classes in order |
|
| 206 | - * to add functionality not present in PEAR_Exception and is a placeholder |
|
| 207 | - * to define API |
|
| 208 | - * |
|
| 209 | - * The returned array must be an associative array of parameter => value like so: |
|
| 210 | - * <pre> |
|
| 211 | - * array('name' => $name, 'context' => array(...)) |
|
| 212 | - * </pre> |
|
| 213 | - * @return array |
|
| 214 | - */ |
|
| 215 | - public function getErrorData() |
|
| 216 | - { |
|
| 217 | - return array(); |
|
| 218 | - } |
|
| 201 | + /** |
|
| 202 | + * Return specific error information that can be used for more detailed |
|
| 203 | + * error messages or translation. |
|
| 204 | + * |
|
| 205 | + * This method may be overridden in child exception classes in order |
|
| 206 | + * to add functionality not present in PEAR_Exception and is a placeholder |
|
| 207 | + * to define API |
|
| 208 | + * |
|
| 209 | + * The returned array must be an associative array of parameter => value like so: |
|
| 210 | + * <pre> |
|
| 211 | + * array('name' => $name, 'context' => array(...)) |
|
| 212 | + * </pre> |
|
| 213 | + * @return array |
|
| 214 | + */ |
|
| 215 | + public function getErrorData() |
|
| 216 | + { |
|
| 217 | + return array(); |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - /** |
|
| 221 | - * Returns the exception that caused this exception to be thrown |
|
| 222 | - * @access public |
|
| 223 | - * @return Exception|array The context of the exception |
|
| 224 | - */ |
|
| 225 | - public function getCause() |
|
| 226 | - { |
|
| 227 | - return $this->cause; |
|
| 228 | - } |
|
| 220 | + /** |
|
| 221 | + * Returns the exception that caused this exception to be thrown |
|
| 222 | + * @access public |
|
| 223 | + * @return Exception|array The context of the exception |
|
| 224 | + */ |
|
| 225 | + public function getCause() |
|
| 226 | + { |
|
| 227 | + return $this->cause; |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - /** |
|
| 231 | - * Function must be public to call on caused exceptions |
|
| 232 | - * @param array |
|
| 233 | - */ |
|
| 234 | - public function getCauseMessage(&$causes) |
|
| 235 | - { |
|
| 236 | - $trace = $this->getTraceSafe(); |
|
| 237 | - $cause = array('class' => get_class($this), |
|
| 238 | - 'message' => $this->message, |
|
| 239 | - 'file' => 'unknown', |
|
| 240 | - 'line' => 'unknown'); |
|
| 241 | - if (isset($trace[0])) { |
|
| 242 | - if (isset($trace[0]['file'])) { |
|
| 243 | - $cause['file'] = $trace[0]['file']; |
|
| 244 | - $cause['line'] = $trace[0]['line']; |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - $causes[] = $cause; |
|
| 248 | - if ($this->cause instanceof PEAR_Exception) { |
|
| 249 | - $this->cause->getCauseMessage($causes); |
|
| 250 | - } elseif ($this->cause instanceof Exception) { |
|
| 251 | - $causes[] = array('class' => get_class($this->cause), |
|
| 252 | - 'message' => $this->cause->getMessage(), |
|
| 253 | - 'file' => $this->cause->getFile(), |
|
| 254 | - 'line' => $this->cause->getLine()); |
|
| 255 | - } elseif (class_exists('PEAR_Error') && $this->cause instanceof PEAR_Error) { |
|
| 256 | - $causes[] = array('class' => get_class($this->cause), |
|
| 257 | - 'message' => $this->cause->getMessage(), |
|
| 258 | - 'file' => 'unknown', |
|
| 259 | - 'line' => 'unknown'); |
|
| 260 | - } elseif (is_array($this->cause)) { |
|
| 261 | - foreach ($this->cause as $cause) { |
|
| 262 | - if ($cause instanceof PEAR_Exception) { |
|
| 263 | - $cause->getCauseMessage($causes); |
|
| 264 | - } elseif ($cause instanceof Exception) { |
|
| 265 | - $causes[] = array('class' => get_class($cause), |
|
| 266 | - 'message' => $cause->getMessage(), |
|
| 267 | - 'file' => $cause->getFile(), |
|
| 268 | - 'line' => $cause->getLine()); |
|
| 269 | - } elseif (class_exists('PEAR_Error') && $cause instanceof PEAR_Error) { |
|
| 270 | - $causes[] = array('class' => get_class($cause), |
|
| 271 | - 'message' => $cause->getMessage(), |
|
| 272 | - 'file' => 'unknown', |
|
| 273 | - 'line' => 'unknown'); |
|
| 274 | - } elseif (is_array($cause) && isset($cause['message'])) { |
|
| 275 | - // PEAR_ErrorStack warning |
|
| 276 | - $causes[] = array( |
|
| 277 | - 'class' => $cause['package'], |
|
| 278 | - 'message' => $cause['message'], |
|
| 279 | - 'file' => isset($cause['context']['file']) ? |
|
| 280 | - $cause['context']['file'] : |
|
| 281 | - 'unknown', |
|
| 282 | - 'line' => isset($cause['context']['line']) ? |
|
| 283 | - $cause['context']['line'] : |
|
| 284 | - 'unknown', |
|
| 285 | - ); |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - } |
|
| 230 | + /** |
|
| 231 | + * Function must be public to call on caused exceptions |
|
| 232 | + * @param array |
|
| 233 | + */ |
|
| 234 | + public function getCauseMessage(&$causes) |
|
| 235 | + { |
|
| 236 | + $trace = $this->getTraceSafe(); |
|
| 237 | + $cause = array('class' => get_class($this), |
|
| 238 | + 'message' => $this->message, |
|
| 239 | + 'file' => 'unknown', |
|
| 240 | + 'line' => 'unknown'); |
|
| 241 | + if (isset($trace[0])) { |
|
| 242 | + if (isset($trace[0]['file'])) { |
|
| 243 | + $cause['file'] = $trace[0]['file']; |
|
| 244 | + $cause['line'] = $trace[0]['line']; |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + $causes[] = $cause; |
|
| 248 | + if ($this->cause instanceof PEAR_Exception) { |
|
| 249 | + $this->cause->getCauseMessage($causes); |
|
| 250 | + } elseif ($this->cause instanceof Exception) { |
|
| 251 | + $causes[] = array('class' => get_class($this->cause), |
|
| 252 | + 'message' => $this->cause->getMessage(), |
|
| 253 | + 'file' => $this->cause->getFile(), |
|
| 254 | + 'line' => $this->cause->getLine()); |
|
| 255 | + } elseif (class_exists('PEAR_Error') && $this->cause instanceof PEAR_Error) { |
|
| 256 | + $causes[] = array('class' => get_class($this->cause), |
|
| 257 | + 'message' => $this->cause->getMessage(), |
|
| 258 | + 'file' => 'unknown', |
|
| 259 | + 'line' => 'unknown'); |
|
| 260 | + } elseif (is_array($this->cause)) { |
|
| 261 | + foreach ($this->cause as $cause) { |
|
| 262 | + if ($cause instanceof PEAR_Exception) { |
|
| 263 | + $cause->getCauseMessage($causes); |
|
| 264 | + } elseif ($cause instanceof Exception) { |
|
| 265 | + $causes[] = array('class' => get_class($cause), |
|
| 266 | + 'message' => $cause->getMessage(), |
|
| 267 | + 'file' => $cause->getFile(), |
|
| 268 | + 'line' => $cause->getLine()); |
|
| 269 | + } elseif (class_exists('PEAR_Error') && $cause instanceof PEAR_Error) { |
|
| 270 | + $causes[] = array('class' => get_class($cause), |
|
| 271 | + 'message' => $cause->getMessage(), |
|
| 272 | + 'file' => 'unknown', |
|
| 273 | + 'line' => 'unknown'); |
|
| 274 | + } elseif (is_array($cause) && isset($cause['message'])) { |
|
| 275 | + // PEAR_ErrorStack warning |
|
| 276 | + $causes[] = array( |
|
| 277 | + 'class' => $cause['package'], |
|
| 278 | + 'message' => $cause['message'], |
|
| 279 | + 'file' => isset($cause['context']['file']) ? |
|
| 280 | + $cause['context']['file'] : |
|
| 281 | + 'unknown', |
|
| 282 | + 'line' => isset($cause['context']['line']) ? |
|
| 283 | + $cause['context']['line'] : |
|
| 284 | + 'unknown', |
|
| 285 | + ); |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - public function getTraceSafe() |
|
| 292 | - { |
|
| 293 | - if (!isset($this->_trace)) { |
|
| 294 | - $this->_trace = $this->getTrace(); |
|
| 295 | - if (empty($this->_trace)) { |
|
| 296 | - $backtrace = debug_backtrace(); |
|
| 297 | - $this->_trace = array($backtrace[count($backtrace)-1]); |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - return $this->_trace; |
|
| 301 | - } |
|
| 291 | + public function getTraceSafe() |
|
| 292 | + { |
|
| 293 | + if (!isset($this->_trace)) { |
|
| 294 | + $this->_trace = $this->getTrace(); |
|
| 295 | + if (empty($this->_trace)) { |
|
| 296 | + $backtrace = debug_backtrace(); |
|
| 297 | + $this->_trace = array($backtrace[count($backtrace)-1]); |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + return $this->_trace; |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | - public function getErrorClass() |
|
| 304 | - { |
|
| 305 | - $trace = $this->getTraceSafe(); |
|
| 306 | - return $trace[0]['class']; |
|
| 307 | - } |
|
| 303 | + public function getErrorClass() |
|
| 304 | + { |
|
| 305 | + $trace = $this->getTraceSafe(); |
|
| 306 | + return $trace[0]['class']; |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - public function getErrorMethod() |
|
| 310 | - { |
|
| 311 | - $trace = $this->getTraceSafe(); |
|
| 312 | - return $trace[0]['function']; |
|
| 313 | - } |
|
| 309 | + public function getErrorMethod() |
|
| 310 | + { |
|
| 311 | + $trace = $this->getTraceSafe(); |
|
| 312 | + return $trace[0]['function']; |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - public function __toString() |
|
| 316 | - { |
|
| 317 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 318 | - return $this->toHtml(); |
|
| 319 | - } |
|
| 320 | - return $this->toText(); |
|
| 321 | - } |
|
| 315 | + public function __toString() |
|
| 316 | + { |
|
| 317 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 318 | + return $this->toHtml(); |
|
| 319 | + } |
|
| 320 | + return $this->toText(); |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | - public function toHtml() |
|
| 324 | - { |
|
| 325 | - $trace = $this->getTraceSafe(); |
|
| 326 | - $causes = array(); |
|
| 327 | - $this->getCauseMessage($causes); |
|
| 328 | - $html = '<table border="1" cellspacing="0">' . "\n"; |
|
| 329 | - foreach ($causes as $i => $cause) { |
|
| 330 | - $html .= '<tr><td colspan="3" bgcolor="#ff9999">' |
|
| 331 | - . str_repeat('-', $i) . ' <b>' . $cause['class'] . '</b>: ' |
|
| 332 | - . htmlspecialchars($cause['message'], ENT_COMPAT | ENT_HTML401, 'UTF-8', false) . ' in <b>' . $cause['file'] . '</b> ' |
|
| 333 | - . 'on line <b>' . $cause['line'] . '</b>' |
|
| 334 | - . "</td></tr>\n"; |
|
| 335 | - } |
|
| 336 | - $html .= '<tr><td colspan="3" bgcolor="#aaaaaa" align="center"><b>Exception trace</b></td></tr>' . "\n" |
|
| 337 | - . '<tr><td align="center" bgcolor="#cccccc" width="20"><b>#</b></td>' |
|
| 338 | - . '<td align="center" bgcolor="#cccccc"><b>Function</b></td>' |
|
| 339 | - . '<td align="center" bgcolor="#cccccc"><b>Location</b></td></tr>' . "\n"; |
|
| 323 | + public function toHtml() |
|
| 324 | + { |
|
| 325 | + $trace = $this->getTraceSafe(); |
|
| 326 | + $causes = array(); |
|
| 327 | + $this->getCauseMessage($causes); |
|
| 328 | + $html = '<table border="1" cellspacing="0">' . "\n"; |
|
| 329 | + foreach ($causes as $i => $cause) { |
|
| 330 | + $html .= '<tr><td colspan="3" bgcolor="#ff9999">' |
|
| 331 | + . str_repeat('-', $i) . ' <b>' . $cause['class'] . '</b>: ' |
|
| 332 | + . htmlspecialchars($cause['message'], ENT_COMPAT | ENT_HTML401, 'UTF-8', false) . ' in <b>' . $cause['file'] . '</b> ' |
|
| 333 | + . 'on line <b>' . $cause['line'] . '</b>' |
|
| 334 | + . "</td></tr>\n"; |
|
| 335 | + } |
|
| 336 | + $html .= '<tr><td colspan="3" bgcolor="#aaaaaa" align="center"><b>Exception trace</b></td></tr>' . "\n" |
|
| 337 | + . '<tr><td align="center" bgcolor="#cccccc" width="20"><b>#</b></td>' |
|
| 338 | + . '<td align="center" bgcolor="#cccccc"><b>Function</b></td>' |
|
| 339 | + . '<td align="center" bgcolor="#cccccc"><b>Location</b></td></tr>' . "\n"; |
|
| 340 | 340 | |
| 341 | - foreach ($trace as $k => $v) { |
|
| 342 | - $html .= '<tr><td align="center">' . $k . '</td>' |
|
| 343 | - . '<td>'; |
|
| 344 | - if (!empty($v['class'])) { |
|
| 345 | - $html .= $v['class'] . $v['type']; |
|
| 346 | - } |
|
| 347 | - $html .= $v['function']; |
|
| 348 | - $args = array(); |
|
| 349 | - if (!empty($v['args'])) { |
|
| 350 | - foreach ($v['args'] as $arg) { |
|
| 351 | - if (is_null($arg)) $args[] = 'null'; |
|
| 352 | - elseif (is_array($arg)) $args[] = 'Array'; |
|
| 353 | - elseif (is_object($arg)) $args[] = 'Object('.get_class($arg).')'; |
|
| 354 | - elseif (is_bool($arg)) $args[] = $arg ? 'true' : 'false'; |
|
| 355 | - elseif (is_int($arg) || is_double($arg)) $args[] = $arg; |
|
| 356 | - else { |
|
| 357 | - $arg = (string)$arg; |
|
| 358 | - $str = htmlspecialchars(substr($arg, 0, 16), ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
|
| 359 | - if (strlen($arg) > 16) $str .= '…'; |
|
| 360 | - $args[] = "'" . $str . "'"; |
|
| 361 | - } |
|
| 362 | - } |
|
| 363 | - } |
|
| 364 | - $html .= '(' . implode(', ',$args) . ')' |
|
| 365 | - . '</td>' |
|
| 366 | - . '<td>' . (isset($v['file']) ? $v['file'] : 'unknown') |
|
| 367 | - . ':' . (isset($v['line']) ? $v['line'] : 'unknown') |
|
| 368 | - . '</td></tr>' . "\n"; |
|
| 369 | - } |
|
| 370 | - $html .= '<tr><td align="center">' . ($k+1) . '</td>' |
|
| 371 | - . '<td>{main}</td>' |
|
| 372 | - . '<td> </td></tr>' . "\n" |
|
| 373 | - . '</table>'; |
|
| 374 | - return $html; |
|
| 375 | - } |
|
| 341 | + foreach ($trace as $k => $v) { |
|
| 342 | + $html .= '<tr><td align="center">' . $k . '</td>' |
|
| 343 | + . '<td>'; |
|
| 344 | + if (!empty($v['class'])) { |
|
| 345 | + $html .= $v['class'] . $v['type']; |
|
| 346 | + } |
|
| 347 | + $html .= $v['function']; |
|
| 348 | + $args = array(); |
|
| 349 | + if (!empty($v['args'])) { |
|
| 350 | + foreach ($v['args'] as $arg) { |
|
| 351 | + if (is_null($arg)) $args[] = 'null'; |
|
| 352 | + elseif (is_array($arg)) $args[] = 'Array'; |
|
| 353 | + elseif (is_object($arg)) $args[] = 'Object('.get_class($arg).')'; |
|
| 354 | + elseif (is_bool($arg)) $args[] = $arg ? 'true' : 'false'; |
|
| 355 | + elseif (is_int($arg) || is_double($arg)) $args[] = $arg; |
|
| 356 | + else { |
|
| 357 | + $arg = (string)$arg; |
|
| 358 | + $str = htmlspecialchars(substr($arg, 0, 16), ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
|
| 359 | + if (strlen($arg) > 16) $str .= '…'; |
|
| 360 | + $args[] = "'" . $str . "'"; |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | + } |
|
| 364 | + $html .= '(' . implode(', ',$args) . ')' |
|
| 365 | + . '</td>' |
|
| 366 | + . '<td>' . (isset($v['file']) ? $v['file'] : 'unknown') |
|
| 367 | + . ':' . (isset($v['line']) ? $v['line'] : 'unknown') |
|
| 368 | + . '</td></tr>' . "\n"; |
|
| 369 | + } |
|
| 370 | + $html .= '<tr><td align="center">' . ($k+1) . '</td>' |
|
| 371 | + . '<td>{main}</td>' |
|
| 372 | + . '<td> </td></tr>' . "\n" |
|
| 373 | + . '</table>'; |
|
| 374 | + return $html; |
|
| 375 | + } |
|
| 376 | 376 | |
| 377 | - public function toText() |
|
| 378 | - { |
|
| 379 | - $causes = array(); |
|
| 380 | - $this->getCauseMessage($causes); |
|
| 381 | - $causeMsg = ''; |
|
| 382 | - foreach ($causes as $i => $cause) { |
|
| 383 | - $causeMsg .= str_repeat(' ', $i) . $cause['class'] . ': ' |
|
| 384 | - . $cause['message'] . ' in ' . $cause['file'] |
|
| 385 | - . ' on line ' . $cause['line'] . "\n"; |
|
| 386 | - } |
|
| 387 | - return $causeMsg . $this->getTraceAsString(); |
|
| 388 | - } |
|
| 377 | + public function toText() |
|
| 378 | + { |
|
| 379 | + $causes = array(); |
|
| 380 | + $this->getCauseMessage($causes); |
|
| 381 | + $causeMsg = ''; |
|
| 382 | + foreach ($causes as $i => $cause) { |
|
| 383 | + $causeMsg .= str_repeat(' ', $i) . $cause['class'] . ': ' |
|
| 384 | + . $cause['message'] . ' in ' . $cause['file'] |
|
| 385 | + . ' on line ' . $cause['line'] . "\n"; |
|
| 386 | + } |
|
| 387 | + return $causeMsg . $this->getTraceAsString(); |
|
| 388 | + } |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | ?> |
@@ -348,15 +348,22 @@ |
||
| 348 | 348 | $args = array(); |
| 349 | 349 | if (!empty($v['args'])) { |
| 350 | 350 | foreach ($v['args'] as $arg) { |
| 351 | - if (is_null($arg)) $args[] = 'null'; |
|
| 352 | - elseif (is_array($arg)) $args[] = 'Array'; |
|
| 353 | - elseif (is_object($arg)) $args[] = 'Object('.get_class($arg).')'; |
|
| 354 | - elseif (is_bool($arg)) $args[] = $arg ? 'true' : 'false'; |
|
| 355 | - elseif (is_int($arg) || is_double($arg)) $args[] = $arg; |
|
| 356 | - else { |
|
| 351 | + if (is_null($arg)) { |
|
| 352 | + $args[] = 'null'; |
|
| 353 | + } elseif (is_array($arg)) { |
|
| 354 | + $args[] = 'Array'; |
|
| 355 | + } elseif (is_object($arg)) { |
|
| 356 | + $args[] = 'Object('.get_class($arg).')'; |
|
| 357 | + } elseif (is_bool($arg)) { |
|
| 358 | + $args[] = $arg ? 'true' : 'false'; |
|
| 359 | + } elseif (is_int($arg) || is_double($arg)) { |
|
| 360 | + $args[] = $arg; |
|
| 361 | + } else { |
|
| 357 | 362 | $arg = (string)$arg; |
| 358 | 363 | $str = htmlspecialchars(substr($arg, 0, 16), ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
| 359 | - if (strlen($arg) > 16) $str .= '…'; |
|
| 364 | + if (strlen($arg) > 16) { |
|
| 365 | + $str .= '…'; |
|
| 366 | + } |
|
| 360 | 367 | $args[] = "'" . $str . "'"; |
| 361 | 368 | } |
| 362 | 369 | } |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | // using is_object allows both Exception and PEAR_Error |
| 128 | 128 | if (is_object($p2) && !($p2 instanceof Exception)) { |
| 129 | 129 | if (!class_exists('PEAR_Error') || !($p2 instanceof PEAR_Error)) { |
| 130 | - throw new PEAR_Exception('exception cause must be Exception, ' . |
|
| 130 | + throw new PEAR_Exception('exception cause must be Exception, '. |
|
| 131 | 131 | 'array, or PEAR_Error'); |
| 132 | 132 | } |
| 133 | 133 | } |
@@ -277,11 +277,9 @@ discard block |
||
| 277 | 277 | 'class' => $cause['package'], |
| 278 | 278 | 'message' => $cause['message'], |
| 279 | 279 | 'file' => isset($cause['context']['file']) ? |
| 280 | - $cause['context']['file'] : |
|
| 281 | - 'unknown', |
|
| 280 | + $cause['context']['file'] : 'unknown', |
|
| 282 | 281 | 'line' => isset($cause['context']['line']) ? |
| 283 | - $cause['context']['line'] : |
|
| 284 | - 'unknown', |
|
| 282 | + $cause['context']['line'] : 'unknown', |
|
| 285 | 283 | ); |
| 286 | 284 | } |
| 287 | 285 | } |
@@ -294,7 +292,7 @@ discard block |
||
| 294 | 292 | $this->_trace = $this->getTrace(); |
| 295 | 293 | if (empty($this->_trace)) { |
| 296 | 294 | $backtrace = debug_backtrace(); |
| 297 | - $this->_trace = array($backtrace[count($backtrace)-1]); |
|
| 295 | + $this->_trace = array($backtrace[count($backtrace) - 1]); |
|
| 298 | 296 | } |
| 299 | 297 | } |
| 300 | 298 | return $this->_trace; |
@@ -325,24 +323,24 @@ discard block |
||
| 325 | 323 | $trace = $this->getTraceSafe(); |
| 326 | 324 | $causes = array(); |
| 327 | 325 | $this->getCauseMessage($causes); |
| 328 | - $html = '<table border="1" cellspacing="0">' . "\n"; |
|
| 326 | + $html = '<table border="1" cellspacing="0">'."\n"; |
|
| 329 | 327 | foreach ($causes as $i => $cause) { |
| 330 | 328 | $html .= '<tr><td colspan="3" bgcolor="#ff9999">' |
| 331 | - . str_repeat('-', $i) . ' <b>' . $cause['class'] . '</b>: ' |
|
| 332 | - . htmlspecialchars($cause['message'], ENT_COMPAT | ENT_HTML401, 'UTF-8', false) . ' in <b>' . $cause['file'] . '</b> ' |
|
| 333 | - . 'on line <b>' . $cause['line'] . '</b>' |
|
| 329 | + . str_repeat('-', $i).' <b>'.$cause['class'].'</b>: ' |
|
| 330 | + . htmlspecialchars($cause['message'], ENT_COMPAT | ENT_HTML401, 'UTF-8', false).' in <b>'.$cause['file'].'</b> ' |
|
| 331 | + . 'on line <b>'.$cause['line'].'</b>' |
|
| 334 | 332 | . "</td></tr>\n"; |
| 335 | 333 | } |
| 336 | - $html .= '<tr><td colspan="3" bgcolor="#aaaaaa" align="center"><b>Exception trace</b></td></tr>' . "\n" |
|
| 334 | + $html .= '<tr><td colspan="3" bgcolor="#aaaaaa" align="center"><b>Exception trace</b></td></tr>'."\n" |
|
| 337 | 335 | . '<tr><td align="center" bgcolor="#cccccc" width="20"><b>#</b></td>' |
| 338 | 336 | . '<td align="center" bgcolor="#cccccc"><b>Function</b></td>' |
| 339 | - . '<td align="center" bgcolor="#cccccc"><b>Location</b></td></tr>' . "\n"; |
|
| 337 | + . '<td align="center" bgcolor="#cccccc"><b>Location</b></td></tr>'."\n"; |
|
| 340 | 338 | |
| 341 | 339 | foreach ($trace as $k => $v) { |
| 342 | - $html .= '<tr><td align="center">' . $k . '</td>' |
|
| 340 | + $html .= '<tr><td align="center">'.$k.'</td>' |
|
| 343 | 341 | . '<td>'; |
| 344 | 342 | if (!empty($v['class'])) { |
| 345 | - $html .= $v['class'] . $v['type']; |
|
| 343 | + $html .= $v['class'].$v['type']; |
|
| 346 | 344 | } |
| 347 | 345 | $html .= $v['function']; |
| 348 | 346 | $args = array(); |
@@ -354,22 +352,22 @@ discard block |
||
| 354 | 352 | elseif (is_bool($arg)) $args[] = $arg ? 'true' : 'false'; |
| 355 | 353 | elseif (is_int($arg) || is_double($arg)) $args[] = $arg; |
| 356 | 354 | else { |
| 357 | - $arg = (string)$arg; |
|
| 355 | + $arg = (string) $arg; |
|
| 358 | 356 | $str = htmlspecialchars(substr($arg, 0, 16), ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
| 359 | 357 | if (strlen($arg) > 16) $str .= '…'; |
| 360 | - $args[] = "'" . $str . "'"; |
|
| 358 | + $args[] = "'".$str."'"; |
|
| 361 | 359 | } |
| 362 | 360 | } |
| 363 | 361 | } |
| 364 | - $html .= '(' . implode(', ',$args) . ')' |
|
| 362 | + $html .= '('.implode(', ', $args).')' |
|
| 365 | 363 | . '</td>' |
| 366 | - . '<td>' . (isset($v['file']) ? $v['file'] : 'unknown') |
|
| 367 | - . ':' . (isset($v['line']) ? $v['line'] : 'unknown') |
|
| 368 | - . '</td></tr>' . "\n"; |
|
| 364 | + . '<td>'.(isset($v['file']) ? $v['file'] : 'unknown') |
|
| 365 | + . ':'.(isset($v['line']) ? $v['line'] : 'unknown') |
|
| 366 | + . '</td></tr>'."\n"; |
|
| 369 | 367 | } |
| 370 | - $html .= '<tr><td align="center">' . ($k+1) . '</td>' |
|
| 368 | + $html .= '<tr><td align="center">'.($k + 1).'</td>' |
|
| 371 | 369 | . '<td>{main}</td>' |
| 372 | - . '<td> </td></tr>' . "\n" |
|
| 370 | + . '<td> </td></tr>'."\n" |
|
| 373 | 371 | . '</table>'; |
| 374 | 372 | return $html; |
| 375 | 373 | } |
@@ -380,11 +378,11 @@ discard block |
||
| 380 | 378 | $this->getCauseMessage($causes); |
| 381 | 379 | $causeMsg = ''; |
| 382 | 380 | foreach ($causes as $i => $cause) { |
| 383 | - $causeMsg .= str_repeat(' ', $i) . $cause['class'] . ': ' |
|
| 384 | - . $cause['message'] . ' in ' . $cause['file'] |
|
| 385 | - . ' on line ' . $cause['line'] . "\n"; |
|
| 381 | + $causeMsg .= str_repeat(' ', $i).$cause['class'].': ' |
|
| 382 | + . $cause['message'].' in '.$cause['file'] |
|
| 383 | + . ' on line '.$cause['line']."\n"; |
|
| 386 | 384 | } |
| 387 | - return $causeMsg . $this->getTraceAsString(); |
|
| 385 | + return $causeMsg.$this->getTraceAsString(); |
|
| 388 | 386 | } |
| 389 | 387 | } |
| 390 | 388 | |
@@ -1267,6 +1267,7 @@ discard block |
||
| 1267 | 1267 | * |
| 1268 | 1268 | * @access private |
| 1269 | 1269 | * @param string value of Set-Cookie header |
| 1270 | + * @param string $headervalue |
|
| 1270 | 1271 | */ |
| 1271 | 1272 | function _parseCookie($headervalue) |
| 1272 | 1273 | { |
@@ -1349,6 +1350,7 @@ discard block |
||
| 1349 | 1350 | * |
| 1350 | 1351 | * @param string Event name |
| 1351 | 1352 | * @param mixed Additional data |
| 1353 | + * @param string $event |
|
| 1352 | 1354 | * @access private |
| 1353 | 1355 | * @see HTTP_Request::_notify() |
| 1354 | 1356 | */ |
@@ -1369,6 +1371,7 @@ discard block |
||
| 1369 | 1371 | * |
| 1370 | 1372 | * @access private |
| 1371 | 1373 | * @param string gzip-encoded data |
| 1374 | + * @param string $data |
|
| 1372 | 1375 | * @return string decoded data |
| 1373 | 1376 | */ |
| 1374 | 1377 | function _decodeGzip($data) |
@@ -80,12 +80,12 @@ discard block |
||
| 80 | 80 | /** |
| 81 | 81 | * Whether string functions are overloaded by their mbstring equivalents |
| 82 | 82 | */ |
| 83 | - define('HTTP_REQUEST_MBSTRING', true); |
|
| 83 | + define('HTTP_REQUEST_MBSTRING', true); |
|
| 84 | 84 | } else { |
| 85 | 85 | /** |
| 86 | 86 | * @ignore |
| 87 | 87 | */ |
| 88 | - define('HTTP_REQUEST_MBSTRING', false); |
|
| 88 | + define('HTTP_REQUEST_MBSTRING', false); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -109,297 +109,297 @@ discard block |
||
| 109 | 109 | /**#@+ |
| 110 | 110 | * @access private |
| 111 | 111 | */ |
| 112 | - /** |
|
| 113 | - * Instance of Net_URL |
|
| 114 | - * @var Net_URL |
|
| 115 | - */ |
|
| 116 | - var $_url; |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Type of request |
|
| 120 | - * @var string |
|
| 121 | - */ |
|
| 122 | - var $_method; |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * HTTP Version |
|
| 126 | - * @var string |
|
| 127 | - */ |
|
| 128 | - var $_http; |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Request headers |
|
| 132 | - * @var array |
|
| 133 | - */ |
|
| 134 | - var $_requestHeaders; |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Basic Auth Username |
|
| 138 | - * @var string |
|
| 139 | - */ |
|
| 140 | - var $_user; |
|
| 112 | + /** |
|
| 113 | + * Instance of Net_URL |
|
| 114 | + * @var Net_URL |
|
| 115 | + */ |
|
| 116 | + var $_url; |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Type of request |
|
| 120 | + * @var string |
|
| 121 | + */ |
|
| 122 | + var $_method; |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * HTTP Version |
|
| 126 | + * @var string |
|
| 127 | + */ |
|
| 128 | + var $_http; |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Request headers |
|
| 132 | + * @var array |
|
| 133 | + */ |
|
| 134 | + var $_requestHeaders; |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Basic Auth Username |
|
| 138 | + * @var string |
|
| 139 | + */ |
|
| 140 | + var $_user; |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Basic Auth Password |
|
| 144 | - * @var string |
|
| 145 | - */ |
|
| 146 | - var $_pass; |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Socket object |
|
| 150 | - * @var Net_Socket |
|
| 151 | - */ |
|
| 152 | - var $_sock; |
|
| 142 | + /** |
|
| 143 | + * Basic Auth Password |
|
| 144 | + * @var string |
|
| 145 | + */ |
|
| 146 | + var $_pass; |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Socket object |
|
| 150 | + * @var Net_Socket |
|
| 151 | + */ |
|
| 152 | + var $_sock; |
|
| 153 | 153 | |
| 154 | - /** |
|
| 155 | - * Proxy server |
|
| 156 | - * @var string |
|
| 157 | - */ |
|
| 158 | - var $_proxy_host; |
|
| 154 | + /** |
|
| 155 | + * Proxy server |
|
| 156 | + * @var string |
|
| 157 | + */ |
|
| 158 | + var $_proxy_host; |
|
| 159 | 159 | |
| 160 | - /** |
|
| 161 | - * Proxy port |
|
| 162 | - * @var integer |
|
| 163 | - */ |
|
| 164 | - var $_proxy_port; |
|
| 160 | + /** |
|
| 161 | + * Proxy port |
|
| 162 | + * @var integer |
|
| 163 | + */ |
|
| 164 | + var $_proxy_port; |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * Proxy username |
|
| 168 | - * @var string |
|
| 169 | - */ |
|
| 170 | - var $_proxy_user; |
|
| 166 | + /** |
|
| 167 | + * Proxy username |
|
| 168 | + * @var string |
|
| 169 | + */ |
|
| 170 | + var $_proxy_user; |
|
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * Proxy password |
|
| 174 | - * @var string |
|
| 175 | - */ |
|
| 176 | - var $_proxy_pass; |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Post data |
|
| 180 | - * @var array |
|
| 181 | - */ |
|
| 182 | - var $_postData; |
|
| 172 | + /** |
|
| 173 | + * Proxy password |
|
| 174 | + * @var string |
|
| 175 | + */ |
|
| 176 | + var $_proxy_pass; |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Post data |
|
| 180 | + * @var array |
|
| 181 | + */ |
|
| 182 | + var $_postData; |
|
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | 185 | * Request body |
| 186 | 186 | * @var string |
| 187 | 187 | */ |
| 188 | - var $_body; |
|
| 188 | + var $_body; |
|
| 189 | 189 | |
| 190 | 190 | /** |
| 191 | 191 | * A list of methods that MUST NOT have a request body, per RFC 2616 |
| 192 | 192 | * @var array |
| 193 | 193 | */ |
| 194 | - var $_bodyDisallowed = array('TRACE'); |
|
| 194 | + var $_bodyDisallowed = array('TRACE'); |
|
| 195 | 195 | |
| 196 | 196 | /** |
| 197 | 197 | * Files to post |
| 198 | 198 | * @var array |
| 199 | 199 | */ |
| 200 | - var $_postFiles = array(); |
|
| 200 | + var $_postFiles = array(); |
|
| 201 | 201 | |
| 202 | - /** |
|
| 203 | - * Connection timeout. |
|
| 204 | - * @var float |
|
| 205 | - */ |
|
| 206 | - var $_timeout; |
|
| 202 | + /** |
|
| 203 | + * Connection timeout. |
|
| 204 | + * @var float |
|
| 205 | + */ |
|
| 206 | + var $_timeout; |
|
| 207 | 207 | |
| 208 | - /** |
|
| 209 | - * HTTP_Response object |
|
| 210 | - * @var HTTP_Response |
|
| 211 | - */ |
|
| 212 | - var $_response; |
|
| 208 | + /** |
|
| 209 | + * HTTP_Response object |
|
| 210 | + * @var HTTP_Response |
|
| 211 | + */ |
|
| 212 | + var $_response; |
|
| 213 | 213 | |
| 214 | - /** |
|
| 215 | - * Whether to allow redirects |
|
| 216 | - * @var boolean |
|
| 217 | - */ |
|
| 218 | - var $_allowRedirects; |
|
| 214 | + /** |
|
| 215 | + * Whether to allow redirects |
|
| 216 | + * @var boolean |
|
| 217 | + */ |
|
| 218 | + var $_allowRedirects; |
|
| 219 | 219 | |
| 220 | - /** |
|
| 221 | - * Maximum redirects allowed |
|
| 222 | - * @var integer |
|
| 223 | - */ |
|
| 224 | - var $_maxRedirects; |
|
| 220 | + /** |
|
| 221 | + * Maximum redirects allowed |
|
| 222 | + * @var integer |
|
| 223 | + */ |
|
| 224 | + var $_maxRedirects; |
|
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * Current number of redirects |
|
| 228 | - * @var integer |
|
| 229 | - */ |
|
| 230 | - var $_redirects; |
|
| 226 | + /** |
|
| 227 | + * Current number of redirects |
|
| 228 | + * @var integer |
|
| 229 | + */ |
|
| 230 | + var $_redirects; |
|
| 231 | 231 | |
| 232 | 232 | /** |
| 233 | 233 | * Whether to append brackets [] to array variables |
| 234 | 234 | * @var bool |
| 235 | 235 | */ |
| 236 | - var $_useBrackets = true; |
|
| 236 | + var $_useBrackets = true; |
|
| 237 | 237 | |
| 238 | 238 | /** |
| 239 | 239 | * Attached listeners |
| 240 | 240 | * @var array |
| 241 | 241 | */ |
| 242 | - var $_listeners = array(); |
|
| 242 | + var $_listeners = array(); |
|
| 243 | 243 | |
| 244 | 244 | /** |
| 245 | 245 | * Whether to save response body in response object property |
| 246 | 246 | * @var bool |
| 247 | 247 | */ |
| 248 | - var $_saveBody = true; |
|
| 248 | + var $_saveBody = true; |
|
| 249 | 249 | |
| 250 | 250 | /** |
| 251 | 251 | * Timeout for reading from socket (array(seconds, microseconds)) |
| 252 | 252 | * @var array |
| 253 | 253 | */ |
| 254 | - var $_readTimeout = null; |
|
| 254 | + var $_readTimeout = null; |
|
| 255 | 255 | |
| 256 | 256 | /** |
| 257 | 257 | * Options to pass to Net_Socket::connect. See stream_context_create |
| 258 | 258 | * @var array |
| 259 | 259 | */ |
| 260 | - var $_socketOptions = null; |
|
| 260 | + var $_socketOptions = null; |
|
| 261 | 261 | /**#@-*/ |
| 262 | 262 | |
| 263 | - /** |
|
| 264 | - * Constructor |
|
| 265 | - * |
|
| 266 | - * Sets up the object |
|
| 267 | - * @param string The url to fetch/access |
|
| 268 | - * @param array Associative array of parameters which can have the following keys: |
|
| 269 | - * <ul> |
|
| 270 | - * <li>method - Method to use, GET, POST etc (string)</li> |
|
| 271 | - * <li>http - HTTP Version to use, 1.0 or 1.1 (string)</li> |
|
| 272 | - * <li>user - Basic Auth username (string)</li> |
|
| 273 | - * <li>pass - Basic Auth password (string)</li> |
|
| 274 | - * <li>proxy_host - Proxy server host (string)</li> |
|
| 275 | - * <li>proxy_port - Proxy server port (integer)</li> |
|
| 276 | - * <li>proxy_user - Proxy auth username (string)</li> |
|
| 277 | - * <li>proxy_pass - Proxy auth password (string)</li> |
|
| 278 | - * <li>timeout - Connection timeout in seconds (float)</li> |
|
| 279 | - * <li>allowRedirects - Whether to follow redirects or not (bool)</li> |
|
| 280 | - * <li>maxRedirects - Max number of redirects to follow (integer)</li> |
|
| 281 | - * <li>useBrackets - Whether to append [] to array variable names (bool)</li> |
|
| 282 | - * <li>saveBody - Whether to save response body in response object property (bool)</li> |
|
| 283 | - * <li>readTimeout - Timeout for reading / writing data over the socket (array (seconds, microseconds))</li> |
|
| 284 | - * <li>socketOptions - Options to pass to Net_Socket object (array)</li> |
|
| 285 | - * </ul> |
|
| 286 | - * @access public |
|
| 287 | - */ |
|
| 288 | - function HTTP_Request($url = '', $params = array()) |
|
| 289 | - { |
|
| 290 | - $this->_method = HTTP_REQUEST_METHOD_GET; |
|
| 291 | - $this->_http = HTTP_REQUEST_HTTP_VER_1_1; |
|
| 292 | - $this->_requestHeaders = array(); |
|
| 293 | - $this->_postData = array(); |
|
| 294 | - $this->_body = null; |
|
| 295 | - |
|
| 296 | - $this->_user = null; |
|
| 297 | - $this->_pass = null; |
|
| 298 | - |
|
| 299 | - $this->_proxy_host = null; |
|
| 300 | - $this->_proxy_port = null; |
|
| 301 | - $this->_proxy_user = null; |
|
| 302 | - $this->_proxy_pass = null; |
|
| 303 | - |
|
| 304 | - $this->_allowRedirects = false; |
|
| 305 | - $this->_maxRedirects = 3; |
|
| 306 | - $this->_redirects = 0; |
|
| 307 | - |
|
| 308 | - $this->_timeout = null; |
|
| 309 | - $this->_response = null; |
|
| 310 | - |
|
| 311 | - foreach ($params as $key => $value) { |
|
| 312 | - $this->{'_' . $key} = $value; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - if (!empty($url)) { |
|
| 316 | - $this->setURL($url); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - // Default useragent |
|
| 320 | - $this->addHeader('User-Agent', 'PEAR HTTP_Request class ( http://pear.php.net/ )'); |
|
| 321 | - |
|
| 322 | - // We don't do keep-alives by default |
|
| 323 | - $this->addHeader('Connection', 'close'); |
|
| 324 | - |
|
| 325 | - // Basic authentication |
|
| 326 | - if (!empty($this->_user)) { |
|
| 327 | - $this->addHeader('Authorization', 'Basic ' . base64_encode($this->_user . ':' . $this->_pass)); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - // Proxy authentication (see bug #5913) |
|
| 331 | - if (!empty($this->_proxy_user)) { |
|
| 332 | - $this->addHeader('Proxy-Authorization', 'Basic ' . base64_encode($this->_proxy_user . ':' . $this->_proxy_pass)); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - // Use gzip encoding if possible |
|
| 336 | - if (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http && extension_loaded('zlib')) { |
|
| 337 | - $this->addHeader('Accept-Encoding', 'gzip'); |
|
| 338 | - } |
|
| 339 | - } |
|
| 263 | + /** |
|
| 264 | + * Constructor |
|
| 265 | + * |
|
| 266 | + * Sets up the object |
|
| 267 | + * @param string The url to fetch/access |
|
| 268 | + * @param array Associative array of parameters which can have the following keys: |
|
| 269 | + * <ul> |
|
| 270 | + * <li>method - Method to use, GET, POST etc (string)</li> |
|
| 271 | + * <li>http - HTTP Version to use, 1.0 or 1.1 (string)</li> |
|
| 272 | + * <li>user - Basic Auth username (string)</li> |
|
| 273 | + * <li>pass - Basic Auth password (string)</li> |
|
| 274 | + * <li>proxy_host - Proxy server host (string)</li> |
|
| 275 | + * <li>proxy_port - Proxy server port (integer)</li> |
|
| 276 | + * <li>proxy_user - Proxy auth username (string)</li> |
|
| 277 | + * <li>proxy_pass - Proxy auth password (string)</li> |
|
| 278 | + * <li>timeout - Connection timeout in seconds (float)</li> |
|
| 279 | + * <li>allowRedirects - Whether to follow redirects or not (bool)</li> |
|
| 280 | + * <li>maxRedirects - Max number of redirects to follow (integer)</li> |
|
| 281 | + * <li>useBrackets - Whether to append [] to array variable names (bool)</li> |
|
| 282 | + * <li>saveBody - Whether to save response body in response object property (bool)</li> |
|
| 283 | + * <li>readTimeout - Timeout for reading / writing data over the socket (array (seconds, microseconds))</li> |
|
| 284 | + * <li>socketOptions - Options to pass to Net_Socket object (array)</li> |
|
| 285 | + * </ul> |
|
| 286 | + * @access public |
|
| 287 | + */ |
|
| 288 | + function HTTP_Request($url = '', $params = array()) |
|
| 289 | + { |
|
| 290 | + $this->_method = HTTP_REQUEST_METHOD_GET; |
|
| 291 | + $this->_http = HTTP_REQUEST_HTTP_VER_1_1; |
|
| 292 | + $this->_requestHeaders = array(); |
|
| 293 | + $this->_postData = array(); |
|
| 294 | + $this->_body = null; |
|
| 295 | + |
|
| 296 | + $this->_user = null; |
|
| 297 | + $this->_pass = null; |
|
| 298 | + |
|
| 299 | + $this->_proxy_host = null; |
|
| 300 | + $this->_proxy_port = null; |
|
| 301 | + $this->_proxy_user = null; |
|
| 302 | + $this->_proxy_pass = null; |
|
| 303 | + |
|
| 304 | + $this->_allowRedirects = false; |
|
| 305 | + $this->_maxRedirects = 3; |
|
| 306 | + $this->_redirects = 0; |
|
| 307 | + |
|
| 308 | + $this->_timeout = null; |
|
| 309 | + $this->_response = null; |
|
| 310 | + |
|
| 311 | + foreach ($params as $key => $value) { |
|
| 312 | + $this->{'_' . $key} = $value; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + if (!empty($url)) { |
|
| 316 | + $this->setURL($url); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + // Default useragent |
|
| 320 | + $this->addHeader('User-Agent', 'PEAR HTTP_Request class ( http://pear.php.net/ )'); |
|
| 321 | + |
|
| 322 | + // We don't do keep-alives by default |
|
| 323 | + $this->addHeader('Connection', 'close'); |
|
| 324 | + |
|
| 325 | + // Basic authentication |
|
| 326 | + if (!empty($this->_user)) { |
|
| 327 | + $this->addHeader('Authorization', 'Basic ' . base64_encode($this->_user . ':' . $this->_pass)); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + // Proxy authentication (see bug #5913) |
|
| 331 | + if (!empty($this->_proxy_user)) { |
|
| 332 | + $this->addHeader('Proxy-Authorization', 'Basic ' . base64_encode($this->_proxy_user . ':' . $this->_proxy_pass)); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + // Use gzip encoding if possible |
|
| 336 | + if (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http && extension_loaded('zlib')) { |
|
| 337 | + $this->addHeader('Accept-Encoding', 'gzip'); |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | - /** |
|
| 342 | - * Generates a Host header for HTTP/1.1 requests |
|
| 343 | - * |
|
| 344 | - * @access private |
|
| 345 | - * @return string |
|
| 346 | - */ |
|
| 347 | - function _generateHostHeader() |
|
| 348 | - { |
|
| 349 | - if ($this->_url->port != 80 AND strcasecmp($this->_url->protocol, 'http') == 0) { |
|
| 350 | - $host = $this->_url->host . ':' . $this->_url->port; |
|
| 351 | - |
|
| 352 | - } elseif ($this->_url->port != 443 AND strcasecmp($this->_url->protocol, 'https') == 0) { |
|
| 353 | - $host = $this->_url->host . ':' . $this->_url->port; |
|
| 354 | - |
|
| 355 | - } elseif ($this->_url->port == 443 AND strcasecmp($this->_url->protocol, 'https') == 0 AND strpos($this->_url->url, ':443') !== false) { |
|
| 356 | - $host = $this->_url->host . ':' . $this->_url->port; |
|
| 341 | + /** |
|
| 342 | + * Generates a Host header for HTTP/1.1 requests |
|
| 343 | + * |
|
| 344 | + * @access private |
|
| 345 | + * @return string |
|
| 346 | + */ |
|
| 347 | + function _generateHostHeader() |
|
| 348 | + { |
|
| 349 | + if ($this->_url->port != 80 AND strcasecmp($this->_url->protocol, 'http') == 0) { |
|
| 350 | + $host = $this->_url->host . ':' . $this->_url->port; |
|
| 351 | + |
|
| 352 | + } elseif ($this->_url->port != 443 AND strcasecmp($this->_url->protocol, 'https') == 0) { |
|
| 353 | + $host = $this->_url->host . ':' . $this->_url->port; |
|
| 354 | + |
|
| 355 | + } elseif ($this->_url->port == 443 AND strcasecmp($this->_url->protocol, 'https') == 0 AND strpos($this->_url->url, ':443') !== false) { |
|
| 356 | + $host = $this->_url->host . ':' . $this->_url->port; |
|
| 357 | 357 | |
| 358 | - } else { |
|
| 359 | - $host = $this->_url->host; |
|
| 360 | - } |
|
| 358 | + } else { |
|
| 359 | + $host = $this->_url->host; |
|
| 360 | + } |
|
| 361 | 361 | |
| 362 | - return $host; |
|
| 363 | - } |
|
| 362 | + return $host; |
|
| 363 | + } |
|
| 364 | 364 | |
| 365 | - /** |
|
| 366 | - * Resets the object to its initial state (DEPRECATED). |
|
| 367 | - * Takes the same parameters as the constructor. |
|
| 368 | - * |
|
| 369 | - * @param string $url The url to be requested |
|
| 370 | - * @param array $params Associative array of parameters |
|
| 371 | - * (see constructor for details) |
|
| 372 | - * @access public |
|
| 373 | - * @deprecated deprecated since 1.2, call the constructor if this is necessary |
|
| 374 | - */ |
|
| 375 | - function reset($url, $params = array()) |
|
| 376 | - { |
|
| 377 | - $this->HTTP_Request($url, $params); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Sets the URL to be requested |
|
| 382 | - * |
|
| 383 | - * @param string The url to be requested |
|
| 384 | - * @access public |
|
| 385 | - */ |
|
| 386 | - function setURL($url) |
|
| 387 | - { |
|
| 388 | - $this->_url = &new Net_URL($url, $this->_useBrackets); |
|
| 389 | - |
|
| 390 | - if (!empty($this->_url->user) || !empty($this->_url->pass)) { |
|
| 391 | - $this->setBasicAuth($this->_url->user, $this->_url->pass); |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - if (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http) { |
|
| 395 | - $this->addHeader('Host', $this->_generateHostHeader()); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - // set '/' instead of empty path rather than check later (see bug #8662) |
|
| 399 | - if (empty($this->_url->path)) { |
|
| 400 | - $this->_url->path = '/'; |
|
| 401 | - } |
|
| 402 | - } |
|
| 365 | + /** |
|
| 366 | + * Resets the object to its initial state (DEPRECATED). |
|
| 367 | + * Takes the same parameters as the constructor. |
|
| 368 | + * |
|
| 369 | + * @param string $url The url to be requested |
|
| 370 | + * @param array $params Associative array of parameters |
|
| 371 | + * (see constructor for details) |
|
| 372 | + * @access public |
|
| 373 | + * @deprecated deprecated since 1.2, call the constructor if this is necessary |
|
| 374 | + */ |
|
| 375 | + function reset($url, $params = array()) |
|
| 376 | + { |
|
| 377 | + $this->HTTP_Request($url, $params); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * Sets the URL to be requested |
|
| 382 | + * |
|
| 383 | + * @param string The url to be requested |
|
| 384 | + * @access public |
|
| 385 | + */ |
|
| 386 | + function setURL($url) |
|
| 387 | + { |
|
| 388 | + $this->_url = &new Net_URL($url, $this->_useBrackets); |
|
| 389 | + |
|
| 390 | + if (!empty($this->_url->user) || !empty($this->_url->pass)) { |
|
| 391 | + $this->setBasicAuth($this->_url->user, $this->_url->pass); |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + if (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http) { |
|
| 395 | + $this->addHeader('Host', $this->_generateHostHeader()); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + // set '/' instead of empty path rather than check later (see bug #8662) |
|
| 399 | + if (empty($this->_url->path)) { |
|
| 400 | + $this->_url->path = '/'; |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | 403 | |
| 404 | 404 | /** |
| 405 | 405 | * Returns the current request URL |
@@ -407,134 +407,134 @@ discard block |
||
| 407 | 407 | * @return string Current request URL |
| 408 | 408 | * @access public |
| 409 | 409 | */ |
| 410 | - function getUrl() |
|
| 411 | - { |
|
| 412 | - return empty($this->_url)? '': $this->_url->getUrl(); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * Sets a proxy to be used |
|
| 417 | - * |
|
| 418 | - * @param string Proxy host |
|
| 419 | - * @param int Proxy port |
|
| 420 | - * @param string Proxy username |
|
| 421 | - * @param string Proxy password |
|
| 422 | - * @access public |
|
| 423 | - */ |
|
| 424 | - function setProxy($host, $port = 8080, $user = null, $pass = null) |
|
| 425 | - { |
|
| 426 | - $this->_proxy_host = $host; |
|
| 427 | - $this->_proxy_port = $port; |
|
| 428 | - $this->_proxy_user = $user; |
|
| 429 | - $this->_proxy_pass = $pass; |
|
| 430 | - |
|
| 431 | - if (!empty($user)) { |
|
| 432 | - $this->addHeader('Proxy-Authorization', 'Basic ' . base64_encode($user . ':' . $pass)); |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * Sets basic authentication parameters |
|
| 438 | - * |
|
| 439 | - * @param string Username |
|
| 440 | - * @param string Password |
|
| 441 | - */ |
|
| 442 | - function setBasicAuth($user, $pass) |
|
| 443 | - { |
|
| 444 | - $this->_user = $user; |
|
| 445 | - $this->_pass = $pass; |
|
| 446 | - |
|
| 447 | - $this->addHeader('Authorization', 'Basic ' . base64_encode($user . ':' . $pass)); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * Sets the method to be used, GET, POST etc. |
|
| 452 | - * |
|
| 453 | - * @param string Method to use. Use the defined constants for this |
|
| 454 | - * @access public |
|
| 455 | - */ |
|
| 456 | - function setMethod($method) |
|
| 457 | - { |
|
| 458 | - $this->_method = $method; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * Sets the HTTP version to use, 1.0 or 1.1 |
|
| 463 | - * |
|
| 464 | - * @param string Version to use. Use the defined constants for this |
|
| 465 | - * @access public |
|
| 466 | - */ |
|
| 467 | - function setHttpVer($http) |
|
| 468 | - { |
|
| 469 | - $this->_http = $http; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * Adds a request header |
|
| 474 | - * |
|
| 475 | - * @param string Header name |
|
| 476 | - * @param string Header value |
|
| 477 | - * @access public |
|
| 478 | - */ |
|
| 479 | - function addHeader($name, $value) |
|
| 480 | - { |
|
| 481 | - $this->_requestHeaders[strtolower($name)] = $value; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * Removes a request header |
|
| 486 | - * |
|
| 487 | - * @param string Header name to remove |
|
| 488 | - * @access public |
|
| 489 | - */ |
|
| 490 | - function removeHeader($name) |
|
| 491 | - { |
|
| 492 | - if (isset($this->_requestHeaders[strtolower($name)])) { |
|
| 493 | - unset($this->_requestHeaders[strtolower($name)]); |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * Adds a querystring parameter |
|
| 499 | - * |
|
| 500 | - * @param string Querystring parameter name |
|
| 501 | - * @param string Querystring parameter value |
|
| 502 | - * @param bool Whether the value is already urlencoded or not, default = not |
|
| 503 | - * @access public |
|
| 504 | - */ |
|
| 505 | - function addQueryString($name, $value, $preencoded = false) |
|
| 506 | - { |
|
| 507 | - $this->_url->addQueryString($name, $value, $preencoded); |
|
| 508 | - } |
|
| 410 | + function getUrl() |
|
| 411 | + { |
|
| 412 | + return empty($this->_url)? '': $this->_url->getUrl(); |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * Sets a proxy to be used |
|
| 417 | + * |
|
| 418 | + * @param string Proxy host |
|
| 419 | + * @param int Proxy port |
|
| 420 | + * @param string Proxy username |
|
| 421 | + * @param string Proxy password |
|
| 422 | + * @access public |
|
| 423 | + */ |
|
| 424 | + function setProxy($host, $port = 8080, $user = null, $pass = null) |
|
| 425 | + { |
|
| 426 | + $this->_proxy_host = $host; |
|
| 427 | + $this->_proxy_port = $port; |
|
| 428 | + $this->_proxy_user = $user; |
|
| 429 | + $this->_proxy_pass = $pass; |
|
| 430 | + |
|
| 431 | + if (!empty($user)) { |
|
| 432 | + $this->addHeader('Proxy-Authorization', 'Basic ' . base64_encode($user . ':' . $pass)); |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * Sets basic authentication parameters |
|
| 438 | + * |
|
| 439 | + * @param string Username |
|
| 440 | + * @param string Password |
|
| 441 | + */ |
|
| 442 | + function setBasicAuth($user, $pass) |
|
| 443 | + { |
|
| 444 | + $this->_user = $user; |
|
| 445 | + $this->_pass = $pass; |
|
| 446 | + |
|
| 447 | + $this->addHeader('Authorization', 'Basic ' . base64_encode($user . ':' . $pass)); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * Sets the method to be used, GET, POST etc. |
|
| 452 | + * |
|
| 453 | + * @param string Method to use. Use the defined constants for this |
|
| 454 | + * @access public |
|
| 455 | + */ |
|
| 456 | + function setMethod($method) |
|
| 457 | + { |
|
| 458 | + $this->_method = $method; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * Sets the HTTP version to use, 1.0 or 1.1 |
|
| 463 | + * |
|
| 464 | + * @param string Version to use. Use the defined constants for this |
|
| 465 | + * @access public |
|
| 466 | + */ |
|
| 467 | + function setHttpVer($http) |
|
| 468 | + { |
|
| 469 | + $this->_http = $http; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * Adds a request header |
|
| 474 | + * |
|
| 475 | + * @param string Header name |
|
| 476 | + * @param string Header value |
|
| 477 | + * @access public |
|
| 478 | + */ |
|
| 479 | + function addHeader($name, $value) |
|
| 480 | + { |
|
| 481 | + $this->_requestHeaders[strtolower($name)] = $value; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * Removes a request header |
|
| 486 | + * |
|
| 487 | + * @param string Header name to remove |
|
| 488 | + * @access public |
|
| 489 | + */ |
|
| 490 | + function removeHeader($name) |
|
| 491 | + { |
|
| 492 | + if (isset($this->_requestHeaders[strtolower($name)])) { |
|
| 493 | + unset($this->_requestHeaders[strtolower($name)]); |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * Adds a querystring parameter |
|
| 499 | + * |
|
| 500 | + * @param string Querystring parameter name |
|
| 501 | + * @param string Querystring parameter value |
|
| 502 | + * @param bool Whether the value is already urlencoded or not, default = not |
|
| 503 | + * @access public |
|
| 504 | + */ |
|
| 505 | + function addQueryString($name, $value, $preencoded = false) |
|
| 506 | + { |
|
| 507 | + $this->_url->addQueryString($name, $value, $preencoded); |
|
| 508 | + } |
|
| 509 | 509 | |
| 510 | - /** |
|
| 511 | - * Sets the querystring to literally what you supply |
|
| 512 | - * |
|
| 513 | - * @param string The querystring data. Should be of the format foo=bar&x=y etc |
|
| 514 | - * @param bool Whether data is already urlencoded or not, default = already encoded |
|
| 515 | - * @access public |
|
| 516 | - */ |
|
| 517 | - function addRawQueryString($querystring, $preencoded = true) |
|
| 518 | - { |
|
| 519 | - $this->_url->addRawQueryString($querystring, $preencoded); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * Adds postdata items |
|
| 524 | - * |
|
| 525 | - * @param string Post data name |
|
| 526 | - * @param string Post data value |
|
| 527 | - * @param bool Whether data is already urlencoded or not, default = not |
|
| 528 | - * @access public |
|
| 529 | - */ |
|
| 530 | - function addPostData($name, $value, $preencoded = false) |
|
| 531 | - { |
|
| 532 | - if ($preencoded) { |
|
| 533 | - $this->_postData[$name] = $value; |
|
| 534 | - } else { |
|
| 535 | - $this->_postData[$name] = $this->_arrayMapRecursive('urlencode', $value); |
|
| 536 | - } |
|
| 537 | - } |
|
| 510 | + /** |
|
| 511 | + * Sets the querystring to literally what you supply |
|
| 512 | + * |
|
| 513 | + * @param string The querystring data. Should be of the format foo=bar&x=y etc |
|
| 514 | + * @param bool Whether data is already urlencoded or not, default = already encoded |
|
| 515 | + * @access public |
|
| 516 | + */ |
|
| 517 | + function addRawQueryString($querystring, $preencoded = true) |
|
| 518 | + { |
|
| 519 | + $this->_url->addRawQueryString($querystring, $preencoded); |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * Adds postdata items |
|
| 524 | + * |
|
| 525 | + * @param string Post data name |
|
| 526 | + * @param string Post data value |
|
| 527 | + * @param bool Whether data is already urlencoded or not, default = not |
|
| 528 | + * @access public |
|
| 529 | + */ |
|
| 530 | + function addPostData($name, $value, $preencoded = false) |
|
| 531 | + { |
|
| 532 | + if ($preencoded) { |
|
| 533 | + $this->_postData[$name] = $value; |
|
| 534 | + } else { |
|
| 535 | + $this->_postData[$name] = $this->_arrayMapRecursive('urlencode', $value); |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | 538 | |
| 539 | 539 | /** |
| 540 | 540 | * Recursively applies the callback function to the value |
@@ -544,18 +544,18 @@ discard block |
||
| 544 | 544 | * @access private |
| 545 | 545 | * @return mixed Processed value |
| 546 | 546 | */ |
| 547 | - function _arrayMapRecursive($callback, $value) |
|
| 548 | - { |
|
| 549 | - if (!is_array($value)) { |
|
| 550 | - return call_user_func($callback, $value); |
|
| 551 | - } else { |
|
| 552 | - $map = array(); |
|
| 553 | - foreach ($value as $k => $v) { |
|
| 554 | - $map[$k] = $this->_arrayMapRecursive($callback, $v); |
|
| 555 | - } |
|
| 556 | - return $map; |
|
| 557 | - } |
|
| 558 | - } |
|
| 547 | + function _arrayMapRecursive($callback, $value) |
|
| 548 | + { |
|
| 549 | + if (!is_array($value)) { |
|
| 550 | + return call_user_func($callback, $value); |
|
| 551 | + } else { |
|
| 552 | + $map = array(); |
|
| 553 | + foreach ($value as $k => $v) { |
|
| 554 | + $map[$k] = $this->_arrayMapRecursive($callback, $v); |
|
| 555 | + } |
|
| 556 | + return $map; |
|
| 557 | + } |
|
| 558 | + } |
|
| 559 | 559 | |
| 560 | 560 | /** |
| 561 | 561 | * Adds a file to upload |
@@ -569,37 +569,37 @@ discard block |
||
| 569 | 569 | * @return bool true on success |
| 570 | 570 | * @throws PEAR_Error |
| 571 | 571 | */ |
| 572 | - function addFile($inputName, $fileName, $contentType = 'application/octet-stream') |
|
| 573 | - { |
|
| 574 | - if (!is_array($fileName) && !is_readable($fileName)) { |
|
| 575 | - return PEAR::raiseError("File '{$fileName}' is not readable"); |
|
| 576 | - } elseif (is_array($fileName)) { |
|
| 577 | - foreach ($fileName as $name) { |
|
| 578 | - if (!is_readable($name)) { |
|
| 579 | - return PEAR::raiseError("File '{$name}' is not readable"); |
|
| 580 | - } |
|
| 581 | - } |
|
| 582 | - } |
|
| 583 | - $this->addHeader('Content-Type', 'multipart/form-data'); |
|
| 584 | - $this->_postFiles[$inputName] = array( |
|
| 585 | - 'name' => $fileName, |
|
| 586 | - 'type' => $contentType |
|
| 587 | - ); |
|
| 588 | - return true; |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - /** |
|
| 592 | - * Adds raw postdata (DEPRECATED) |
|
| 593 | - * |
|
| 594 | - * @param string The data |
|
| 595 | - * @param bool Whether data is preencoded or not, default = already encoded |
|
| 596 | - * @access public |
|
| 597 | - * @deprecated deprecated since 1.3.0, method setBody() should be used instead |
|
| 598 | - */ |
|
| 599 | - function addRawPostData($postdata, $preencoded = true) |
|
| 600 | - { |
|
| 601 | - $this->_body = $preencoded ? $postdata : urlencode($postdata); |
|
| 602 | - } |
|
| 572 | + function addFile($inputName, $fileName, $contentType = 'application/octet-stream') |
|
| 573 | + { |
|
| 574 | + if (!is_array($fileName) && !is_readable($fileName)) { |
|
| 575 | + return PEAR::raiseError("File '{$fileName}' is not readable"); |
|
| 576 | + } elseif (is_array($fileName)) { |
|
| 577 | + foreach ($fileName as $name) { |
|
| 578 | + if (!is_readable($name)) { |
|
| 579 | + return PEAR::raiseError("File '{$name}' is not readable"); |
|
| 580 | + } |
|
| 581 | + } |
|
| 582 | + } |
|
| 583 | + $this->addHeader('Content-Type', 'multipart/form-data'); |
|
| 584 | + $this->_postFiles[$inputName] = array( |
|
| 585 | + 'name' => $fileName, |
|
| 586 | + 'type' => $contentType |
|
| 587 | + ); |
|
| 588 | + return true; |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + /** |
|
| 592 | + * Adds raw postdata (DEPRECATED) |
|
| 593 | + * |
|
| 594 | + * @param string The data |
|
| 595 | + * @param bool Whether data is preencoded or not, default = already encoded |
|
| 596 | + * @access public |
|
| 597 | + * @deprecated deprecated since 1.3.0, method setBody() should be used instead |
|
| 598 | + */ |
|
| 599 | + function addRawPostData($postdata, $preencoded = true) |
|
| 600 | + { |
|
| 601 | + $this->_body = $preencoded ? $postdata : urlencode($postdata); |
|
| 602 | + } |
|
| 603 | 603 | |
| 604 | 604 | /** |
| 605 | 605 | * Sets the request body (for POST, PUT and similar requests) |
@@ -607,370 +607,370 @@ discard block |
||
| 607 | 607 | * @param string Request body |
| 608 | 608 | * @access public |
| 609 | 609 | */ |
| 610 | - function setBody($body) |
|
| 611 | - { |
|
| 612 | - $this->_body = $body; |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * Clears any postdata that has been added (DEPRECATED). |
|
| 617 | - * |
|
| 618 | - * Useful for multiple request scenarios. |
|
| 619 | - * |
|
| 620 | - * @access public |
|
| 621 | - * @deprecated deprecated since 1.2 |
|
| 622 | - */ |
|
| 623 | - function clearPostData() |
|
| 624 | - { |
|
| 625 | - $this->_postData = null; |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - /** |
|
| 629 | - * Appends a cookie to "Cookie:" header |
|
| 630 | - * |
|
| 631 | - * @param string $name cookie name |
|
| 632 | - * @param string $value cookie value |
|
| 633 | - * @access public |
|
| 634 | - */ |
|
| 635 | - function addCookie($name, $value) |
|
| 636 | - { |
|
| 637 | - $cookies = isset($this->_requestHeaders['cookie']) ? $this->_requestHeaders['cookie']. '; ' : ''; |
|
| 638 | - $this->addHeader('Cookie', $cookies . $name . '=' . $value); |
|
| 639 | - } |
|
| 610 | + function setBody($body) |
|
| 611 | + { |
|
| 612 | + $this->_body = $body; |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * Clears any postdata that has been added (DEPRECATED). |
|
| 617 | + * |
|
| 618 | + * Useful for multiple request scenarios. |
|
| 619 | + * |
|
| 620 | + * @access public |
|
| 621 | + * @deprecated deprecated since 1.2 |
|
| 622 | + */ |
|
| 623 | + function clearPostData() |
|
| 624 | + { |
|
| 625 | + $this->_postData = null; |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + /** |
|
| 629 | + * Appends a cookie to "Cookie:" header |
|
| 630 | + * |
|
| 631 | + * @param string $name cookie name |
|
| 632 | + * @param string $value cookie value |
|
| 633 | + * @access public |
|
| 634 | + */ |
|
| 635 | + function addCookie($name, $value) |
|
| 636 | + { |
|
| 637 | + $cookies = isset($this->_requestHeaders['cookie']) ? $this->_requestHeaders['cookie']. '; ' : ''; |
|
| 638 | + $this->addHeader('Cookie', $cookies . $name . '=' . $value); |
|
| 639 | + } |
|
| 640 | 640 | |
| 641 | - /** |
|
| 642 | - * Clears any cookies that have been added (DEPRECATED). |
|
| 643 | - * |
|
| 644 | - * Useful for multiple request scenarios |
|
| 645 | - * |
|
| 646 | - * @access public |
|
| 647 | - * @deprecated deprecated since 1.2 |
|
| 648 | - */ |
|
| 649 | - function clearCookies() |
|
| 650 | - { |
|
| 651 | - $this->removeHeader('Cookie'); |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * Sends the request |
|
| 656 | - * |
|
| 657 | - * @access public |
|
| 658 | - * @param bool Whether to store response body in Response object property, |
|
| 659 | - * set this to false if downloading a LARGE file and using a Listener |
|
| 660 | - * @return mixed PEAR error on error, true otherwise |
|
| 661 | - */ |
|
| 662 | - function sendRequest($saveBody = true) |
|
| 663 | - { |
|
| 664 | - if (!is_a($this->_url, 'Net_URL')) { |
|
| 665 | - return PEAR::raiseError('No URL given.'); |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - $host = isset($this->_proxy_host) ? $this->_proxy_host : $this->_url->host; |
|
| 669 | - $port = isset($this->_proxy_port) ? $this->_proxy_port : $this->_url->port; |
|
| 670 | - |
|
| 671 | - // 4.3.0 supports SSL connections using OpenSSL. The function test determines |
|
| 672 | - // we running on at least 4.3.0 |
|
| 673 | - if (strcasecmp($this->_url->protocol, 'https') == 0 AND function_exists('file_get_contents') AND extension_loaded('openssl')) { |
|
| 674 | - if (isset($this->_proxy_host)) { |
|
| 675 | - return PEAR::raiseError('HTTPS proxies are not supported.'); |
|
| 676 | - } |
|
| 677 | - $host = 'ssl://' . $host; |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - // magic quotes may fuck up file uploads and chunked response processing |
|
| 681 | - $magicQuotes = ini_get('magic_quotes_runtime'); |
|
| 682 | - ini_set('magic_quotes_runtime', false); |
|
| 683 | - |
|
| 684 | - // RFC 2068, section 19.7.1: A client MUST NOT send the Keep-Alive |
|
| 685 | - // connection token to a proxy server... |
|
| 686 | - if (isset($this->_proxy_host) && !empty($this->_requestHeaders['connection']) && |
|
| 687 | - 'Keep-Alive' == $this->_requestHeaders['connection']) |
|
| 688 | - { |
|
| 689 | - $this->removeHeader('connection'); |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - $keepAlive = (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http && empty($this->_requestHeaders['connection'])) || |
|
| 693 | - (!empty($this->_requestHeaders['connection']) && 'Keep-Alive' == $this->_requestHeaders['connection']); |
|
| 694 | - $sockets = &PEAR::getStaticProperty('HTTP_Request', 'sockets'); |
|
| 695 | - $sockKey = $host . ':' . $port; |
|
| 696 | - unset($this->_sock); |
|
| 697 | - |
|
| 698 | - // There is a connected socket in the "static" property? |
|
| 699 | - if ($keepAlive && !empty($sockets[$sockKey]) && |
|
| 700 | - !empty($sockets[$sockKey]->fp)) |
|
| 701 | - { |
|
| 702 | - $this->_sock =& $sockets[$sockKey]; |
|
| 703 | - $err = null; |
|
| 704 | - } else { |
|
| 705 | - $this->_notify('connect'); |
|
| 706 | - $this->_sock =& new Net_Socket(); |
|
| 707 | - $err = $this->_sock->connect($host, $port, null, $this->_timeout, $this->_socketOptions); |
|
| 708 | - } |
|
| 709 | - PEAR::isError($err) or $err = $this->_sock->write($this->_buildRequest()); |
|
| 710 | - |
|
| 711 | - if (!PEAR::isError($err)) { |
|
| 712 | - if (!empty($this->_readTimeout)) { |
|
| 713 | - $this->_sock->setTimeout($this->_readTimeout[0], $this->_readTimeout[1]); |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - $this->_notify('sentRequest'); |
|
| 717 | - |
|
| 718 | - // Read the response |
|
| 719 | - $this->_response = &new HTTP_Response($this->_sock, $this->_listeners); |
|
| 720 | - $err = $this->_response->process( |
|
| 721 | - $this->_saveBody && $saveBody, |
|
| 722 | - HTTP_REQUEST_METHOD_HEAD != $this->_method |
|
| 723 | - ); |
|
| 724 | - |
|
| 725 | - if ($keepAlive) { |
|
| 726 | - $keepAlive = (isset($this->_response->_headers['content-length']) |
|
| 727 | - || (isset($this->_response->_headers['transfer-encoding']) |
|
| 728 | - && strtolower($this->_response->_headers['transfer-encoding']) == 'chunked')); |
|
| 729 | - if ($keepAlive) { |
|
| 730 | - if (isset($this->_response->_headers['connection'])) { |
|
| 731 | - $keepAlive = strtolower($this->_response->_headers['connection']) == 'keep-alive'; |
|
| 732 | - } else { |
|
| 733 | - $keepAlive = 'HTTP/'.HTTP_REQUEST_HTTP_VER_1_1 == $this->_response->_protocol; |
|
| 734 | - } |
|
| 735 | - } |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - ini_set('magic_quotes_runtime', $magicQuotes); |
|
| 740 | - |
|
| 741 | - if (PEAR::isError($err)) { |
|
| 742 | - return $err; |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - if (!$keepAlive) { |
|
| 746 | - $this->disconnect(); |
|
| 747 | - // Store the connected socket in "static" property |
|
| 748 | - } elseif (empty($sockets[$sockKey]) || empty($sockets[$sockKey]->fp)) { |
|
| 749 | - $sockets[$sockKey] =& $this->_sock; |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - // Check for redirection |
|
| 753 | - if ( $this->_allowRedirects |
|
| 754 | - AND $this->_redirects <= $this->_maxRedirects |
|
| 755 | - AND $this->getResponseCode() > 300 |
|
| 756 | - AND $this->getResponseCode() < 399 |
|
| 757 | - AND !empty($this->_response->_headers['location'])) { |
|
| 641 | + /** |
|
| 642 | + * Clears any cookies that have been added (DEPRECATED). |
|
| 643 | + * |
|
| 644 | + * Useful for multiple request scenarios |
|
| 645 | + * |
|
| 646 | + * @access public |
|
| 647 | + * @deprecated deprecated since 1.2 |
|
| 648 | + */ |
|
| 649 | + function clearCookies() |
|
| 650 | + { |
|
| 651 | + $this->removeHeader('Cookie'); |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * Sends the request |
|
| 656 | + * |
|
| 657 | + * @access public |
|
| 658 | + * @param bool Whether to store response body in Response object property, |
|
| 659 | + * set this to false if downloading a LARGE file and using a Listener |
|
| 660 | + * @return mixed PEAR error on error, true otherwise |
|
| 661 | + */ |
|
| 662 | + function sendRequest($saveBody = true) |
|
| 663 | + { |
|
| 664 | + if (!is_a($this->_url, 'Net_URL')) { |
|
| 665 | + return PEAR::raiseError('No URL given.'); |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + $host = isset($this->_proxy_host) ? $this->_proxy_host : $this->_url->host; |
|
| 669 | + $port = isset($this->_proxy_port) ? $this->_proxy_port : $this->_url->port; |
|
| 670 | + |
|
| 671 | + // 4.3.0 supports SSL connections using OpenSSL. The function test determines |
|
| 672 | + // we running on at least 4.3.0 |
|
| 673 | + if (strcasecmp($this->_url->protocol, 'https') == 0 AND function_exists('file_get_contents') AND extension_loaded('openssl')) { |
|
| 674 | + if (isset($this->_proxy_host)) { |
|
| 675 | + return PEAR::raiseError('HTTPS proxies are not supported.'); |
|
| 676 | + } |
|
| 677 | + $host = 'ssl://' . $host; |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + // magic quotes may fuck up file uploads and chunked response processing |
|
| 681 | + $magicQuotes = ini_get('magic_quotes_runtime'); |
|
| 682 | + ini_set('magic_quotes_runtime', false); |
|
| 683 | + |
|
| 684 | + // RFC 2068, section 19.7.1: A client MUST NOT send the Keep-Alive |
|
| 685 | + // connection token to a proxy server... |
|
| 686 | + if (isset($this->_proxy_host) && !empty($this->_requestHeaders['connection']) && |
|
| 687 | + 'Keep-Alive' == $this->_requestHeaders['connection']) |
|
| 688 | + { |
|
| 689 | + $this->removeHeader('connection'); |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + $keepAlive = (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http && empty($this->_requestHeaders['connection'])) || |
|
| 693 | + (!empty($this->_requestHeaders['connection']) && 'Keep-Alive' == $this->_requestHeaders['connection']); |
|
| 694 | + $sockets = &PEAR::getStaticProperty('HTTP_Request', 'sockets'); |
|
| 695 | + $sockKey = $host . ':' . $port; |
|
| 696 | + unset($this->_sock); |
|
| 697 | + |
|
| 698 | + // There is a connected socket in the "static" property? |
|
| 699 | + if ($keepAlive && !empty($sockets[$sockKey]) && |
|
| 700 | + !empty($sockets[$sockKey]->fp)) |
|
| 701 | + { |
|
| 702 | + $this->_sock =& $sockets[$sockKey]; |
|
| 703 | + $err = null; |
|
| 704 | + } else { |
|
| 705 | + $this->_notify('connect'); |
|
| 706 | + $this->_sock =& new Net_Socket(); |
|
| 707 | + $err = $this->_sock->connect($host, $port, null, $this->_timeout, $this->_socketOptions); |
|
| 708 | + } |
|
| 709 | + PEAR::isError($err) or $err = $this->_sock->write($this->_buildRequest()); |
|
| 710 | + |
|
| 711 | + if (!PEAR::isError($err)) { |
|
| 712 | + if (!empty($this->_readTimeout)) { |
|
| 713 | + $this->_sock->setTimeout($this->_readTimeout[0], $this->_readTimeout[1]); |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + $this->_notify('sentRequest'); |
|
| 717 | + |
|
| 718 | + // Read the response |
|
| 719 | + $this->_response = &new HTTP_Response($this->_sock, $this->_listeners); |
|
| 720 | + $err = $this->_response->process( |
|
| 721 | + $this->_saveBody && $saveBody, |
|
| 722 | + HTTP_REQUEST_METHOD_HEAD != $this->_method |
|
| 723 | + ); |
|
| 724 | + |
|
| 725 | + if ($keepAlive) { |
|
| 726 | + $keepAlive = (isset($this->_response->_headers['content-length']) |
|
| 727 | + || (isset($this->_response->_headers['transfer-encoding']) |
|
| 728 | + && strtolower($this->_response->_headers['transfer-encoding']) == 'chunked')); |
|
| 729 | + if ($keepAlive) { |
|
| 730 | + if (isset($this->_response->_headers['connection'])) { |
|
| 731 | + $keepAlive = strtolower($this->_response->_headers['connection']) == 'keep-alive'; |
|
| 732 | + } else { |
|
| 733 | + $keepAlive = 'HTTP/'.HTTP_REQUEST_HTTP_VER_1_1 == $this->_response->_protocol; |
|
| 734 | + } |
|
| 735 | + } |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + ini_set('magic_quotes_runtime', $magicQuotes); |
|
| 740 | + |
|
| 741 | + if (PEAR::isError($err)) { |
|
| 742 | + return $err; |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + if (!$keepAlive) { |
|
| 746 | + $this->disconnect(); |
|
| 747 | + // Store the connected socket in "static" property |
|
| 748 | + } elseif (empty($sockets[$sockKey]) || empty($sockets[$sockKey]->fp)) { |
|
| 749 | + $sockets[$sockKey] =& $this->_sock; |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + // Check for redirection |
|
| 753 | + if ( $this->_allowRedirects |
|
| 754 | + AND $this->_redirects <= $this->_maxRedirects |
|
| 755 | + AND $this->getResponseCode() > 300 |
|
| 756 | + AND $this->getResponseCode() < 399 |
|
| 757 | + AND !empty($this->_response->_headers['location'])) { |
|
| 758 | 758 | |
| 759 | 759 | |
| 760 | - $redirect = $this->_response->_headers['location']; |
|
| 761 | - |
|
| 762 | - // Absolute URL |
|
| 763 | - if (preg_match('/^https?:\/\//i', $redirect)) { |
|
| 764 | - $this->_url = &new Net_URL($redirect); |
|
| 765 | - $this->addHeader('Host', $this->_generateHostHeader()); |
|
| 766 | - // Absolute path |
|
| 767 | - } elseif ($redirect{0} == '/') { |
|
| 768 | - $this->_url->path = $redirect; |
|
| 760 | + $redirect = $this->_response->_headers['location']; |
|
| 761 | + |
|
| 762 | + // Absolute URL |
|
| 763 | + if (preg_match('/^https?:\/\//i', $redirect)) { |
|
| 764 | + $this->_url = &new Net_URL($redirect); |
|
| 765 | + $this->addHeader('Host', $this->_generateHostHeader()); |
|
| 766 | + // Absolute path |
|
| 767 | + } elseif ($redirect{0} == '/') { |
|
| 768 | + $this->_url->path = $redirect; |
|
| 769 | 769 | |
| 770 | - // Relative path |
|
| 771 | - } elseif (substr($redirect, 0, 3) == '../' OR substr($redirect, 0, 2) == './') { |
|
| 772 | - if (substr($this->_url->path, -1) == '/') { |
|
| 773 | - $redirect = $this->_url->path . $redirect; |
|
| 774 | - } else { |
|
| 775 | - $redirect = dirname($this->_url->path) . '/' . $redirect; |
|
| 776 | - } |
|
| 777 | - $redirect = Net_URL::resolvePath($redirect); |
|
| 778 | - $this->_url->path = $redirect; |
|
| 770 | + // Relative path |
|
| 771 | + } elseif (substr($redirect, 0, 3) == '../' OR substr($redirect, 0, 2) == './') { |
|
| 772 | + if (substr($this->_url->path, -1) == '/') { |
|
| 773 | + $redirect = $this->_url->path . $redirect; |
|
| 774 | + } else { |
|
| 775 | + $redirect = dirname($this->_url->path) . '/' . $redirect; |
|
| 776 | + } |
|
| 777 | + $redirect = Net_URL::resolvePath($redirect); |
|
| 778 | + $this->_url->path = $redirect; |
|
| 779 | 779 | |
| 780 | - // Filename, no path |
|
| 781 | - } else { |
|
| 782 | - if (substr($this->_url->path, -1) == '/') { |
|
| 783 | - $redirect = $this->_url->path . $redirect; |
|
| 784 | - } else { |
|
| 785 | - $redirect = dirname($this->_url->path) . '/' . $redirect; |
|
| 786 | - } |
|
| 787 | - $this->_url->path = $redirect; |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - $this->_redirects++; |
|
| 791 | - return $this->sendRequest($saveBody); |
|
| 792 | - |
|
| 793 | - // Too many redirects |
|
| 794 | - } elseif ($this->_allowRedirects AND $this->_redirects > $this->_maxRedirects) { |
|
| 795 | - return PEAR::raiseError('Too many redirects'); |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - return true; |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - /** |
|
| 802 | - * Disconnect the socket, if connected. Only useful if using Keep-Alive. |
|
| 803 | - * |
|
| 804 | - * @access public |
|
| 805 | - */ |
|
| 806 | - function disconnect() |
|
| 807 | - { |
|
| 808 | - if (!empty($this->_sock) && !empty($this->_sock->fp)) { |
|
| 809 | - $this->_notify('disconnect'); |
|
| 810 | - $this->_sock->disconnect(); |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - /** |
|
| 815 | - * Returns the response code |
|
| 816 | - * |
|
| 817 | - * @access public |
|
| 818 | - * @return mixed Response code, false if not set |
|
| 819 | - */ |
|
| 820 | - function getResponseCode() |
|
| 821 | - { |
|
| 822 | - return isset($this->_response->_code) ? $this->_response->_code : false; |
|
| 823 | - } |
|
| 824 | - |
|
| 825 | - /** |
|
| 826 | - * Returns either the named header or all if no name given |
|
| 827 | - * |
|
| 828 | - * @access public |
|
| 829 | - * @param string The header name to return, do not set to get all headers |
|
| 830 | - * @return mixed either the value of $headername (false if header is not present) |
|
| 831 | - * or an array of all headers |
|
| 832 | - */ |
|
| 833 | - function getResponseHeader($headername = null) |
|
| 834 | - { |
|
| 835 | - if (!isset($headername)) { |
|
| 836 | - return isset($this->_response->_headers)? $this->_response->_headers: array(); |
|
| 837 | - } else { |
|
| 838 | - $headername = strtolower($headername); |
|
| 839 | - return isset($this->_response->_headers[$headername]) ? $this->_response->_headers[$headername] : false; |
|
| 840 | - } |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - /** |
|
| 844 | - * Returns the body of the response |
|
| 845 | - * |
|
| 846 | - * @access public |
|
| 847 | - * @return mixed response body, false if not set |
|
| 848 | - */ |
|
| 849 | - function getResponseBody() |
|
| 850 | - { |
|
| 851 | - return isset($this->_response->_body) ? $this->_response->_body : false; |
|
| 852 | - } |
|
| 853 | - |
|
| 854 | - /** |
|
| 855 | - * Returns cookies set in response |
|
| 856 | - * |
|
| 857 | - * @access public |
|
| 858 | - * @return mixed array of response cookies, false if none are present |
|
| 859 | - */ |
|
| 860 | - function getResponseCookies() |
|
| 861 | - { |
|
| 862 | - return isset($this->_response->_cookies) ? $this->_response->_cookies : false; |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - /** |
|
| 866 | - * Builds the request string |
|
| 867 | - * |
|
| 868 | - * @access private |
|
| 869 | - * @return string The request string |
|
| 870 | - */ |
|
| 871 | - function _buildRequest() |
|
| 872 | - { |
|
| 873 | - $separator = ini_get('arg_separator.output'); |
|
| 874 | - ini_set('arg_separator.output', '&'); |
|
| 875 | - $querystring = ($querystring = $this->_url->getQueryString()) ? '?' . $querystring : ''; |
|
| 876 | - ini_set('arg_separator.output', $separator); |
|
| 877 | - |
|
| 878 | - $host = isset($this->_proxy_host) ? $this->_url->protocol . '://' . $this->_url->host : ''; |
|
| 879 | - $port = (isset($this->_proxy_host) AND $this->_url->port != 80) ? ':' . $this->_url->port : ''; |
|
| 880 | - $path = $this->_url->path . $querystring; |
|
| 881 | - $url = $host . $port . $path; |
|
| 882 | - |
|
| 883 | - $request = $this->_method . ' ' . $url . ' HTTP/' . $this->_http . "\r\n"; |
|
| 884 | - |
|
| 885 | - if (in_array($this->_method, $this->_bodyDisallowed) || |
|
| 886 | - (empty($this->_body) && (HTTP_REQUEST_METHOD_POST != $this->_method || |
|
| 887 | - (empty($this->_postData) && empty($this->_postFiles))))) |
|
| 888 | - { |
|
| 889 | - $this->removeHeader('Content-Type'); |
|
| 890 | - } else { |
|
| 891 | - if (empty($this->_requestHeaders['content-type'])) { |
|
| 892 | - // Add default content-type |
|
| 893 | - $this->addHeader('Content-Type', 'application/x-www-form-urlencoded'); |
|
| 894 | - } elseif ('multipart/form-data' == $this->_requestHeaders['content-type']) { |
|
| 895 | - $boundary = 'HTTP_Request_' . md5(uniqid('request') . microtime()); |
|
| 896 | - $this->addHeader('Content-Type', 'multipart/form-data; boundary=' . $boundary); |
|
| 897 | - } |
|
| 898 | - } |
|
| 899 | - |
|
| 900 | - // Request Headers |
|
| 901 | - if (!empty($this->_requestHeaders)) { |
|
| 902 | - foreach ($this->_requestHeaders as $name => $value) { |
|
| 903 | - $canonicalName = implode('-', array_map('ucfirst', explode('-', $name))); |
|
| 904 | - $request .= $canonicalName . ': ' . $value . "\r\n"; |
|
| 905 | - } |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - // No post data or wrong method, so simply add a final CRLF |
|
| 909 | - if (in_array($this->_method, $this->_bodyDisallowed) || |
|
| 910 | - (HTTP_REQUEST_METHOD_POST != $this->_method && empty($this->_body))) { |
|
| 911 | - |
|
| 912 | - $request .= "\r\n"; |
|
| 913 | - |
|
| 914 | - // Post data if it's an array |
|
| 915 | - } elseif (HTTP_REQUEST_METHOD_POST == $this->_method && |
|
| 916 | - (!empty($this->_postData) || !empty($this->_postFiles))) { |
|
| 917 | - |
|
| 918 | - // "normal" POST request |
|
| 919 | - if (!isset($boundary)) { |
|
| 920 | - $postdata = implode('&', array_map( |
|
| 921 | - create_function('$a', 'return $a[0] . \'=\' . $a[1];'), |
|
| 922 | - $this->_flattenArray('', $this->_postData) |
|
| 923 | - )); |
|
| 924 | - |
|
| 925 | - // multipart request, probably with file uploads |
|
| 926 | - } else { |
|
| 927 | - $postdata = ''; |
|
| 928 | - if (!empty($this->_postData)) { |
|
| 929 | - $flatData = $this->_flattenArray('', $this->_postData); |
|
| 930 | - foreach ($flatData as $item) { |
|
| 931 | - $postdata .= '--' . $boundary . "\r\n"; |
|
| 932 | - $postdata .= 'Content-Disposition: form-data; name="' . $item[0] . '"'; |
|
| 933 | - $postdata .= "\r\n\r\n" . urldecode($item[1]) . "\r\n"; |
|
| 934 | - } |
|
| 935 | - } |
|
| 936 | - foreach ($this->_postFiles as $name => $value) { |
|
| 937 | - if (is_array($value['name'])) { |
|
| 938 | - $varname = $name . ($this->_useBrackets? '[]': ''); |
|
| 939 | - } else { |
|
| 940 | - $varname = $name; |
|
| 941 | - $value['name'] = array($value['name']); |
|
| 942 | - } |
|
| 943 | - foreach ($value['name'] as $key => $filename) { |
|
| 944 | - $fp = fopen($filename, 'r'); |
|
| 945 | - $data = fread($fp, filesize($filename)); |
|
| 946 | - fclose($fp); |
|
| 947 | - $basename = basename($filename); |
|
| 948 | - $type = is_array($value['type'])? @$value['type'][$key]: $value['type']; |
|
| 949 | - |
|
| 950 | - $postdata .= '--' . $boundary . "\r\n"; |
|
| 951 | - $postdata .= 'Content-Disposition: form-data; name="' . $varname . '"; filename="' . $basename . '"'; |
|
| 952 | - $postdata .= "\r\nContent-Type: " . $type; |
|
| 953 | - $postdata .= "\r\n\r\n" . $data . "\r\n"; |
|
| 954 | - } |
|
| 955 | - } |
|
| 956 | - $postdata .= '--' . $boundary . "--\r\n"; |
|
| 957 | - } |
|
| 958 | - $request .= 'Content-Length: ' . |
|
| 959 | - (HTTP_REQUEST_MBSTRING? mb_strlen($postdata, 'iso-8859-1'): strlen($postdata)) . |
|
| 960 | - "\r\n\r\n"; |
|
| 961 | - $request .= $postdata; |
|
| 962 | - |
|
| 963 | - // Explicitly set request body |
|
| 964 | - } elseif (!empty($this->_body)) { |
|
| 965 | - |
|
| 966 | - $request .= 'Content-Length: ' . |
|
| 967 | - (HTTP_REQUEST_MBSTRING? mb_strlen($this->_body, 'iso-8859-1'): strlen($this->_body)) . |
|
| 968 | - "\r\n\r\n"; |
|
| 969 | - $request .= $this->_body; |
|
| 970 | - } |
|
| 780 | + // Filename, no path |
|
| 781 | + } else { |
|
| 782 | + if (substr($this->_url->path, -1) == '/') { |
|
| 783 | + $redirect = $this->_url->path . $redirect; |
|
| 784 | + } else { |
|
| 785 | + $redirect = dirname($this->_url->path) . '/' . $redirect; |
|
| 786 | + } |
|
| 787 | + $this->_url->path = $redirect; |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + $this->_redirects++; |
|
| 791 | + return $this->sendRequest($saveBody); |
|
| 792 | + |
|
| 793 | + // Too many redirects |
|
| 794 | + } elseif ($this->_allowRedirects AND $this->_redirects > $this->_maxRedirects) { |
|
| 795 | + return PEAR::raiseError('Too many redirects'); |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + return true; |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + /** |
|
| 802 | + * Disconnect the socket, if connected. Only useful if using Keep-Alive. |
|
| 803 | + * |
|
| 804 | + * @access public |
|
| 805 | + */ |
|
| 806 | + function disconnect() |
|
| 807 | + { |
|
| 808 | + if (!empty($this->_sock) && !empty($this->_sock->fp)) { |
|
| 809 | + $this->_notify('disconnect'); |
|
| 810 | + $this->_sock->disconnect(); |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + /** |
|
| 815 | + * Returns the response code |
|
| 816 | + * |
|
| 817 | + * @access public |
|
| 818 | + * @return mixed Response code, false if not set |
|
| 819 | + */ |
|
| 820 | + function getResponseCode() |
|
| 821 | + { |
|
| 822 | + return isset($this->_response->_code) ? $this->_response->_code : false; |
|
| 823 | + } |
|
| 824 | + |
|
| 825 | + /** |
|
| 826 | + * Returns either the named header or all if no name given |
|
| 827 | + * |
|
| 828 | + * @access public |
|
| 829 | + * @param string The header name to return, do not set to get all headers |
|
| 830 | + * @return mixed either the value of $headername (false if header is not present) |
|
| 831 | + * or an array of all headers |
|
| 832 | + */ |
|
| 833 | + function getResponseHeader($headername = null) |
|
| 834 | + { |
|
| 835 | + if (!isset($headername)) { |
|
| 836 | + return isset($this->_response->_headers)? $this->_response->_headers: array(); |
|
| 837 | + } else { |
|
| 838 | + $headername = strtolower($headername); |
|
| 839 | + return isset($this->_response->_headers[$headername]) ? $this->_response->_headers[$headername] : false; |
|
| 840 | + } |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + /** |
|
| 844 | + * Returns the body of the response |
|
| 845 | + * |
|
| 846 | + * @access public |
|
| 847 | + * @return mixed response body, false if not set |
|
| 848 | + */ |
|
| 849 | + function getResponseBody() |
|
| 850 | + { |
|
| 851 | + return isset($this->_response->_body) ? $this->_response->_body : false; |
|
| 852 | + } |
|
| 853 | + |
|
| 854 | + /** |
|
| 855 | + * Returns cookies set in response |
|
| 856 | + * |
|
| 857 | + * @access public |
|
| 858 | + * @return mixed array of response cookies, false if none are present |
|
| 859 | + */ |
|
| 860 | + function getResponseCookies() |
|
| 861 | + { |
|
| 862 | + return isset($this->_response->_cookies) ? $this->_response->_cookies : false; |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + /** |
|
| 866 | + * Builds the request string |
|
| 867 | + * |
|
| 868 | + * @access private |
|
| 869 | + * @return string The request string |
|
| 870 | + */ |
|
| 871 | + function _buildRequest() |
|
| 872 | + { |
|
| 873 | + $separator = ini_get('arg_separator.output'); |
|
| 874 | + ini_set('arg_separator.output', '&'); |
|
| 875 | + $querystring = ($querystring = $this->_url->getQueryString()) ? '?' . $querystring : ''; |
|
| 876 | + ini_set('arg_separator.output', $separator); |
|
| 877 | + |
|
| 878 | + $host = isset($this->_proxy_host) ? $this->_url->protocol . '://' . $this->_url->host : ''; |
|
| 879 | + $port = (isset($this->_proxy_host) AND $this->_url->port != 80) ? ':' . $this->_url->port : ''; |
|
| 880 | + $path = $this->_url->path . $querystring; |
|
| 881 | + $url = $host . $port . $path; |
|
| 882 | + |
|
| 883 | + $request = $this->_method . ' ' . $url . ' HTTP/' . $this->_http . "\r\n"; |
|
| 884 | + |
|
| 885 | + if (in_array($this->_method, $this->_bodyDisallowed) || |
|
| 886 | + (empty($this->_body) && (HTTP_REQUEST_METHOD_POST != $this->_method || |
|
| 887 | + (empty($this->_postData) && empty($this->_postFiles))))) |
|
| 888 | + { |
|
| 889 | + $this->removeHeader('Content-Type'); |
|
| 890 | + } else { |
|
| 891 | + if (empty($this->_requestHeaders['content-type'])) { |
|
| 892 | + // Add default content-type |
|
| 893 | + $this->addHeader('Content-Type', 'application/x-www-form-urlencoded'); |
|
| 894 | + } elseif ('multipart/form-data' == $this->_requestHeaders['content-type']) { |
|
| 895 | + $boundary = 'HTTP_Request_' . md5(uniqid('request') . microtime()); |
|
| 896 | + $this->addHeader('Content-Type', 'multipart/form-data; boundary=' . $boundary); |
|
| 897 | + } |
|
| 898 | + } |
|
| 899 | + |
|
| 900 | + // Request Headers |
|
| 901 | + if (!empty($this->_requestHeaders)) { |
|
| 902 | + foreach ($this->_requestHeaders as $name => $value) { |
|
| 903 | + $canonicalName = implode('-', array_map('ucfirst', explode('-', $name))); |
|
| 904 | + $request .= $canonicalName . ': ' . $value . "\r\n"; |
|
| 905 | + } |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + // No post data or wrong method, so simply add a final CRLF |
|
| 909 | + if (in_array($this->_method, $this->_bodyDisallowed) || |
|
| 910 | + (HTTP_REQUEST_METHOD_POST != $this->_method && empty($this->_body))) { |
|
| 911 | + |
|
| 912 | + $request .= "\r\n"; |
|
| 913 | + |
|
| 914 | + // Post data if it's an array |
|
| 915 | + } elseif (HTTP_REQUEST_METHOD_POST == $this->_method && |
|
| 916 | + (!empty($this->_postData) || !empty($this->_postFiles))) { |
|
| 917 | + |
|
| 918 | + // "normal" POST request |
|
| 919 | + if (!isset($boundary)) { |
|
| 920 | + $postdata = implode('&', array_map( |
|
| 921 | + create_function('$a', 'return $a[0] . \'=\' . $a[1];'), |
|
| 922 | + $this->_flattenArray('', $this->_postData) |
|
| 923 | + )); |
|
| 924 | + |
|
| 925 | + // multipart request, probably with file uploads |
|
| 926 | + } else { |
|
| 927 | + $postdata = ''; |
|
| 928 | + if (!empty($this->_postData)) { |
|
| 929 | + $flatData = $this->_flattenArray('', $this->_postData); |
|
| 930 | + foreach ($flatData as $item) { |
|
| 931 | + $postdata .= '--' . $boundary . "\r\n"; |
|
| 932 | + $postdata .= 'Content-Disposition: form-data; name="' . $item[0] . '"'; |
|
| 933 | + $postdata .= "\r\n\r\n" . urldecode($item[1]) . "\r\n"; |
|
| 934 | + } |
|
| 935 | + } |
|
| 936 | + foreach ($this->_postFiles as $name => $value) { |
|
| 937 | + if (is_array($value['name'])) { |
|
| 938 | + $varname = $name . ($this->_useBrackets? '[]': ''); |
|
| 939 | + } else { |
|
| 940 | + $varname = $name; |
|
| 941 | + $value['name'] = array($value['name']); |
|
| 942 | + } |
|
| 943 | + foreach ($value['name'] as $key => $filename) { |
|
| 944 | + $fp = fopen($filename, 'r'); |
|
| 945 | + $data = fread($fp, filesize($filename)); |
|
| 946 | + fclose($fp); |
|
| 947 | + $basename = basename($filename); |
|
| 948 | + $type = is_array($value['type'])? @$value['type'][$key]: $value['type']; |
|
| 949 | + |
|
| 950 | + $postdata .= '--' . $boundary . "\r\n"; |
|
| 951 | + $postdata .= 'Content-Disposition: form-data; name="' . $varname . '"; filename="' . $basename . '"'; |
|
| 952 | + $postdata .= "\r\nContent-Type: " . $type; |
|
| 953 | + $postdata .= "\r\n\r\n" . $data . "\r\n"; |
|
| 954 | + } |
|
| 955 | + } |
|
| 956 | + $postdata .= '--' . $boundary . "--\r\n"; |
|
| 957 | + } |
|
| 958 | + $request .= 'Content-Length: ' . |
|
| 959 | + (HTTP_REQUEST_MBSTRING? mb_strlen($postdata, 'iso-8859-1'): strlen($postdata)) . |
|
| 960 | + "\r\n\r\n"; |
|
| 961 | + $request .= $postdata; |
|
| 962 | + |
|
| 963 | + // Explicitly set request body |
|
| 964 | + } elseif (!empty($this->_body)) { |
|
| 965 | + |
|
| 966 | + $request .= 'Content-Length: ' . |
|
| 967 | + (HTTP_REQUEST_MBSTRING? mb_strlen($this->_body, 'iso-8859-1'): strlen($this->_body)) . |
|
| 968 | + "\r\n\r\n"; |
|
| 969 | + $request .= $this->_body; |
|
| 970 | + } |
|
| 971 | 971 | |
| 972 | - return $request; |
|
| 973 | - } |
|
| 972 | + return $request; |
|
| 973 | + } |
|
| 974 | 974 | |
| 975 | 975 | /** |
| 976 | 976 | * Helper function to change the (probably multidimensional) associative array |
@@ -981,25 +981,25 @@ discard block |
||
| 981 | 981 | * @return array array with the following items: array('item name', 'item value'); |
| 982 | 982 | * @access private |
| 983 | 983 | */ |
| 984 | - function _flattenArray($name, $values) |
|
| 985 | - { |
|
| 986 | - if (!is_array($values)) { |
|
| 987 | - return array(array($name, $values)); |
|
| 988 | - } else { |
|
| 989 | - $ret = array(); |
|
| 990 | - foreach ($values as $k => $v) { |
|
| 991 | - if (empty($name)) { |
|
| 992 | - $newName = $k; |
|
| 993 | - } elseif ($this->_useBrackets) { |
|
| 994 | - $newName = $name . '[' . $k . ']'; |
|
| 995 | - } else { |
|
| 996 | - $newName = $name; |
|
| 997 | - } |
|
| 998 | - $ret = array_merge($ret, $this->_flattenArray($newName, $v)); |
|
| 999 | - } |
|
| 1000 | - return $ret; |
|
| 1001 | - } |
|
| 1002 | - } |
|
| 984 | + function _flattenArray($name, $values) |
|
| 985 | + { |
|
| 986 | + if (!is_array($values)) { |
|
| 987 | + return array(array($name, $values)); |
|
| 988 | + } else { |
|
| 989 | + $ret = array(); |
|
| 990 | + foreach ($values as $k => $v) { |
|
| 991 | + if (empty($name)) { |
|
| 992 | + $newName = $k; |
|
| 993 | + } elseif ($this->_useBrackets) { |
|
| 994 | + $newName = $name . '[' . $k . ']'; |
|
| 995 | + } else { |
|
| 996 | + $newName = $name; |
|
| 997 | + } |
|
| 998 | + $ret = array_merge($ret, $this->_flattenArray($newName, $v)); |
|
| 999 | + } |
|
| 1000 | + return $ret; |
|
| 1001 | + } |
|
| 1002 | + } |
|
| 1003 | 1003 | |
| 1004 | 1004 | |
| 1005 | 1005 | /** |
@@ -1021,14 +1021,14 @@ discard block |
||
| 1021 | 1021 | * @return boolean whether the listener was successfully attached |
| 1022 | 1022 | * @access public |
| 1023 | 1023 | */ |
| 1024 | - function attach(&$listener) |
|
| 1025 | - { |
|
| 1026 | - if (!is_a($listener, 'HTTP_Request_Listener')) { |
|
| 1027 | - return false; |
|
| 1028 | - } |
|
| 1029 | - $this->_listeners[$listener->getId()] =& $listener; |
|
| 1030 | - return true; |
|
| 1031 | - } |
|
| 1024 | + function attach(&$listener) |
|
| 1025 | + { |
|
| 1026 | + if (!is_a($listener, 'HTTP_Request_Listener')) { |
|
| 1027 | + return false; |
|
| 1028 | + } |
|
| 1029 | + $this->_listeners[$listener->getId()] =& $listener; |
|
| 1030 | + return true; |
|
| 1031 | + } |
|
| 1032 | 1032 | |
| 1033 | 1033 | |
| 1034 | 1034 | /** |
@@ -1038,15 +1038,15 @@ discard block |
||
| 1038 | 1038 | * @return boolean whether the listener was successfully detached |
| 1039 | 1039 | * @access public |
| 1040 | 1040 | */ |
| 1041 | - function detach(&$listener) |
|
| 1042 | - { |
|
| 1043 | - if (!is_a($listener, 'HTTP_Request_Listener') || |
|
| 1044 | - !isset($this->_listeners[$listener->getId()])) { |
|
| 1045 | - return false; |
|
| 1046 | - } |
|
| 1047 | - unset($this->_listeners[$listener->getId()]); |
|
| 1048 | - return true; |
|
| 1049 | - } |
|
| 1041 | + function detach(&$listener) |
|
| 1042 | + { |
|
| 1043 | + if (!is_a($listener, 'HTTP_Request_Listener') || |
|
| 1044 | + !isset($this->_listeners[$listener->getId()])) { |
|
| 1045 | + return false; |
|
| 1046 | + } |
|
| 1047 | + unset($this->_listeners[$listener->getId()]); |
|
| 1048 | + return true; |
|
| 1049 | + } |
|
| 1050 | 1050 | |
| 1051 | 1051 | |
| 1052 | 1052 | /** |
@@ -1057,12 +1057,12 @@ discard block |
||
| 1057 | 1057 | * @access private |
| 1058 | 1058 | * @see HTTP_Request::attach() |
| 1059 | 1059 | */ |
| 1060 | - function _notify($event, $data = null) |
|
| 1061 | - { |
|
| 1062 | - foreach (array_keys($this->_listeners) as $id) { |
|
| 1063 | - $this->_listeners[$id]->update($this, $event, $data); |
|
| 1064 | - } |
|
| 1065 | - } |
|
| 1060 | + function _notify($event, $data = null) |
|
| 1061 | + { |
|
| 1062 | + foreach (array_keys($this->_listeners) as $id) { |
|
| 1063 | + $this->_listeners[$id]->update($this, $event, $data); |
|
| 1064 | + } |
|
| 1065 | + } |
|
| 1066 | 1066 | } |
| 1067 | 1067 | |
| 1068 | 1068 | |
@@ -1077,71 +1077,71 @@ discard block |
||
| 1077 | 1077 | */ |
| 1078 | 1078 | class HTTP_Response |
| 1079 | 1079 | { |
| 1080 | - /** |
|
| 1081 | - * Socket object |
|
| 1082 | - * @var Net_Socket |
|
| 1083 | - */ |
|
| 1084 | - var $_sock; |
|
| 1085 | - |
|
| 1086 | - /** |
|
| 1087 | - * Protocol |
|
| 1088 | - * @var string |
|
| 1089 | - */ |
|
| 1090 | - var $_protocol; |
|
| 1080 | + /** |
|
| 1081 | + * Socket object |
|
| 1082 | + * @var Net_Socket |
|
| 1083 | + */ |
|
| 1084 | + var $_sock; |
|
| 1085 | + |
|
| 1086 | + /** |
|
| 1087 | + * Protocol |
|
| 1088 | + * @var string |
|
| 1089 | + */ |
|
| 1090 | + var $_protocol; |
|
| 1091 | 1091 | |
| 1092 | - /** |
|
| 1093 | - * Return code |
|
| 1094 | - * @var string |
|
| 1095 | - */ |
|
| 1096 | - var $_code; |
|
| 1092 | + /** |
|
| 1093 | + * Return code |
|
| 1094 | + * @var string |
|
| 1095 | + */ |
|
| 1096 | + var $_code; |
|
| 1097 | 1097 | |
| 1098 | - /** |
|
| 1099 | - * Response headers |
|
| 1100 | - * @var array |
|
| 1101 | - */ |
|
| 1102 | - var $_headers; |
|
| 1103 | - |
|
| 1104 | - /** |
|
| 1105 | - * Cookies set in response |
|
| 1106 | - * @var array |
|
| 1107 | - */ |
|
| 1108 | - var $_cookies; |
|
| 1109 | - |
|
| 1110 | - /** |
|
| 1111 | - * Response body |
|
| 1112 | - * @var string |
|
| 1113 | - */ |
|
| 1114 | - var $_body = ''; |
|
| 1098 | + /** |
|
| 1099 | + * Response headers |
|
| 1100 | + * @var array |
|
| 1101 | + */ |
|
| 1102 | + var $_headers; |
|
| 1103 | + |
|
| 1104 | + /** |
|
| 1105 | + * Cookies set in response |
|
| 1106 | + * @var array |
|
| 1107 | + */ |
|
| 1108 | + var $_cookies; |
|
| 1109 | + |
|
| 1110 | + /** |
|
| 1111 | + * Response body |
|
| 1112 | + * @var string |
|
| 1113 | + */ |
|
| 1114 | + var $_body = ''; |
|
| 1115 | 1115 | |
| 1116 | 1116 | /** |
| 1117 | 1117 | * Used by _readChunked(): remaining length of the current chunk |
| 1118 | 1118 | * @var string |
| 1119 | 1119 | */ |
| 1120 | - var $_chunkLength = 0; |
|
| 1120 | + var $_chunkLength = 0; |
|
| 1121 | 1121 | |
| 1122 | 1122 | /** |
| 1123 | 1123 | * Attached listeners |
| 1124 | 1124 | * @var array |
| 1125 | 1125 | */ |
| 1126 | - var $_listeners = array(); |
|
| 1126 | + var $_listeners = array(); |
|
| 1127 | 1127 | |
| 1128 | 1128 | /** |
| 1129 | 1129 | * Bytes left to read from message-body |
| 1130 | 1130 | * @var null|int |
| 1131 | 1131 | */ |
| 1132 | - var $_toRead; |
|
| 1132 | + var $_toRead; |
|
| 1133 | 1133 | |
| 1134 | - /** |
|
| 1135 | - * Constructor |
|
| 1136 | - * |
|
| 1137 | - * @param Net_Socket socket to read the response from |
|
| 1138 | - * @param array listeners attached to request |
|
| 1139 | - */ |
|
| 1140 | - function HTTP_Response(&$sock, &$listeners) |
|
| 1141 | - { |
|
| 1142 | - $this->_sock =& $sock; |
|
| 1143 | - $this->_listeners =& $listeners; |
|
| 1144 | - } |
|
| 1134 | + /** |
|
| 1135 | + * Constructor |
|
| 1136 | + * |
|
| 1137 | + * @param Net_Socket socket to read the response from |
|
| 1138 | + * @param array listeners attached to request |
|
| 1139 | + */ |
|
| 1140 | + function HTTP_Response(&$sock, &$listeners) |
|
| 1141 | + { |
|
| 1142 | + $this->_sock =& $sock; |
|
| 1143 | + $this->_listeners =& $listeners; |
|
| 1144 | + } |
|
| 1145 | 1145 | |
| 1146 | 1146 | |
| 1147 | 1147 | /** |
@@ -1159,80 +1159,80 @@ discard block |
||
| 1159 | 1159 | * @throws PEAR_Error |
| 1160 | 1160 | * @return mixed true on success, PEAR_Error in case of malformed response |
| 1161 | 1161 | */ |
| 1162 | - function process($saveBody = true, $canHaveBody = true) |
|
| 1163 | - { |
|
| 1164 | - do { |
|
| 1165 | - $line = $this->_sock->readLine(); |
|
| 1166 | - if (sscanf($line, 'HTTP/%s %s', $http_version, $returncode) != 2) { |
|
| 1167 | - return PEAR::raiseError('Malformed response.'); |
|
| 1168 | - } else { |
|
| 1169 | - $this->_protocol = 'HTTP/' . $http_version; |
|
| 1170 | - $this->_code = intval($returncode); |
|
| 1171 | - } |
|
| 1172 | - while ('' !== ($header = $this->_sock->readLine())) { |
|
| 1173 | - $this->_processHeader($header); |
|
| 1174 | - } |
|
| 1175 | - } while (100 == $this->_code); |
|
| 1176 | - |
|
| 1177 | - $this->_notify('gotHeaders', $this->_headers); |
|
| 1178 | - |
|
| 1179 | - // RFC 2616, section 4.4: |
|
| 1180 | - // 1. Any response message which "MUST NOT" include a message-body ... |
|
| 1181 | - // is always terminated by the first empty line after the header fields |
|
| 1182 | - // 3. ... If a message is received with both a |
|
| 1183 | - // Transfer-Encoding header field and a Content-Length header field, |
|
| 1184 | - // the latter MUST be ignored. |
|
| 1185 | - $canHaveBody = $canHaveBody && $this->_code >= 200 && |
|
| 1186 | - $this->_code != 204 && $this->_code != 304; |
|
| 1187 | - |
|
| 1188 | - // If response body is present, read it and decode |
|
| 1189 | - $chunked = isset($this->_headers['transfer-encoding']) && ('chunked' == $this->_headers['transfer-encoding']); |
|
| 1190 | - $gzipped = isset($this->_headers['content-encoding']) && ('gzip' == $this->_headers['content-encoding']); |
|
| 1191 | - $hasBody = false; |
|
| 1192 | - if ($canHaveBody && ($chunked || !isset($this->_headers['content-length']) || |
|
| 1193 | - 0 != $this->_headers['content-length'])) |
|
| 1194 | - { |
|
| 1195 | - if ($chunked || !isset($this->_headers['content-length'])) { |
|
| 1196 | - $this->_toRead = null; |
|
| 1197 | - } else { |
|
| 1198 | - $this->_toRead = $this->_headers['content-length']; |
|
| 1199 | - } |
|
| 1200 | - while (!$this->_sock->eof() && (is_null($this->_toRead) || 0 < $this->_toRead)) { |
|
| 1201 | - if ($chunked) { |
|
| 1202 | - $data = $this->_readChunked(); |
|
| 1203 | - } elseif (is_null($this->_toRead)) { |
|
| 1204 | - $data = $this->_sock->read(4096); |
|
| 1205 | - } else { |
|
| 1206 | - $data = $this->_sock->read(min(4096, $this->_toRead)); |
|
| 1207 | - $this->_toRead -= HTTP_REQUEST_MBSTRING? mb_strlen($data, 'iso-8859-1'): strlen($data); |
|
| 1208 | - } |
|
| 1209 | - if ('' == $data) { |
|
| 1210 | - break; |
|
| 1211 | - } else { |
|
| 1212 | - $hasBody = true; |
|
| 1213 | - if ($saveBody || $gzipped) { |
|
| 1214 | - $this->_body .= $data; |
|
| 1215 | - } |
|
| 1216 | - $this->_notify($gzipped? 'gzTick': 'tick', $data); |
|
| 1217 | - } |
|
| 1218 | - } |
|
| 1219 | - } |
|
| 1220 | - |
|
| 1221 | - if ($hasBody) { |
|
| 1222 | - // Uncompress the body if needed |
|
| 1223 | - if ($gzipped) { |
|
| 1224 | - $body = $this->_decodeGzip($this->_body); |
|
| 1225 | - if (PEAR::isError($body)) { |
|
| 1226 | - return $body; |
|
| 1227 | - } |
|
| 1228 | - $this->_body = $body; |
|
| 1229 | - $this->_notify('gotBody', $this->_body); |
|
| 1230 | - } else { |
|
| 1231 | - $this->_notify('gotBody'); |
|
| 1232 | - } |
|
| 1233 | - } |
|
| 1234 | - return true; |
|
| 1235 | - } |
|
| 1162 | + function process($saveBody = true, $canHaveBody = true) |
|
| 1163 | + { |
|
| 1164 | + do { |
|
| 1165 | + $line = $this->_sock->readLine(); |
|
| 1166 | + if (sscanf($line, 'HTTP/%s %s', $http_version, $returncode) != 2) { |
|
| 1167 | + return PEAR::raiseError('Malformed response.'); |
|
| 1168 | + } else { |
|
| 1169 | + $this->_protocol = 'HTTP/' . $http_version; |
|
| 1170 | + $this->_code = intval($returncode); |
|
| 1171 | + } |
|
| 1172 | + while ('' !== ($header = $this->_sock->readLine())) { |
|
| 1173 | + $this->_processHeader($header); |
|
| 1174 | + } |
|
| 1175 | + } while (100 == $this->_code); |
|
| 1176 | + |
|
| 1177 | + $this->_notify('gotHeaders', $this->_headers); |
|
| 1178 | + |
|
| 1179 | + // RFC 2616, section 4.4: |
|
| 1180 | + // 1. Any response message which "MUST NOT" include a message-body ... |
|
| 1181 | + // is always terminated by the first empty line after the header fields |
|
| 1182 | + // 3. ... If a message is received with both a |
|
| 1183 | + // Transfer-Encoding header field and a Content-Length header field, |
|
| 1184 | + // the latter MUST be ignored. |
|
| 1185 | + $canHaveBody = $canHaveBody && $this->_code >= 200 && |
|
| 1186 | + $this->_code != 204 && $this->_code != 304; |
|
| 1187 | + |
|
| 1188 | + // If response body is present, read it and decode |
|
| 1189 | + $chunked = isset($this->_headers['transfer-encoding']) && ('chunked' == $this->_headers['transfer-encoding']); |
|
| 1190 | + $gzipped = isset($this->_headers['content-encoding']) && ('gzip' == $this->_headers['content-encoding']); |
|
| 1191 | + $hasBody = false; |
|
| 1192 | + if ($canHaveBody && ($chunked || !isset($this->_headers['content-length']) || |
|
| 1193 | + 0 != $this->_headers['content-length'])) |
|
| 1194 | + { |
|
| 1195 | + if ($chunked || !isset($this->_headers['content-length'])) { |
|
| 1196 | + $this->_toRead = null; |
|
| 1197 | + } else { |
|
| 1198 | + $this->_toRead = $this->_headers['content-length']; |
|
| 1199 | + } |
|
| 1200 | + while (!$this->_sock->eof() && (is_null($this->_toRead) || 0 < $this->_toRead)) { |
|
| 1201 | + if ($chunked) { |
|
| 1202 | + $data = $this->_readChunked(); |
|
| 1203 | + } elseif (is_null($this->_toRead)) { |
|
| 1204 | + $data = $this->_sock->read(4096); |
|
| 1205 | + } else { |
|
| 1206 | + $data = $this->_sock->read(min(4096, $this->_toRead)); |
|
| 1207 | + $this->_toRead -= HTTP_REQUEST_MBSTRING? mb_strlen($data, 'iso-8859-1'): strlen($data); |
|
| 1208 | + } |
|
| 1209 | + if ('' == $data) { |
|
| 1210 | + break; |
|
| 1211 | + } else { |
|
| 1212 | + $hasBody = true; |
|
| 1213 | + if ($saveBody || $gzipped) { |
|
| 1214 | + $this->_body .= $data; |
|
| 1215 | + } |
|
| 1216 | + $this->_notify($gzipped? 'gzTick': 'tick', $data); |
|
| 1217 | + } |
|
| 1218 | + } |
|
| 1219 | + } |
|
| 1220 | + |
|
| 1221 | + if ($hasBody) { |
|
| 1222 | + // Uncompress the body if needed |
|
| 1223 | + if ($gzipped) { |
|
| 1224 | + $body = $this->_decodeGzip($this->_body); |
|
| 1225 | + if (PEAR::isError($body)) { |
|
| 1226 | + return $body; |
|
| 1227 | + } |
|
| 1228 | + $this->_body = $body; |
|
| 1229 | + $this->_notify('gotBody', $this->_body); |
|
| 1230 | + } else { |
|
| 1231 | + $this->_notify('gotBody'); |
|
| 1232 | + } |
|
| 1233 | + } |
|
| 1234 | + return true; |
|
| 1235 | + } |
|
| 1236 | 1236 | |
| 1237 | 1237 | |
| 1238 | 1238 | /** |
@@ -1241,25 +1241,25 @@ discard block |
||
| 1241 | 1241 | * @access private |
| 1242 | 1242 | * @param string HTTP header |
| 1243 | 1243 | */ |
| 1244 | - function _processHeader($header) |
|
| 1245 | - { |
|
| 1246 | - if (false === strpos($header, ':')) { |
|
| 1247 | - return; |
|
| 1248 | - } |
|
| 1249 | - list($headername, $headervalue) = explode(':', $header, 2); |
|
| 1250 | - $headername = strtolower($headername); |
|
| 1251 | - $headervalue = ltrim($headervalue); |
|
| 1244 | + function _processHeader($header) |
|
| 1245 | + { |
|
| 1246 | + if (false === strpos($header, ':')) { |
|
| 1247 | + return; |
|
| 1248 | + } |
|
| 1249 | + list($headername, $headervalue) = explode(':', $header, 2); |
|
| 1250 | + $headername = strtolower($headername); |
|
| 1251 | + $headervalue = ltrim($headervalue); |
|
| 1252 | 1252 | |
| 1253 | - if ('set-cookie' != $headername) { |
|
| 1254 | - if (isset($this->_headers[$headername])) { |
|
| 1255 | - $this->_headers[$headername] .= ',' . $headervalue; |
|
| 1256 | - } else { |
|
| 1257 | - $this->_headers[$headername] = $headervalue; |
|
| 1258 | - } |
|
| 1259 | - } else { |
|
| 1260 | - $this->_parseCookie($headervalue); |
|
| 1261 | - } |
|
| 1262 | - } |
|
| 1253 | + if ('set-cookie' != $headername) { |
|
| 1254 | + if (isset($this->_headers[$headername])) { |
|
| 1255 | + $this->_headers[$headername] .= ',' . $headervalue; |
|
| 1256 | + } else { |
|
| 1257 | + $this->_headers[$headername] = $headervalue; |
|
| 1258 | + } |
|
| 1259 | + } else { |
|
| 1260 | + $this->_parseCookie($headervalue); |
|
| 1261 | + } |
|
| 1262 | + } |
|
| 1263 | 1263 | |
| 1264 | 1264 | |
| 1265 | 1265 | /** |
@@ -1268,49 +1268,49 @@ discard block |
||
| 1268 | 1268 | * @access private |
| 1269 | 1269 | * @param string value of Set-Cookie header |
| 1270 | 1270 | */ |
| 1271 | - function _parseCookie($headervalue) |
|
| 1272 | - { |
|
| 1273 | - $cookie = array( |
|
| 1274 | - 'expires' => null, |
|
| 1275 | - 'domain' => null, |
|
| 1276 | - 'path' => null, |
|
| 1277 | - 'secure' => false |
|
| 1278 | - ); |
|
| 1279 | - |
|
| 1280 | - // Only a name=value pair |
|
| 1281 | - if (!strpos($headervalue, ';')) { |
|
| 1282 | - $pos = strpos($headervalue, '='); |
|
| 1283 | - $cookie['name'] = trim(substr($headervalue, 0, $pos)); |
|
| 1284 | - $cookie['value'] = trim(substr($headervalue, $pos + 1)); |
|
| 1285 | - |
|
| 1286 | - // Some optional parameters are supplied |
|
| 1287 | - } else { |
|
| 1288 | - $elements = explode(';', $headervalue); |
|
| 1289 | - $pos = strpos($elements[0], '='); |
|
| 1290 | - $cookie['name'] = trim(substr($elements[0], 0, $pos)); |
|
| 1291 | - $cookie['value'] = trim(substr($elements[0], $pos + 1)); |
|
| 1292 | - |
|
| 1293 | - for ($i = 1; $i < count($elements); $i++) { |
|
| 1294 | - if (false === strpos($elements[$i], '=')) { |
|
| 1295 | - $elName = trim($elements[$i]); |
|
| 1296 | - $elValue = null; |
|
| 1297 | - } else { |
|
| 1298 | - list ($elName, $elValue) = array_map('trim', explode('=', $elements[$i])); |
|
| 1299 | - } |
|
| 1300 | - $elName = strtolower($elName); |
|
| 1301 | - if ('secure' == $elName) { |
|
| 1302 | - $cookie['secure'] = true; |
|
| 1303 | - } elseif ('expires' == $elName) { |
|
| 1304 | - $cookie['expires'] = str_replace('"', '', $elValue); |
|
| 1305 | - } elseif ('path' == $elName || 'domain' == $elName) { |
|
| 1306 | - $cookie[$elName] = urldecode($elValue); |
|
| 1307 | - } else { |
|
| 1308 | - $cookie[$elName] = $elValue; |
|
| 1309 | - } |
|
| 1310 | - } |
|
| 1311 | - } |
|
| 1312 | - $this->_cookies[] = $cookie; |
|
| 1313 | - } |
|
| 1271 | + function _parseCookie($headervalue) |
|
| 1272 | + { |
|
| 1273 | + $cookie = array( |
|
| 1274 | + 'expires' => null, |
|
| 1275 | + 'domain' => null, |
|
| 1276 | + 'path' => null, |
|
| 1277 | + 'secure' => false |
|
| 1278 | + ); |
|
| 1279 | + |
|
| 1280 | + // Only a name=value pair |
|
| 1281 | + if (!strpos($headervalue, ';')) { |
|
| 1282 | + $pos = strpos($headervalue, '='); |
|
| 1283 | + $cookie['name'] = trim(substr($headervalue, 0, $pos)); |
|
| 1284 | + $cookie['value'] = trim(substr($headervalue, $pos + 1)); |
|
| 1285 | + |
|
| 1286 | + // Some optional parameters are supplied |
|
| 1287 | + } else { |
|
| 1288 | + $elements = explode(';', $headervalue); |
|
| 1289 | + $pos = strpos($elements[0], '='); |
|
| 1290 | + $cookie['name'] = trim(substr($elements[0], 0, $pos)); |
|
| 1291 | + $cookie['value'] = trim(substr($elements[0], $pos + 1)); |
|
| 1292 | + |
|
| 1293 | + for ($i = 1; $i < count($elements); $i++) { |
|
| 1294 | + if (false === strpos($elements[$i], '=')) { |
|
| 1295 | + $elName = trim($elements[$i]); |
|
| 1296 | + $elValue = null; |
|
| 1297 | + } else { |
|
| 1298 | + list ($elName, $elValue) = array_map('trim', explode('=', $elements[$i])); |
|
| 1299 | + } |
|
| 1300 | + $elName = strtolower($elName); |
|
| 1301 | + if ('secure' == $elName) { |
|
| 1302 | + $cookie['secure'] = true; |
|
| 1303 | + } elseif ('expires' == $elName) { |
|
| 1304 | + $cookie['expires'] = str_replace('"', '', $elValue); |
|
| 1305 | + } elseif ('path' == $elName || 'domain' == $elName) { |
|
| 1306 | + $cookie[$elName] = urldecode($elValue); |
|
| 1307 | + } else { |
|
| 1308 | + $cookie[$elName] = $elValue; |
|
| 1309 | + } |
|
| 1310 | + } |
|
| 1311 | + } |
|
| 1312 | + $this->_cookies[] = $cookie; |
|
| 1313 | + } |
|
| 1314 | 1314 | |
| 1315 | 1315 | |
| 1316 | 1316 | /** |
@@ -1319,29 +1319,29 @@ discard block |
||
| 1319 | 1319 | * @access private |
| 1320 | 1320 | * @return string |
| 1321 | 1321 | */ |
| 1322 | - function _readChunked() |
|
| 1323 | - { |
|
| 1324 | - // at start of the next chunk? |
|
| 1325 | - if (0 == $this->_chunkLength) { |
|
| 1326 | - $line = $this->_sock->readLine(); |
|
| 1327 | - if (preg_match('/^([0-9a-f]+)/i', $line, $matches)) { |
|
| 1328 | - $this->_chunkLength = hexdec($matches[1]); |
|
| 1329 | - // Chunk with zero length indicates the end |
|
| 1330 | - if (0 == $this->_chunkLength) { |
|
| 1331 | - $this->_sock->readLine(); // make this an eof() |
|
| 1332 | - return ''; |
|
| 1333 | - } |
|
| 1334 | - } else { |
|
| 1335 | - return ''; |
|
| 1336 | - } |
|
| 1337 | - } |
|
| 1338 | - $data = $this->_sock->read($this->_chunkLength); |
|
| 1339 | - $this->_chunkLength -= HTTP_REQUEST_MBSTRING? mb_strlen($data, 'iso-8859-1'): strlen($data); |
|
| 1340 | - if (0 == $this->_chunkLength) { |
|
| 1341 | - $this->_sock->readLine(); // Trailing CRLF |
|
| 1342 | - } |
|
| 1343 | - return $data; |
|
| 1344 | - } |
|
| 1322 | + function _readChunked() |
|
| 1323 | + { |
|
| 1324 | + // at start of the next chunk? |
|
| 1325 | + if (0 == $this->_chunkLength) { |
|
| 1326 | + $line = $this->_sock->readLine(); |
|
| 1327 | + if (preg_match('/^([0-9a-f]+)/i', $line, $matches)) { |
|
| 1328 | + $this->_chunkLength = hexdec($matches[1]); |
|
| 1329 | + // Chunk with zero length indicates the end |
|
| 1330 | + if (0 == $this->_chunkLength) { |
|
| 1331 | + $this->_sock->readLine(); // make this an eof() |
|
| 1332 | + return ''; |
|
| 1333 | + } |
|
| 1334 | + } else { |
|
| 1335 | + return ''; |
|
| 1336 | + } |
|
| 1337 | + } |
|
| 1338 | + $data = $this->_sock->read($this->_chunkLength); |
|
| 1339 | + $this->_chunkLength -= HTTP_REQUEST_MBSTRING? mb_strlen($data, 'iso-8859-1'): strlen($data); |
|
| 1340 | + if (0 == $this->_chunkLength) { |
|
| 1341 | + $this->_sock->readLine(); // Trailing CRLF |
|
| 1342 | + } |
|
| 1343 | + return $data; |
|
| 1344 | + } |
|
| 1345 | 1345 | |
| 1346 | 1346 | |
| 1347 | 1347 | /** |
@@ -1352,12 +1352,12 @@ discard block |
||
| 1352 | 1352 | * @access private |
| 1353 | 1353 | * @see HTTP_Request::_notify() |
| 1354 | 1354 | */ |
| 1355 | - function _notify($event, $data = null) |
|
| 1356 | - { |
|
| 1357 | - foreach (array_keys($this->_listeners) as $id) { |
|
| 1358 | - $this->_listeners[$id]->update($this, $event, $data); |
|
| 1359 | - } |
|
| 1360 | - } |
|
| 1355 | + function _notify($event, $data = null) |
|
| 1356 | + { |
|
| 1357 | + foreach (array_keys($this->_listeners) as $id) { |
|
| 1358 | + $this->_listeners[$id]->update($this, $event, $data); |
|
| 1359 | + } |
|
| 1360 | + } |
|
| 1361 | 1361 | |
| 1362 | 1362 | |
| 1363 | 1363 | /** |
@@ -1371,91 +1371,91 @@ discard block |
||
| 1371 | 1371 | * @param string gzip-encoded data |
| 1372 | 1372 | * @return string decoded data |
| 1373 | 1373 | */ |
| 1374 | - function _decodeGzip($data) |
|
| 1375 | - { |
|
| 1376 | - if (HTTP_REQUEST_MBSTRING) { |
|
| 1377 | - $oldEncoding = mb_internal_encoding(); |
|
| 1378 | - mb_internal_encoding('iso-8859-1'); |
|
| 1379 | - } |
|
| 1380 | - $length = strlen($data); |
|
| 1381 | - // If it doesn't look like gzip-encoded data, don't bother |
|
| 1382 | - if (18 > $length || strcmp(substr($data, 0, 2), "\x1f\x8b")) { |
|
| 1383 | - return $data; |
|
| 1384 | - } |
|
| 1385 | - $method = ord(substr($data, 2, 1)); |
|
| 1386 | - if (8 != $method) { |
|
| 1387 | - return PEAR::raiseError('_decodeGzip(): unknown compression method'); |
|
| 1388 | - } |
|
| 1389 | - $flags = ord(substr($data, 3, 1)); |
|
| 1390 | - if ($flags & 224) { |
|
| 1391 | - return PEAR::raiseError('_decodeGzip(): reserved bits are set'); |
|
| 1392 | - } |
|
| 1393 | - |
|
| 1394 | - // header is 10 bytes minimum. may be longer, though. |
|
| 1395 | - $headerLength = 10; |
|
| 1396 | - // extra fields, need to skip 'em |
|
| 1397 | - if ($flags & 4) { |
|
| 1398 | - if ($length - $headerLength - 2 < 8) { |
|
| 1399 | - return PEAR::raiseError('_decodeGzip(): data too short'); |
|
| 1400 | - } |
|
| 1401 | - $extraLength = unpack('v', substr($data, 10, 2)); |
|
| 1402 | - if ($length - $headerLength - 2 - $extraLength[1] < 8) { |
|
| 1403 | - return PEAR::raiseError('_decodeGzip(): data too short'); |
|
| 1404 | - } |
|
| 1405 | - $headerLength += $extraLength[1] + 2; |
|
| 1406 | - } |
|
| 1407 | - // file name, need to skip that |
|
| 1408 | - if ($flags & 8) { |
|
| 1409 | - if ($length - $headerLength - 1 < 8) { |
|
| 1410 | - return PEAR::raiseError('_decodeGzip(): data too short'); |
|
| 1411 | - } |
|
| 1412 | - $filenameLength = strpos(substr($data, $headerLength), chr(0)); |
|
| 1413 | - if (false === $filenameLength || $length - $headerLength - $filenameLength - 1 < 8) { |
|
| 1414 | - return PEAR::raiseError('_decodeGzip(): data too short'); |
|
| 1415 | - } |
|
| 1416 | - $headerLength += $filenameLength + 1; |
|
| 1417 | - } |
|
| 1418 | - // comment, need to skip that also |
|
| 1419 | - if ($flags & 16) { |
|
| 1420 | - if ($length - $headerLength - 1 < 8) { |
|
| 1421 | - return PEAR::raiseError('_decodeGzip(): data too short'); |
|
| 1422 | - } |
|
| 1423 | - $commentLength = strpos(substr($data, $headerLength), chr(0)); |
|
| 1424 | - if (false === $commentLength || $length - $headerLength - $commentLength - 1 < 8) { |
|
| 1425 | - return PEAR::raiseError('_decodeGzip(): data too short'); |
|
| 1426 | - } |
|
| 1427 | - $headerLength += $commentLength + 1; |
|
| 1428 | - } |
|
| 1429 | - // have a CRC for header. let's check |
|
| 1430 | - if ($flags & 1) { |
|
| 1431 | - if ($length - $headerLength - 2 < 8) { |
|
| 1432 | - return PEAR::raiseError('_decodeGzip(): data too short'); |
|
| 1433 | - } |
|
| 1434 | - $crcReal = 0xffff & crc32(substr($data, 0, $headerLength)); |
|
| 1435 | - $crcStored = unpack('v', substr($data, $headerLength, 2)); |
|
| 1436 | - if ($crcReal != $crcStored[1]) { |
|
| 1437 | - return PEAR::raiseError('_decodeGzip(): header CRC check failed'); |
|
| 1438 | - } |
|
| 1439 | - $headerLength += 2; |
|
| 1440 | - } |
|
| 1441 | - // unpacked data CRC and size at the end of encoded data |
|
| 1442 | - $tmp = unpack('V2', substr($data, -8)); |
|
| 1443 | - $dataCrc = $tmp[1]; |
|
| 1444 | - $dataSize = $tmp[2]; |
|
| 1445 | - |
|
| 1446 | - // finally, call the gzinflate() function |
|
| 1447 | - $unpacked = @gzinflate(substr($data, $headerLength, -8), $dataSize); |
|
| 1448 | - if (false === $unpacked) { |
|
| 1449 | - return PEAR::raiseError('_decodeGzip(): gzinflate() call failed'); |
|
| 1450 | - } elseif ($dataSize != strlen($unpacked)) { |
|
| 1451 | - return PEAR::raiseError('_decodeGzip(): data size check failed'); |
|
| 1452 | - } elseif ((0xffffffff & $dataCrc) != (0xffffffff & crc32($unpacked))) { |
|
| 1453 | - return PEAR::raiseError('_decodeGzip(): data CRC check failed'); |
|
| 1454 | - } |
|
| 1455 | - if (HTTP_REQUEST_MBSTRING) { |
|
| 1456 | - mb_internal_encoding($oldEncoding); |
|
| 1457 | - } |
|
| 1458 | - return $unpacked; |
|
| 1459 | - } |
|
| 1374 | + function _decodeGzip($data) |
|
| 1375 | + { |
|
| 1376 | + if (HTTP_REQUEST_MBSTRING) { |
|
| 1377 | + $oldEncoding = mb_internal_encoding(); |
|
| 1378 | + mb_internal_encoding('iso-8859-1'); |
|
| 1379 | + } |
|
| 1380 | + $length = strlen($data); |
|
| 1381 | + // If it doesn't look like gzip-encoded data, don't bother |
|
| 1382 | + if (18 > $length || strcmp(substr($data, 0, 2), "\x1f\x8b")) { |
|
| 1383 | + return $data; |
|
| 1384 | + } |
|
| 1385 | + $method = ord(substr($data, 2, 1)); |
|
| 1386 | + if (8 != $method) { |
|
| 1387 | + return PEAR::raiseError('_decodeGzip(): unknown compression method'); |
|
| 1388 | + } |
|
| 1389 | + $flags = ord(substr($data, 3, 1)); |
|
| 1390 | + if ($flags & 224) { |
|
| 1391 | + return PEAR::raiseError('_decodeGzip(): reserved bits are set'); |
|
| 1392 | + } |
|
| 1393 | + |
|
| 1394 | + // header is 10 bytes minimum. may be longer, though. |
|
| 1395 | + $headerLength = 10; |
|
| 1396 | + // extra fields, need to skip 'em |
|
| 1397 | + if ($flags & 4) { |
|
| 1398 | + if ($length - $headerLength - 2 < 8) { |
|
| 1399 | + return PEAR::raiseError('_decodeGzip(): data too short'); |
|
| 1400 | + } |
|
| 1401 | + $extraLength = unpack('v', substr($data, 10, 2)); |
|
| 1402 | + if ($length - $headerLength - 2 - $extraLength[1] < 8) { |
|
| 1403 | + return PEAR::raiseError('_decodeGzip(): data too short'); |
|
| 1404 | + } |
|
| 1405 | + $headerLength += $extraLength[1] + 2; |
|
| 1406 | + } |
|
| 1407 | + // file name, need to skip that |
|
| 1408 | + if ($flags & 8) { |
|
| 1409 | + if ($length - $headerLength - 1 < 8) { |
|
| 1410 | + return PEAR::raiseError('_decodeGzip(): data too short'); |
|
| 1411 | + } |
|
| 1412 | + $filenameLength = strpos(substr($data, $headerLength), chr(0)); |
|
| 1413 | + if (false === $filenameLength || $length - $headerLength - $filenameLength - 1 < 8) { |
|
| 1414 | + return PEAR::raiseError('_decodeGzip(): data too short'); |
|
| 1415 | + } |
|
| 1416 | + $headerLength += $filenameLength + 1; |
|
| 1417 | + } |
|
| 1418 | + // comment, need to skip that also |
|
| 1419 | + if ($flags & 16) { |
|
| 1420 | + if ($length - $headerLength - 1 < 8) { |
|
| 1421 | + return PEAR::raiseError('_decodeGzip(): data too short'); |
|
| 1422 | + } |
|
| 1423 | + $commentLength = strpos(substr($data, $headerLength), chr(0)); |
|
| 1424 | + if (false === $commentLength || $length - $headerLength - $commentLength - 1 < 8) { |
|
| 1425 | + return PEAR::raiseError('_decodeGzip(): data too short'); |
|
| 1426 | + } |
|
| 1427 | + $headerLength += $commentLength + 1; |
|
| 1428 | + } |
|
| 1429 | + // have a CRC for header. let's check |
|
| 1430 | + if ($flags & 1) { |
|
| 1431 | + if ($length - $headerLength - 2 < 8) { |
|
| 1432 | + return PEAR::raiseError('_decodeGzip(): data too short'); |
|
| 1433 | + } |
|
| 1434 | + $crcReal = 0xffff & crc32(substr($data, 0, $headerLength)); |
|
| 1435 | + $crcStored = unpack('v', substr($data, $headerLength, 2)); |
|
| 1436 | + if ($crcReal != $crcStored[1]) { |
|
| 1437 | + return PEAR::raiseError('_decodeGzip(): header CRC check failed'); |
|
| 1438 | + } |
|
| 1439 | + $headerLength += 2; |
|
| 1440 | + } |
|
| 1441 | + // unpacked data CRC and size at the end of encoded data |
|
| 1442 | + $tmp = unpack('V2', substr($data, -8)); |
|
| 1443 | + $dataCrc = $tmp[1]; |
|
| 1444 | + $dataSize = $tmp[2]; |
|
| 1445 | + |
|
| 1446 | + // finally, call the gzinflate() function |
|
| 1447 | + $unpacked = @gzinflate(substr($data, $headerLength, -8), $dataSize); |
|
| 1448 | + if (false === $unpacked) { |
|
| 1449 | + return PEAR::raiseError('_decodeGzip(): gzinflate() call failed'); |
|
| 1450 | + } elseif ($dataSize != strlen($unpacked)) { |
|
| 1451 | + return PEAR::raiseError('_decodeGzip(): data size check failed'); |
|
| 1452 | + } elseif ((0xffffffff & $dataCrc) != (0xffffffff & crc32($unpacked))) { |
|
| 1453 | + return PEAR::raiseError('_decodeGzip(): data CRC check failed'); |
|
| 1454 | + } |
|
| 1455 | + if (HTTP_REQUEST_MBSTRING) { |
|
| 1456 | + mb_internal_encoding($oldEncoding); |
|
| 1457 | + } |
|
| 1458 | + return $unpacked; |
|
| 1459 | + } |
|
| 1460 | 1460 | } // End class HTTP_Response |
| 1461 | 1461 | ?> |
@@ -60,13 +60,13 @@ discard block |
||
| 60 | 60 | /**#@+ |
| 61 | 61 | * Constants for HTTP request methods |
| 62 | 62 | */ |
| 63 | -define('HTTP_REQUEST_METHOD_GET', 'GET', true); |
|
| 64 | -define('HTTP_REQUEST_METHOD_HEAD', 'HEAD', true); |
|
| 65 | -define('HTTP_REQUEST_METHOD_POST', 'POST', true); |
|
| 66 | -define('HTTP_REQUEST_METHOD_PUT', 'PUT', true); |
|
| 67 | -define('HTTP_REQUEST_METHOD_DELETE', 'DELETE', true); |
|
| 63 | +define('HTTP_REQUEST_METHOD_GET', 'GET', true); |
|
| 64 | +define('HTTP_REQUEST_METHOD_HEAD', 'HEAD', true); |
|
| 65 | +define('HTTP_REQUEST_METHOD_POST', 'POST', true); |
|
| 66 | +define('HTTP_REQUEST_METHOD_PUT', 'PUT', true); |
|
| 67 | +define('HTTP_REQUEST_METHOD_DELETE', 'DELETE', true); |
|
| 68 | 68 | define('HTTP_REQUEST_METHOD_OPTIONS', 'OPTIONS', true); |
| 69 | -define('HTTP_REQUEST_METHOD_TRACE', 'TRACE', true); |
|
| 69 | +define('HTTP_REQUEST_METHOD_TRACE', 'TRACE', true); |
|
| 70 | 70 | /**#@-*/ |
| 71 | 71 | |
| 72 | 72 | /**#@+ |
@@ -287,8 +287,8 @@ discard block |
||
| 287 | 287 | */ |
| 288 | 288 | function HTTP_Request($url = '', $params = array()) |
| 289 | 289 | { |
| 290 | - $this->_method = HTTP_REQUEST_METHOD_GET; |
|
| 291 | - $this->_http = HTTP_REQUEST_HTTP_VER_1_1; |
|
| 290 | + $this->_method = HTTP_REQUEST_METHOD_GET; |
|
| 291 | + $this->_http = HTTP_REQUEST_HTTP_VER_1_1; |
|
| 292 | 292 | $this->_requestHeaders = array(); |
| 293 | 293 | $this->_postData = array(); |
| 294 | 294 | $this->_body = null; |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | $this->_response = null; |
| 310 | 310 | |
| 311 | 311 | foreach ($params as $key => $value) { |
| 312 | - $this->{'_' . $key} = $value; |
|
| 312 | + $this->{'_'.$key} = $value; |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | if (!empty($url)) { |
@@ -324,12 +324,12 @@ discard block |
||
| 324 | 324 | |
| 325 | 325 | // Basic authentication |
| 326 | 326 | if (!empty($this->_user)) { |
| 327 | - $this->addHeader('Authorization', 'Basic ' . base64_encode($this->_user . ':' . $this->_pass)); |
|
| 327 | + $this->addHeader('Authorization', 'Basic '.base64_encode($this->_user.':'.$this->_pass)); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | // Proxy authentication (see bug #5913) |
| 331 | 331 | if (!empty($this->_proxy_user)) { |
| 332 | - $this->addHeader('Proxy-Authorization', 'Basic ' . base64_encode($this->_proxy_user . ':' . $this->_proxy_pass)); |
|
| 332 | + $this->addHeader('Proxy-Authorization', 'Basic '.base64_encode($this->_proxy_user.':'.$this->_proxy_pass)); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | // Use gzip encoding if possible |
@@ -347,13 +347,13 @@ discard block |
||
| 347 | 347 | function _generateHostHeader() |
| 348 | 348 | { |
| 349 | 349 | if ($this->_url->port != 80 AND strcasecmp($this->_url->protocol, 'http') == 0) { |
| 350 | - $host = $this->_url->host . ':' . $this->_url->port; |
|
| 350 | + $host = $this->_url->host.':'.$this->_url->port; |
|
| 351 | 351 | |
| 352 | 352 | } elseif ($this->_url->port != 443 AND strcasecmp($this->_url->protocol, 'https') == 0) { |
| 353 | - $host = $this->_url->host . ':' . $this->_url->port; |
|
| 353 | + $host = $this->_url->host.':'.$this->_url->port; |
|
| 354 | 354 | |
| 355 | 355 | } elseif ($this->_url->port == 443 AND strcasecmp($this->_url->protocol, 'https') == 0 AND strpos($this->_url->url, ':443') !== false) { |
| 356 | - $host = $this->_url->host . ':' . $this->_url->port; |
|
| 356 | + $host = $this->_url->host.':'.$this->_url->port; |
|
| 357 | 357 | |
| 358 | 358 | } else { |
| 359 | 359 | $host = $this->_url->host; |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | */ |
| 410 | 410 | function getUrl() |
| 411 | 411 | { |
| 412 | - return empty($this->_url)? '': $this->_url->getUrl(); |
|
| 412 | + return empty($this->_url) ? '' : $this->_url->getUrl(); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | /** |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | $this->_proxy_pass = $pass; |
| 430 | 430 | |
| 431 | 431 | if (!empty($user)) { |
| 432 | - $this->addHeader('Proxy-Authorization', 'Basic ' . base64_encode($user . ':' . $pass)); |
|
| 432 | + $this->addHeader('Proxy-Authorization', 'Basic '.base64_encode($user.':'.$pass)); |
|
| 433 | 433 | } |
| 434 | 434 | } |
| 435 | 435 | |
@@ -444,7 +444,7 @@ discard block |
||
| 444 | 444 | $this->_user = $user; |
| 445 | 445 | $this->_pass = $pass; |
| 446 | 446 | |
| 447 | - $this->addHeader('Authorization', 'Basic ' . base64_encode($user . ':' . $pass)); |
|
| 447 | + $this->addHeader('Authorization', 'Basic '.base64_encode($user.':'.$pass)); |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | /** |
@@ -634,8 +634,8 @@ discard block |
||
| 634 | 634 | */ |
| 635 | 635 | function addCookie($name, $value) |
| 636 | 636 | { |
| 637 | - $cookies = isset($this->_requestHeaders['cookie']) ? $this->_requestHeaders['cookie']. '; ' : ''; |
|
| 638 | - $this->addHeader('Cookie', $cookies . $name . '=' . $value); |
|
| 637 | + $cookies = isset($this->_requestHeaders['cookie']) ? $this->_requestHeaders['cookie'].'; ' : ''; |
|
| 638 | + $this->addHeader('Cookie', $cookies.$name.'='.$value); |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | /** |
@@ -674,7 +674,7 @@ discard block |
||
| 674 | 674 | if (isset($this->_proxy_host)) { |
| 675 | 675 | return PEAR::raiseError('HTTPS proxies are not supported.'); |
| 676 | 676 | } |
| 677 | - $host = 'ssl://' . $host; |
|
| 677 | + $host = 'ssl://'.$host; |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | // magic quotes may fuck up file uploads and chunked response processing |
@@ -692,18 +692,18 @@ discard block |
||
| 692 | 692 | $keepAlive = (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http && empty($this->_requestHeaders['connection'])) || |
| 693 | 693 | (!empty($this->_requestHeaders['connection']) && 'Keep-Alive' == $this->_requestHeaders['connection']); |
| 694 | 694 | $sockets = &PEAR::getStaticProperty('HTTP_Request', 'sockets'); |
| 695 | - $sockKey = $host . ':' . $port; |
|
| 695 | + $sockKey = $host.':'.$port; |
|
| 696 | 696 | unset($this->_sock); |
| 697 | 697 | |
| 698 | 698 | // There is a connected socket in the "static" property? |
| 699 | 699 | if ($keepAlive && !empty($sockets[$sockKey]) && |
| 700 | 700 | !empty($sockets[$sockKey]->fp)) |
| 701 | 701 | { |
| 702 | - $this->_sock =& $sockets[$sockKey]; |
|
| 702 | + $this->_sock = & $sockets[$sockKey]; |
|
| 703 | 703 | $err = null; |
| 704 | 704 | } else { |
| 705 | 705 | $this->_notify('connect'); |
| 706 | - $this->_sock =& new Net_Socket(); |
|
| 706 | + $this->_sock = & new Net_Socket(); |
|
| 707 | 707 | $err = $this->_sock->connect($host, $port, null, $this->_timeout, $this->_socketOptions); |
| 708 | 708 | } |
| 709 | 709 | PEAR::isError($err) or $err = $this->_sock->write($this->_buildRequest()); |
@@ -746,11 +746,11 @@ discard block |
||
| 746 | 746 | $this->disconnect(); |
| 747 | 747 | // Store the connected socket in "static" property |
| 748 | 748 | } elseif (empty($sockets[$sockKey]) || empty($sockets[$sockKey]->fp)) { |
| 749 | - $sockets[$sockKey] =& $this->_sock; |
|
| 749 | + $sockets[$sockKey] = & $this->_sock; |
|
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | // Check for redirection |
| 753 | - if ( $this->_allowRedirects |
|
| 753 | + if ($this->_allowRedirects |
|
| 754 | 754 | AND $this->_redirects <= $this->_maxRedirects |
| 755 | 755 | AND $this->getResponseCode() > 300 |
| 756 | 756 | AND $this->getResponseCode() < 399 |
@@ -770,9 +770,9 @@ discard block |
||
| 770 | 770 | // Relative path |
| 771 | 771 | } elseif (substr($redirect, 0, 3) == '../' OR substr($redirect, 0, 2) == './') { |
| 772 | 772 | if (substr($this->_url->path, -1) == '/') { |
| 773 | - $redirect = $this->_url->path . $redirect; |
|
| 773 | + $redirect = $this->_url->path.$redirect; |
|
| 774 | 774 | } else { |
| 775 | - $redirect = dirname($this->_url->path) . '/' . $redirect; |
|
| 775 | + $redirect = dirname($this->_url->path).'/'.$redirect; |
|
| 776 | 776 | } |
| 777 | 777 | $redirect = Net_URL::resolvePath($redirect); |
| 778 | 778 | $this->_url->path = $redirect; |
@@ -780,9 +780,9 @@ discard block |
||
| 780 | 780 | // Filename, no path |
| 781 | 781 | } else { |
| 782 | 782 | if (substr($this->_url->path, -1) == '/') { |
| 783 | - $redirect = $this->_url->path . $redirect; |
|
| 783 | + $redirect = $this->_url->path.$redirect; |
|
| 784 | 784 | } else { |
| 785 | - $redirect = dirname($this->_url->path) . '/' . $redirect; |
|
| 785 | + $redirect = dirname($this->_url->path).'/'.$redirect; |
|
| 786 | 786 | } |
| 787 | 787 | $this->_url->path = $redirect; |
| 788 | 788 | } |
@@ -833,7 +833,7 @@ discard block |
||
| 833 | 833 | function getResponseHeader($headername = null) |
| 834 | 834 | { |
| 835 | 835 | if (!isset($headername)) { |
| 836 | - return isset($this->_response->_headers)? $this->_response->_headers: array(); |
|
| 836 | + return isset($this->_response->_headers) ? $this->_response->_headers : array(); |
|
| 837 | 837 | } else { |
| 838 | 838 | $headername = strtolower($headername); |
| 839 | 839 | return isset($this->_response->_headers[$headername]) ? $this->_response->_headers[$headername] : false; |
@@ -872,15 +872,15 @@ discard block |
||
| 872 | 872 | { |
| 873 | 873 | $separator = ini_get('arg_separator.output'); |
| 874 | 874 | ini_set('arg_separator.output', '&'); |
| 875 | - $querystring = ($querystring = $this->_url->getQueryString()) ? '?' . $querystring : ''; |
|
| 875 | + $querystring = ($querystring = $this->_url->getQueryString()) ? '?'.$querystring : ''; |
|
| 876 | 876 | ini_set('arg_separator.output', $separator); |
| 877 | 877 | |
| 878 | - $host = isset($this->_proxy_host) ? $this->_url->protocol . '://' . $this->_url->host : ''; |
|
| 879 | - $port = (isset($this->_proxy_host) AND $this->_url->port != 80) ? ':' . $this->_url->port : ''; |
|
| 880 | - $path = $this->_url->path . $querystring; |
|
| 881 | - $url = $host . $port . $path; |
|
| 878 | + $host = isset($this->_proxy_host) ? $this->_url->protocol.'://'.$this->_url->host : ''; |
|
| 879 | + $port = (isset($this->_proxy_host) AND $this->_url->port != 80) ? ':'.$this->_url->port : ''; |
|
| 880 | + $path = $this->_url->path.$querystring; |
|
| 881 | + $url = $host.$port.$path; |
|
| 882 | 882 | |
| 883 | - $request = $this->_method . ' ' . $url . ' HTTP/' . $this->_http . "\r\n"; |
|
| 883 | + $request = $this->_method.' '.$url.' HTTP/'.$this->_http."\r\n"; |
|
| 884 | 884 | |
| 885 | 885 | if (in_array($this->_method, $this->_bodyDisallowed) || |
| 886 | 886 | (empty($this->_body) && (HTTP_REQUEST_METHOD_POST != $this->_method || |
@@ -892,8 +892,8 @@ discard block |
||
| 892 | 892 | // Add default content-type |
| 893 | 893 | $this->addHeader('Content-Type', 'application/x-www-form-urlencoded'); |
| 894 | 894 | } elseif ('multipart/form-data' == $this->_requestHeaders['content-type']) { |
| 895 | - $boundary = 'HTTP_Request_' . md5(uniqid('request') . microtime()); |
|
| 896 | - $this->addHeader('Content-Type', 'multipart/form-data; boundary=' . $boundary); |
|
| 895 | + $boundary = 'HTTP_Request_'.md5(uniqid('request').microtime()); |
|
| 896 | + $this->addHeader('Content-Type', 'multipart/form-data; boundary='.$boundary); |
|
| 897 | 897 | } |
| 898 | 898 | } |
| 899 | 899 | |
@@ -901,7 +901,7 @@ discard block |
||
| 901 | 901 | if (!empty($this->_requestHeaders)) { |
| 902 | 902 | foreach ($this->_requestHeaders as $name => $value) { |
| 903 | 903 | $canonicalName = implode('-', array_map('ucfirst', explode('-', $name))); |
| 904 | - $request .= $canonicalName . ': ' . $value . "\r\n"; |
|
| 904 | + $request .= $canonicalName.': '.$value."\r\n"; |
|
| 905 | 905 | } |
| 906 | 906 | } |
| 907 | 907 | |
@@ -928,14 +928,14 @@ discard block |
||
| 928 | 928 | if (!empty($this->_postData)) { |
| 929 | 929 | $flatData = $this->_flattenArray('', $this->_postData); |
| 930 | 930 | foreach ($flatData as $item) { |
| 931 | - $postdata .= '--' . $boundary . "\r\n"; |
|
| 932 | - $postdata .= 'Content-Disposition: form-data; name="' . $item[0] . '"'; |
|
| 933 | - $postdata .= "\r\n\r\n" . urldecode($item[1]) . "\r\n"; |
|
| 931 | + $postdata .= '--'.$boundary."\r\n"; |
|
| 932 | + $postdata .= 'Content-Disposition: form-data; name="'.$item[0].'"'; |
|
| 933 | + $postdata .= "\r\n\r\n".urldecode($item[1])."\r\n"; |
|
| 934 | 934 | } |
| 935 | 935 | } |
| 936 | 936 | foreach ($this->_postFiles as $name => $value) { |
| 937 | 937 | if (is_array($value['name'])) { |
| 938 | - $varname = $name . ($this->_useBrackets? '[]': ''); |
|
| 938 | + $varname = $name.($this->_useBrackets ? '[]' : ''); |
|
| 939 | 939 | } else { |
| 940 | 940 | $varname = $name; |
| 941 | 941 | $value['name'] = array($value['name']); |
@@ -945,26 +945,26 @@ discard block |
||
| 945 | 945 | $data = fread($fp, filesize($filename)); |
| 946 | 946 | fclose($fp); |
| 947 | 947 | $basename = basename($filename); |
| 948 | - $type = is_array($value['type'])? @$value['type'][$key]: $value['type']; |
|
| 948 | + $type = is_array($value['type']) ? @$value['type'][$key] : $value['type']; |
|
| 949 | 949 | |
| 950 | - $postdata .= '--' . $boundary . "\r\n"; |
|
| 951 | - $postdata .= 'Content-Disposition: form-data; name="' . $varname . '"; filename="' . $basename . '"'; |
|
| 952 | - $postdata .= "\r\nContent-Type: " . $type; |
|
| 953 | - $postdata .= "\r\n\r\n" . $data . "\r\n"; |
|
| 950 | + $postdata .= '--'.$boundary."\r\n"; |
|
| 951 | + $postdata .= 'Content-Disposition: form-data; name="'.$varname.'"; filename="'.$basename.'"'; |
|
| 952 | + $postdata .= "\r\nContent-Type: ".$type; |
|
| 953 | + $postdata .= "\r\n\r\n".$data."\r\n"; |
|
| 954 | 954 | } |
| 955 | 955 | } |
| 956 | - $postdata .= '--' . $boundary . "--\r\n"; |
|
| 956 | + $postdata .= '--'.$boundary."--\r\n"; |
|
| 957 | 957 | } |
| 958 | - $request .= 'Content-Length: ' . |
|
| 959 | - (HTTP_REQUEST_MBSTRING? mb_strlen($postdata, 'iso-8859-1'): strlen($postdata)) . |
|
| 958 | + $request .= 'Content-Length: '. |
|
| 959 | + (HTTP_REQUEST_MBSTRING ? mb_strlen($postdata, 'iso-8859-1') : strlen($postdata)). |
|
| 960 | 960 | "\r\n\r\n"; |
| 961 | 961 | $request .= $postdata; |
| 962 | 962 | |
| 963 | 963 | // Explicitly set request body |
| 964 | 964 | } elseif (!empty($this->_body)) { |
| 965 | 965 | |
| 966 | - $request .= 'Content-Length: ' . |
|
| 967 | - (HTTP_REQUEST_MBSTRING? mb_strlen($this->_body, 'iso-8859-1'): strlen($this->_body)) . |
|
| 966 | + $request .= 'Content-Length: '. |
|
| 967 | + (HTTP_REQUEST_MBSTRING ? mb_strlen($this->_body, 'iso-8859-1') : strlen($this->_body)). |
|
| 968 | 968 | "\r\n\r\n"; |
| 969 | 969 | $request .= $this->_body; |
| 970 | 970 | } |
@@ -991,7 +991,7 @@ discard block |
||
| 991 | 991 | if (empty($name)) { |
| 992 | 992 | $newName = $k; |
| 993 | 993 | } elseif ($this->_useBrackets) { |
| 994 | - $newName = $name . '[' . $k . ']'; |
|
| 994 | + $newName = $name.'['.$k.']'; |
|
| 995 | 995 | } else { |
| 996 | 996 | $newName = $name; |
| 997 | 997 | } |
@@ -1026,7 +1026,7 @@ discard block |
||
| 1026 | 1026 | if (!is_a($listener, 'HTTP_Request_Listener')) { |
| 1027 | 1027 | return false; |
| 1028 | 1028 | } |
| 1029 | - $this->_listeners[$listener->getId()] =& $listener; |
|
| 1029 | + $this->_listeners[$listener->getId()] = & $listener; |
|
| 1030 | 1030 | return true; |
| 1031 | 1031 | } |
| 1032 | 1032 | |
@@ -1139,8 +1139,8 @@ discard block |
||
| 1139 | 1139 | */ |
| 1140 | 1140 | function HTTP_Response(&$sock, &$listeners) |
| 1141 | 1141 | { |
| 1142 | - $this->_sock =& $sock; |
|
| 1143 | - $this->_listeners =& $listeners; |
|
| 1142 | + $this->_sock = & $sock; |
|
| 1143 | + $this->_listeners = & $listeners; |
|
| 1144 | 1144 | } |
| 1145 | 1145 | |
| 1146 | 1146 | |
@@ -1166,7 +1166,7 @@ discard block |
||
| 1166 | 1166 | if (sscanf($line, 'HTTP/%s %s', $http_version, $returncode) != 2) { |
| 1167 | 1167 | return PEAR::raiseError('Malformed response.'); |
| 1168 | 1168 | } else { |
| 1169 | - $this->_protocol = 'HTTP/' . $http_version; |
|
| 1169 | + $this->_protocol = 'HTTP/'.$http_version; |
|
| 1170 | 1170 | $this->_code = intval($returncode); |
| 1171 | 1171 | } |
| 1172 | 1172 | while ('' !== ($header = $this->_sock->readLine())) { |
@@ -1204,7 +1204,7 @@ discard block |
||
| 1204 | 1204 | $data = $this->_sock->read(4096); |
| 1205 | 1205 | } else { |
| 1206 | 1206 | $data = $this->_sock->read(min(4096, $this->_toRead)); |
| 1207 | - $this->_toRead -= HTTP_REQUEST_MBSTRING? mb_strlen($data, 'iso-8859-1'): strlen($data); |
|
| 1207 | + $this->_toRead -= HTTP_REQUEST_MBSTRING ? mb_strlen($data, 'iso-8859-1') : strlen($data); |
|
| 1208 | 1208 | } |
| 1209 | 1209 | if ('' == $data) { |
| 1210 | 1210 | break; |
@@ -1213,7 +1213,7 @@ discard block |
||
| 1213 | 1213 | if ($saveBody || $gzipped) { |
| 1214 | 1214 | $this->_body .= $data; |
| 1215 | 1215 | } |
| 1216 | - $this->_notify($gzipped? 'gzTick': 'tick', $data); |
|
| 1216 | + $this->_notify($gzipped ? 'gzTick' : 'tick', $data); |
|
| 1217 | 1217 | } |
| 1218 | 1218 | } |
| 1219 | 1219 | } |
@@ -1252,7 +1252,7 @@ discard block |
||
| 1252 | 1252 | |
| 1253 | 1253 | if ('set-cookie' != $headername) { |
| 1254 | 1254 | if (isset($this->_headers[$headername])) { |
| 1255 | - $this->_headers[$headername] .= ',' . $headervalue; |
|
| 1255 | + $this->_headers[$headername] .= ','.$headervalue; |
|
| 1256 | 1256 | } else { |
| 1257 | 1257 | $this->_headers[$headername] = $headervalue; |
| 1258 | 1258 | } |
@@ -1336,7 +1336,7 @@ discard block |
||
| 1336 | 1336 | } |
| 1337 | 1337 | } |
| 1338 | 1338 | $data = $this->_sock->read($this->_chunkLength); |
| 1339 | - $this->_chunkLength -= HTTP_REQUEST_MBSTRING? mb_strlen($data, 'iso-8859-1'): strlen($data); |
|
| 1339 | + $this->_chunkLength -= HTTP_REQUEST_MBSTRING ? mb_strlen($data, 'iso-8859-1') : strlen($data); |
|
| 1340 | 1340 | if (0 == $this->_chunkLength) { |
| 1341 | 1341 | $this->_sock->readLine(); // Trailing CRLF |
| 1342 | 1342 | } |
@@ -340,7 +340,7 @@ |
||
| 340 | 340 | * |
| 341 | 341 | * This method can also be called statically. |
| 342 | 342 | * |
| 343 | - * @param string $url URL path to resolve |
|
| 343 | + * @param string $path |
|
| 344 | 344 | * @return string The result |
| 345 | 345 | */ |
| 346 | 346 | function resolvePath($path) |
@@ -38,373 +38,373 @@ |
||
| 38 | 38 | |
| 39 | 39 | class Net_URL |
| 40 | 40 | { |
| 41 | - /** |
|
| 42 | - * Full url |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - var $url; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Protocol |
|
| 49 | - * @var string |
|
| 50 | - */ |
|
| 51 | - var $protocol; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Username |
|
| 55 | - * @var string |
|
| 56 | - */ |
|
| 57 | - var $username; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Password |
|
| 61 | - * @var string |
|
| 62 | - */ |
|
| 63 | - var $password; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Host |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 69 | - var $host; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Port |
|
| 73 | - * @var integer |
|
| 74 | - */ |
|
| 75 | - var $port; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Path |
|
| 79 | - * @var string |
|
| 80 | - */ |
|
| 81 | - var $path; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Query string |
|
| 85 | - * @var array |
|
| 86 | - */ |
|
| 87 | - var $querystring; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Anchor |
|
| 91 | - * @var string |
|
| 92 | - */ |
|
| 93 | - var $anchor; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Whether to use [] |
|
| 97 | - * @var bool |
|
| 98 | - */ |
|
| 99 | - var $useBrackets; |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * PHP4 Constructor |
|
| 103 | - * |
|
| 104 | - * @see __construct() |
|
| 105 | - */ |
|
| 106 | - function Net_URL($url = null, $useBrackets = true) |
|
| 107 | - { |
|
| 108 | - $this->__construct($url, $useBrackets); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * PHP5 Constructor |
|
| 113 | - * |
|
| 114 | - * Parses the given url and stores the various parts |
|
| 115 | - * Defaults are used in certain cases |
|
| 116 | - * |
|
| 117 | - * @param string $url Optional URL |
|
| 118 | - * @param bool $useBrackets Whether to use square brackets when |
|
| 119 | - * multiple querystrings with the same name |
|
| 120 | - * exist |
|
| 121 | - */ |
|
| 122 | - function __construct($url = null, $useBrackets = true) |
|
| 123 | - { |
|
| 124 | - $HTTP_SERVER_VARS = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; |
|
| 125 | - |
|
| 126 | - $this->useBrackets = $useBrackets; |
|
| 127 | - $this->url = $url; |
|
| 128 | - $this->user = ''; |
|
| 129 | - $this->pass = ''; |
|
| 130 | - $this->host = ''; |
|
| 131 | - $this->port = 80; |
|
| 132 | - $this->path = ''; |
|
| 133 | - $this->querystring = array(); |
|
| 134 | - $this->anchor = ''; |
|
| 135 | - |
|
| 136 | - // Only use defaults if not an absolute URL given |
|
| 137 | - if (!preg_match('/^[a-z0-9]+:\/\//i', $url)) { |
|
| 138 | - |
|
| 139 | - $this->protocol = (@$HTTP_SERVER_VARS['HTTPS'] == 'on' ? 'https' : 'http'); |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Figure out host/port |
|
| 143 | - */ |
|
| 144 | - if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) AND preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches)) { |
|
| 145 | - $host = $matches[1]; |
|
| 146 | - if (!empty($matches[3])) { |
|
| 147 | - $port = $matches[3]; |
|
| 148 | - } else { |
|
| 149 | - $port = $this->getStandardPort($this->protocol); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - $this->user = ''; |
|
| 154 | - $this->pass = ''; |
|
| 155 | - $this->host = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost'); |
|
| 156 | - $this->port = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : $this->getStandardPort($this->protocol)); |
|
| 157 | - $this->path = !empty($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : '/'; |
|
| 158 | - $this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null; |
|
| 159 | - $this->anchor = ''; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - // Parse the url and store the various parts |
|
| 163 | - if (!empty($url)) { |
|
| 164 | - $urlinfo = parse_url($url); |
|
| 165 | - |
|
| 166 | - // Default querystring |
|
| 167 | - $this->querystring = array(); |
|
| 168 | - |
|
| 169 | - foreach ($urlinfo as $key => $value) { |
|
| 170 | - switch ($key) { |
|
| 171 | - case 'scheme': |
|
| 172 | - $this->protocol = $value; |
|
| 173 | - $this->port = $this->getStandardPort($value); |
|
| 174 | - break; |
|
| 175 | - |
|
| 176 | - case 'user': |
|
| 177 | - case 'pass': |
|
| 178 | - case 'host': |
|
| 179 | - case 'port': |
|
| 180 | - $this->$key = $value; |
|
| 181 | - break; |
|
| 182 | - |
|
| 183 | - case 'path': |
|
| 184 | - if ($value{0} == '/') { |
|
| 185 | - $this->path = $value; |
|
| 186 | - } else { |
|
| 187 | - $path = dirname($this->path) == DIRECTORY_SEPARATOR ? '' : dirname($this->path); |
|
| 188 | - $this->path = sprintf('%s/%s', $path, $value); |
|
| 189 | - } |
|
| 190 | - break; |
|
| 191 | - |
|
| 192 | - case 'query': |
|
| 193 | - $this->querystring = $this->_parseRawQueryString($value); |
|
| 194 | - break; |
|
| 195 | - |
|
| 196 | - case 'fragment': |
|
| 197 | - $this->anchor = $value; |
|
| 198 | - break; |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Returns full url |
|
| 206 | - * |
|
| 207 | - * @return string Full url |
|
| 208 | - * @access public |
|
| 209 | - */ |
|
| 210 | - function getURL() |
|
| 211 | - { |
|
| 212 | - $querystring = $this->getQueryString(); |
|
| 213 | - |
|
| 214 | - $this->url = $this->protocol . '://' |
|
| 215 | - . $this->user . (!empty($this->pass) ? ':' : '') |
|
| 216 | - . $this->pass . (!empty($this->user) ? '@' : '') |
|
| 217 | - . $this->host . ($this->port == $this->getStandardPort($this->protocol) ? '' : ':' . $this->port) |
|
| 218 | - . $this->path |
|
| 219 | - . (!empty($querystring) ? '?' . $querystring : '') |
|
| 220 | - . (!empty($this->anchor) ? '#' . $this->anchor : ''); |
|
| 221 | - |
|
| 222 | - return $this->url; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * Adds a querystring item |
|
| 227 | - * |
|
| 228 | - * @param string $name Name of item |
|
| 229 | - * @param string $value Value of item |
|
| 230 | - * @param bool $preencoded Whether value is urlencoded or not, default = not |
|
| 231 | - * @access public |
|
| 232 | - */ |
|
| 233 | - function addQueryString($name, $value, $preencoded = false) |
|
| 234 | - { |
|
| 235 | - if ($preencoded) { |
|
| 236 | - $this->querystring[$name] = $value; |
|
| 237 | - } else { |
|
| 238 | - $this->querystring[$name] = is_array($value) ? array_map('rawurlencode', $value): rawurlencode($value); |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Removes a querystring item |
|
| 244 | - * |
|
| 245 | - * @param string $name Name of item |
|
| 246 | - * @access public |
|
| 247 | - */ |
|
| 248 | - function removeQueryString($name) |
|
| 249 | - { |
|
| 250 | - if (isset($this->querystring[$name])) { |
|
| 251 | - unset($this->querystring[$name]); |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * Sets the querystring to literally what you supply |
|
| 257 | - * |
|
| 258 | - * @param string $querystring The querystring data. Should be of the format foo=bar&x=y etc |
|
| 259 | - * @access public |
|
| 260 | - */ |
|
| 261 | - function addRawQueryString($querystring) |
|
| 262 | - { |
|
| 263 | - $this->querystring = $this->_parseRawQueryString($querystring); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * Returns flat querystring |
|
| 268 | - * |
|
| 269 | - * @return string Querystring |
|
| 270 | - * @access public |
|
| 271 | - */ |
|
| 272 | - function getQueryString() |
|
| 273 | - { |
|
| 274 | - if (!empty($this->querystring)) { |
|
| 275 | - foreach ($this->querystring as $name => $value) { |
|
| 276 | - if (is_array($value)) { |
|
| 277 | - foreach ($value as $k => $v) { |
|
| 278 | - $querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name . '=' . $v); |
|
| 279 | - } |
|
| 280 | - } elseif (!is_null($value)) { |
|
| 281 | - $querystring[] = $name . '=' . $value; |
|
| 282 | - } else { |
|
| 283 | - $querystring[] = $name; |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - $querystring = implode(ini_get('arg_separator.output'), $querystring); |
|
| 287 | - } else { |
|
| 288 | - $querystring = ''; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - return $querystring; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * Parses raw querystring and returns an array of it |
|
| 296 | - * |
|
| 297 | - * @param string $querystring The querystring to parse |
|
| 298 | - * @return array An array of the querystring data |
|
| 299 | - * @access private |
|
| 300 | - */ |
|
| 301 | - function _parseRawQuerystring($querystring) |
|
| 302 | - { |
|
| 303 | - $parts = preg_split('/[' . preg_quote(ini_get('arg_separator.input'), '/') . ']/', $querystring, -1, PREG_SPLIT_NO_EMPTY); |
|
| 304 | - $return = array(); |
|
| 305 | - |
|
| 306 | - foreach ($parts as $part) { |
|
| 307 | - if (strpos($part, '=') !== false) { |
|
| 308 | - $value = substr($part, strpos($part, '=') + 1); |
|
| 309 | - $key = substr($part, 0, strpos($part, '=')); |
|
| 310 | - } else { |
|
| 311 | - $value = null; |
|
| 312 | - $key = $part; |
|
| 313 | - } |
|
| 314 | - if (substr($key, -2) == '[]') { |
|
| 315 | - $key = substr($key, 0, -2); |
|
| 316 | - if (@!is_array($return[$key])) { |
|
| 317 | - $return[$key] = array(); |
|
| 318 | - $return[$key][] = $value; |
|
| 319 | - } else { |
|
| 320 | - $return[$key][] = $value; |
|
| 321 | - } |
|
| 322 | - } elseif (!$this->useBrackets AND !empty($return[$key])) { |
|
| 323 | - $return[$key] = (array)$return[$key]; |
|
| 324 | - $return[$key][] = $value; |
|
| 325 | - } else { |
|
| 326 | - $return[$key] = $value; |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - return $return; |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * Resolves //, ../ and ./ from a path and returns |
|
| 335 | - * the result. Eg: |
|
| 336 | - * |
|
| 337 | - * /foo/bar/../boo.php => /foo/boo.php |
|
| 338 | - * /foo/bar/../../boo.php => /boo.php |
|
| 339 | - * /foo/bar/.././/boo.php => /foo/boo.php |
|
| 340 | - * |
|
| 341 | - * This method can also be called statically. |
|
| 342 | - * |
|
| 343 | - * @param string $url URL path to resolve |
|
| 344 | - * @return string The result |
|
| 345 | - */ |
|
| 346 | - function resolvePath($path) |
|
| 347 | - { |
|
| 348 | - $path = explode('/', str_replace('//', '/', $path)); |
|
| 349 | - |
|
| 350 | - for ($i=0; $i<count($path); $i++) { |
|
| 351 | - if ($path[$i] == '.') { |
|
| 352 | - unset($path[$i]); |
|
| 353 | - $path = array_values($path); |
|
| 354 | - $i--; |
|
| 355 | - |
|
| 356 | - } elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != '') ) ) { |
|
| 357 | - unset($path[$i]); |
|
| 358 | - unset($path[$i-1]); |
|
| 359 | - $path = array_values($path); |
|
| 360 | - $i -= 2; |
|
| 361 | - |
|
| 362 | - } elseif ($path[$i] == '..' AND $i == 1 AND $path[0] == '') { |
|
| 363 | - unset($path[$i]); |
|
| 364 | - $path = array_values($path); |
|
| 365 | - $i--; |
|
| 366 | - |
|
| 367 | - } else { |
|
| 368 | - continue; |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - return implode('/', $path); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * Returns the standard port number for a protocol |
|
| 377 | - * |
|
| 378 | - * @param string $scheme The protocol to lookup |
|
| 379 | - * @return integer Port number or NULL if no scheme matches |
|
| 380 | - * |
|
| 381 | - * @author Philippe Jausions <[email protected]> |
|
| 382 | - */ |
|
| 383 | - function getStandardPort($scheme) |
|
| 384 | - { |
|
| 385 | - switch (strtolower($scheme)) { |
|
| 386 | - case 'http': return 80; |
|
| 387 | - case 'https': return 443; |
|
| 388 | - case 'ftp': return 21; |
|
| 389 | - case 'imap': return 143; |
|
| 390 | - case 'imaps': return 993; |
|
| 391 | - case 'pop3': return 110; |
|
| 392 | - case 'pop3s': return 995; |
|
| 393 | - default: return null; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Forces the URL to a particular protocol |
|
| 399 | - * |
|
| 400 | - * @param string $protocol Protocol to force the URL to |
|
| 401 | - * @param integer $port Optional port (standard port is used by default) |
|
| 402 | - */ |
|
| 403 | - function setProtocol($protocol, $port = null) |
|
| 404 | - { |
|
| 405 | - $this->protocol = $protocol; |
|
| 406 | - $this->port = is_null($port) ? $this->getStandardPort() : $port; |
|
| 407 | - } |
|
| 41 | + /** |
|
| 42 | + * Full url |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + var $url; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Protocol |
|
| 49 | + * @var string |
|
| 50 | + */ |
|
| 51 | + var $protocol; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Username |
|
| 55 | + * @var string |
|
| 56 | + */ |
|
| 57 | + var $username; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Password |
|
| 61 | + * @var string |
|
| 62 | + */ |
|
| 63 | + var $password; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Host |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | + var $host; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Port |
|
| 73 | + * @var integer |
|
| 74 | + */ |
|
| 75 | + var $port; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Path |
|
| 79 | + * @var string |
|
| 80 | + */ |
|
| 81 | + var $path; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Query string |
|
| 85 | + * @var array |
|
| 86 | + */ |
|
| 87 | + var $querystring; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Anchor |
|
| 91 | + * @var string |
|
| 92 | + */ |
|
| 93 | + var $anchor; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Whether to use [] |
|
| 97 | + * @var bool |
|
| 98 | + */ |
|
| 99 | + var $useBrackets; |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * PHP4 Constructor |
|
| 103 | + * |
|
| 104 | + * @see __construct() |
|
| 105 | + */ |
|
| 106 | + function Net_URL($url = null, $useBrackets = true) |
|
| 107 | + { |
|
| 108 | + $this->__construct($url, $useBrackets); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * PHP5 Constructor |
|
| 113 | + * |
|
| 114 | + * Parses the given url and stores the various parts |
|
| 115 | + * Defaults are used in certain cases |
|
| 116 | + * |
|
| 117 | + * @param string $url Optional URL |
|
| 118 | + * @param bool $useBrackets Whether to use square brackets when |
|
| 119 | + * multiple querystrings with the same name |
|
| 120 | + * exist |
|
| 121 | + */ |
|
| 122 | + function __construct($url = null, $useBrackets = true) |
|
| 123 | + { |
|
| 124 | + $HTTP_SERVER_VARS = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; |
|
| 125 | + |
|
| 126 | + $this->useBrackets = $useBrackets; |
|
| 127 | + $this->url = $url; |
|
| 128 | + $this->user = ''; |
|
| 129 | + $this->pass = ''; |
|
| 130 | + $this->host = ''; |
|
| 131 | + $this->port = 80; |
|
| 132 | + $this->path = ''; |
|
| 133 | + $this->querystring = array(); |
|
| 134 | + $this->anchor = ''; |
|
| 135 | + |
|
| 136 | + // Only use defaults if not an absolute URL given |
|
| 137 | + if (!preg_match('/^[a-z0-9]+:\/\//i', $url)) { |
|
| 138 | + |
|
| 139 | + $this->protocol = (@$HTTP_SERVER_VARS['HTTPS'] == 'on' ? 'https' : 'http'); |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Figure out host/port |
|
| 143 | + */ |
|
| 144 | + if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) AND preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches)) { |
|
| 145 | + $host = $matches[1]; |
|
| 146 | + if (!empty($matches[3])) { |
|
| 147 | + $port = $matches[3]; |
|
| 148 | + } else { |
|
| 149 | + $port = $this->getStandardPort($this->protocol); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + $this->user = ''; |
|
| 154 | + $this->pass = ''; |
|
| 155 | + $this->host = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost'); |
|
| 156 | + $this->port = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : $this->getStandardPort($this->protocol)); |
|
| 157 | + $this->path = !empty($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : '/'; |
|
| 158 | + $this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null; |
|
| 159 | + $this->anchor = ''; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + // Parse the url and store the various parts |
|
| 163 | + if (!empty($url)) { |
|
| 164 | + $urlinfo = parse_url($url); |
|
| 165 | + |
|
| 166 | + // Default querystring |
|
| 167 | + $this->querystring = array(); |
|
| 168 | + |
|
| 169 | + foreach ($urlinfo as $key => $value) { |
|
| 170 | + switch ($key) { |
|
| 171 | + case 'scheme': |
|
| 172 | + $this->protocol = $value; |
|
| 173 | + $this->port = $this->getStandardPort($value); |
|
| 174 | + break; |
|
| 175 | + |
|
| 176 | + case 'user': |
|
| 177 | + case 'pass': |
|
| 178 | + case 'host': |
|
| 179 | + case 'port': |
|
| 180 | + $this->$key = $value; |
|
| 181 | + break; |
|
| 182 | + |
|
| 183 | + case 'path': |
|
| 184 | + if ($value{0} == '/') { |
|
| 185 | + $this->path = $value; |
|
| 186 | + } else { |
|
| 187 | + $path = dirname($this->path) == DIRECTORY_SEPARATOR ? '' : dirname($this->path); |
|
| 188 | + $this->path = sprintf('%s/%s', $path, $value); |
|
| 189 | + } |
|
| 190 | + break; |
|
| 191 | + |
|
| 192 | + case 'query': |
|
| 193 | + $this->querystring = $this->_parseRawQueryString($value); |
|
| 194 | + break; |
|
| 195 | + |
|
| 196 | + case 'fragment': |
|
| 197 | + $this->anchor = $value; |
|
| 198 | + break; |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Returns full url |
|
| 206 | + * |
|
| 207 | + * @return string Full url |
|
| 208 | + * @access public |
|
| 209 | + */ |
|
| 210 | + function getURL() |
|
| 211 | + { |
|
| 212 | + $querystring = $this->getQueryString(); |
|
| 213 | + |
|
| 214 | + $this->url = $this->protocol . '://' |
|
| 215 | + . $this->user . (!empty($this->pass) ? ':' : '') |
|
| 216 | + . $this->pass . (!empty($this->user) ? '@' : '') |
|
| 217 | + . $this->host . ($this->port == $this->getStandardPort($this->protocol) ? '' : ':' . $this->port) |
|
| 218 | + . $this->path |
|
| 219 | + . (!empty($querystring) ? '?' . $querystring : '') |
|
| 220 | + . (!empty($this->anchor) ? '#' . $this->anchor : ''); |
|
| 221 | + |
|
| 222 | + return $this->url; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * Adds a querystring item |
|
| 227 | + * |
|
| 228 | + * @param string $name Name of item |
|
| 229 | + * @param string $value Value of item |
|
| 230 | + * @param bool $preencoded Whether value is urlencoded or not, default = not |
|
| 231 | + * @access public |
|
| 232 | + */ |
|
| 233 | + function addQueryString($name, $value, $preencoded = false) |
|
| 234 | + { |
|
| 235 | + if ($preencoded) { |
|
| 236 | + $this->querystring[$name] = $value; |
|
| 237 | + } else { |
|
| 238 | + $this->querystring[$name] = is_array($value) ? array_map('rawurlencode', $value): rawurlencode($value); |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Removes a querystring item |
|
| 244 | + * |
|
| 245 | + * @param string $name Name of item |
|
| 246 | + * @access public |
|
| 247 | + */ |
|
| 248 | + function removeQueryString($name) |
|
| 249 | + { |
|
| 250 | + if (isset($this->querystring[$name])) { |
|
| 251 | + unset($this->querystring[$name]); |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * Sets the querystring to literally what you supply |
|
| 257 | + * |
|
| 258 | + * @param string $querystring The querystring data. Should be of the format foo=bar&x=y etc |
|
| 259 | + * @access public |
|
| 260 | + */ |
|
| 261 | + function addRawQueryString($querystring) |
|
| 262 | + { |
|
| 263 | + $this->querystring = $this->_parseRawQueryString($querystring); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * Returns flat querystring |
|
| 268 | + * |
|
| 269 | + * @return string Querystring |
|
| 270 | + * @access public |
|
| 271 | + */ |
|
| 272 | + function getQueryString() |
|
| 273 | + { |
|
| 274 | + if (!empty($this->querystring)) { |
|
| 275 | + foreach ($this->querystring as $name => $value) { |
|
| 276 | + if (is_array($value)) { |
|
| 277 | + foreach ($value as $k => $v) { |
|
| 278 | + $querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name . '=' . $v); |
|
| 279 | + } |
|
| 280 | + } elseif (!is_null($value)) { |
|
| 281 | + $querystring[] = $name . '=' . $value; |
|
| 282 | + } else { |
|
| 283 | + $querystring[] = $name; |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + $querystring = implode(ini_get('arg_separator.output'), $querystring); |
|
| 287 | + } else { |
|
| 288 | + $querystring = ''; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + return $querystring; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * Parses raw querystring and returns an array of it |
|
| 296 | + * |
|
| 297 | + * @param string $querystring The querystring to parse |
|
| 298 | + * @return array An array of the querystring data |
|
| 299 | + * @access private |
|
| 300 | + */ |
|
| 301 | + function _parseRawQuerystring($querystring) |
|
| 302 | + { |
|
| 303 | + $parts = preg_split('/[' . preg_quote(ini_get('arg_separator.input'), '/') . ']/', $querystring, -1, PREG_SPLIT_NO_EMPTY); |
|
| 304 | + $return = array(); |
|
| 305 | + |
|
| 306 | + foreach ($parts as $part) { |
|
| 307 | + if (strpos($part, '=') !== false) { |
|
| 308 | + $value = substr($part, strpos($part, '=') + 1); |
|
| 309 | + $key = substr($part, 0, strpos($part, '=')); |
|
| 310 | + } else { |
|
| 311 | + $value = null; |
|
| 312 | + $key = $part; |
|
| 313 | + } |
|
| 314 | + if (substr($key, -2) == '[]') { |
|
| 315 | + $key = substr($key, 0, -2); |
|
| 316 | + if (@!is_array($return[$key])) { |
|
| 317 | + $return[$key] = array(); |
|
| 318 | + $return[$key][] = $value; |
|
| 319 | + } else { |
|
| 320 | + $return[$key][] = $value; |
|
| 321 | + } |
|
| 322 | + } elseif (!$this->useBrackets AND !empty($return[$key])) { |
|
| 323 | + $return[$key] = (array)$return[$key]; |
|
| 324 | + $return[$key][] = $value; |
|
| 325 | + } else { |
|
| 326 | + $return[$key] = $value; |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + return $return; |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * Resolves //, ../ and ./ from a path and returns |
|
| 335 | + * the result. Eg: |
|
| 336 | + * |
|
| 337 | + * /foo/bar/../boo.php => /foo/boo.php |
|
| 338 | + * /foo/bar/../../boo.php => /boo.php |
|
| 339 | + * /foo/bar/.././/boo.php => /foo/boo.php |
|
| 340 | + * |
|
| 341 | + * This method can also be called statically. |
|
| 342 | + * |
|
| 343 | + * @param string $url URL path to resolve |
|
| 344 | + * @return string The result |
|
| 345 | + */ |
|
| 346 | + function resolvePath($path) |
|
| 347 | + { |
|
| 348 | + $path = explode('/', str_replace('//', '/', $path)); |
|
| 349 | + |
|
| 350 | + for ($i=0; $i<count($path); $i++) { |
|
| 351 | + if ($path[$i] == '.') { |
|
| 352 | + unset($path[$i]); |
|
| 353 | + $path = array_values($path); |
|
| 354 | + $i--; |
|
| 355 | + |
|
| 356 | + } elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != '') ) ) { |
|
| 357 | + unset($path[$i]); |
|
| 358 | + unset($path[$i-1]); |
|
| 359 | + $path = array_values($path); |
|
| 360 | + $i -= 2; |
|
| 361 | + |
|
| 362 | + } elseif ($path[$i] == '..' AND $i == 1 AND $path[0] == '') { |
|
| 363 | + unset($path[$i]); |
|
| 364 | + $path = array_values($path); |
|
| 365 | + $i--; |
|
| 366 | + |
|
| 367 | + } else { |
|
| 368 | + continue; |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + return implode('/', $path); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * Returns the standard port number for a protocol |
|
| 377 | + * |
|
| 378 | + * @param string $scheme The protocol to lookup |
|
| 379 | + * @return integer Port number or NULL if no scheme matches |
|
| 380 | + * |
|
| 381 | + * @author Philippe Jausions <[email protected]> |
|
| 382 | + */ |
|
| 383 | + function getStandardPort($scheme) |
|
| 384 | + { |
|
| 385 | + switch (strtolower($scheme)) { |
|
| 386 | + case 'http': return 80; |
|
| 387 | + case 'https': return 443; |
|
| 388 | + case 'ftp': return 21; |
|
| 389 | + case 'imap': return 143; |
|
| 390 | + case 'imaps': return 993; |
|
| 391 | + case 'pop3': return 110; |
|
| 392 | + case 'pop3s': return 995; |
|
| 393 | + default: return null; |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Forces the URL to a particular protocol |
|
| 399 | + * |
|
| 400 | + * @param string $protocol Protocol to force the URL to |
|
| 401 | + * @param integer $port Optional port (standard port is used by default) |
|
| 402 | + */ |
|
| 403 | + function setProtocol($protocol, $port = null) |
|
| 404 | + { |
|
| 405 | + $this->protocol = $protocol; |
|
| 406 | + $this->port = is_null($port) ? $this->getStandardPort() : $port; |
|
| 407 | + } |
|
| 408 | 408 | |
| 409 | 409 | } |
| 410 | 410 | ?> |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | // Only use defaults if not an absolute URL given |
| 137 | 137 | if (!preg_match('/^[a-z0-9]+:\/\//i', $url)) { |
| 138 | 138 | |
| 139 | - $this->protocol = (@$HTTP_SERVER_VARS['HTTPS'] == 'on' ? 'https' : 'http'); |
|
| 139 | + $this->protocol = (@$HTTP_SERVER_VARS['HTTPS'] == 'on' ? 'https' : 'http'); |
|
| 140 | 140 | |
| 141 | 141 | /** |
| 142 | 142 | * Figure out host/port |
@@ -211,13 +211,13 @@ discard block |
||
| 211 | 211 | { |
| 212 | 212 | $querystring = $this->getQueryString(); |
| 213 | 213 | |
| 214 | - $this->url = $this->protocol . '://' |
|
| 215 | - . $this->user . (!empty($this->pass) ? ':' : '') |
|
| 216 | - . $this->pass . (!empty($this->user) ? '@' : '') |
|
| 217 | - . $this->host . ($this->port == $this->getStandardPort($this->protocol) ? '' : ':' . $this->port) |
|
| 214 | + $this->url = $this->protocol.'://' |
|
| 215 | + . $this->user.(!empty($this->pass) ? ':' : '') |
|
| 216 | + . $this->pass.(!empty($this->user) ? '@' : '') |
|
| 217 | + . $this->host.($this->port == $this->getStandardPort($this->protocol) ? '' : ':'.$this->port) |
|
| 218 | 218 | . $this->path |
| 219 | - . (!empty($querystring) ? '?' . $querystring : '') |
|
| 220 | - . (!empty($this->anchor) ? '#' . $this->anchor : ''); |
|
| 219 | + . (!empty($querystring) ? '?'.$querystring : '') |
|
| 220 | + . (!empty($this->anchor) ? '#'.$this->anchor : ''); |
|
| 221 | 221 | |
| 222 | 222 | return $this->url; |
| 223 | 223 | } |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | if ($preencoded) { |
| 236 | 236 | $this->querystring[$name] = $value; |
| 237 | 237 | } else { |
| 238 | - $this->querystring[$name] = is_array($value) ? array_map('rawurlencode', $value): rawurlencode($value); |
|
| 238 | + $this->querystring[$name] = is_array($value) ? array_map('rawurlencode', $value) : rawurlencode($value); |
|
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | 241 | |
@@ -275,10 +275,10 @@ discard block |
||
| 275 | 275 | foreach ($this->querystring as $name => $value) { |
| 276 | 276 | if (is_array($value)) { |
| 277 | 277 | foreach ($value as $k => $v) { |
| 278 | - $querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name . '=' . $v); |
|
| 278 | + $querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name.'='.$v); |
|
| 279 | 279 | } |
| 280 | 280 | } elseif (!is_null($value)) { |
| 281 | - $querystring[] = $name . '=' . $value; |
|
| 281 | + $querystring[] = $name.'='.$value; |
|
| 282 | 282 | } else { |
| 283 | 283 | $querystring[] = $name; |
| 284 | 284 | } |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | */ |
| 301 | 301 | function _parseRawQuerystring($querystring) |
| 302 | 302 | { |
| 303 | - $parts = preg_split('/[' . preg_quote(ini_get('arg_separator.input'), '/') . ']/', $querystring, -1, PREG_SPLIT_NO_EMPTY); |
|
| 303 | + $parts = preg_split('/['.preg_quote(ini_get('arg_separator.input'), '/').']/', $querystring, -1, PREG_SPLIT_NO_EMPTY); |
|
| 304 | 304 | $return = array(); |
| 305 | 305 | |
| 306 | 306 | foreach ($parts as $part) { |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | $return[$key][] = $value; |
| 321 | 321 | } |
| 322 | 322 | } elseif (!$this->useBrackets AND !empty($return[$key])) { |
| 323 | - $return[$key] = (array)$return[$key]; |
|
| 323 | + $return[$key] = (array) $return[$key]; |
|
| 324 | 324 | $return[$key][] = $value; |
| 325 | 325 | } else { |
| 326 | 326 | $return[$key] = $value; |
@@ -347,15 +347,15 @@ discard block |
||
| 347 | 347 | { |
| 348 | 348 | $path = explode('/', str_replace('//', '/', $path)); |
| 349 | 349 | |
| 350 | - for ($i=0; $i<count($path); $i++) { |
|
| 350 | + for ($i = 0; $i < count($path); $i++) { |
|
| 351 | 351 | if ($path[$i] == '.') { |
| 352 | 352 | unset($path[$i]); |
| 353 | 353 | $path = array_values($path); |
| 354 | 354 | $i--; |
| 355 | 355 | |
| 356 | - } elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != '') ) ) { |
|
| 356 | + } elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != ''))) { |
|
| 357 | 357 | unset($path[$i]); |
| 358 | - unset($path[$i-1]); |
|
| 358 | + unset($path[$i - 1]); |
|
| 359 | 359 | $path = array_values($path); |
| 360 | 360 | $i -= 2; |
| 361 | 361 | |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | * Adds a "To" address. |
| 320 | 320 | * @param string $address |
| 321 | 321 | * @param string $name |
| 322 | - * @return void |
|
| 322 | + * @return boolean |
|
| 323 | 323 | */ |
| 324 | 324 | function AddAddress($address, $name = '') { |
| 325 | 325 | $cur = count($this->to); |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | * mailer. |
| 334 | 334 | * @param string $address |
| 335 | 335 | * @param string $name |
| 336 | - * @return void |
|
| 336 | + * @return boolean |
|
| 337 | 337 | */ |
| 338 | 338 | function AddCC($address, $name = '') { |
| 339 | 339 | $cur = count($this->cc); |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | * mailer. |
| 348 | 348 | * @param string $address |
| 349 | 349 | * @param string $name |
| 350 | - * @return void |
|
| 350 | + * @return boolean |
|
| 351 | 351 | */ |
| 352 | 352 | function AddBCC($address, $name = '') { |
| 353 | 353 | $cur = count($this->bcc); |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | * Adds a "Reply-To" address. |
| 360 | 360 | * @param string $address |
| 361 | 361 | * @param string $name |
| 362 | - * @return void |
|
| 362 | + * @return boolean |
|
| 363 | 363 | */ |
| 364 | 364 | function AddReplyTo($address, $name = '') { |
| 365 | 365 | $cur = count($this->ReplyTo); |
@@ -426,6 +426,8 @@ discard block |
||
| 426 | 426 | /** |
| 427 | 427 | * Sends mail using the $Sendmail program. |
| 428 | 428 | * @access private |
| 429 | + * @param string $header |
|
| 430 | + * @param string $body |
|
| 429 | 431 | * @return bool |
| 430 | 432 | */ |
| 431 | 433 | function SendmailSend($header, $body) { |
@@ -457,6 +459,8 @@ discard block |
||
| 457 | 459 | /** |
| 458 | 460 | * Sends mail using the PHP mail() function. |
| 459 | 461 | * @access private |
| 462 | + * @param string $header |
|
| 463 | + * @param string $body |
|
| 460 | 464 | * @return bool |
| 461 | 465 | */ |
| 462 | 466 | function MailSend($header, $body) { |
@@ -507,6 +511,8 @@ discard block |
||
| 507 | 511 | * Chris Ryan). Returns bool. Returns false if there is a |
| 508 | 512 | * bad MAIL FROM, RCPT, or DATA input. |
| 509 | 513 | * @access private |
| 514 | + * @param string $header |
|
| 515 | + * @param string $body |
|
| 510 | 516 | * @return bool |
| 511 | 517 | */ |
| 512 | 518 | function SmtpSend($header, $body) { |
@@ -677,6 +683,7 @@ discard block |
||
| 677 | 683 | /** |
| 678 | 684 | * Creates recipient headers. |
| 679 | 685 | * @access private |
| 686 | + * @param string $type |
|
| 680 | 687 | * @return string |
| 681 | 688 | */ |
| 682 | 689 | function AddrAppend($type, $addr) { |
@@ -712,6 +719,8 @@ discard block |
||
| 712 | 719 | * automatically perform wrapping and for quoted-printable. |
| 713 | 720 | * Original written by philippe. |
| 714 | 721 | * @access private |
| 722 | + * @param string $message |
|
| 723 | + * @param integer $length |
|
| 715 | 724 | * @return string |
| 716 | 725 | */ |
| 717 | 726 | function WrapText($message, $length, $qp_mode = false) { |
@@ -1040,6 +1049,9 @@ discard block |
||
| 1040 | 1049 | /** |
| 1041 | 1050 | * Returns the start of a message boundary. |
| 1042 | 1051 | * @access private |
| 1052 | + * @param string $charSet |
|
| 1053 | + * @param string $contentType |
|
| 1054 | + * @param string $encoding |
|
| 1043 | 1055 | */ |
| 1044 | 1056 | function GetBoundary($boundary, $charSet, $contentType, $encoding) { |
| 1045 | 1057 | $result = ''; |
@@ -1094,6 +1106,10 @@ discard block |
||
| 1094 | 1106 | * @access private |
| 1095 | 1107 | * @return string |
| 1096 | 1108 | */ |
| 1109 | + |
|
| 1110 | + /** |
|
| 1111 | + * @param string $name |
|
| 1112 | + */ |
|
| 1097 | 1113 | function HeaderLine($name, $value) { |
| 1098 | 1114 | return $name . ': ' . $value . $this->LE; |
| 1099 | 1115 | } |
@@ -1101,6 +1117,7 @@ discard block |
||
| 1101 | 1117 | /** |
| 1102 | 1118 | * Returns a formatted mail line. |
| 1103 | 1119 | * @access private |
| 1120 | + * @param string $value |
|
| 1104 | 1121 | * @return string |
| 1105 | 1122 | */ |
| 1106 | 1123 | function TextLine($value) { |
@@ -1259,6 +1276,7 @@ discard block |
||
| 1259 | 1276 | /** |
| 1260 | 1277 | * Encode a header string to best of Q, B, quoted or none. |
| 1261 | 1278 | * @access private |
| 1279 | + * @param string $str |
|
| 1262 | 1280 | * @return string |
| 1263 | 1281 | */ |
| 1264 | 1282 | function EncodeHeader ($str, $position = 'text') { |
@@ -1596,6 +1614,7 @@ discard block |
||
| 1596 | 1614 | * Adds the error message to the error container. |
| 1597 | 1615 | * Returns void. |
| 1598 | 1616 | * @access private |
| 1617 | + * @param string $msg |
|
| 1599 | 1618 | * @return void |
| 1600 | 1619 | */ |
| 1601 | 1620 | function SetError($msg) { |
@@ -1623,6 +1642,7 @@ discard block |
||
| 1623 | 1642 | * PHP 4.1.0+ as well as older versions. Returns an empty string |
| 1624 | 1643 | * if nothing is found. |
| 1625 | 1644 | * @access private |
| 1645 | + * @param string $varName |
|
| 1626 | 1646 | * @return mixed |
| 1627 | 1647 | */ |
| 1628 | 1648 | function ServerVar($varName) { |
@@ -1663,6 +1683,7 @@ discard block |
||
| 1663 | 1683 | /** |
| 1664 | 1684 | * Returns a message in the appropriate language. |
| 1665 | 1685 | * @access private |
| 1686 | + * @param string $key |
|
| 1666 | 1687 | * @return string |
| 1667 | 1688 | */ |
| 1668 | 1689 | function Lang($key) { |
@@ -1708,6 +1729,7 @@ discard block |
||
| 1708 | 1729 | /** |
| 1709 | 1730 | * Evaluates the message and returns modifications for inline images and backgrounds |
| 1710 | 1731 | * @access public |
| 1732 | + * @param string $message |
|
| 1711 | 1733 | * @return $message |
| 1712 | 1734 | */ |
| 1713 | 1735 | function MsgHTML($message,$basedir='') { |
@@ -1745,7 +1767,7 @@ discard block |
||
| 1745 | 1767 | /** |
| 1746 | 1768 | * Gets the mime type of the embedded or inline image |
| 1747 | 1769 | * @access private |
| 1748 | - * @return mime type of ext |
|
| 1770 | + * @return string type of ext |
|
| 1749 | 1771 | */ |
| 1750 | 1772 | function _mime_types($ext = '') { |
| 1751 | 1773 | $mimes = array( |
@@ -271,11 +271,11 @@ discard block |
||
| 271 | 271 | * @return void |
| 272 | 272 | */ |
| 273 | 273 | function IsHTML($bool) { |
| 274 | - if($bool == true) { |
|
| 275 | - $this->ContentType = 'text/html'; |
|
| 276 | - } else { |
|
| 277 | - $this->ContentType = 'text/plain'; |
|
| 278 | - } |
|
| 274 | + if($bool == true) { |
|
| 275 | + $this->ContentType = 'text/html'; |
|
| 276 | + } else { |
|
| 277 | + $this->ContentType = 'text/plain'; |
|
| 278 | + } |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | * @return void |
| 284 | 284 | */ |
| 285 | 285 | function IsSMTP() { |
| 286 | - $this->Mailer = 'smtp'; |
|
| 286 | + $this->Mailer = 'smtp'; |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | /** |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | * @return void |
| 292 | 292 | */ |
| 293 | 293 | function IsMail() { |
| 294 | - $this->Mailer = 'mail'; |
|
| 294 | + $this->Mailer = 'mail'; |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | /** |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @return void |
| 300 | 300 | */ |
| 301 | 301 | function IsSendmail() { |
| 302 | - $this->Mailer = 'sendmail'; |
|
| 302 | + $this->Mailer = 'sendmail'; |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -307,8 +307,8 @@ discard block |
||
| 307 | 307 | * @return void |
| 308 | 308 | */ |
| 309 | 309 | function IsQmail() { |
| 310 | - $this->Sendmail = '/var/qmail/bin/sendmail'; |
|
| 311 | - $this->Mailer = 'sendmail'; |
|
| 310 | + $this->Sendmail = '/var/qmail/bin/sendmail'; |
|
| 311 | + $this->Mailer = 'sendmail'; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | ///////////////////////////////////////////////// |
@@ -322,9 +322,9 @@ discard block |
||
| 322 | 322 | * @return void |
| 323 | 323 | */ |
| 324 | 324 | function AddAddress($address, $name = '') { |
| 325 | - $cur = count($this->to); |
|
| 326 | - $this->to[$cur][0] = trim($address); |
|
| 327 | - $this->to[$cur][1] = $name; |
|
| 325 | + $cur = count($this->to); |
|
| 326 | + $this->to[$cur][0] = trim($address); |
|
| 327 | + $this->to[$cur][1] = $name; |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -336,9 +336,9 @@ discard block |
||
| 336 | 336 | * @return void |
| 337 | 337 | */ |
| 338 | 338 | function AddCC($address, $name = '') { |
| 339 | - $cur = count($this->cc); |
|
| 340 | - $this->cc[$cur][0] = trim($address); |
|
| 341 | - $this->cc[$cur][1] = $name; |
|
| 339 | + $cur = count($this->cc); |
|
| 340 | + $this->cc[$cur][0] = trim($address); |
|
| 341 | + $this->cc[$cur][1] = $name; |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | /** |
@@ -350,9 +350,9 @@ discard block |
||
| 350 | 350 | * @return void |
| 351 | 351 | */ |
| 352 | 352 | function AddBCC($address, $name = '') { |
| 353 | - $cur = count($this->bcc); |
|
| 354 | - $this->bcc[$cur][0] = trim($address); |
|
| 355 | - $this->bcc[$cur][1] = $name; |
|
| 353 | + $cur = count($this->bcc); |
|
| 354 | + $this->bcc[$cur][0] = trim($address); |
|
| 355 | + $this->bcc[$cur][1] = $name; |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | /** |
@@ -362,9 +362,9 @@ discard block |
||
| 362 | 362 | * @return void |
| 363 | 363 | */ |
| 364 | 364 | function AddReplyTo($address, $name = '') { |
| 365 | - $cur = count($this->ReplyTo); |
|
| 366 | - $this->ReplyTo[$cur][0] = trim($address); |
|
| 367 | - $this->ReplyTo[$cur][1] = $name; |
|
| 365 | + $cur = count($this->ReplyTo); |
|
| 366 | + $this->ReplyTo[$cur][0] = trim($address); |
|
| 367 | + $this->ReplyTo[$cur][1] = $name; |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | ///////////////////////////////////////////////// |
@@ -378,49 +378,49 @@ discard block |
||
| 378 | 378 | * @return bool |
| 379 | 379 | */ |
| 380 | 380 | function Send() { |
| 381 | - $header = ''; |
|
| 382 | - $body = ''; |
|
| 383 | - $result = true; |
|
| 384 | - |
|
| 385 | - if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { |
|
| 386 | - $this->SetError($this->Lang('provide_address')); |
|
| 387 | - return false; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /* Set whether the message is multipart/alternative */ |
|
| 391 | - if(!empty($this->AltBody)) { |
|
| 392 | - $this->ContentType = 'multipart/alternative'; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - $this->error_count = 0; // reset errors |
|
| 396 | - $this->SetMessageType(); |
|
| 397 | - $header .= $this->CreateHeader(); |
|
| 398 | - $body = $this->CreateBody(); |
|
| 399 | - |
|
| 400 | - if($body == '') { |
|
| 401 | - return false; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /* Choose the mailer */ |
|
| 405 | - switch($this->Mailer) { |
|
| 406 | - case 'sendmail': |
|
| 407 | - $result = $this->SendmailSend($header, $body); |
|
| 408 | - break; |
|
| 409 | - case 'smtp': |
|
| 410 | - $result = $this->SmtpSend($header, $body); |
|
| 411 | - break; |
|
| 412 | - case 'mail': |
|
| 413 | - $result = $this->MailSend($header, $body); |
|
| 414 | - break; |
|
| 415 | - default: |
|
| 416 | - $result = $this->MailSend($header, $body); |
|
| 417 | - break; |
|
| 418 | - //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported')); |
|
| 419 | - //$result = false; |
|
| 420 | - //break; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - return $result; |
|
| 381 | + $header = ''; |
|
| 382 | + $body = ''; |
|
| 383 | + $result = true; |
|
| 384 | + |
|
| 385 | + if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { |
|
| 386 | + $this->SetError($this->Lang('provide_address')); |
|
| 387 | + return false; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /* Set whether the message is multipart/alternative */ |
|
| 391 | + if(!empty($this->AltBody)) { |
|
| 392 | + $this->ContentType = 'multipart/alternative'; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + $this->error_count = 0; // reset errors |
|
| 396 | + $this->SetMessageType(); |
|
| 397 | + $header .= $this->CreateHeader(); |
|
| 398 | + $body = $this->CreateBody(); |
|
| 399 | + |
|
| 400 | + if($body == '') { |
|
| 401 | + return false; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /* Choose the mailer */ |
|
| 405 | + switch($this->Mailer) { |
|
| 406 | + case 'sendmail': |
|
| 407 | + $result = $this->SendmailSend($header, $body); |
|
| 408 | + break; |
|
| 409 | + case 'smtp': |
|
| 410 | + $result = $this->SmtpSend($header, $body); |
|
| 411 | + break; |
|
| 412 | + case 'mail': |
|
| 413 | + $result = $this->MailSend($header, $body); |
|
| 414 | + break; |
|
| 415 | + default: |
|
| 416 | + $result = $this->MailSend($header, $body); |
|
| 417 | + break; |
|
| 418 | + //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported')); |
|
| 419 | + //$result = false; |
|
| 420 | + //break; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + return $result; |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | /** |
@@ -429,29 +429,29 @@ discard block |
||
| 429 | 429 | * @return bool |
| 430 | 430 | */ |
| 431 | 431 | function SendmailSend($header, $body) { |
| 432 | - if ($this->Sender != '') { |
|
| 433 | - $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender)); |
|
| 434 | - } else { |
|
| 435 | - $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail)); |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - if(!@$mail = popen($sendmail, 'w')) { |
|
| 439 | - $this->SetError($this->Lang('execute') . $this->Sendmail); |
|
| 440 | - return false; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - fputs($mail, $header); |
|
| 444 | - fputs($mail, $body); |
|
| 445 | - |
|
| 446 | - $result = pclose($mail); |
|
| 447 | - if (version_compare(phpversion(), '4.2.3') == -1) { |
|
| 448 | - $result = $result >> 8 & 0xFF; |
|
| 449 | - } |
|
| 450 | - if($result != 0) { |
|
| 451 | - $this->SetError($this->Lang('execute') . $this->Sendmail); |
|
| 452 | - return false; |
|
| 453 | - } |
|
| 454 | - return true; |
|
| 432 | + if ($this->Sender != '') { |
|
| 433 | + $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender)); |
|
| 434 | + } else { |
|
| 435 | + $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail)); |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + if(!@$mail = popen($sendmail, 'w')) { |
|
| 439 | + $this->SetError($this->Lang('execute') . $this->Sendmail); |
|
| 440 | + return false; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + fputs($mail, $header); |
|
| 444 | + fputs($mail, $body); |
|
| 445 | + |
|
| 446 | + $result = pclose($mail); |
|
| 447 | + if (version_compare(phpversion(), '4.2.3') == -1) { |
|
| 448 | + $result = $result >> 8 & 0xFF; |
|
| 449 | + } |
|
| 450 | + if($result != 0) { |
|
| 451 | + $this->SetError($this->Lang('execute') . $this->Sendmail); |
|
| 452 | + return false; |
|
| 453 | + } |
|
| 454 | + return true; |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | /** |
@@ -461,45 +461,45 @@ discard block |
||
| 461 | 461 | */ |
| 462 | 462 | function MailSend($header, $body) { |
| 463 | 463 | |
| 464 | - $to = ''; |
|
| 465 | - for($i = 0; $i < count($this->to); $i++) { |
|
| 466 | - if($i != 0) { $to .= ', '; } |
|
| 467 | - $to .= $this->AddrFormat($this->to[$i]); |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - $toArr = split(',', $to); |
|
| 471 | - |
|
| 472 | - $params = sprintf("-oi -f %s", $this->Sender); |
|
| 473 | - if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) { |
|
| 474 | - $old_from = ini_get('sendmail_from'); |
|
| 475 | - ini_set('sendmail_from', $this->Sender); |
|
| 476 | - if ($this->SingleTo === true && count($toArr) > 1) { |
|
| 477 | - foreach ($toArr as $key => $val) { |
|
| 478 | - $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|
| 479 | - } |
|
| 480 | - } else { |
|
| 481 | - $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|
| 482 | - } |
|
| 483 | - } else { |
|
| 484 | - if ($this->SingleTo === true && count($toArr) > 1) { |
|
| 485 | - foreach ($toArr as $key => $val) { |
|
| 486 | - $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|
| 487 | - } |
|
| 488 | - } else { |
|
| 489 | - $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header); |
|
| 490 | - } |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - if (isset($old_from)) { |
|
| 494 | - ini_set('sendmail_from', $old_from); |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - if(!$rt) { |
|
| 498 | - $this->SetError($this->Lang('instantiate')); |
|
| 499 | - return false; |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - return true; |
|
| 464 | + $to = ''; |
|
| 465 | + for($i = 0; $i < count($this->to); $i++) { |
|
| 466 | + if($i != 0) { $to .= ', '; } |
|
| 467 | + $to .= $this->AddrFormat($this->to[$i]); |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + $toArr = split(',', $to); |
|
| 471 | + |
|
| 472 | + $params = sprintf("-oi -f %s", $this->Sender); |
|
| 473 | + if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) { |
|
| 474 | + $old_from = ini_get('sendmail_from'); |
|
| 475 | + ini_set('sendmail_from', $this->Sender); |
|
| 476 | + if ($this->SingleTo === true && count($toArr) > 1) { |
|
| 477 | + foreach ($toArr as $key => $val) { |
|
| 478 | + $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|
| 479 | + } |
|
| 480 | + } else { |
|
| 481 | + $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|
| 482 | + } |
|
| 483 | + } else { |
|
| 484 | + if ($this->SingleTo === true && count($toArr) > 1) { |
|
| 485 | + foreach ($toArr as $key => $val) { |
|
| 486 | + $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|
| 487 | + } |
|
| 488 | + } else { |
|
| 489 | + $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header); |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + if (isset($old_from)) { |
|
| 494 | + ini_set('sendmail_from', $old_from); |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + if(!$rt) { |
|
| 498 | + $this->SetError($this->Lang('instantiate')); |
|
| 499 | + return false; |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + return true; |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | /** |
@@ -510,64 +510,64 @@ discard block |
||
| 510 | 510 | * @return bool |
| 511 | 511 | */ |
| 512 | 512 | function SmtpSend($header, $body) { |
| 513 | - include_once($this->PluginDir . 'class.smtp.php'); |
|
| 514 | - $error = ''; |
|
| 515 | - $bad_rcpt = array(); |
|
| 516 | - |
|
| 517 | - if(!$this->SmtpConnect()) { |
|
| 518 | - return false; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender; |
|
| 522 | - if(!$this->smtp->Mail($smtp_from)) { |
|
| 523 | - $error = $this->Lang('from_failed') . $smtp_from; |
|
| 524 | - $this->SetError($error); |
|
| 525 | - $this->smtp->Reset(); |
|
| 526 | - return false; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - /* Attempt to send attach all recipients */ |
|
| 530 | - for($i = 0; $i < count($this->to); $i++) { |
|
| 531 | - if(!$this->smtp->Recipient($this->to[$i][0])) { |
|
| 532 | - $bad_rcpt[] = $this->to[$i][0]; |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - for($i = 0; $i < count($this->cc); $i++) { |
|
| 536 | - if(!$this->smtp->Recipient($this->cc[$i][0])) { |
|
| 537 | - $bad_rcpt[] = $this->cc[$i][0]; |
|
| 538 | - } |
|
| 539 | - } |
|
| 540 | - for($i = 0; $i < count($this->bcc); $i++) { |
|
| 541 | - if(!$this->smtp->Recipient($this->bcc[$i][0])) { |
|
| 542 | - $bad_rcpt[] = $this->bcc[$i][0]; |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - if(count($bad_rcpt) > 0) { // Create error message |
|
| 547 | - for($i = 0; $i < count($bad_rcpt); $i++) { |
|
| 548 | - if($i != 0) { |
|
| 549 | - $error .= ', '; |
|
| 550 | - } |
|
| 551 | - $error .= $bad_rcpt[$i]; |
|
| 552 | - } |
|
| 553 | - $error = $this->Lang('recipients_failed') . $error; |
|
| 554 | - $this->SetError($error); |
|
| 555 | - $this->smtp->Reset(); |
|
| 556 | - return false; |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - if(!$this->smtp->Data($header . $body)) { |
|
| 560 | - $this->SetError($this->Lang('data_not_accepted')); |
|
| 561 | - $this->smtp->Reset(); |
|
| 562 | - return false; |
|
| 563 | - } |
|
| 564 | - if($this->SMTPKeepAlive == true) { |
|
| 565 | - $this->smtp->Reset(); |
|
| 566 | - } else { |
|
| 567 | - $this->SmtpClose(); |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - return true; |
|
| 513 | + include_once($this->PluginDir . 'class.smtp.php'); |
|
| 514 | + $error = ''; |
|
| 515 | + $bad_rcpt = array(); |
|
| 516 | + |
|
| 517 | + if(!$this->SmtpConnect()) { |
|
| 518 | + return false; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender; |
|
| 522 | + if(!$this->smtp->Mail($smtp_from)) { |
|
| 523 | + $error = $this->Lang('from_failed') . $smtp_from; |
|
| 524 | + $this->SetError($error); |
|
| 525 | + $this->smtp->Reset(); |
|
| 526 | + return false; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + /* Attempt to send attach all recipients */ |
|
| 530 | + for($i = 0; $i < count($this->to); $i++) { |
|
| 531 | + if(!$this->smtp->Recipient($this->to[$i][0])) { |
|
| 532 | + $bad_rcpt[] = $this->to[$i][0]; |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + for($i = 0; $i < count($this->cc); $i++) { |
|
| 536 | + if(!$this->smtp->Recipient($this->cc[$i][0])) { |
|
| 537 | + $bad_rcpt[] = $this->cc[$i][0]; |
|
| 538 | + } |
|
| 539 | + } |
|
| 540 | + for($i = 0; $i < count($this->bcc); $i++) { |
|
| 541 | + if(!$this->smtp->Recipient($this->bcc[$i][0])) { |
|
| 542 | + $bad_rcpt[] = $this->bcc[$i][0]; |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + if(count($bad_rcpt) > 0) { // Create error message |
|
| 547 | + for($i = 0; $i < count($bad_rcpt); $i++) { |
|
| 548 | + if($i != 0) { |
|
| 549 | + $error .= ', '; |
|
| 550 | + } |
|
| 551 | + $error .= $bad_rcpt[$i]; |
|
| 552 | + } |
|
| 553 | + $error = $this->Lang('recipients_failed') . $error; |
|
| 554 | + $this->SetError($error); |
|
| 555 | + $this->smtp->Reset(); |
|
| 556 | + return false; |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + if(!$this->smtp->Data($header . $body)) { |
|
| 560 | + $this->SetError($this->Lang('data_not_accepted')); |
|
| 561 | + $this->smtp->Reset(); |
|
| 562 | + return false; |
|
| 563 | + } |
|
| 564 | + if($this->SMTPKeepAlive == true) { |
|
| 565 | + $this->smtp->Reset(); |
|
| 566 | + } else { |
|
| 567 | + $this->SmtpClose(); |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + return true; |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | /** |
@@ -577,49 +577,49 @@ discard block |
||
| 577 | 577 | * @return bool |
| 578 | 578 | */ |
| 579 | 579 | function SmtpConnect() { |
| 580 | - if($this->smtp == NULL) { |
|
| 581 | - $this->smtp = new SMTP(); |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - $this->smtp->do_debug = $this->SMTPDebug; |
|
| 585 | - $hosts = explode(';', $this->Host); |
|
| 586 | - $index = 0; |
|
| 587 | - $connection = ($this->smtp->Connected()); |
|
| 588 | - |
|
| 589 | - /* Retry while there is no connection */ |
|
| 590 | - while($index < count($hosts) && $connection == false) { |
|
| 591 | - $hostinfo = array(); |
|
| 592 | - if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) { |
|
| 593 | - $host = $hostinfo[1]; |
|
| 594 | - $port = $hostinfo[2]; |
|
| 595 | - } else { |
|
| 596 | - $host = $hosts[$index]; |
|
| 597 | - $port = $this->Port; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) { |
|
| 601 | - if ($this->Helo != '') { |
|
| 602 | - $this->smtp->Hello($this->Helo); |
|
| 603 | - } else { |
|
| 604 | - $this->smtp->Hello($this->ServerHostname()); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - $connection = true; |
|
| 608 | - if($this->SMTPAuth) { |
|
| 609 | - if(!$this->smtp->Authenticate($this->Username, $this->Password)) { |
|
| 610 | - $this->SetError($this->Lang('authenticate')); |
|
| 611 | - $this->smtp->Reset(); |
|
| 612 | - $connection = false; |
|
| 613 | - } |
|
| 614 | - } |
|
| 615 | - } |
|
| 616 | - $index++; |
|
| 617 | - } |
|
| 618 | - if(!$connection) { |
|
| 619 | - $this->SetError($this->Lang('connect_host')); |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - return $connection; |
|
| 580 | + if($this->smtp == NULL) { |
|
| 581 | + $this->smtp = new SMTP(); |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + $this->smtp->do_debug = $this->SMTPDebug; |
|
| 585 | + $hosts = explode(';', $this->Host); |
|
| 586 | + $index = 0; |
|
| 587 | + $connection = ($this->smtp->Connected()); |
|
| 588 | + |
|
| 589 | + /* Retry while there is no connection */ |
|
| 590 | + while($index < count($hosts) && $connection == false) { |
|
| 591 | + $hostinfo = array(); |
|
| 592 | + if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) { |
|
| 593 | + $host = $hostinfo[1]; |
|
| 594 | + $port = $hostinfo[2]; |
|
| 595 | + } else { |
|
| 596 | + $host = $hosts[$index]; |
|
| 597 | + $port = $this->Port; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) { |
|
| 601 | + if ($this->Helo != '') { |
|
| 602 | + $this->smtp->Hello($this->Helo); |
|
| 603 | + } else { |
|
| 604 | + $this->smtp->Hello($this->ServerHostname()); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + $connection = true; |
|
| 608 | + if($this->SMTPAuth) { |
|
| 609 | + if(!$this->smtp->Authenticate($this->Username, $this->Password)) { |
|
| 610 | + $this->SetError($this->Lang('authenticate')); |
|
| 611 | + $this->smtp->Reset(); |
|
| 612 | + $connection = false; |
|
| 613 | + } |
|
| 614 | + } |
|
| 615 | + } |
|
| 616 | + $index++; |
|
| 617 | + } |
|
| 618 | + if(!$connection) { |
|
| 619 | + $this->SetError($this->Lang('connect_host')); |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + return $connection; |
|
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | /** |
@@ -627,12 +627,12 @@ discard block |
||
| 627 | 627 | * @return void |
| 628 | 628 | */ |
| 629 | 629 | function SmtpClose() { |
| 630 | - if($this->smtp != NULL) { |
|
| 631 | - if($this->smtp->Connected()) { |
|
| 632 | - $this->smtp->Quit(); |
|
| 633 | - $this->smtp->Close(); |
|
| 634 | - } |
|
| 635 | - } |
|
| 630 | + if($this->smtp != NULL) { |
|
| 631 | + if($this->smtp->Connected()) { |
|
| 632 | + $this->smtp->Quit(); |
|
| 633 | + $this->smtp->Close(); |
|
| 634 | + } |
|
| 635 | + } |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | /** |
@@ -645,29 +645,29 @@ discard block |
||
| 645 | 645 | * @return bool |
| 646 | 646 | */ |
| 647 | 647 | function SetLanguage($lang_type, $lang_path = 'language/') { |
| 648 | - if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) { |
|
| 649 | - include($lang_path.'phpmailer.lang-'.$lang_type.'.php'); |
|
| 650 | - } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) { |
|
| 651 | - include($lang_path.'phpmailer.lang-en.php'); |
|
| 652 | - } else { |
|
| 653 | - $PHPMAILER_LANG = array(); |
|
| 654 | - $PHPMAILER_LANG["provide_address"] = 'You must provide at least one ' . |
|
| 655 | - $PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.'; |
|
| 656 | - $PHPMAILER_LANG["execute"] = 'Could not execute: '; |
|
| 657 | - $PHPMAILER_LANG["instantiate"] = 'Could not instantiate mail function.'; |
|
| 658 | - $PHPMAILER_LANG["authenticate"] = 'SMTP Error: Could not authenticate.'; |
|
| 659 | - $PHPMAILER_LANG["from_failed"] = 'The following From address failed: '; |
|
| 660 | - $PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: The following ' . |
|
| 661 | - $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: Data not accepted.'; |
|
| 662 | - $PHPMAILER_LANG["connect_host"] = 'SMTP Error: Could not connect to SMTP host.'; |
|
| 663 | - $PHPMAILER_LANG["file_access"] = 'Could not access file: '; |
|
| 664 | - $PHPMAILER_LANG["file_open"] = 'File Error: Could not open file: '; |
|
| 665 | - $PHPMAILER_LANG["encoding"] = 'Unknown encoding: '; |
|
| 666 | - $PHPMAILER_LANG["signing"] = 'Signing Error: '; |
|
| 667 | - } |
|
| 668 | - $this->language = $PHPMAILER_LANG; |
|
| 669 | - |
|
| 670 | - return true; |
|
| 648 | + if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) { |
|
| 649 | + include($lang_path.'phpmailer.lang-'.$lang_type.'.php'); |
|
| 650 | + } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) { |
|
| 651 | + include($lang_path.'phpmailer.lang-en.php'); |
|
| 652 | + } else { |
|
| 653 | + $PHPMAILER_LANG = array(); |
|
| 654 | + $PHPMAILER_LANG["provide_address"] = 'You must provide at least one ' . |
|
| 655 | + $PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.'; |
|
| 656 | + $PHPMAILER_LANG["execute"] = 'Could not execute: '; |
|
| 657 | + $PHPMAILER_LANG["instantiate"] = 'Could not instantiate mail function.'; |
|
| 658 | + $PHPMAILER_LANG["authenticate"] = 'SMTP Error: Could not authenticate.'; |
|
| 659 | + $PHPMAILER_LANG["from_failed"] = 'The following From address failed: '; |
|
| 660 | + $PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: The following ' . |
|
| 661 | + $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: Data not accepted.'; |
|
| 662 | + $PHPMAILER_LANG["connect_host"] = 'SMTP Error: Could not connect to SMTP host.'; |
|
| 663 | + $PHPMAILER_LANG["file_access"] = 'Could not access file: '; |
|
| 664 | + $PHPMAILER_LANG["file_open"] = 'File Error: Could not open file: '; |
|
| 665 | + $PHPMAILER_LANG["encoding"] = 'Unknown encoding: '; |
|
| 666 | + $PHPMAILER_LANG["signing"] = 'Signing Error: '; |
|
| 667 | + } |
|
| 668 | + $this->language = $PHPMAILER_LANG; |
|
| 669 | + |
|
| 670 | + return true; |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | ///////////////////////////////////////////////// |
@@ -680,16 +680,16 @@ discard block |
||
| 680 | 680 | * @return string |
| 681 | 681 | */ |
| 682 | 682 | function AddrAppend($type, $addr) { |
| 683 | - $addr_str = $type . ': '; |
|
| 684 | - $addr_str .= $this->AddrFormat($addr[0]); |
|
| 685 | - if(count($addr) > 1) { |
|
| 686 | - for($i = 1; $i < count($addr); $i++) { |
|
| 687 | - $addr_str .= ', ' . $this->AddrFormat($addr[$i]); |
|
| 688 | - } |
|
| 689 | - } |
|
| 690 | - $addr_str .= $this->LE; |
|
| 691 | - |
|
| 692 | - return $addr_str; |
|
| 683 | + $addr_str = $type . ': '; |
|
| 684 | + $addr_str .= $this->AddrFormat($addr[0]); |
|
| 685 | + if(count($addr) > 1) { |
|
| 686 | + for($i = 1; $i < count($addr); $i++) { |
|
| 687 | + $addr_str .= ', ' . $this->AddrFormat($addr[$i]); |
|
| 688 | + } |
|
| 689 | + } |
|
| 690 | + $addr_str .= $this->LE; |
|
| 691 | + |
|
| 692 | + return $addr_str; |
|
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | /** |
@@ -698,13 +698,13 @@ discard block |
||
| 698 | 698 | * @return string |
| 699 | 699 | */ |
| 700 | 700 | function AddrFormat($addr) { |
| 701 | - if(empty($addr[1])) { |
|
| 702 | - $formatted = $this->SecureHeader($addr[0]); |
|
| 703 | - } else { |
|
| 704 | - $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">"; |
|
| 705 | - } |
|
| 701 | + if(empty($addr[1])) { |
|
| 702 | + $formatted = $this->SecureHeader($addr[0]); |
|
| 703 | + } else { |
|
| 704 | + $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">"; |
|
| 705 | + } |
|
| 706 | 706 | |
| 707 | - return $formatted; |
|
| 707 | + return $formatted; |
|
| 708 | 708 | } |
| 709 | 709 | |
| 710 | 710 | /** |
@@ -715,76 +715,76 @@ discard block |
||
| 715 | 715 | * @return string |
| 716 | 716 | */ |
| 717 | 717 | function WrapText($message, $length, $qp_mode = false) { |
| 718 | - $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE; |
|
| 719 | - // If utf-8 encoding is used, we will need to make sure we don't |
|
| 720 | - // split multibyte characters when we wrap |
|
| 721 | - $is_utf8 = (strtolower($this->CharSet) == "utf-8"); |
|
| 722 | - |
|
| 723 | - $message = $this->FixEOL($message); |
|
| 724 | - if (substr($message, -1) == $this->LE) { |
|
| 725 | - $message = substr($message, 0, -1); |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - $line = explode($this->LE, $message); |
|
| 729 | - $message = ''; |
|
| 730 | - for ($i=0 ;$i < count($line); $i++) { |
|
| 731 | - $line_part = explode(' ', $line[$i]); |
|
| 732 | - $buf = ''; |
|
| 733 | - for ($e = 0; $e<count($line_part); $e++) { |
|
| 734 | - $word = $line_part[$e]; |
|
| 735 | - if ($qp_mode and (strlen($word) > $length)) { |
|
| 736 | - $space_left = $length - strlen($buf) - 1; |
|
| 737 | - if ($e != 0) { |
|
| 738 | - if ($space_left > 20) { |
|
| 739 | - $len = $space_left; |
|
| 740 | - if ($is_utf8) { |
|
| 741 | - $len = $this->UTF8CharBoundary($word, $len); |
|
| 742 | - } elseif (substr($word, $len - 1, 1) == "=") { |
|
| 743 | - $len--; |
|
| 744 | - } elseif (substr($word, $len - 2, 1) == "=") { |
|
| 745 | - $len -= 2; |
|
| 746 | - } |
|
| 747 | - $part = substr($word, 0, $len); |
|
| 748 | - $word = substr($word, $len); |
|
| 749 | - $buf .= ' ' . $part; |
|
| 750 | - $message .= $buf . sprintf("=%s", $this->LE); |
|
| 751 | - } else { |
|
| 752 | - $message .= $buf . $soft_break; |
|
| 753 | - } |
|
| 754 | - $buf = ''; |
|
| 755 | - } |
|
| 756 | - while (strlen($word) > 0) { |
|
| 757 | - $len = $length; |
|
| 758 | - if ($is_utf8) { |
|
| 759 | - $len = $this->UTF8CharBoundary($word, $len); |
|
| 760 | - } elseif (substr($word, $len - 1, 1) == "=") { |
|
| 761 | - $len--; |
|
| 762 | - } elseif (substr($word, $len - 2, 1) == "=") { |
|
| 763 | - $len -= 2; |
|
| 764 | - } |
|
| 765 | - $part = substr($word, 0, $len); |
|
| 766 | - $word = substr($word, $len); |
|
| 767 | - |
|
| 768 | - if (strlen($word) > 0) { |
|
| 769 | - $message .= $part . sprintf("=%s", $this->LE); |
|
| 770 | - } else { |
|
| 771 | - $buf = $part; |
|
| 772 | - } |
|
| 773 | - } |
|
| 774 | - } else { |
|
| 775 | - $buf_o = $buf; |
|
| 776 | - $buf .= ($e == 0) ? $word : (' ' . $word); |
|
| 777 | - |
|
| 778 | - if (strlen($buf) > $length and $buf_o != '') { |
|
| 779 | - $message .= $buf_o . $soft_break; |
|
| 780 | - $buf = $word; |
|
| 781 | - } |
|
| 782 | - } |
|
| 783 | - } |
|
| 784 | - $message .= $buf . $this->LE; |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - return $message; |
|
| 718 | + $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE; |
|
| 719 | + // If utf-8 encoding is used, we will need to make sure we don't |
|
| 720 | + // split multibyte characters when we wrap |
|
| 721 | + $is_utf8 = (strtolower($this->CharSet) == "utf-8"); |
|
| 722 | + |
|
| 723 | + $message = $this->FixEOL($message); |
|
| 724 | + if (substr($message, -1) == $this->LE) { |
|
| 725 | + $message = substr($message, 0, -1); |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + $line = explode($this->LE, $message); |
|
| 729 | + $message = ''; |
|
| 730 | + for ($i=0 ;$i < count($line); $i++) { |
|
| 731 | + $line_part = explode(' ', $line[$i]); |
|
| 732 | + $buf = ''; |
|
| 733 | + for ($e = 0; $e<count($line_part); $e++) { |
|
| 734 | + $word = $line_part[$e]; |
|
| 735 | + if ($qp_mode and (strlen($word) > $length)) { |
|
| 736 | + $space_left = $length - strlen($buf) - 1; |
|
| 737 | + if ($e != 0) { |
|
| 738 | + if ($space_left > 20) { |
|
| 739 | + $len = $space_left; |
|
| 740 | + if ($is_utf8) { |
|
| 741 | + $len = $this->UTF8CharBoundary($word, $len); |
|
| 742 | + } elseif (substr($word, $len - 1, 1) == "=") { |
|
| 743 | + $len--; |
|
| 744 | + } elseif (substr($word, $len - 2, 1) == "=") { |
|
| 745 | + $len -= 2; |
|
| 746 | + } |
|
| 747 | + $part = substr($word, 0, $len); |
|
| 748 | + $word = substr($word, $len); |
|
| 749 | + $buf .= ' ' . $part; |
|
| 750 | + $message .= $buf . sprintf("=%s", $this->LE); |
|
| 751 | + } else { |
|
| 752 | + $message .= $buf . $soft_break; |
|
| 753 | + } |
|
| 754 | + $buf = ''; |
|
| 755 | + } |
|
| 756 | + while (strlen($word) > 0) { |
|
| 757 | + $len = $length; |
|
| 758 | + if ($is_utf8) { |
|
| 759 | + $len = $this->UTF8CharBoundary($word, $len); |
|
| 760 | + } elseif (substr($word, $len - 1, 1) == "=") { |
|
| 761 | + $len--; |
|
| 762 | + } elseif (substr($word, $len - 2, 1) == "=") { |
|
| 763 | + $len -= 2; |
|
| 764 | + } |
|
| 765 | + $part = substr($word, 0, $len); |
|
| 766 | + $word = substr($word, $len); |
|
| 767 | + |
|
| 768 | + if (strlen($word) > 0) { |
|
| 769 | + $message .= $part . sprintf("=%s", $this->LE); |
|
| 770 | + } else { |
|
| 771 | + $buf = $part; |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | + } else { |
|
| 775 | + $buf_o = $buf; |
|
| 776 | + $buf .= ($e == 0) ? $word : (' ' . $word); |
|
| 777 | + |
|
| 778 | + if (strlen($buf) > $length and $buf_o != '') { |
|
| 779 | + $message .= $buf_o . $soft_break; |
|
| 780 | + $buf = $word; |
|
| 781 | + } |
|
| 782 | + } |
|
| 783 | + } |
|
| 784 | + $message .= $buf . $this->LE; |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + return $message; |
|
| 788 | 788 | } |
| 789 | 789 | |
| 790 | 790 | /** |
@@ -797,35 +797,35 @@ discard block |
||
| 797 | 797 | * @return int |
| 798 | 798 | */ |
| 799 | 799 | function UTF8CharBoundary($encodedText, $maxLength) { |
| 800 | - $foundSplitPos = false; |
|
| 801 | - $lookBack = 3; |
|
| 802 | - while (!$foundSplitPos) { |
|
| 803 | - $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack); |
|
| 804 | - $encodedCharPos = strpos($lastChunk, "="); |
|
| 805 | - if ($encodedCharPos !== false) { |
|
| 806 | - // Found start of encoded character byte within $lookBack block. |
|
| 807 | - // Check the encoded byte value (the 2 chars after the '=') |
|
| 808 | - $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2); |
|
| 809 | - $dec = hexdec($hex); |
|
| 810 | - if ($dec < 128) { // Single byte character. |
|
| 811 | - // If the encoded char was found at pos 0, it will fit |
|
| 812 | - // otherwise reduce maxLength to start of the encoded char |
|
| 813 | - $maxLength = ($encodedCharPos == 0) ? $maxLength : |
|
| 814 | - $maxLength - ($lookBack - $encodedCharPos); |
|
| 815 | - $foundSplitPos = true; |
|
| 816 | - } elseif ($dec >= 192) { // First byte of a multi byte character |
|
| 817 | - // Reduce maxLength to split at start of character |
|
| 818 | - $maxLength = $maxLength - ($lookBack - $encodedCharPos); |
|
| 819 | - $foundSplitPos = true; |
|
| 820 | - } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back |
|
| 821 | - $lookBack += 3; |
|
| 822 | - } |
|
| 823 | - } else { |
|
| 824 | - // No encoded character found |
|
| 825 | - $foundSplitPos = true; |
|
| 826 | - } |
|
| 827 | - } |
|
| 828 | - return $maxLength; |
|
| 800 | + $foundSplitPos = false; |
|
| 801 | + $lookBack = 3; |
|
| 802 | + while (!$foundSplitPos) { |
|
| 803 | + $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack); |
|
| 804 | + $encodedCharPos = strpos($lastChunk, "="); |
|
| 805 | + if ($encodedCharPos !== false) { |
|
| 806 | + // Found start of encoded character byte within $lookBack block. |
|
| 807 | + // Check the encoded byte value (the 2 chars after the '=') |
|
| 808 | + $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2); |
|
| 809 | + $dec = hexdec($hex); |
|
| 810 | + if ($dec < 128) { // Single byte character. |
|
| 811 | + // If the encoded char was found at pos 0, it will fit |
|
| 812 | + // otherwise reduce maxLength to start of the encoded char |
|
| 813 | + $maxLength = ($encodedCharPos == 0) ? $maxLength : |
|
| 814 | + $maxLength - ($lookBack - $encodedCharPos); |
|
| 815 | + $foundSplitPos = true; |
|
| 816 | + } elseif ($dec >= 192) { // First byte of a multi byte character |
|
| 817 | + // Reduce maxLength to split at start of character |
|
| 818 | + $maxLength = $maxLength - ($lookBack - $encodedCharPos); |
|
| 819 | + $foundSplitPos = true; |
|
| 820 | + } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back |
|
| 821 | + $lookBack += 3; |
|
| 822 | + } |
|
| 823 | + } else { |
|
| 824 | + // No encoded character found |
|
| 825 | + $foundSplitPos = true; |
|
| 826 | + } |
|
| 827 | + } |
|
| 828 | + return $maxLength; |
|
| 829 | 829 | } |
| 830 | 830 | |
| 831 | 831 | /** |
@@ -834,20 +834,20 @@ discard block |
||
| 834 | 834 | * @return void |
| 835 | 835 | */ |
| 836 | 836 | function SetWordWrap() { |
| 837 | - if($this->WordWrap < 1) { |
|
| 838 | - return; |
|
| 839 | - } |
|
| 840 | - |
|
| 841 | - switch($this->message_type) { |
|
| 842 | - case 'alt': |
|
| 843 | - /* fall through */ |
|
| 844 | - case 'alt_attachments': |
|
| 845 | - $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap); |
|
| 846 | - break; |
|
| 847 | - default: |
|
| 848 | - $this->Body = $this->WrapText($this->Body, $this->WordWrap); |
|
| 849 | - break; |
|
| 850 | - } |
|
| 837 | + if($this->WordWrap < 1) { |
|
| 838 | + return; |
|
| 839 | + } |
|
| 840 | + |
|
| 841 | + switch($this->message_type) { |
|
| 842 | + case 'alt': |
|
| 843 | + /* fall through */ |
|
| 844 | + case 'alt_attachments': |
|
| 845 | + $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap); |
|
| 846 | + break; |
|
| 847 | + default: |
|
| 848 | + $this->Body = $this->WrapText($this->Body, $this->WordWrap); |
|
| 849 | + break; |
|
| 850 | + } |
|
| 851 | 851 | } |
| 852 | 852 | |
| 853 | 853 | /** |
@@ -856,75 +856,75 @@ discard block |
||
| 856 | 856 | * @return string |
| 857 | 857 | */ |
| 858 | 858 | function CreateHeader() { |
| 859 | - $result = ''; |
|
| 860 | - |
|
| 861 | - /* Set the boundaries */ |
|
| 862 | - $uniq_id = md5(uniqid(time())); |
|
| 863 | - $this->boundary[1] = 'b1_' . $uniq_id; |
|
| 864 | - $this->boundary[2] = 'b2_' . $uniq_id; |
|
| 865 | - |
|
| 866 | - $result .= $this->HeaderLine('Date', $this->RFCDate()); |
|
| 867 | - if($this->Sender == '') { |
|
| 868 | - $result .= $this->HeaderLine('Return-Path', trim($this->From)); |
|
| 869 | - } else { |
|
| 870 | - $result .= $this->HeaderLine('Return-Path', trim($this->Sender)); |
|
| 871 | - } |
|
| 872 | - |
|
| 873 | - /* To be created automatically by mail() */ |
|
| 874 | - if($this->Mailer != 'mail') { |
|
| 875 | - if(count($this->to) > 0) { |
|
| 876 | - $result .= $this->AddrAppend('To', $this->to); |
|
| 877 | - } elseif (count($this->cc) == 0) { |
|
| 878 | - $result .= $this->HeaderLine('To', 'undisclosed-recipients:;'); |
|
| 879 | - } |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - $from = array(); |
|
| 883 | - $from[0][0] = trim($this->From); |
|
| 884 | - $from[0][1] = $this->FromName; |
|
| 885 | - $result .= $this->AddrAppend('From', $from); |
|
| 886 | - |
|
| 887 | - /* sendmail and mail() extract Cc from the header before sending */ |
|
| 888 | - if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) { |
|
| 889 | - $result .= $this->AddrAppend('Cc', $this->cc); |
|
| 890 | - } |
|
| 891 | - |
|
| 892 | - /* sendmail and mail() extract Bcc from the header before sending */ |
|
| 893 | - if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) { |
|
| 894 | - $result .= $this->AddrAppend('Bcc', $this->bcc); |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - if(count($this->ReplyTo) > 0) { |
|
| 898 | - $result .= $this->AddrAppend('Reply-To', $this->ReplyTo); |
|
| 899 | - } |
|
| 900 | - |
|
| 901 | - /* mail() sets the subject itself */ |
|
| 902 | - if($this->Mailer != 'mail') { |
|
| 903 | - $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject))); |
|
| 904 | - } |
|
| 905 | - |
|
| 906 | - if($this->MessageID != '') { |
|
| 907 | - $result .= $this->HeaderLine('Message-ID',$this->MessageID); |
|
| 908 | - } else { |
|
| 909 | - $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); |
|
| 910 | - } |
|
| 911 | - $result .= $this->HeaderLine('X-Priority', $this->Priority); |
|
| 912 | - $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version ' . $this->Version . ']'); |
|
| 913 | - |
|
| 914 | - if($this->ConfirmReadingTo != '') { |
|
| 915 | - $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>'); |
|
| 916 | - } |
|
| 917 | - |
|
| 918 | - // Add custom headers |
|
| 919 | - for($index = 0; $index < count($this->CustomHeader); $index++) { |
|
| 920 | - $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1]))); |
|
| 921 | - } |
|
| 922 | - if (!$this->sign_key_file) { |
|
| 923 | - $result .= $this->HeaderLine('MIME-Version', '1.0'); |
|
| 924 | - $result .= $this->GetMailMIME(); |
|
| 925 | - } |
|
| 926 | - |
|
| 927 | - return $result; |
|
| 859 | + $result = ''; |
|
| 860 | + |
|
| 861 | + /* Set the boundaries */ |
|
| 862 | + $uniq_id = md5(uniqid(time())); |
|
| 863 | + $this->boundary[1] = 'b1_' . $uniq_id; |
|
| 864 | + $this->boundary[2] = 'b2_' . $uniq_id; |
|
| 865 | + |
|
| 866 | + $result .= $this->HeaderLine('Date', $this->RFCDate()); |
|
| 867 | + if($this->Sender == '') { |
|
| 868 | + $result .= $this->HeaderLine('Return-Path', trim($this->From)); |
|
| 869 | + } else { |
|
| 870 | + $result .= $this->HeaderLine('Return-Path', trim($this->Sender)); |
|
| 871 | + } |
|
| 872 | + |
|
| 873 | + /* To be created automatically by mail() */ |
|
| 874 | + if($this->Mailer != 'mail') { |
|
| 875 | + if(count($this->to) > 0) { |
|
| 876 | + $result .= $this->AddrAppend('To', $this->to); |
|
| 877 | + } elseif (count($this->cc) == 0) { |
|
| 878 | + $result .= $this->HeaderLine('To', 'undisclosed-recipients:;'); |
|
| 879 | + } |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + $from = array(); |
|
| 883 | + $from[0][0] = trim($this->From); |
|
| 884 | + $from[0][1] = $this->FromName; |
|
| 885 | + $result .= $this->AddrAppend('From', $from); |
|
| 886 | + |
|
| 887 | + /* sendmail and mail() extract Cc from the header before sending */ |
|
| 888 | + if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) { |
|
| 889 | + $result .= $this->AddrAppend('Cc', $this->cc); |
|
| 890 | + } |
|
| 891 | + |
|
| 892 | + /* sendmail and mail() extract Bcc from the header before sending */ |
|
| 893 | + if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) { |
|
| 894 | + $result .= $this->AddrAppend('Bcc', $this->bcc); |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + if(count($this->ReplyTo) > 0) { |
|
| 898 | + $result .= $this->AddrAppend('Reply-To', $this->ReplyTo); |
|
| 899 | + } |
|
| 900 | + |
|
| 901 | + /* mail() sets the subject itself */ |
|
| 902 | + if($this->Mailer != 'mail') { |
|
| 903 | + $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject))); |
|
| 904 | + } |
|
| 905 | + |
|
| 906 | + if($this->MessageID != '') { |
|
| 907 | + $result .= $this->HeaderLine('Message-ID',$this->MessageID); |
|
| 908 | + } else { |
|
| 909 | + $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); |
|
| 910 | + } |
|
| 911 | + $result .= $this->HeaderLine('X-Priority', $this->Priority); |
|
| 912 | + $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version ' . $this->Version . ']'); |
|
| 913 | + |
|
| 914 | + if($this->ConfirmReadingTo != '') { |
|
| 915 | + $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>'); |
|
| 916 | + } |
|
| 917 | + |
|
| 918 | + // Add custom headers |
|
| 919 | + for($index = 0; $index < count($this->CustomHeader); $index++) { |
|
| 920 | + $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1]))); |
|
| 921 | + } |
|
| 922 | + if (!$this->sign_key_file) { |
|
| 923 | + $result .= $this->HeaderLine('MIME-Version', '1.0'); |
|
| 924 | + $result .= $this->GetMailMIME(); |
|
| 925 | + } |
|
| 926 | + |
|
| 927 | + return $result; |
|
| 928 | 928 | } |
| 929 | 929 | |
| 930 | 930 | /** |
@@ -933,33 +933,33 @@ discard block |
||
| 933 | 933 | * @return string |
| 934 | 934 | */ |
| 935 | 935 | function GetMailMIME() { |
| 936 | - $result = ''; |
|
| 937 | - switch($this->message_type) { |
|
| 938 | - case 'plain': |
|
| 939 | - $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); |
|
| 940 | - $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet); |
|
| 941 | - break; |
|
| 942 | - case 'attachments': |
|
| 943 | - /* fall through */ |
|
| 944 | - case 'alt_attachments': |
|
| 945 | - if($this->InlineImageExists()){ |
|
| 946 | - $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE); |
|
| 947 | - } else { |
|
| 948 | - $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;'); |
|
| 949 | - $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|
| 950 | - } |
|
| 951 | - break; |
|
| 952 | - case 'alt': |
|
| 953 | - $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); |
|
| 954 | - $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|
| 955 | - break; |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - if($this->Mailer != 'mail') { |
|
| 959 | - $result .= $this->LE.$this->LE; |
|
| 960 | - } |
|
| 961 | - |
|
| 962 | - return $result; |
|
| 936 | + $result = ''; |
|
| 937 | + switch($this->message_type) { |
|
| 938 | + case 'plain': |
|
| 939 | + $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); |
|
| 940 | + $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet); |
|
| 941 | + break; |
|
| 942 | + case 'attachments': |
|
| 943 | + /* fall through */ |
|
| 944 | + case 'alt_attachments': |
|
| 945 | + if($this->InlineImageExists()){ |
|
| 946 | + $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE); |
|
| 947 | + } else { |
|
| 948 | + $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;'); |
|
| 949 | + $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|
| 950 | + } |
|
| 951 | + break; |
|
| 952 | + case 'alt': |
|
| 953 | + $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); |
|
| 954 | + $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|
| 955 | + break; |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | + if($this->Mailer != 'mail') { |
|
| 959 | + $result .= $this->LE.$this->LE; |
|
| 960 | + } |
|
| 961 | + |
|
| 962 | + return $result; |
|
| 963 | 963 | } |
| 964 | 964 | |
| 965 | 965 | /** |
@@ -968,73 +968,73 @@ discard block |
||
| 968 | 968 | * @return string |
| 969 | 969 | */ |
| 970 | 970 | function CreateBody() { |
| 971 | - $result = ''; |
|
| 972 | - if ($this->sign_key_file) { |
|
| 973 | - $result .= $this->GetMailMIME(); |
|
| 974 | - } |
|
| 975 | - |
|
| 976 | - $this->SetWordWrap(); |
|
| 977 | - |
|
| 978 | - switch($this->message_type) { |
|
| 979 | - case 'alt': |
|
| 980 | - $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', ''); |
|
| 981 | - $result .= $this->EncodeString($this->AltBody, $this->Encoding); |
|
| 982 | - $result .= $this->LE.$this->LE; |
|
| 983 | - $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', ''); |
|
| 984 | - $result .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 985 | - $result .= $this->LE.$this->LE; |
|
| 986 | - $result .= $this->EndBoundary($this->boundary[1]); |
|
| 987 | - break; |
|
| 988 | - case 'plain': |
|
| 989 | - $result .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 990 | - break; |
|
| 991 | - case 'attachments': |
|
| 992 | - $result .= $this->GetBoundary($this->boundary[1], '', '', ''); |
|
| 993 | - $result .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 994 | - $result .= $this->LE; |
|
| 995 | - $result .= $this->AttachAll(); |
|
| 996 | - break; |
|
| 997 | - case 'alt_attachments': |
|
| 998 | - $result .= sprintf("--%s%s", $this->boundary[1], $this->LE); |
|
| 999 | - $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE); |
|
| 1000 | - $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body |
|
| 1001 | - $result .= $this->EncodeString($this->AltBody, $this->Encoding); |
|
| 1002 | - $result .= $this->LE.$this->LE; |
|
| 1003 | - $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body |
|
| 1004 | - $result .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1005 | - $result .= $this->LE.$this->LE; |
|
| 1006 | - $result .= $this->EndBoundary($this->boundary[2]); |
|
| 1007 | - $result .= $this->AttachAll(); |
|
| 1008 | - break; |
|
| 1009 | - } |
|
| 1010 | - |
|
| 1011 | - if($this->IsError()) { |
|
| 1012 | - $result = ''; |
|
| 1013 | - } else if ($this->sign_key_file) { |
|
| 1014 | - $file = tempnam("", "mail"); |
|
| 1015 | - $fp = fopen($file, "w"); |
|
| 1016 | - fwrite($fp, $result); |
|
| 1017 | - fclose($fp); |
|
| 1018 | - $signed = tempnam("", "signed"); |
|
| 1019 | - |
|
| 1020 | - if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), null)) { |
|
| 1021 | - $fp = fopen($signed, "r"); |
|
| 1022 | - $result = fread($fp, filesize($this->sign_key_file)); |
|
| 1023 | - $result = ''; |
|
| 1024 | - while(!feof($fp)){ |
|
| 1025 | - $result = $result . fread($fp, 1024); |
|
| 1026 | - } |
|
| 1027 | - fclose($fp); |
|
| 1028 | - } else { |
|
| 1029 | - $this->SetError($this->Lang("signing").openssl_error_string()); |
|
| 1030 | - $result = ''; |
|
| 1031 | - } |
|
| 1032 | - |
|
| 1033 | - unlink($file); |
|
| 1034 | - unlink($signed); |
|
| 1035 | - } |
|
| 1036 | - |
|
| 1037 | - return $result; |
|
| 971 | + $result = ''; |
|
| 972 | + if ($this->sign_key_file) { |
|
| 973 | + $result .= $this->GetMailMIME(); |
|
| 974 | + } |
|
| 975 | + |
|
| 976 | + $this->SetWordWrap(); |
|
| 977 | + |
|
| 978 | + switch($this->message_type) { |
|
| 979 | + case 'alt': |
|
| 980 | + $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', ''); |
|
| 981 | + $result .= $this->EncodeString($this->AltBody, $this->Encoding); |
|
| 982 | + $result .= $this->LE.$this->LE; |
|
| 983 | + $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', ''); |
|
| 984 | + $result .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 985 | + $result .= $this->LE.$this->LE; |
|
| 986 | + $result .= $this->EndBoundary($this->boundary[1]); |
|
| 987 | + break; |
|
| 988 | + case 'plain': |
|
| 989 | + $result .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 990 | + break; |
|
| 991 | + case 'attachments': |
|
| 992 | + $result .= $this->GetBoundary($this->boundary[1], '', '', ''); |
|
| 993 | + $result .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 994 | + $result .= $this->LE; |
|
| 995 | + $result .= $this->AttachAll(); |
|
| 996 | + break; |
|
| 997 | + case 'alt_attachments': |
|
| 998 | + $result .= sprintf("--%s%s", $this->boundary[1], $this->LE); |
|
| 999 | + $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE); |
|
| 1000 | + $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body |
|
| 1001 | + $result .= $this->EncodeString($this->AltBody, $this->Encoding); |
|
| 1002 | + $result .= $this->LE.$this->LE; |
|
| 1003 | + $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body |
|
| 1004 | + $result .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1005 | + $result .= $this->LE.$this->LE; |
|
| 1006 | + $result .= $this->EndBoundary($this->boundary[2]); |
|
| 1007 | + $result .= $this->AttachAll(); |
|
| 1008 | + break; |
|
| 1009 | + } |
|
| 1010 | + |
|
| 1011 | + if($this->IsError()) { |
|
| 1012 | + $result = ''; |
|
| 1013 | + } else if ($this->sign_key_file) { |
|
| 1014 | + $file = tempnam("", "mail"); |
|
| 1015 | + $fp = fopen($file, "w"); |
|
| 1016 | + fwrite($fp, $result); |
|
| 1017 | + fclose($fp); |
|
| 1018 | + $signed = tempnam("", "signed"); |
|
| 1019 | + |
|
| 1020 | + if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), null)) { |
|
| 1021 | + $fp = fopen($signed, "r"); |
|
| 1022 | + $result = fread($fp, filesize($this->sign_key_file)); |
|
| 1023 | + $result = ''; |
|
| 1024 | + while(!feof($fp)){ |
|
| 1025 | + $result = $result . fread($fp, 1024); |
|
| 1026 | + } |
|
| 1027 | + fclose($fp); |
|
| 1028 | + } else { |
|
| 1029 | + $this->SetError($this->Lang("signing").openssl_error_string()); |
|
| 1030 | + $result = ''; |
|
| 1031 | + } |
|
| 1032 | + |
|
| 1033 | + unlink($file); |
|
| 1034 | + unlink($signed); |
|
| 1035 | + } |
|
| 1036 | + |
|
| 1037 | + return $result; |
|
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | 1040 | /** |
@@ -1042,23 +1042,23 @@ discard block |
||
| 1042 | 1042 | * @access private |
| 1043 | 1043 | */ |
| 1044 | 1044 | function GetBoundary($boundary, $charSet, $contentType, $encoding) { |
| 1045 | - $result = ''; |
|
| 1046 | - if($charSet == '') { |
|
| 1047 | - $charSet = $this->CharSet; |
|
| 1048 | - } |
|
| 1049 | - if($contentType == '') { |
|
| 1050 | - $contentType = $this->ContentType; |
|
| 1051 | - } |
|
| 1052 | - if($encoding == '') { |
|
| 1053 | - $encoding = $this->Encoding; |
|
| 1054 | - } |
|
| 1055 | - $result .= $this->TextLine('--' . $boundary); |
|
| 1056 | - $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet); |
|
| 1057 | - $result .= $this->LE; |
|
| 1058 | - $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding); |
|
| 1059 | - $result .= $this->LE; |
|
| 1060 | - |
|
| 1061 | - return $result; |
|
| 1045 | + $result = ''; |
|
| 1046 | + if($charSet == '') { |
|
| 1047 | + $charSet = $this->CharSet; |
|
| 1048 | + } |
|
| 1049 | + if($contentType == '') { |
|
| 1050 | + $contentType = $this->ContentType; |
|
| 1051 | + } |
|
| 1052 | + if($encoding == '') { |
|
| 1053 | + $encoding = $this->Encoding; |
|
| 1054 | + } |
|
| 1055 | + $result .= $this->TextLine('--' . $boundary); |
|
| 1056 | + $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet); |
|
| 1057 | + $result .= $this->LE; |
|
| 1058 | + $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding); |
|
| 1059 | + $result .= $this->LE; |
|
| 1060 | + |
|
| 1061 | + return $result; |
|
| 1062 | 1062 | } |
| 1063 | 1063 | |
| 1064 | 1064 | /** |
@@ -1066,7 +1066,7 @@ discard block |
||
| 1066 | 1066 | * @access private |
| 1067 | 1067 | */ |
| 1068 | 1068 | function EndBoundary($boundary) { |
| 1069 | - return $this->LE . '--' . $boundary . '--' . $this->LE; |
|
| 1069 | + return $this->LE . '--' . $boundary . '--' . $this->LE; |
|
| 1070 | 1070 | } |
| 1071 | 1071 | |
| 1072 | 1072 | /** |
@@ -1075,19 +1075,19 @@ discard block |
||
| 1075 | 1075 | * @return void |
| 1076 | 1076 | */ |
| 1077 | 1077 | function SetMessageType() { |
| 1078 | - if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) { |
|
| 1079 | - $this->message_type = 'plain'; |
|
| 1080 | - } else { |
|
| 1081 | - if(count($this->attachment) > 0) { |
|
| 1082 | - $this->message_type = 'attachments'; |
|
| 1083 | - } |
|
| 1084 | - if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) { |
|
| 1085 | - $this->message_type = 'alt'; |
|
| 1086 | - } |
|
| 1087 | - if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) { |
|
| 1088 | - $this->message_type = 'alt_attachments'; |
|
| 1089 | - } |
|
| 1090 | - } |
|
| 1078 | + if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) { |
|
| 1079 | + $this->message_type = 'plain'; |
|
| 1080 | + } else { |
|
| 1081 | + if(count($this->attachment) > 0) { |
|
| 1082 | + $this->message_type = 'attachments'; |
|
| 1083 | + } |
|
| 1084 | + if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) { |
|
| 1085 | + $this->message_type = 'alt'; |
|
| 1086 | + } |
|
| 1087 | + if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) { |
|
| 1088 | + $this->message_type = 'alt_attachments'; |
|
| 1089 | + } |
|
| 1090 | + } |
|
| 1091 | 1091 | } |
| 1092 | 1092 | |
| 1093 | 1093 | /* Returns a formatted header line. |
@@ -1095,7 +1095,7 @@ discard block |
||
| 1095 | 1095 | * @return string |
| 1096 | 1096 | */ |
| 1097 | 1097 | function HeaderLine($name, $value) { |
| 1098 | - return $name . ': ' . $value . $this->LE; |
|
| 1098 | + return $name . ': ' . $value . $this->LE; |
|
| 1099 | 1099 | } |
| 1100 | 1100 | |
| 1101 | 1101 | /** |
@@ -1104,7 +1104,7 @@ discard block |
||
| 1104 | 1104 | * @return string |
| 1105 | 1105 | */ |
| 1106 | 1106 | function TextLine($value) { |
| 1107 | - return $value . $this->LE; |
|
| 1107 | + return $value . $this->LE; |
|
| 1108 | 1108 | } |
| 1109 | 1109 | |
| 1110 | 1110 | ///////////////////////////////////////////////// |
@@ -1122,27 +1122,27 @@ discard block |
||
| 1122 | 1122 | * @return bool |
| 1123 | 1123 | */ |
| 1124 | 1124 | function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { |
| 1125 | - if(!@is_file($path)) { |
|
| 1126 | - $this->SetError($this->Lang('file_access') . $path); |
|
| 1127 | - return false; |
|
| 1128 | - } |
|
| 1129 | - |
|
| 1130 | - $filename = basename($path); |
|
| 1131 | - if($name == '') { |
|
| 1132 | - $name = $filename; |
|
| 1133 | - } |
|
| 1134 | - |
|
| 1135 | - $cur = count($this->attachment); |
|
| 1136 | - $this->attachment[$cur][0] = $path; |
|
| 1137 | - $this->attachment[$cur][1] = $filename; |
|
| 1138 | - $this->attachment[$cur][2] = $name; |
|
| 1139 | - $this->attachment[$cur][3] = $encoding; |
|
| 1140 | - $this->attachment[$cur][4] = $type; |
|
| 1141 | - $this->attachment[$cur][5] = false; // isStringAttachment |
|
| 1142 | - $this->attachment[$cur][6] = 'attachment'; |
|
| 1143 | - $this->attachment[$cur][7] = 0; |
|
| 1144 | - |
|
| 1145 | - return true; |
|
| 1125 | + if(!@is_file($path)) { |
|
| 1126 | + $this->SetError($this->Lang('file_access') . $path); |
|
| 1127 | + return false; |
|
| 1128 | + } |
|
| 1129 | + |
|
| 1130 | + $filename = basename($path); |
|
| 1131 | + if($name == '') { |
|
| 1132 | + $name = $filename; |
|
| 1133 | + } |
|
| 1134 | + |
|
| 1135 | + $cur = count($this->attachment); |
|
| 1136 | + $this->attachment[$cur][0] = $path; |
|
| 1137 | + $this->attachment[$cur][1] = $filename; |
|
| 1138 | + $this->attachment[$cur][2] = $name; |
|
| 1139 | + $this->attachment[$cur][3] = $encoding; |
|
| 1140 | + $this->attachment[$cur][4] = $type; |
|
| 1141 | + $this->attachment[$cur][5] = false; // isStringAttachment |
|
| 1142 | + $this->attachment[$cur][6] = 'attachment'; |
|
| 1143 | + $this->attachment[$cur][7] = 0; |
|
| 1144 | + |
|
| 1145 | + return true; |
|
| 1146 | 1146 | } |
| 1147 | 1147 | |
| 1148 | 1148 | /** |
@@ -1152,55 +1152,55 @@ discard block |
||
| 1152 | 1152 | * @return string |
| 1153 | 1153 | */ |
| 1154 | 1154 | function AttachAll() { |
| 1155 | - /* Return text of body */ |
|
| 1156 | - $mime = array(); |
|
| 1157 | - |
|
| 1158 | - /* Add all attachments */ |
|
| 1159 | - for($i = 0; $i < count($this->attachment); $i++) { |
|
| 1160 | - /* Check for string attachment */ |
|
| 1161 | - $bString = $this->attachment[$i][5]; |
|
| 1162 | - if ($bString) { |
|
| 1163 | - $string = $this->attachment[$i][0]; |
|
| 1164 | - } else { |
|
| 1165 | - $path = $this->attachment[$i][0]; |
|
| 1166 | - } |
|
| 1167 | - |
|
| 1168 | - $filename = $this->attachment[$i][1]; |
|
| 1169 | - $name = $this->attachment[$i][2]; |
|
| 1170 | - $encoding = $this->attachment[$i][3]; |
|
| 1171 | - $type = $this->attachment[$i][4]; |
|
| 1172 | - $disposition = $this->attachment[$i][6]; |
|
| 1173 | - $cid = $this->attachment[$i][7]; |
|
| 1174 | - |
|
| 1175 | - $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE); |
|
| 1176 | - $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE); |
|
| 1177 | - $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE); |
|
| 1178 | - |
|
| 1179 | - if($disposition == 'inline') { |
|
| 1180 | - $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE); |
|
| 1181 | - } |
|
| 1182 | - |
|
| 1183 | - $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE); |
|
| 1184 | - |
|
| 1185 | - /* Encode as string attachment */ |
|
| 1186 | - if($bString) { |
|
| 1187 | - $mime[] = $this->EncodeString($string, $encoding); |
|
| 1188 | - if($this->IsError()) { |
|
| 1189 | - return ''; |
|
| 1190 | - } |
|
| 1191 | - $mime[] = $this->LE.$this->LE; |
|
| 1192 | - } else { |
|
| 1193 | - $mime[] = $this->EncodeFile($path, $encoding); |
|
| 1194 | - if($this->IsError()) { |
|
| 1195 | - return ''; |
|
| 1196 | - } |
|
| 1197 | - $mime[] = $this->LE.$this->LE; |
|
| 1198 | - } |
|
| 1199 | - } |
|
| 1200 | - |
|
| 1201 | - $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE); |
|
| 1202 | - |
|
| 1203 | - return join('', $mime); |
|
| 1155 | + /* Return text of body */ |
|
| 1156 | + $mime = array(); |
|
| 1157 | + |
|
| 1158 | + /* Add all attachments */ |
|
| 1159 | + for($i = 0; $i < count($this->attachment); $i++) { |
|
| 1160 | + /* Check for string attachment */ |
|
| 1161 | + $bString = $this->attachment[$i][5]; |
|
| 1162 | + if ($bString) { |
|
| 1163 | + $string = $this->attachment[$i][0]; |
|
| 1164 | + } else { |
|
| 1165 | + $path = $this->attachment[$i][0]; |
|
| 1166 | + } |
|
| 1167 | + |
|
| 1168 | + $filename = $this->attachment[$i][1]; |
|
| 1169 | + $name = $this->attachment[$i][2]; |
|
| 1170 | + $encoding = $this->attachment[$i][3]; |
|
| 1171 | + $type = $this->attachment[$i][4]; |
|
| 1172 | + $disposition = $this->attachment[$i][6]; |
|
| 1173 | + $cid = $this->attachment[$i][7]; |
|
| 1174 | + |
|
| 1175 | + $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE); |
|
| 1176 | + $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE); |
|
| 1177 | + $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE); |
|
| 1178 | + |
|
| 1179 | + if($disposition == 'inline') { |
|
| 1180 | + $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE); |
|
| 1181 | + } |
|
| 1182 | + |
|
| 1183 | + $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE); |
|
| 1184 | + |
|
| 1185 | + /* Encode as string attachment */ |
|
| 1186 | + if($bString) { |
|
| 1187 | + $mime[] = $this->EncodeString($string, $encoding); |
|
| 1188 | + if($this->IsError()) { |
|
| 1189 | + return ''; |
|
| 1190 | + } |
|
| 1191 | + $mime[] = $this->LE.$this->LE; |
|
| 1192 | + } else { |
|
| 1193 | + $mime[] = $this->EncodeFile($path, $encoding); |
|
| 1194 | + if($this->IsError()) { |
|
| 1195 | + return ''; |
|
| 1196 | + } |
|
| 1197 | + $mime[] = $this->LE.$this->LE; |
|
| 1198 | + } |
|
| 1199 | + } |
|
| 1200 | + |
|
| 1201 | + $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE); |
|
| 1202 | + |
|
| 1203 | + return join('', $mime); |
|
| 1204 | 1204 | } |
| 1205 | 1205 | |
| 1206 | 1206 | /** |
@@ -1210,18 +1210,18 @@ discard block |
||
| 1210 | 1210 | * @return string |
| 1211 | 1211 | */ |
| 1212 | 1212 | function EncodeFile ($path, $encoding = 'base64') { |
| 1213 | - if(!@$fd = fopen($path, 'rb')) { |
|
| 1214 | - $this->SetError($this->Lang('file_open') . $path); |
|
| 1215 | - return ''; |
|
| 1216 | - } |
|
| 1217 | - $magic_quotes = get_magic_quotes_runtime(); |
|
| 1218 | - set_magic_quotes_runtime(0); |
|
| 1219 | - $file_buffer = fread($fd, filesize($path)); |
|
| 1220 | - $file_buffer = $this->EncodeString($file_buffer, $encoding); |
|
| 1221 | - fclose($fd); |
|
| 1222 | - set_magic_quotes_runtime($magic_quotes); |
|
| 1223 | - |
|
| 1224 | - return $file_buffer; |
|
| 1213 | + if(!@$fd = fopen($path, 'rb')) { |
|
| 1214 | + $this->SetError($this->Lang('file_open') . $path); |
|
| 1215 | + return ''; |
|
| 1216 | + } |
|
| 1217 | + $magic_quotes = get_magic_quotes_runtime(); |
|
| 1218 | + set_magic_quotes_runtime(0); |
|
| 1219 | + $file_buffer = fread($fd, filesize($path)); |
|
| 1220 | + $file_buffer = $this->EncodeString($file_buffer, $encoding); |
|
| 1221 | + fclose($fd); |
|
| 1222 | + set_magic_quotes_runtime($magic_quotes); |
|
| 1223 | + |
|
| 1224 | + return $file_buffer; |
|
| 1225 | 1225 | } |
| 1226 | 1226 | |
| 1227 | 1227 | /** |
@@ -1231,29 +1231,29 @@ discard block |
||
| 1231 | 1231 | * @return string |
| 1232 | 1232 | */ |
| 1233 | 1233 | function EncodeString ($str, $encoding = 'base64') { |
| 1234 | - $encoded = ''; |
|
| 1235 | - switch(strtolower($encoding)) { |
|
| 1236 | - case 'base64': |
|
| 1237 | - /* chunk_split is found in PHP >= 3.0.6 */ |
|
| 1238 | - $encoded = chunk_split(base64_encode($str), 76, $this->LE); |
|
| 1239 | - break; |
|
| 1240 | - case '7bit': |
|
| 1241 | - case '8bit': |
|
| 1242 | - $encoded = $this->FixEOL($str); |
|
| 1243 | - if (substr($encoded, -(strlen($this->LE))) != $this->LE) |
|
| 1244 | - $encoded .= $this->LE; |
|
| 1245 | - break; |
|
| 1246 | - case 'binary': |
|
| 1247 | - $encoded = $str; |
|
| 1248 | - break; |
|
| 1249 | - case 'quoted-printable': |
|
| 1250 | - $encoded = $this->EncodeQP($str); |
|
| 1251 | - break; |
|
| 1252 | - default: |
|
| 1253 | - $this->SetError($this->Lang('encoding') . $encoding); |
|
| 1254 | - break; |
|
| 1255 | - } |
|
| 1256 | - return $encoded; |
|
| 1234 | + $encoded = ''; |
|
| 1235 | + switch(strtolower($encoding)) { |
|
| 1236 | + case 'base64': |
|
| 1237 | + /* chunk_split is found in PHP >= 3.0.6 */ |
|
| 1238 | + $encoded = chunk_split(base64_encode($str), 76, $this->LE); |
|
| 1239 | + break; |
|
| 1240 | + case '7bit': |
|
| 1241 | + case '8bit': |
|
| 1242 | + $encoded = $this->FixEOL($str); |
|
| 1243 | + if (substr($encoded, -(strlen($this->LE))) != $this->LE) |
|
| 1244 | + $encoded .= $this->LE; |
|
| 1245 | + break; |
|
| 1246 | + case 'binary': |
|
| 1247 | + $encoded = $str; |
|
| 1248 | + break; |
|
| 1249 | + case 'quoted-printable': |
|
| 1250 | + $encoded = $this->EncodeQP($str); |
|
| 1251 | + break; |
|
| 1252 | + default: |
|
| 1253 | + $this->SetError($this->Lang('encoding') . $encoding); |
|
| 1254 | + break; |
|
| 1255 | + } |
|
| 1256 | + return $encoded; |
|
| 1257 | 1257 | } |
| 1258 | 1258 | |
| 1259 | 1259 | /** |
@@ -1262,58 +1262,58 @@ discard block |
||
| 1262 | 1262 | * @return string |
| 1263 | 1263 | */ |
| 1264 | 1264 | function EncodeHeader ($str, $position = 'text') { |
| 1265 | - $x = 0; |
|
| 1266 | - |
|
| 1267 | - switch (strtolower($position)) { |
|
| 1268 | - case 'phrase': |
|
| 1269 | - if (!preg_match('/[\200-\377]/', $str)) { |
|
| 1270 | - /* Can't use addslashes as we don't know what value has magic_quotes_sybase. */ |
|
| 1271 | - $encoded = addcslashes($str, "\0..\37\177\\\""); |
|
| 1272 | - if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) { |
|
| 1273 | - return ($encoded); |
|
| 1274 | - } else { |
|
| 1275 | - return ("\"$encoded\""); |
|
| 1276 | - } |
|
| 1277 | - } |
|
| 1278 | - $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches); |
|
| 1279 | - break; |
|
| 1280 | - case 'comment': |
|
| 1281 | - $x = preg_match_all('/[()"]/', $str, $matches); |
|
| 1282 | - /* Fall-through */ |
|
| 1283 | - case 'text': |
|
| 1284 | - default: |
|
| 1285 | - $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches); |
|
| 1286 | - break; |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - if ($x == 0) { |
|
| 1290 | - return ($str); |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - $maxlen = 75 - 7 - strlen($this->CharSet); |
|
| 1294 | - /* Try to select the encoding which should produce the shortest output */ |
|
| 1295 | - if (strlen($str)/3 < $x) { |
|
| 1296 | - $encoding = 'B'; |
|
| 1297 | - if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) { |
|
| 1298 | - // Use a custom function which correctly encodes and wraps long |
|
| 1299 | - // multibyte strings without breaking lines within a character |
|
| 1300 | - $encoded = $this->Base64EncodeWrapMB($str); |
|
| 1301 | - } else { |
|
| 1302 | - $encoded = base64_encode($str); |
|
| 1303 | - $maxlen -= $maxlen % 4; |
|
| 1304 | - $encoded = trim(chunk_split($encoded, $maxlen, "\n")); |
|
| 1305 | - } |
|
| 1306 | - } else { |
|
| 1307 | - $encoding = 'Q'; |
|
| 1308 | - $encoded = $this->EncodeQ($str, $position); |
|
| 1309 | - $encoded = $this->WrapText($encoded, $maxlen, true); |
|
| 1310 | - $encoded = str_replace('='.$this->LE, "\n", trim($encoded)); |
|
| 1311 | - } |
|
| 1312 | - |
|
| 1313 | - $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded); |
|
| 1314 | - $encoded = trim(str_replace("\n", $this->LE, $encoded)); |
|
| 1315 | - |
|
| 1316 | - return $encoded; |
|
| 1265 | + $x = 0; |
|
| 1266 | + |
|
| 1267 | + switch (strtolower($position)) { |
|
| 1268 | + case 'phrase': |
|
| 1269 | + if (!preg_match('/[\200-\377]/', $str)) { |
|
| 1270 | + /* Can't use addslashes as we don't know what value has magic_quotes_sybase. */ |
|
| 1271 | + $encoded = addcslashes($str, "\0..\37\177\\\""); |
|
| 1272 | + if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) { |
|
| 1273 | + return ($encoded); |
|
| 1274 | + } else { |
|
| 1275 | + return ("\"$encoded\""); |
|
| 1276 | + } |
|
| 1277 | + } |
|
| 1278 | + $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches); |
|
| 1279 | + break; |
|
| 1280 | + case 'comment': |
|
| 1281 | + $x = preg_match_all('/[()"]/', $str, $matches); |
|
| 1282 | + /* Fall-through */ |
|
| 1283 | + case 'text': |
|
| 1284 | + default: |
|
| 1285 | + $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches); |
|
| 1286 | + break; |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + if ($x == 0) { |
|
| 1290 | + return ($str); |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + $maxlen = 75 - 7 - strlen($this->CharSet); |
|
| 1294 | + /* Try to select the encoding which should produce the shortest output */ |
|
| 1295 | + if (strlen($str)/3 < $x) { |
|
| 1296 | + $encoding = 'B'; |
|
| 1297 | + if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) { |
|
| 1298 | + // Use a custom function which correctly encodes and wraps long |
|
| 1299 | + // multibyte strings without breaking lines within a character |
|
| 1300 | + $encoded = $this->Base64EncodeWrapMB($str); |
|
| 1301 | + } else { |
|
| 1302 | + $encoded = base64_encode($str); |
|
| 1303 | + $maxlen -= $maxlen % 4; |
|
| 1304 | + $encoded = trim(chunk_split($encoded, $maxlen, "\n")); |
|
| 1305 | + } |
|
| 1306 | + } else { |
|
| 1307 | + $encoding = 'Q'; |
|
| 1308 | + $encoded = $this->EncodeQ($str, $position); |
|
| 1309 | + $encoded = $this->WrapText($encoded, $maxlen, true); |
|
| 1310 | + $encoded = str_replace('='.$this->LE, "\n", trim($encoded)); |
|
| 1311 | + } |
|
| 1312 | + |
|
| 1313 | + $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded); |
|
| 1314 | + $encoded = trim(str_replace("\n", $this->LE, $encoded)); |
|
| 1315 | + |
|
| 1316 | + return $encoded; |
|
| 1317 | 1317 | } |
| 1318 | 1318 | |
| 1319 | 1319 | /** |
@@ -1323,11 +1323,11 @@ discard block |
||
| 1323 | 1323 | * @return bool |
| 1324 | 1324 | */ |
| 1325 | 1325 | function HasMultiBytes($str) { |
| 1326 | - if (function_exists('mb_strlen')) { |
|
| 1327 | - return (strlen($str) > mb_strlen($str, $this->CharSet)); |
|
| 1328 | - } else { // Assume no multibytes (we can't handle without mbstring functions anyway) |
|
| 1329 | - return False; |
|
| 1330 | - } |
|
| 1326 | + if (function_exists('mb_strlen')) { |
|
| 1327 | + return (strlen($str) > mb_strlen($str, $this->CharSet)); |
|
| 1328 | + } else { // Assume no multibytes (we can't handle without mbstring functions anyway) |
|
| 1329 | + return False; |
|
| 1330 | + } |
|
| 1331 | 1331 | } |
| 1332 | 1332 | |
| 1333 | 1333 | /** |
@@ -1339,35 +1339,35 @@ discard block |
||
| 1339 | 1339 | * @return string |
| 1340 | 1340 | */ |
| 1341 | 1341 | function Base64EncodeWrapMB($str) { |
| 1342 | - $start = "=?".$this->CharSet."?B?"; |
|
| 1343 | - $end = "?="; |
|
| 1344 | - $encoded = ""; |
|
| 1345 | - |
|
| 1346 | - $mb_length = mb_strlen($str, $this->CharSet); |
|
| 1347 | - // Each line must have length <= 75, including $start and $end |
|
| 1348 | - $length = 75 - strlen($start) - strlen($end); |
|
| 1349 | - // Average multi-byte ratio |
|
| 1350 | - $ratio = $mb_length / strlen($str); |
|
| 1351 | - // Base64 has a 4:3 ratio |
|
| 1352 | - $offset = $avgLength = floor($length * $ratio * .75); |
|
| 1353 | - |
|
| 1354 | - for ($i = 0; $i < $mb_length; $i += $offset) { |
|
| 1355 | - $lookBack = 0; |
|
| 1356 | - |
|
| 1357 | - do { |
|
| 1358 | - $offset = $avgLength - $lookBack; |
|
| 1359 | - $chunk = mb_substr($str, $i, $offset, $this->CharSet); |
|
| 1360 | - $chunk = base64_encode($chunk); |
|
| 1361 | - $lookBack++; |
|
| 1362 | - } |
|
| 1363 | - while (strlen($chunk) > $length); |
|
| 1364 | - |
|
| 1365 | - $encoded .= $chunk . $this->LE; |
|
| 1366 | - } |
|
| 1367 | - |
|
| 1368 | - // Chomp the last linefeed |
|
| 1369 | - $encoded = substr($encoded, 0, -strlen($this->LE)); |
|
| 1370 | - return $encoded; |
|
| 1342 | + $start = "=?".$this->CharSet."?B?"; |
|
| 1343 | + $end = "?="; |
|
| 1344 | + $encoded = ""; |
|
| 1345 | + |
|
| 1346 | + $mb_length = mb_strlen($str, $this->CharSet); |
|
| 1347 | + // Each line must have length <= 75, including $start and $end |
|
| 1348 | + $length = 75 - strlen($start) - strlen($end); |
|
| 1349 | + // Average multi-byte ratio |
|
| 1350 | + $ratio = $mb_length / strlen($str); |
|
| 1351 | + // Base64 has a 4:3 ratio |
|
| 1352 | + $offset = $avgLength = floor($length * $ratio * .75); |
|
| 1353 | + |
|
| 1354 | + for ($i = 0; $i < $mb_length; $i += $offset) { |
|
| 1355 | + $lookBack = 0; |
|
| 1356 | + |
|
| 1357 | + do { |
|
| 1358 | + $offset = $avgLength - $lookBack; |
|
| 1359 | + $chunk = mb_substr($str, $i, $offset, $this->CharSet); |
|
| 1360 | + $chunk = base64_encode($chunk); |
|
| 1361 | + $lookBack++; |
|
| 1362 | + } |
|
| 1363 | + while (strlen($chunk) > $length); |
|
| 1364 | + |
|
| 1365 | + $encoded .= $chunk . $this->LE; |
|
| 1366 | + } |
|
| 1367 | + |
|
| 1368 | + // Chomp the last linefeed |
|
| 1369 | + $encoded = substr($encoded, 0, -strlen($this->LE)); |
|
| 1370 | + return $encoded; |
|
| 1371 | 1371 | } |
| 1372 | 1372 | |
| 1373 | 1373 | /** |
@@ -1376,44 +1376,44 @@ discard block |
||
| 1376 | 1376 | * @return string |
| 1377 | 1377 | */ |
| 1378 | 1378 | function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) { |
| 1379 | - $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
|
| 1380 | - $lines = preg_split('/(?:\r\n|\r|\n)/', $input); |
|
| 1381 | - $eol = "\r\n"; |
|
| 1382 | - $escape = '='; |
|
| 1383 | - $output = ''; |
|
| 1384 | - while( list(, $line) = each($lines) ) { |
|
| 1385 | - $linlen = strlen($line); |
|
| 1386 | - $newline = ''; |
|
| 1387 | - for($i = 0; $i < $linlen; $i++) { |
|
| 1388 | - $c = substr( $line, $i, 1 ); |
|
| 1389 | - $dec = ord( $c ); |
|
| 1390 | - if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E |
|
| 1391 | - $c = '=2E'; |
|
| 1392 | - } |
|
| 1393 | - if ( $dec == 32 ) { |
|
| 1394 | - if ( $i == ( $linlen - 1 ) ) { // convert space at eol only |
|
| 1395 | - $c = '=20'; |
|
| 1396 | - } else if ( $space_conv ) { |
|
| 1397 | - $c = '=20'; |
|
| 1398 | - } |
|
| 1399 | - } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required |
|
| 1400 | - $h2 = floor($dec/16); |
|
| 1401 | - $h1 = floor($dec%16); |
|
| 1402 | - $c = $escape.$hex[$h2].$hex[$h1]; |
|
| 1403 | - } |
|
| 1404 | - if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted |
|
| 1405 | - $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay |
|
| 1406 | - $newline = ''; |
|
| 1407 | - // check if newline first character will be point or not |
|
| 1408 | - if ( $dec == 46 ) { |
|
| 1409 | - $c = '=2E'; |
|
| 1410 | - } |
|
| 1411 | - } |
|
| 1412 | - $newline .= $c; |
|
| 1413 | - } // end of for |
|
| 1414 | - $output .= $newline.$eol; |
|
| 1415 | - } // end of while |
|
| 1416 | - return $output; |
|
| 1379 | + $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
|
| 1380 | + $lines = preg_split('/(?:\r\n|\r|\n)/', $input); |
|
| 1381 | + $eol = "\r\n"; |
|
| 1382 | + $escape = '='; |
|
| 1383 | + $output = ''; |
|
| 1384 | + while( list(, $line) = each($lines) ) { |
|
| 1385 | + $linlen = strlen($line); |
|
| 1386 | + $newline = ''; |
|
| 1387 | + for($i = 0; $i < $linlen; $i++) { |
|
| 1388 | + $c = substr( $line, $i, 1 ); |
|
| 1389 | + $dec = ord( $c ); |
|
| 1390 | + if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E |
|
| 1391 | + $c = '=2E'; |
|
| 1392 | + } |
|
| 1393 | + if ( $dec == 32 ) { |
|
| 1394 | + if ( $i == ( $linlen - 1 ) ) { // convert space at eol only |
|
| 1395 | + $c = '=20'; |
|
| 1396 | + } else if ( $space_conv ) { |
|
| 1397 | + $c = '=20'; |
|
| 1398 | + } |
|
| 1399 | + } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required |
|
| 1400 | + $h2 = floor($dec/16); |
|
| 1401 | + $h1 = floor($dec%16); |
|
| 1402 | + $c = $escape.$hex[$h2].$hex[$h1]; |
|
| 1403 | + } |
|
| 1404 | + if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted |
|
| 1405 | + $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay |
|
| 1406 | + $newline = ''; |
|
| 1407 | + // check if newline first character will be point or not |
|
| 1408 | + if ( $dec == 46 ) { |
|
| 1409 | + $c = '=2E'; |
|
| 1410 | + } |
|
| 1411 | + } |
|
| 1412 | + $newline .= $c; |
|
| 1413 | + } // end of for |
|
| 1414 | + $output .= $newline.$eol; |
|
| 1415 | + } // end of while |
|
| 1416 | + return $output; |
|
| 1417 | 1417 | } |
| 1418 | 1418 | |
| 1419 | 1419 | /** |
@@ -1422,27 +1422,27 @@ discard block |
||
| 1422 | 1422 | * @return string |
| 1423 | 1423 | */ |
| 1424 | 1424 | function EncodeQ ($str, $position = 'text') { |
| 1425 | - /* There should not be any EOL in the string */ |
|
| 1426 | - $encoded = preg_replace("[\r\n]", '', $str); |
|
| 1427 | - |
|
| 1428 | - switch (strtolower($position)) { |
|
| 1429 | - case 'phrase': |
|
| 1430 | - $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); |
|
| 1431 | - break; |
|
| 1432 | - case 'comment': |
|
| 1433 | - $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); |
|
| 1434 | - case 'text': |
|
| 1435 | - default: |
|
| 1436 | - /* Replace every high ascii, control =, ? and _ characters */ |
|
| 1437 | - $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e', |
|
| 1438 | - "'='.sprintf('%02X', ord('\\1'))", $encoded); |
|
| 1439 | - break; |
|
| 1440 | - } |
|
| 1441 | - |
|
| 1442 | - /* Replace every spaces to _ (more readable than =20) */ |
|
| 1443 | - $encoded = str_replace(' ', '_', $encoded); |
|
| 1444 | - |
|
| 1445 | - return $encoded; |
|
| 1425 | + /* There should not be any EOL in the string */ |
|
| 1426 | + $encoded = preg_replace("[\r\n]", '', $str); |
|
| 1427 | + |
|
| 1428 | + switch (strtolower($position)) { |
|
| 1429 | + case 'phrase': |
|
| 1430 | + $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); |
|
| 1431 | + break; |
|
| 1432 | + case 'comment': |
|
| 1433 | + $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); |
|
| 1434 | + case 'text': |
|
| 1435 | + default: |
|
| 1436 | + /* Replace every high ascii, control =, ? and _ characters */ |
|
| 1437 | + $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e', |
|
| 1438 | + "'='.sprintf('%02X', ord('\\1'))", $encoded); |
|
| 1439 | + break; |
|
| 1440 | + } |
|
| 1441 | + |
|
| 1442 | + /* Replace every spaces to _ (more readable than =20) */ |
|
| 1443 | + $encoded = str_replace(' ', '_', $encoded); |
|
| 1444 | + |
|
| 1445 | + return $encoded; |
|
| 1446 | 1446 | } |
| 1447 | 1447 | |
| 1448 | 1448 | /** |
@@ -1456,16 +1456,16 @@ discard block |
||
| 1456 | 1456 | * @return void |
| 1457 | 1457 | */ |
| 1458 | 1458 | function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') { |
| 1459 | - /* Append to $attachment array */ |
|
| 1460 | - $cur = count($this->attachment); |
|
| 1461 | - $this->attachment[$cur][0] = $string; |
|
| 1462 | - $this->attachment[$cur][1] = $filename; |
|
| 1463 | - $this->attachment[$cur][2] = $filename; |
|
| 1464 | - $this->attachment[$cur][3] = $encoding; |
|
| 1465 | - $this->attachment[$cur][4] = $type; |
|
| 1466 | - $this->attachment[$cur][5] = true; // isString |
|
| 1467 | - $this->attachment[$cur][6] = 'attachment'; |
|
| 1468 | - $this->attachment[$cur][7] = 0; |
|
| 1459 | + /* Append to $attachment array */ |
|
| 1460 | + $cur = count($this->attachment); |
|
| 1461 | + $this->attachment[$cur][0] = $string; |
|
| 1462 | + $this->attachment[$cur][1] = $filename; |
|
| 1463 | + $this->attachment[$cur][2] = $filename; |
|
| 1464 | + $this->attachment[$cur][3] = $encoding; |
|
| 1465 | + $this->attachment[$cur][4] = $type; |
|
| 1466 | + $this->attachment[$cur][5] = true; // isString |
|
| 1467 | + $this->attachment[$cur][6] = 'attachment'; |
|
| 1468 | + $this->attachment[$cur][7] = 0; |
|
| 1469 | 1469 | } |
| 1470 | 1470 | |
| 1471 | 1471 | /** |
@@ -1483,28 +1483,28 @@ discard block |
||
| 1483 | 1483 | */ |
| 1484 | 1484 | function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { |
| 1485 | 1485 | |
| 1486 | - if(!@is_file($path)) { |
|
| 1487 | - $this->SetError($this->Lang('file_access') . $path); |
|
| 1488 | - return false; |
|
| 1489 | - } |
|
| 1490 | - |
|
| 1491 | - $filename = basename($path); |
|
| 1492 | - if($name == '') { |
|
| 1493 | - $name = $filename; |
|
| 1494 | - } |
|
| 1495 | - |
|
| 1496 | - /* Append to $attachment array */ |
|
| 1497 | - $cur = count($this->attachment); |
|
| 1498 | - $this->attachment[$cur][0] = $path; |
|
| 1499 | - $this->attachment[$cur][1] = $filename; |
|
| 1500 | - $this->attachment[$cur][2] = $name; |
|
| 1501 | - $this->attachment[$cur][3] = $encoding; |
|
| 1502 | - $this->attachment[$cur][4] = $type; |
|
| 1503 | - $this->attachment[$cur][5] = false; |
|
| 1504 | - $this->attachment[$cur][6] = 'inline'; |
|
| 1505 | - $this->attachment[$cur][7] = $cid; |
|
| 1506 | - |
|
| 1507 | - return true; |
|
| 1486 | + if(!@is_file($path)) { |
|
| 1487 | + $this->SetError($this->Lang('file_access') . $path); |
|
| 1488 | + return false; |
|
| 1489 | + } |
|
| 1490 | + |
|
| 1491 | + $filename = basename($path); |
|
| 1492 | + if($name == '') { |
|
| 1493 | + $name = $filename; |
|
| 1494 | + } |
|
| 1495 | + |
|
| 1496 | + /* Append to $attachment array */ |
|
| 1497 | + $cur = count($this->attachment); |
|
| 1498 | + $this->attachment[$cur][0] = $path; |
|
| 1499 | + $this->attachment[$cur][1] = $filename; |
|
| 1500 | + $this->attachment[$cur][2] = $name; |
|
| 1501 | + $this->attachment[$cur][3] = $encoding; |
|
| 1502 | + $this->attachment[$cur][4] = $type; |
|
| 1503 | + $this->attachment[$cur][5] = false; |
|
| 1504 | + $this->attachment[$cur][6] = 'inline'; |
|
| 1505 | + $this->attachment[$cur][7] = $cid; |
|
| 1506 | + |
|
| 1507 | + return true; |
|
| 1508 | 1508 | } |
| 1509 | 1509 | |
| 1510 | 1510 | /** |
@@ -1513,15 +1513,15 @@ discard block |
||
| 1513 | 1513 | * @return bool |
| 1514 | 1514 | */ |
| 1515 | 1515 | function InlineImageExists() { |
| 1516 | - $result = false; |
|
| 1517 | - for($i = 0; $i < count($this->attachment); $i++) { |
|
| 1518 | - if($this->attachment[$i][6] == 'inline') { |
|
| 1519 | - $result = true; |
|
| 1520 | - break; |
|
| 1521 | - } |
|
| 1522 | - } |
|
| 1523 | - |
|
| 1524 | - return $result; |
|
| 1516 | + $result = false; |
|
| 1517 | + for($i = 0; $i < count($this->attachment); $i++) { |
|
| 1518 | + if($this->attachment[$i][6] == 'inline') { |
|
| 1519 | + $result = true; |
|
| 1520 | + break; |
|
| 1521 | + } |
|
| 1522 | + } |
|
| 1523 | + |
|
| 1524 | + return $result; |
|
| 1525 | 1525 | } |
| 1526 | 1526 | |
| 1527 | 1527 | ///////////////////////////////////////////////// |
@@ -1533,7 +1533,7 @@ discard block |
||
| 1533 | 1533 | * @return void |
| 1534 | 1534 | */ |
| 1535 | 1535 | function ClearAddresses() { |
| 1536 | - $this->to = array(); |
|
| 1536 | + $this->to = array(); |
|
| 1537 | 1537 | } |
| 1538 | 1538 | |
| 1539 | 1539 | /** |
@@ -1541,7 +1541,7 @@ discard block |
||
| 1541 | 1541 | * @return void |
| 1542 | 1542 | */ |
| 1543 | 1543 | function ClearCCs() { |
| 1544 | - $this->cc = array(); |
|
| 1544 | + $this->cc = array(); |
|
| 1545 | 1545 | } |
| 1546 | 1546 | |
| 1547 | 1547 | /** |
@@ -1549,7 +1549,7 @@ discard block |
||
| 1549 | 1549 | * @return void |
| 1550 | 1550 | */ |
| 1551 | 1551 | function ClearBCCs() { |
| 1552 | - $this->bcc = array(); |
|
| 1552 | + $this->bcc = array(); |
|
| 1553 | 1553 | } |
| 1554 | 1554 | |
| 1555 | 1555 | /** |
@@ -1557,7 +1557,7 @@ discard block |
||
| 1557 | 1557 | * @return void |
| 1558 | 1558 | */ |
| 1559 | 1559 | function ClearReplyTos() { |
| 1560 | - $this->ReplyTo = array(); |
|
| 1560 | + $this->ReplyTo = array(); |
|
| 1561 | 1561 | } |
| 1562 | 1562 | |
| 1563 | 1563 | /** |
@@ -1566,9 +1566,9 @@ discard block |
||
| 1566 | 1566 | * @return void |
| 1567 | 1567 | */ |
| 1568 | 1568 | function ClearAllRecipients() { |
| 1569 | - $this->to = array(); |
|
| 1570 | - $this->cc = array(); |
|
| 1571 | - $this->bcc = array(); |
|
| 1569 | + $this->to = array(); |
|
| 1570 | + $this->cc = array(); |
|
| 1571 | + $this->bcc = array(); |
|
| 1572 | 1572 | } |
| 1573 | 1573 | |
| 1574 | 1574 | /** |
@@ -1577,7 +1577,7 @@ discard block |
||
| 1577 | 1577 | * @return void |
| 1578 | 1578 | */ |
| 1579 | 1579 | function ClearAttachments() { |
| 1580 | - $this->attachment = array(); |
|
| 1580 | + $this->attachment = array(); |
|
| 1581 | 1581 | } |
| 1582 | 1582 | |
| 1583 | 1583 | /** |
@@ -1585,7 +1585,7 @@ discard block |
||
| 1585 | 1585 | * @return void |
| 1586 | 1586 | */ |
| 1587 | 1587 | function ClearCustomHeaders() { |
| 1588 | - $this->CustomHeader = array(); |
|
| 1588 | + $this->CustomHeader = array(); |
|
| 1589 | 1589 | } |
| 1590 | 1590 | |
| 1591 | 1591 | ///////////////////////////////////////////////// |
@@ -1599,8 +1599,8 @@ discard block |
||
| 1599 | 1599 | * @return void |
| 1600 | 1600 | */ |
| 1601 | 1601 | function SetError($msg) { |
| 1602 | - $this->error_count++; |
|
| 1603 | - $this->ErrorInfo = $msg; |
|
| 1602 | + $this->error_count++; |
|
| 1603 | + $this->ErrorInfo = $msg; |
|
| 1604 | 1604 | } |
| 1605 | 1605 | |
| 1606 | 1606 | /** |
@@ -1609,13 +1609,13 @@ discard block |
||
| 1609 | 1609 | * @return string |
| 1610 | 1610 | */ |
| 1611 | 1611 | function RFCDate() { |
| 1612 | - $tz = date('Z'); |
|
| 1613 | - $tzs = ($tz < 0) ? '-' : '+'; |
|
| 1614 | - $tz = abs($tz); |
|
| 1615 | - $tz = (int)($tz/3600)*100 + ($tz%3600)/60; |
|
| 1616 | - $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz); |
|
| 1612 | + $tz = date('Z'); |
|
| 1613 | + $tzs = ($tz < 0) ? '-' : '+'; |
|
| 1614 | + $tz = abs($tz); |
|
| 1615 | + $tz = (int)($tz/3600)*100 + ($tz%3600)/60; |
|
| 1616 | + $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz); |
|
| 1617 | 1617 | |
| 1618 | - return $result; |
|
| 1618 | + return $result; |
|
| 1619 | 1619 | } |
| 1620 | 1620 | |
| 1621 | 1621 | /** |
@@ -1626,21 +1626,21 @@ discard block |
||
| 1626 | 1626 | * @return mixed |
| 1627 | 1627 | */ |
| 1628 | 1628 | function ServerVar($varName) { |
| 1629 | - global $HTTP_SERVER_VARS; |
|
| 1630 | - global $HTTP_ENV_VARS; |
|
| 1631 | - |
|
| 1632 | - if(!isset($_SERVER)) { |
|
| 1633 | - $_SERVER = $HTTP_SERVER_VARS; |
|
| 1634 | - if(!isset($_SERVER['REMOTE_ADDR'])) { |
|
| 1635 | - $_SERVER = $HTTP_ENV_VARS; // must be Apache |
|
| 1636 | - } |
|
| 1637 | - } |
|
| 1638 | - |
|
| 1639 | - if(isset($_SERVER[$varName])) { |
|
| 1640 | - return $_SERVER[$varName]; |
|
| 1641 | - } else { |
|
| 1642 | - return ''; |
|
| 1643 | - } |
|
| 1629 | + global $HTTP_SERVER_VARS; |
|
| 1630 | + global $HTTP_ENV_VARS; |
|
| 1631 | + |
|
| 1632 | + if(!isset($_SERVER)) { |
|
| 1633 | + $_SERVER = $HTTP_SERVER_VARS; |
|
| 1634 | + if(!isset($_SERVER['REMOTE_ADDR'])) { |
|
| 1635 | + $_SERVER = $HTTP_ENV_VARS; // must be Apache |
|
| 1636 | + } |
|
| 1637 | + } |
|
| 1638 | + |
|
| 1639 | + if(isset($_SERVER[$varName])) { |
|
| 1640 | + return $_SERVER[$varName]; |
|
| 1641 | + } else { |
|
| 1642 | + return ''; |
|
| 1643 | + } |
|
| 1644 | 1644 | } |
| 1645 | 1645 | |
| 1646 | 1646 | /** |
@@ -1649,15 +1649,15 @@ discard block |
||
| 1649 | 1649 | * @return string |
| 1650 | 1650 | */ |
| 1651 | 1651 | function ServerHostname() { |
| 1652 | - if ($this->Hostname != '') { |
|
| 1653 | - $result = $this->Hostname; |
|
| 1654 | - } elseif ($this->ServerVar('SERVER_NAME') != '') { |
|
| 1655 | - $result = $this->ServerVar('SERVER_NAME'); |
|
| 1656 | - } else { |
|
| 1657 | - $result = 'localhost.localdomain'; |
|
| 1658 | - } |
|
| 1659 | - |
|
| 1660 | - return $result; |
|
| 1652 | + if ($this->Hostname != '') { |
|
| 1653 | + $result = $this->Hostname; |
|
| 1654 | + } elseif ($this->ServerVar('SERVER_NAME') != '') { |
|
| 1655 | + $result = $this->ServerVar('SERVER_NAME'); |
|
| 1656 | + } else { |
|
| 1657 | + $result = 'localhost.localdomain'; |
|
| 1658 | + } |
|
| 1659 | + |
|
| 1660 | + return $result; |
|
| 1661 | 1661 | } |
| 1662 | 1662 | |
| 1663 | 1663 | /** |
@@ -1666,15 +1666,15 @@ discard block |
||
| 1666 | 1666 | * @return string |
| 1667 | 1667 | */ |
| 1668 | 1668 | function Lang($key) { |
| 1669 | - if(count($this->language) < 1) { |
|
| 1670 | - $this->SetLanguage('en'); // set the default language |
|
| 1671 | - } |
|
| 1672 | - |
|
| 1673 | - if(isset($this->language[$key])) { |
|
| 1674 | - return $this->language[$key]; |
|
| 1675 | - } else { |
|
| 1676 | - return 'Language string failed to load: ' . $key; |
|
| 1677 | - } |
|
| 1669 | + if(count($this->language) < 1) { |
|
| 1670 | + $this->SetLanguage('en'); // set the default language |
|
| 1671 | + } |
|
| 1672 | + |
|
| 1673 | + if(isset($this->language[$key])) { |
|
| 1674 | + return $this->language[$key]; |
|
| 1675 | + } else { |
|
| 1676 | + return 'Language string failed to load: ' . $key; |
|
| 1677 | + } |
|
| 1678 | 1678 | } |
| 1679 | 1679 | |
| 1680 | 1680 | /** |
@@ -1682,7 +1682,7 @@ discard block |
||
| 1682 | 1682 | * @return bool |
| 1683 | 1683 | */ |
| 1684 | 1684 | function IsError() { |
| 1685 | - return ($this->error_count > 0); |
|
| 1685 | + return ($this->error_count > 0); |
|
| 1686 | 1686 | } |
| 1687 | 1687 | |
| 1688 | 1688 | /** |
@@ -1691,10 +1691,10 @@ discard block |
||
| 1691 | 1691 | * @return string |
| 1692 | 1692 | */ |
| 1693 | 1693 | function FixEOL($str) { |
| 1694 | - $str = str_replace("\r\n", "\n", $str); |
|
| 1695 | - $str = str_replace("\r", "\n", $str); |
|
| 1696 | - $str = str_replace("\n", $this->LE, $str); |
|
| 1697 | - return $str; |
|
| 1694 | + $str = str_replace("\r\n", "\n", $str); |
|
| 1695 | + $str = str_replace("\r", "\n", $str); |
|
| 1696 | + $str = str_replace("\n", $this->LE, $str); |
|
| 1697 | + return $str; |
|
| 1698 | 1698 | } |
| 1699 | 1699 | |
| 1700 | 1700 | /** |
@@ -1702,7 +1702,7 @@ discard block |
||
| 1702 | 1702 | * @return void |
| 1703 | 1703 | */ |
| 1704 | 1704 | function AddCustomHeader($custom_header) { |
| 1705 | - $this->CustomHeader[] = explode(':', $custom_header, 2); |
|
| 1705 | + $this->CustomHeader[] = explode(':', $custom_header, 2); |
|
| 1706 | 1706 | } |
| 1707 | 1707 | |
| 1708 | 1708 | /** |
@@ -1711,35 +1711,35 @@ discard block |
||
| 1711 | 1711 | * @return $message |
| 1712 | 1712 | */ |
| 1713 | 1713 | function MsgHTML($message,$basedir='') { |
| 1714 | - preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images); |
|
| 1715 | - if(isset($images[2])) { |
|
| 1716 | - foreach($images[2] as $i => $url) { |
|
| 1717 | - // do not change urls for absolute images (thanks to corvuscorax) |
|
| 1718 | - if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) { |
|
| 1719 | - $filename = basename($url); |
|
| 1720 | - $directory = dirname($url); |
|
| 1721 | - ($directory == '.')?$directory='':''; |
|
| 1722 | - $cid = 'cid:' . md5($filename); |
|
| 1723 | - $fileParts = split("\.", $filename); |
|
| 1724 | - $ext = $fileParts[1]; |
|
| 1725 | - $mimeType = $this->_mime_types($ext); |
|
| 1726 | - if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; } |
|
| 1727 | - if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; } |
|
| 1728 | - if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) { |
|
| 1729 | - $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message); |
|
| 1730 | - } |
|
| 1731 | - } |
|
| 1732 | - } |
|
| 1733 | - } |
|
| 1734 | - $this->IsHTML(true); |
|
| 1735 | - $this->Body = $message; |
|
| 1736 | - $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message))); |
|
| 1737 | - if ( !empty($textMsg) && empty($this->AltBody) ) { |
|
| 1738 | - $this->AltBody = html_entity_decode($textMsg); |
|
| 1739 | - } |
|
| 1740 | - if ( empty($this->AltBody) ) { |
|
| 1741 | - $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n"; |
|
| 1742 | - } |
|
| 1714 | + preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images); |
|
| 1715 | + if(isset($images[2])) { |
|
| 1716 | + foreach($images[2] as $i => $url) { |
|
| 1717 | + // do not change urls for absolute images (thanks to corvuscorax) |
|
| 1718 | + if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) { |
|
| 1719 | + $filename = basename($url); |
|
| 1720 | + $directory = dirname($url); |
|
| 1721 | + ($directory == '.')?$directory='':''; |
|
| 1722 | + $cid = 'cid:' . md5($filename); |
|
| 1723 | + $fileParts = split("\.", $filename); |
|
| 1724 | + $ext = $fileParts[1]; |
|
| 1725 | + $mimeType = $this->_mime_types($ext); |
|
| 1726 | + if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; } |
|
| 1727 | + if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; } |
|
| 1728 | + if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) { |
|
| 1729 | + $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message); |
|
| 1730 | + } |
|
| 1731 | + } |
|
| 1732 | + } |
|
| 1733 | + } |
|
| 1734 | + $this->IsHTML(true); |
|
| 1735 | + $this->Body = $message; |
|
| 1736 | + $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message))); |
|
| 1737 | + if ( !empty($textMsg) && empty($this->AltBody) ) { |
|
| 1738 | + $this->AltBody = html_entity_decode($textMsg); |
|
| 1739 | + } |
|
| 1740 | + if ( empty($this->AltBody) ) { |
|
| 1741 | + $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n"; |
|
| 1742 | + } |
|
| 1743 | 1743 | } |
| 1744 | 1744 | |
| 1745 | 1745 | /** |
@@ -1748,95 +1748,95 @@ discard block |
||
| 1748 | 1748 | * @return mime type of ext |
| 1749 | 1749 | */ |
| 1750 | 1750 | function _mime_types($ext = '') { |
| 1751 | - $mimes = array( |
|
| 1752 | - 'ai' => 'application/postscript', |
|
| 1753 | - 'aif' => 'audio/x-aiff', |
|
| 1754 | - 'aifc' => 'audio/x-aiff', |
|
| 1755 | - 'aiff' => 'audio/x-aiff', |
|
| 1756 | - 'avi' => 'video/x-msvideo', |
|
| 1757 | - 'bin' => 'application/macbinary', |
|
| 1758 | - 'bmp' => 'image/bmp', |
|
| 1759 | - 'class' => 'application/octet-stream', |
|
| 1760 | - 'cpt' => 'application/mac-compactpro', |
|
| 1761 | - 'css' => 'text/css', |
|
| 1762 | - 'dcr' => 'application/x-director', |
|
| 1763 | - 'dir' => 'application/x-director', |
|
| 1764 | - 'dll' => 'application/octet-stream', |
|
| 1765 | - 'dms' => 'application/octet-stream', |
|
| 1766 | - 'doc' => 'application/msword', |
|
| 1767 | - 'dvi' => 'application/x-dvi', |
|
| 1768 | - 'dxr' => 'application/x-director', |
|
| 1769 | - 'eml' => 'message/rfc822', |
|
| 1770 | - 'eps' => 'application/postscript', |
|
| 1771 | - 'exe' => 'application/octet-stream', |
|
| 1772 | - 'gif' => 'image/gif', |
|
| 1773 | - 'gtar' => 'application/x-gtar', |
|
| 1774 | - 'htm' => 'text/html', |
|
| 1775 | - 'html' => 'text/html', |
|
| 1776 | - 'jpe' => 'image/jpeg', |
|
| 1777 | - 'jpeg' => 'image/jpeg', |
|
| 1778 | - 'jpg' => 'image/jpeg', |
|
| 1779 | - 'hqx' => 'application/mac-binhex40', |
|
| 1780 | - 'js' => 'application/x-javascript', |
|
| 1781 | - 'lha' => 'application/octet-stream', |
|
| 1782 | - 'log' => 'text/plain', |
|
| 1783 | - 'lzh' => 'application/octet-stream', |
|
| 1784 | - 'mid' => 'audio/midi', |
|
| 1785 | - 'midi' => 'audio/midi', |
|
| 1786 | - 'mif' => 'application/vnd.mif', |
|
| 1787 | - 'mov' => 'video/quicktime', |
|
| 1788 | - 'movie' => 'video/x-sgi-movie', |
|
| 1789 | - 'mp2' => 'audio/mpeg', |
|
| 1790 | - 'mp3' => 'audio/mpeg', |
|
| 1791 | - 'mpe' => 'video/mpeg', |
|
| 1792 | - 'mpeg' => 'video/mpeg', |
|
| 1793 | - 'mpg' => 'video/mpeg', |
|
| 1794 | - 'mpga' => 'audio/mpeg', |
|
| 1795 | - 'oda' => 'application/oda', |
|
| 1796 | - 'pdf' => 'application/pdf', |
|
| 1797 | - 'php' => 'application/x-httpd-php', |
|
| 1798 | - 'php3' => 'application/x-httpd-php', |
|
| 1799 | - 'php4' => 'application/x-httpd-php', |
|
| 1800 | - 'phps' => 'application/x-httpd-php-source', |
|
| 1801 | - 'phtml' => 'application/x-httpd-php', |
|
| 1802 | - 'png' => 'image/png', |
|
| 1803 | - 'ppt' => 'application/vnd.ms-powerpoint', |
|
| 1804 | - 'ps' => 'application/postscript', |
|
| 1805 | - 'psd' => 'application/octet-stream', |
|
| 1806 | - 'qt' => 'video/quicktime', |
|
| 1807 | - 'ra' => 'audio/x-realaudio', |
|
| 1808 | - 'ram' => 'audio/x-pn-realaudio', |
|
| 1809 | - 'rm' => 'audio/x-pn-realaudio', |
|
| 1810 | - 'rpm' => 'audio/x-pn-realaudio-plugin', |
|
| 1811 | - 'rtf' => 'text/rtf', |
|
| 1812 | - 'rtx' => 'text/richtext', |
|
| 1813 | - 'rv' => 'video/vnd.rn-realvideo', |
|
| 1814 | - 'sea' => 'application/octet-stream', |
|
| 1815 | - 'shtml' => 'text/html', |
|
| 1816 | - 'sit' => 'application/x-stuffit', |
|
| 1817 | - 'so' => 'application/octet-stream', |
|
| 1818 | - 'smi' => 'application/smil', |
|
| 1819 | - 'smil' => 'application/smil', |
|
| 1820 | - 'swf' => 'application/x-shockwave-flash', |
|
| 1821 | - 'tar' => 'application/x-tar', |
|
| 1822 | - 'text' => 'text/plain', |
|
| 1823 | - 'txt' => 'text/plain', |
|
| 1824 | - 'tgz' => 'application/x-tar', |
|
| 1825 | - 'tif' => 'image/tiff', |
|
| 1826 | - 'tiff' => 'image/tiff', |
|
| 1827 | - 'wav' => 'audio/x-wav', |
|
| 1828 | - 'wbxml' => 'application/vnd.wap.wbxml', |
|
| 1829 | - 'wmlc' => 'application/vnd.wap.wmlc', |
|
| 1830 | - 'word' => 'application/msword', |
|
| 1831 | - 'xht' => 'application/xhtml+xml', |
|
| 1832 | - 'xhtml' => 'application/xhtml+xml', |
|
| 1833 | - 'xl' => 'application/excel', |
|
| 1834 | - 'xls' => 'application/vnd.ms-excel', |
|
| 1835 | - 'xml' => 'text/xml', |
|
| 1836 | - 'xsl' => 'text/xml', |
|
| 1837 | - 'zip' => 'application/zip' |
|
| 1838 | - ); |
|
| 1839 | - return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; |
|
| 1751 | + $mimes = array( |
|
| 1752 | + 'ai' => 'application/postscript', |
|
| 1753 | + 'aif' => 'audio/x-aiff', |
|
| 1754 | + 'aifc' => 'audio/x-aiff', |
|
| 1755 | + 'aiff' => 'audio/x-aiff', |
|
| 1756 | + 'avi' => 'video/x-msvideo', |
|
| 1757 | + 'bin' => 'application/macbinary', |
|
| 1758 | + 'bmp' => 'image/bmp', |
|
| 1759 | + 'class' => 'application/octet-stream', |
|
| 1760 | + 'cpt' => 'application/mac-compactpro', |
|
| 1761 | + 'css' => 'text/css', |
|
| 1762 | + 'dcr' => 'application/x-director', |
|
| 1763 | + 'dir' => 'application/x-director', |
|
| 1764 | + 'dll' => 'application/octet-stream', |
|
| 1765 | + 'dms' => 'application/octet-stream', |
|
| 1766 | + 'doc' => 'application/msword', |
|
| 1767 | + 'dvi' => 'application/x-dvi', |
|
| 1768 | + 'dxr' => 'application/x-director', |
|
| 1769 | + 'eml' => 'message/rfc822', |
|
| 1770 | + 'eps' => 'application/postscript', |
|
| 1771 | + 'exe' => 'application/octet-stream', |
|
| 1772 | + 'gif' => 'image/gif', |
|
| 1773 | + 'gtar' => 'application/x-gtar', |
|
| 1774 | + 'htm' => 'text/html', |
|
| 1775 | + 'html' => 'text/html', |
|
| 1776 | + 'jpe' => 'image/jpeg', |
|
| 1777 | + 'jpeg' => 'image/jpeg', |
|
| 1778 | + 'jpg' => 'image/jpeg', |
|
| 1779 | + 'hqx' => 'application/mac-binhex40', |
|
| 1780 | + 'js' => 'application/x-javascript', |
|
| 1781 | + 'lha' => 'application/octet-stream', |
|
| 1782 | + 'log' => 'text/plain', |
|
| 1783 | + 'lzh' => 'application/octet-stream', |
|
| 1784 | + 'mid' => 'audio/midi', |
|
| 1785 | + 'midi' => 'audio/midi', |
|
| 1786 | + 'mif' => 'application/vnd.mif', |
|
| 1787 | + 'mov' => 'video/quicktime', |
|
| 1788 | + 'movie' => 'video/x-sgi-movie', |
|
| 1789 | + 'mp2' => 'audio/mpeg', |
|
| 1790 | + 'mp3' => 'audio/mpeg', |
|
| 1791 | + 'mpe' => 'video/mpeg', |
|
| 1792 | + 'mpeg' => 'video/mpeg', |
|
| 1793 | + 'mpg' => 'video/mpeg', |
|
| 1794 | + 'mpga' => 'audio/mpeg', |
|
| 1795 | + 'oda' => 'application/oda', |
|
| 1796 | + 'pdf' => 'application/pdf', |
|
| 1797 | + 'php' => 'application/x-httpd-php', |
|
| 1798 | + 'php3' => 'application/x-httpd-php', |
|
| 1799 | + 'php4' => 'application/x-httpd-php', |
|
| 1800 | + 'phps' => 'application/x-httpd-php-source', |
|
| 1801 | + 'phtml' => 'application/x-httpd-php', |
|
| 1802 | + 'png' => 'image/png', |
|
| 1803 | + 'ppt' => 'application/vnd.ms-powerpoint', |
|
| 1804 | + 'ps' => 'application/postscript', |
|
| 1805 | + 'psd' => 'application/octet-stream', |
|
| 1806 | + 'qt' => 'video/quicktime', |
|
| 1807 | + 'ra' => 'audio/x-realaudio', |
|
| 1808 | + 'ram' => 'audio/x-pn-realaudio', |
|
| 1809 | + 'rm' => 'audio/x-pn-realaudio', |
|
| 1810 | + 'rpm' => 'audio/x-pn-realaudio-plugin', |
|
| 1811 | + 'rtf' => 'text/rtf', |
|
| 1812 | + 'rtx' => 'text/richtext', |
|
| 1813 | + 'rv' => 'video/vnd.rn-realvideo', |
|
| 1814 | + 'sea' => 'application/octet-stream', |
|
| 1815 | + 'shtml' => 'text/html', |
|
| 1816 | + 'sit' => 'application/x-stuffit', |
|
| 1817 | + 'so' => 'application/octet-stream', |
|
| 1818 | + 'smi' => 'application/smil', |
|
| 1819 | + 'smil' => 'application/smil', |
|
| 1820 | + 'swf' => 'application/x-shockwave-flash', |
|
| 1821 | + 'tar' => 'application/x-tar', |
|
| 1822 | + 'text' => 'text/plain', |
|
| 1823 | + 'txt' => 'text/plain', |
|
| 1824 | + 'tgz' => 'application/x-tar', |
|
| 1825 | + 'tif' => 'image/tiff', |
|
| 1826 | + 'tiff' => 'image/tiff', |
|
| 1827 | + 'wav' => 'audio/x-wav', |
|
| 1828 | + 'wbxml' => 'application/vnd.wap.wbxml', |
|
| 1829 | + 'wmlc' => 'application/vnd.wap.wmlc', |
|
| 1830 | + 'word' => 'application/msword', |
|
| 1831 | + 'xht' => 'application/xhtml+xml', |
|
| 1832 | + 'xhtml' => 'application/xhtml+xml', |
|
| 1833 | + 'xl' => 'application/excel', |
|
| 1834 | + 'xls' => 'application/vnd.ms-excel', |
|
| 1835 | + 'xml' => 'text/xml', |
|
| 1836 | + 'xsl' => 'text/xml', |
|
| 1837 | + 'zip' => 'application/zip' |
|
| 1838 | + ); |
|
| 1839 | + return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; |
|
| 1840 | 1840 | } |
| 1841 | 1841 | |
| 1842 | 1842 | /** |
@@ -1851,12 +1851,12 @@ discard block |
||
| 1851 | 1851 | * NOTE: will not work with arrays, there are no arrays to set/reset |
| 1852 | 1852 | */ |
| 1853 | 1853 | function set ( $name, $value = '' ) { |
| 1854 | - if ( isset($this->$name) ) { |
|
| 1855 | - $this->$name = $value; |
|
| 1856 | - } else { |
|
| 1857 | - $this->SetError('Cannot set or reset variable ' . $name); |
|
| 1858 | - return false; |
|
| 1859 | - } |
|
| 1854 | + if ( isset($this->$name) ) { |
|
| 1855 | + $this->$name = $value; |
|
| 1856 | + } else { |
|
| 1857 | + $this->SetError('Cannot set or reset variable ' . $name); |
|
| 1858 | + return false; |
|
| 1859 | + } |
|
| 1860 | 1860 | } |
| 1861 | 1861 | |
| 1862 | 1862 | /** |
@@ -1866,16 +1866,16 @@ discard block |
||
| 1866 | 1866 | * @param string $filename Parameter File Name |
| 1867 | 1867 | */ |
| 1868 | 1868 | function getFile($filename) { |
| 1869 | - $return = ''; |
|
| 1870 | - if ($fp = fopen($filename, 'rb')) { |
|
| 1871 | - while (!feof($fp)) { |
|
| 1872 | - $return .= fread($fp, 1024); |
|
| 1873 | - } |
|
| 1874 | - fclose($fp); |
|
| 1875 | - return $return; |
|
| 1876 | - } else { |
|
| 1877 | - return false; |
|
| 1878 | - } |
|
| 1869 | + $return = ''; |
|
| 1870 | + if ($fp = fopen($filename, 'rb')) { |
|
| 1871 | + while (!feof($fp)) { |
|
| 1872 | + $return .= fread($fp, 1024); |
|
| 1873 | + } |
|
| 1874 | + fclose($fp); |
|
| 1875 | + return $return; |
|
| 1876 | + } else { |
|
| 1877 | + return false; |
|
| 1878 | + } |
|
| 1879 | 1879 | } |
| 1880 | 1880 | |
| 1881 | 1881 | /** |
@@ -1885,10 +1885,10 @@ discard block |
||
| 1885 | 1885 | * @return string |
| 1886 | 1886 | */ |
| 1887 | 1887 | function SecureHeader($str) { |
| 1888 | - $str = trim($str); |
|
| 1889 | - $str = str_replace("\r", "", $str); |
|
| 1890 | - $str = str_replace("\n", "", $str); |
|
| 1891 | - return $str; |
|
| 1888 | + $str = trim($str); |
|
| 1889 | + $str = str_replace("\r", "", $str); |
|
| 1890 | + $str = str_replace("\n", "", $str); |
|
| 1891 | + return $str; |
|
| 1892 | 1892 | } |
| 1893 | 1893 | |
| 1894 | 1894 | /** |
@@ -1899,9 +1899,9 @@ discard block |
||
| 1899 | 1899 | * @param string $key_pass Password for private key |
| 1900 | 1900 | */ |
| 1901 | 1901 | function Sign($cert_filename, $key_filename, $key_pass) { |
| 1902 | - $this->sign_cert_file = $cert_filename; |
|
| 1903 | - $this->sign_key_file = $key_filename; |
|
| 1904 | - $this->sign_key_pass = $key_pass; |
|
| 1902 | + $this->sign_cert_file = $cert_filename; |
|
| 1903 | + $this->sign_key_file = $key_filename; |
|
| 1904 | + $this->sign_key_pass = $key_pass; |
|
| 1905 | 1905 | } |
| 1906 | 1906 | |
| 1907 | 1907 | } |
@@ -1240,8 +1240,9 @@ |
||
| 1240 | 1240 | case '7bit': |
| 1241 | 1241 | case '8bit': |
| 1242 | 1242 | $encoded = $this->FixEOL($str); |
| 1243 | - if (substr($encoded, -(strlen($this->LE))) != $this->LE) |
|
| 1244 | - $encoded .= $this->LE; |
|
| 1243 | + if (substr($encoded, -(strlen($this->LE))) != $this->LE) { |
|
| 1244 | + $encoded .= $this->LE; |
|
| 1245 | + } |
|
| 1245 | 1246 | break; |
| 1246 | 1247 | case 'binary': |
| 1247 | 1248 | $encoded = $str; |
@@ -41,64 +41,64 @@ discard block |
||
| 41 | 41 | * Email priority (1 = High, 3 = Normal, 5 = low). |
| 42 | 42 | * @var int |
| 43 | 43 | */ |
| 44 | - var $Priority = 3; |
|
| 44 | + var $Priority = 3; |
|
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * Sets the CharSet of the message. |
| 48 | 48 | * @var string |
| 49 | 49 | */ |
| 50 | - var $CharSet = 'iso-8859-1'; |
|
| 50 | + var $CharSet = 'iso-8859-1'; |
|
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * Sets the Content-type of the message. |
| 54 | 54 | * @var string |
| 55 | 55 | */ |
| 56 | - var $ContentType = 'text/plain'; |
|
| 56 | + var $ContentType = 'text/plain'; |
|
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * Sets the Encoding of the message. Options for this are "8bit", |
| 60 | 60 | * "7bit", "binary", "base64", and "quoted-printable". |
| 61 | 61 | * @var string |
| 62 | 62 | */ |
| 63 | - var $Encoding = '8bit'; |
|
| 63 | + var $Encoding = '8bit'; |
|
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | 66 | * Holds the most recent mailer error message. |
| 67 | 67 | * @var string |
| 68 | 68 | */ |
| 69 | - var $ErrorInfo = ''; |
|
| 69 | + var $ErrorInfo = ''; |
|
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | 72 | * Sets the From email address for the message. |
| 73 | 73 | * @var string |
| 74 | 74 | */ |
| 75 | - var $From = 'root@localhost'; |
|
| 75 | + var $From = 'root@localhost'; |
|
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | 78 | * Sets the From name of the message. |
| 79 | 79 | * @var string |
| 80 | 80 | */ |
| 81 | - var $FromName = 'Root User'; |
|
| 81 | + var $FromName = 'Root User'; |
|
| 82 | 82 | |
| 83 | 83 | /** |
| 84 | 84 | * Sets the Sender email (Return-Path) of the message. If not empty, |
| 85 | 85 | * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode. |
| 86 | 86 | * @var string |
| 87 | 87 | */ |
| 88 | - var $Sender = ''; |
|
| 88 | + var $Sender = ''; |
|
| 89 | 89 | |
| 90 | 90 | /** |
| 91 | 91 | * Sets the Subject of the message. |
| 92 | 92 | * @var string |
| 93 | 93 | */ |
| 94 | - var $Subject = ''; |
|
| 94 | + var $Subject = ''; |
|
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | 97 | * Sets the Body of the message. This can be either an HTML or text body. |
| 98 | 98 | * If HTML then run IsHTML(true). |
| 99 | 99 | * @var string |
| 100 | 100 | */ |
| 101 | - var $Body = ''; |
|
| 101 | + var $Body = ''; |
|
| 102 | 102 | |
| 103 | 103 | /** |
| 104 | 104 | * Sets the text-only body of the message. This automatically sets the |
@@ -107,45 +107,45 @@ discard block |
||
| 107 | 107 | * that can read HTML will view the normal Body. |
| 108 | 108 | * @var string |
| 109 | 109 | */ |
| 110 | - var $AltBody = ''; |
|
| 110 | + var $AltBody = ''; |
|
| 111 | 111 | |
| 112 | 112 | /** |
| 113 | 113 | * Sets word wrapping on the body of the message to a given number of |
| 114 | 114 | * characters. |
| 115 | 115 | * @var int |
| 116 | 116 | */ |
| 117 | - var $WordWrap = 0; |
|
| 117 | + var $WordWrap = 0; |
|
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | 120 | * Method to send mail: ("mail", "sendmail", or "smtp"). |
| 121 | 121 | * @var string |
| 122 | 122 | */ |
| 123 | - var $Mailer = 'mail'; |
|
| 123 | + var $Mailer = 'mail'; |
|
| 124 | 124 | |
| 125 | 125 | /** |
| 126 | 126 | * Sets the path of the sendmail program. |
| 127 | 127 | * @var string |
| 128 | 128 | */ |
| 129 | - var $Sendmail = '/usr/sbin/sendmail'; |
|
| 129 | + var $Sendmail = '/usr/sbin/sendmail'; |
|
| 130 | 130 | |
| 131 | 131 | /** |
| 132 | 132 | * Path to PHPMailer plugins. This is now only useful if the SMTP class |
| 133 | 133 | * is in a different directory than the PHP include path. |
| 134 | 134 | * @var string |
| 135 | 135 | */ |
| 136 | - var $PluginDir = ''; |
|
| 136 | + var $PluginDir = ''; |
|
| 137 | 137 | |
| 138 | 138 | /** |
| 139 | 139 | * Holds PHPMailer version. |
| 140 | 140 | * @var string |
| 141 | 141 | */ |
| 142 | - var $Version = "2.0.4"; |
|
| 142 | + var $Version = "2.0.4"; |
|
| 143 | 143 | |
| 144 | 144 | /** |
| 145 | 145 | * Sets the email address that a reading confirmation will be sent. |
| 146 | 146 | * @var string |
| 147 | 147 | */ |
| 148 | - var $ConfirmReadingTo = ''; |
|
| 148 | + var $ConfirmReadingTo = ''; |
|
| 149 | 149 | |
| 150 | 150 | /** |
| 151 | 151 | * Sets the hostname to use in Message-Id and Received headers |
@@ -153,14 +153,14 @@ discard block |
||
| 153 | 153 | * by SERVER_NAME is used or 'localhost.localdomain'. |
| 154 | 154 | * @var string |
| 155 | 155 | */ |
| 156 | - var $Hostname = ''; |
|
| 156 | + var $Hostname = ''; |
|
| 157 | 157 | |
| 158 | 158 | /** |
| 159 | 159 | * Sets the message ID to be used in the Message-Id header. |
| 160 | 160 | * If empty, a unique id will be generated. |
| 161 | 161 | * @var string |
| 162 | 162 | */ |
| 163 | - var $MessageID = ''; |
|
| 163 | + var $MessageID = ''; |
|
| 164 | 164 | |
| 165 | 165 | ///////////////////////////////////////////////// |
| 166 | 166 | // PROPERTIES FOR SMTP |
@@ -174,19 +174,19 @@ discard block |
||
| 174 | 174 | * Hosts will be tried in order. |
| 175 | 175 | * @var string |
| 176 | 176 | */ |
| 177 | - var $Host = 'localhost'; |
|
| 177 | + var $Host = 'localhost'; |
|
| 178 | 178 | |
| 179 | 179 | /** |
| 180 | 180 | * Sets the default SMTP server port. |
| 181 | 181 | * @var int |
| 182 | 182 | */ |
| 183 | - var $Port = 25; |
|
| 183 | + var $Port = 25; |
|
| 184 | 184 | |
| 185 | 185 | /** |
| 186 | 186 | * Sets the SMTP HELO of the message (Default is $Hostname). |
| 187 | 187 | * @var string |
| 188 | 188 | */ |
| 189 | - var $Helo = ''; |
|
| 189 | + var $Helo = ''; |
|
| 190 | 190 | |
| 191 | 191 | /** |
| 192 | 192 | * Sets connection prefix. |
@@ -199,32 +199,32 @@ discard block |
||
| 199 | 199 | * Sets SMTP authentication. Utilizes the Username and Password variables. |
| 200 | 200 | * @var bool |
| 201 | 201 | */ |
| 202 | - var $SMTPAuth = false; |
|
| 202 | + var $SMTPAuth = false; |
|
| 203 | 203 | |
| 204 | 204 | /** |
| 205 | 205 | * Sets SMTP username. |
| 206 | 206 | * @var string |
| 207 | 207 | */ |
| 208 | - var $Username = ''; |
|
| 208 | + var $Username = ''; |
|
| 209 | 209 | |
| 210 | 210 | /** |
| 211 | 211 | * Sets SMTP password. |
| 212 | 212 | * @var string |
| 213 | 213 | */ |
| 214 | - var $Password = ''; |
|
| 214 | + var $Password = ''; |
|
| 215 | 215 | |
| 216 | 216 | /** |
| 217 | 217 | * Sets the SMTP server timeout in seconds. This function will not |
| 218 | 218 | * work with the win32 version. |
| 219 | 219 | * @var int |
| 220 | 220 | */ |
| 221 | - var $Timeout = 10; |
|
| 221 | + var $Timeout = 10; |
|
| 222 | 222 | |
| 223 | 223 | /** |
| 224 | 224 | * Sets SMTP class debugging on or off. |
| 225 | 225 | * @var bool |
| 226 | 226 | */ |
| 227 | - var $SMTPDebug = false; |
|
| 227 | + var $SMTPDebug = false; |
|
| 228 | 228 | |
| 229 | 229 | /** |
| 230 | 230 | * Prevents the SMTP connection from being closed after each mail |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | * @return void |
| 272 | 272 | */ |
| 273 | 273 | function IsHTML($bool) { |
| 274 | - if($bool == true) { |
|
| 274 | + if ($bool == true) { |
|
| 275 | 275 | $this->ContentType = 'text/html'; |
| 276 | 276 | } else { |
| 277 | 277 | $this->ContentType = 'text/plain'; |
@@ -382,13 +382,13 @@ discard block |
||
| 382 | 382 | $body = ''; |
| 383 | 383 | $result = true; |
| 384 | 384 | |
| 385 | - if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { |
|
| 385 | + if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { |
|
| 386 | 386 | $this->SetError($this->Lang('provide_address')); |
| 387 | 387 | return false; |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | /* Set whether the message is multipart/alternative */ |
| 391 | - if(!empty($this->AltBody)) { |
|
| 391 | + if (!empty($this->AltBody)) { |
|
| 392 | 392 | $this->ContentType = 'multipart/alternative'; |
| 393 | 393 | } |
| 394 | 394 | |
@@ -397,12 +397,12 @@ discard block |
||
| 397 | 397 | $header .= $this->CreateHeader(); |
| 398 | 398 | $body = $this->CreateBody(); |
| 399 | 399 | |
| 400 | - if($body == '') { |
|
| 400 | + if ($body == '') { |
|
| 401 | 401 | return false; |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | /* Choose the mailer */ |
| 405 | - switch($this->Mailer) { |
|
| 405 | + switch ($this->Mailer) { |
|
| 406 | 406 | case 'sendmail': |
| 407 | 407 | $result = $this->SendmailSend($header, $body); |
| 408 | 408 | break; |
@@ -435,8 +435,8 @@ discard block |
||
| 435 | 435 | $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail)); |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - if(!@$mail = popen($sendmail, 'w')) { |
|
| 439 | - $this->SetError($this->Lang('execute') . $this->Sendmail); |
|
| 438 | + if (!@$mail = popen($sendmail, 'w')) { |
|
| 439 | + $this->SetError($this->Lang('execute').$this->Sendmail); |
|
| 440 | 440 | return false; |
| 441 | 441 | } |
| 442 | 442 | |
@@ -447,8 +447,8 @@ discard block |
||
| 447 | 447 | if (version_compare(phpversion(), '4.2.3') == -1) { |
| 448 | 448 | $result = $result >> 8 & 0xFF; |
| 449 | 449 | } |
| 450 | - if($result != 0) { |
|
| 451 | - $this->SetError($this->Lang('execute') . $this->Sendmail); |
|
| 450 | + if ($result != 0) { |
|
| 451 | + $this->SetError($this->Lang('execute').$this->Sendmail); |
|
| 452 | 452 | return false; |
| 453 | 453 | } |
| 454 | 454 | return true; |
@@ -462,8 +462,8 @@ discard block |
||
| 462 | 462 | function MailSend($header, $body) { |
| 463 | 463 | |
| 464 | 464 | $to = ''; |
| 465 | - for($i = 0; $i < count($this->to); $i++) { |
|
| 466 | - if($i != 0) { $to .= ', '; } |
|
| 465 | + for ($i = 0; $i < count($this->to); $i++) { |
|
| 466 | + if ($i != 0) { $to .= ', '; } |
|
| 467 | 467 | $to .= $this->AddrFormat($this->to[$i]); |
| 468 | 468 | } |
| 469 | 469 | |
@@ -494,7 +494,7 @@ discard block |
||
| 494 | 494 | ini_set('sendmail_from', $old_from); |
| 495 | 495 | } |
| 496 | 496 | |
| 497 | - if(!$rt) { |
|
| 497 | + if (!$rt) { |
|
| 498 | 498 | $this->SetError($this->Lang('instantiate')); |
| 499 | 499 | return false; |
| 500 | 500 | } |
@@ -510,58 +510,58 @@ discard block |
||
| 510 | 510 | * @return bool |
| 511 | 511 | */ |
| 512 | 512 | function SmtpSend($header, $body) { |
| 513 | - include_once($this->PluginDir . 'class.smtp.php'); |
|
| 513 | + include_once($this->PluginDir.'class.smtp.php'); |
|
| 514 | 514 | $error = ''; |
| 515 | 515 | $bad_rcpt = array(); |
| 516 | 516 | |
| 517 | - if(!$this->SmtpConnect()) { |
|
| 517 | + if (!$this->SmtpConnect()) { |
|
| 518 | 518 | return false; |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender; |
| 522 | - if(!$this->smtp->Mail($smtp_from)) { |
|
| 523 | - $error = $this->Lang('from_failed') . $smtp_from; |
|
| 522 | + if (!$this->smtp->Mail($smtp_from)) { |
|
| 523 | + $error = $this->Lang('from_failed').$smtp_from; |
|
| 524 | 524 | $this->SetError($error); |
| 525 | 525 | $this->smtp->Reset(); |
| 526 | 526 | return false; |
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | /* Attempt to send attach all recipients */ |
| 530 | - for($i = 0; $i < count($this->to); $i++) { |
|
| 531 | - if(!$this->smtp->Recipient($this->to[$i][0])) { |
|
| 530 | + for ($i = 0; $i < count($this->to); $i++) { |
|
| 531 | + if (!$this->smtp->Recipient($this->to[$i][0])) { |
|
| 532 | 532 | $bad_rcpt[] = $this->to[$i][0]; |
| 533 | 533 | } |
| 534 | 534 | } |
| 535 | - for($i = 0; $i < count($this->cc); $i++) { |
|
| 536 | - if(!$this->smtp->Recipient($this->cc[$i][0])) { |
|
| 535 | + for ($i = 0; $i < count($this->cc); $i++) { |
|
| 536 | + if (!$this->smtp->Recipient($this->cc[$i][0])) { |
|
| 537 | 537 | $bad_rcpt[] = $this->cc[$i][0]; |
| 538 | 538 | } |
| 539 | 539 | } |
| 540 | - for($i = 0; $i < count($this->bcc); $i++) { |
|
| 541 | - if(!$this->smtp->Recipient($this->bcc[$i][0])) { |
|
| 540 | + for ($i = 0; $i < count($this->bcc); $i++) { |
|
| 541 | + if (!$this->smtp->Recipient($this->bcc[$i][0])) { |
|
| 542 | 542 | $bad_rcpt[] = $this->bcc[$i][0]; |
| 543 | 543 | } |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | - if(count($bad_rcpt) > 0) { // Create error message |
|
| 547 | - for($i = 0; $i < count($bad_rcpt); $i++) { |
|
| 548 | - if($i != 0) { |
|
| 546 | + if (count($bad_rcpt) > 0) { // Create error message |
|
| 547 | + for ($i = 0; $i < count($bad_rcpt); $i++) { |
|
| 548 | + if ($i != 0) { |
|
| 549 | 549 | $error .= ', '; |
| 550 | 550 | } |
| 551 | 551 | $error .= $bad_rcpt[$i]; |
| 552 | 552 | } |
| 553 | - $error = $this->Lang('recipients_failed') . $error; |
|
| 553 | + $error = $this->Lang('recipients_failed').$error; |
|
| 554 | 554 | $this->SetError($error); |
| 555 | 555 | $this->smtp->Reset(); |
| 556 | 556 | return false; |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | - if(!$this->smtp->Data($header . $body)) { |
|
| 559 | + if (!$this->smtp->Data($header.$body)) { |
|
| 560 | 560 | $this->SetError($this->Lang('data_not_accepted')); |
| 561 | 561 | $this->smtp->Reset(); |
| 562 | 562 | return false; |
| 563 | 563 | } |
| 564 | - if($this->SMTPKeepAlive == true) { |
|
| 564 | + if ($this->SMTPKeepAlive == true) { |
|
| 565 | 565 | $this->smtp->Reset(); |
| 566 | 566 | } else { |
| 567 | 567 | $this->SmtpClose(); |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | * @return bool |
| 578 | 578 | */ |
| 579 | 579 | function SmtpConnect() { |
| 580 | - if($this->smtp == NULL) { |
|
| 580 | + if ($this->smtp == NULL) { |
|
| 581 | 581 | $this->smtp = new SMTP(); |
| 582 | 582 | } |
| 583 | 583 | |
@@ -587,9 +587,9 @@ discard block |
||
| 587 | 587 | $connection = ($this->smtp->Connected()); |
| 588 | 588 | |
| 589 | 589 | /* Retry while there is no connection */ |
| 590 | - while($index < count($hosts) && $connection == false) { |
|
| 590 | + while ($index < count($hosts) && $connection == false) { |
|
| 591 | 591 | $hostinfo = array(); |
| 592 | - if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) { |
|
| 592 | + if (eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) { |
|
| 593 | 593 | $host = $hostinfo[1]; |
| 594 | 594 | $port = $hostinfo[2]; |
| 595 | 595 | } else { |
@@ -597,7 +597,7 @@ discard block |
||
| 597 | 597 | $port = $this->Port; |
| 598 | 598 | } |
| 599 | 599 | |
| 600 | - if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) { |
|
| 600 | + if ($this->smtp->Connect(((!empty($this->SMTPSecure)) ? $this->SMTPSecure.'://' : '').$host, $port, $this->Timeout)) { |
|
| 601 | 601 | if ($this->Helo != '') { |
| 602 | 602 | $this->smtp->Hello($this->Helo); |
| 603 | 603 | } else { |
@@ -605,8 +605,8 @@ discard block |
||
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | $connection = true; |
| 608 | - if($this->SMTPAuth) { |
|
| 609 | - if(!$this->smtp->Authenticate($this->Username, $this->Password)) { |
|
| 608 | + if ($this->SMTPAuth) { |
|
| 609 | + if (!$this->smtp->Authenticate($this->Username, $this->Password)) { |
|
| 610 | 610 | $this->SetError($this->Lang('authenticate')); |
| 611 | 611 | $this->smtp->Reset(); |
| 612 | 612 | $connection = false; |
@@ -615,7 +615,7 @@ discard block |
||
| 615 | 615 | } |
| 616 | 616 | $index++; |
| 617 | 617 | } |
| 618 | - if(!$connection) { |
|
| 618 | + if (!$connection) { |
|
| 619 | 619 | $this->SetError($this->Lang('connect_host')); |
| 620 | 620 | } |
| 621 | 621 | |
@@ -627,8 +627,8 @@ discard block |
||
| 627 | 627 | * @return void |
| 628 | 628 | */ |
| 629 | 629 | function SmtpClose() { |
| 630 | - if($this->smtp != NULL) { |
|
| 631 | - if($this->smtp->Connected()) { |
|
| 630 | + if ($this->smtp != NULL) { |
|
| 631 | + if ($this->smtp->Connected()) { |
|
| 632 | 632 | $this->smtp->Quit(); |
| 633 | 633 | $this->smtp->Close(); |
| 634 | 634 | } |
@@ -645,19 +645,19 @@ discard block |
||
| 645 | 645 | * @return bool |
| 646 | 646 | */ |
| 647 | 647 | function SetLanguage($lang_type, $lang_path = 'language/') { |
| 648 | - if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) { |
|
| 648 | + if (file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) { |
|
| 649 | 649 | include($lang_path.'phpmailer.lang-'.$lang_type.'.php'); |
| 650 | 650 | } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) { |
| 651 | 651 | include($lang_path.'phpmailer.lang-en.php'); |
| 652 | 652 | } else { |
| 653 | 653 | $PHPMAILER_LANG = array(); |
| 654 | - $PHPMAILER_LANG["provide_address"] = 'You must provide at least one ' . |
|
| 654 | + $PHPMAILER_LANG["provide_address"] = 'You must provide at least one '. |
|
| 655 | 655 | $PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.'; |
| 656 | 656 | $PHPMAILER_LANG["execute"] = 'Could not execute: '; |
| 657 | 657 | $PHPMAILER_LANG["instantiate"] = 'Could not instantiate mail function.'; |
| 658 | 658 | $PHPMAILER_LANG["authenticate"] = 'SMTP Error: Could not authenticate.'; |
| 659 | 659 | $PHPMAILER_LANG["from_failed"] = 'The following From address failed: '; |
| 660 | - $PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: The following ' . |
|
| 660 | + $PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: The following '. |
|
| 661 | 661 | $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: Data not accepted.'; |
| 662 | 662 | $PHPMAILER_LANG["connect_host"] = 'SMTP Error: Could not connect to SMTP host.'; |
| 663 | 663 | $PHPMAILER_LANG["file_access"] = 'Could not access file: '; |
@@ -680,11 +680,11 @@ discard block |
||
| 680 | 680 | * @return string |
| 681 | 681 | */ |
| 682 | 682 | function AddrAppend($type, $addr) { |
| 683 | - $addr_str = $type . ': '; |
|
| 683 | + $addr_str = $type.': '; |
|
| 684 | 684 | $addr_str .= $this->AddrFormat($addr[0]); |
| 685 | - if(count($addr) > 1) { |
|
| 686 | - for($i = 1; $i < count($addr); $i++) { |
|
| 687 | - $addr_str .= ', ' . $this->AddrFormat($addr[$i]); |
|
| 685 | + if (count($addr) > 1) { |
|
| 686 | + for ($i = 1; $i < count($addr); $i++) { |
|
| 687 | + $addr_str .= ', '.$this->AddrFormat($addr[$i]); |
|
| 688 | 688 | } |
| 689 | 689 | } |
| 690 | 690 | $addr_str .= $this->LE; |
@@ -698,10 +698,10 @@ discard block |
||
| 698 | 698 | * @return string |
| 699 | 699 | */ |
| 700 | 700 | function AddrFormat($addr) { |
| 701 | - if(empty($addr[1])) { |
|
| 701 | + if (empty($addr[1])) { |
|
| 702 | 702 | $formatted = $this->SecureHeader($addr[0]); |
| 703 | 703 | } else { |
| 704 | - $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">"; |
|
| 704 | + $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase')." <".$this->SecureHeader($addr[0]).">"; |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | return $formatted; |
@@ -727,10 +727,10 @@ discard block |
||
| 727 | 727 | |
| 728 | 728 | $line = explode($this->LE, $message); |
| 729 | 729 | $message = ''; |
| 730 | - for ($i=0 ;$i < count($line); $i++) { |
|
| 730 | + for ($i = 0; $i < count($line); $i++) { |
|
| 731 | 731 | $line_part = explode(' ', $line[$i]); |
| 732 | 732 | $buf = ''; |
| 733 | - for ($e = 0; $e<count($line_part); $e++) { |
|
| 733 | + for ($e = 0; $e < count($line_part); $e++) { |
|
| 734 | 734 | $word = $line_part[$e]; |
| 735 | 735 | if ($qp_mode and (strlen($word) > $length)) { |
| 736 | 736 | $space_left = $length - strlen($buf) - 1; |
@@ -746,10 +746,10 @@ discard block |
||
| 746 | 746 | } |
| 747 | 747 | $part = substr($word, 0, $len); |
| 748 | 748 | $word = substr($word, $len); |
| 749 | - $buf .= ' ' . $part; |
|
| 750 | - $message .= $buf . sprintf("=%s", $this->LE); |
|
| 749 | + $buf .= ' '.$part; |
|
| 750 | + $message .= $buf.sprintf("=%s", $this->LE); |
|
| 751 | 751 | } else { |
| 752 | - $message .= $buf . $soft_break; |
|
| 752 | + $message .= $buf.$soft_break; |
|
| 753 | 753 | } |
| 754 | 754 | $buf = ''; |
| 755 | 755 | } |
@@ -766,22 +766,22 @@ discard block |
||
| 766 | 766 | $word = substr($word, $len); |
| 767 | 767 | |
| 768 | 768 | if (strlen($word) > 0) { |
| 769 | - $message .= $part . sprintf("=%s", $this->LE); |
|
| 769 | + $message .= $part.sprintf("=%s", $this->LE); |
|
| 770 | 770 | } else { |
| 771 | 771 | $buf = $part; |
| 772 | 772 | } |
| 773 | 773 | } |
| 774 | 774 | } else { |
| 775 | 775 | $buf_o = $buf; |
| 776 | - $buf .= ($e == 0) ? $word : (' ' . $word); |
|
| 776 | + $buf .= ($e == 0) ? $word : (' '.$word); |
|
| 777 | 777 | |
| 778 | 778 | if (strlen($buf) > $length and $buf_o != '') { |
| 779 | - $message .= $buf_o . $soft_break; |
|
| 779 | + $message .= $buf_o.$soft_break; |
|
| 780 | 780 | $buf = $word; |
| 781 | 781 | } |
| 782 | 782 | } |
| 783 | 783 | } |
| 784 | - $message .= $buf . $this->LE; |
|
| 784 | + $message .= $buf.$this->LE; |
|
| 785 | 785 | } |
| 786 | 786 | |
| 787 | 787 | return $message; |
@@ -810,8 +810,7 @@ discard block |
||
| 810 | 810 | if ($dec < 128) { // Single byte character. |
| 811 | 811 | // If the encoded char was found at pos 0, it will fit |
| 812 | 812 | // otherwise reduce maxLength to start of the encoded char |
| 813 | - $maxLength = ($encodedCharPos == 0) ? $maxLength : |
|
| 814 | - $maxLength - ($lookBack - $encodedCharPos); |
|
| 813 | + $maxLength = ($encodedCharPos == 0) ? $maxLength : $maxLength - ($lookBack - $encodedCharPos); |
|
| 815 | 814 | $foundSplitPos = true; |
| 816 | 815 | } elseif ($dec >= 192) { // First byte of a multi byte character |
| 817 | 816 | // Reduce maxLength to split at start of character |
@@ -834,11 +833,11 @@ discard block |
||
| 834 | 833 | * @return void |
| 835 | 834 | */ |
| 836 | 835 | function SetWordWrap() { |
| 837 | - if($this->WordWrap < 1) { |
|
| 836 | + if ($this->WordWrap < 1) { |
|
| 838 | 837 | return; |
| 839 | 838 | } |
| 840 | 839 | |
| 841 | - switch($this->message_type) { |
|
| 840 | + switch ($this->message_type) { |
|
| 842 | 841 | case 'alt': |
| 843 | 842 | /* fall through */ |
| 844 | 843 | case 'alt_attachments': |
@@ -860,19 +859,19 @@ discard block |
||
| 860 | 859 | |
| 861 | 860 | /* Set the boundaries */ |
| 862 | 861 | $uniq_id = md5(uniqid(time())); |
| 863 | - $this->boundary[1] = 'b1_' . $uniq_id; |
|
| 864 | - $this->boundary[2] = 'b2_' . $uniq_id; |
|
| 862 | + $this->boundary[1] = 'b1_'.$uniq_id; |
|
| 863 | + $this->boundary[2] = 'b2_'.$uniq_id; |
|
| 865 | 864 | |
| 866 | 865 | $result .= $this->HeaderLine('Date', $this->RFCDate()); |
| 867 | - if($this->Sender == '') { |
|
| 866 | + if ($this->Sender == '') { |
|
| 868 | 867 | $result .= $this->HeaderLine('Return-Path', trim($this->From)); |
| 869 | 868 | } else { |
| 870 | 869 | $result .= $this->HeaderLine('Return-Path', trim($this->Sender)); |
| 871 | 870 | } |
| 872 | 871 | |
| 873 | 872 | /* To be created automatically by mail() */ |
| 874 | - if($this->Mailer != 'mail') { |
|
| 875 | - if(count($this->to) > 0) { |
|
| 873 | + if ($this->Mailer != 'mail') { |
|
| 874 | + if (count($this->to) > 0) { |
|
| 876 | 875 | $result .= $this->AddrAppend('To', $this->to); |
| 877 | 876 | } elseif (count($this->cc) == 0) { |
| 878 | 877 | $result .= $this->HeaderLine('To', 'undisclosed-recipients:;'); |
@@ -885,38 +884,38 @@ discard block |
||
| 885 | 884 | $result .= $this->AddrAppend('From', $from); |
| 886 | 885 | |
| 887 | 886 | /* sendmail and mail() extract Cc from the header before sending */ |
| 888 | - if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) { |
|
| 887 | + if ((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) { |
|
| 889 | 888 | $result .= $this->AddrAppend('Cc', $this->cc); |
| 890 | 889 | } |
| 891 | 890 | |
| 892 | 891 | /* sendmail and mail() extract Bcc from the header before sending */ |
| 893 | - if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) { |
|
| 892 | + if ((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) { |
|
| 894 | 893 | $result .= $this->AddrAppend('Bcc', $this->bcc); |
| 895 | 894 | } |
| 896 | 895 | |
| 897 | - if(count($this->ReplyTo) > 0) { |
|
| 896 | + if (count($this->ReplyTo) > 0) { |
|
| 898 | 897 | $result .= $this->AddrAppend('Reply-To', $this->ReplyTo); |
| 899 | 898 | } |
| 900 | 899 | |
| 901 | 900 | /* mail() sets the subject itself */ |
| 902 | - if($this->Mailer != 'mail') { |
|
| 901 | + if ($this->Mailer != 'mail') { |
|
| 903 | 902 | $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject))); |
| 904 | 903 | } |
| 905 | 904 | |
| 906 | - if($this->MessageID != '') { |
|
| 907 | - $result .= $this->HeaderLine('Message-ID',$this->MessageID); |
|
| 905 | + if ($this->MessageID != '') { |
|
| 906 | + $result .= $this->HeaderLine('Message-ID', $this->MessageID); |
|
| 908 | 907 | } else { |
| 909 | 908 | $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); |
| 910 | 909 | } |
| 911 | 910 | $result .= $this->HeaderLine('X-Priority', $this->Priority); |
| 912 | - $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version ' . $this->Version . ']'); |
|
| 911 | + $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version '.$this->Version.']'); |
|
| 913 | 912 | |
| 914 | - if($this->ConfirmReadingTo != '') { |
|
| 915 | - $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>'); |
|
| 913 | + if ($this->ConfirmReadingTo != '') { |
|
| 914 | + $result .= $this->HeaderLine('Disposition-Notification-To', '<'.trim($this->ConfirmReadingTo).'>'); |
|
| 916 | 915 | } |
| 917 | 916 | |
| 918 | 917 | // Add custom headers |
| 919 | - for($index = 0; $index < count($this->CustomHeader); $index++) { |
|
| 918 | + for ($index = 0; $index < count($this->CustomHeader); $index++) { |
|
| 920 | 919 | $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1]))); |
| 921 | 920 | } |
| 922 | 921 | if (!$this->sign_key_file) { |
@@ -934,7 +933,7 @@ discard block |
||
| 934 | 933 | */ |
| 935 | 934 | function GetMailMIME() { |
| 936 | 935 | $result = ''; |
| 937 | - switch($this->message_type) { |
|
| 936 | + switch ($this->message_type) { |
|
| 938 | 937 | case 'plain': |
| 939 | 938 | $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); |
| 940 | 939 | $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet); |
@@ -942,20 +941,20 @@ discard block |
||
| 942 | 941 | case 'attachments': |
| 943 | 942 | /* fall through */ |
| 944 | 943 | case 'alt_attachments': |
| 945 | - if($this->InlineImageExists()){ |
|
| 944 | + if ($this->InlineImageExists()) { |
|
| 946 | 945 | $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE); |
| 947 | 946 | } else { |
| 948 | 947 | $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;'); |
| 949 | - $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|
| 948 | + $result .= $this->TextLine("\tboundary=\"".$this->boundary[1].'"'); |
|
| 950 | 949 | } |
| 951 | 950 | break; |
| 952 | 951 | case 'alt': |
| 953 | 952 | $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); |
| 954 | - $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|
| 953 | + $result .= $this->TextLine("\tboundary=\"".$this->boundary[1].'"'); |
|
| 955 | 954 | break; |
| 956 | 955 | } |
| 957 | 956 | |
| 958 | - if($this->Mailer != 'mail') { |
|
| 957 | + if ($this->Mailer != 'mail') { |
|
| 959 | 958 | $result .= $this->LE.$this->LE; |
| 960 | 959 | } |
| 961 | 960 | |
@@ -975,7 +974,7 @@ discard block |
||
| 975 | 974 | |
| 976 | 975 | $this->SetWordWrap(); |
| 977 | 976 | |
| 978 | - switch($this->message_type) { |
|
| 977 | + switch ($this->message_type) { |
|
| 979 | 978 | case 'alt': |
| 980 | 979 | $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', ''); |
| 981 | 980 | $result .= $this->EncodeString($this->AltBody, $this->Encoding); |
@@ -996,11 +995,11 @@ discard block |
||
| 996 | 995 | break; |
| 997 | 996 | case 'alt_attachments': |
| 998 | 997 | $result .= sprintf("--%s%s", $this->boundary[1], $this->LE); |
| 999 | - $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE); |
|
| 1000 | - $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body |
|
| 998 | + $result .= sprintf("Content-Type: %s;%s"."\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE); |
|
| 999 | + $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '').$this->LE; // Create text body |
|
| 1001 | 1000 | $result .= $this->EncodeString($this->AltBody, $this->Encoding); |
| 1002 | 1001 | $result .= $this->LE.$this->LE; |
| 1003 | - $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body |
|
| 1002 | + $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '').$this->LE; // Create the HTML body |
|
| 1004 | 1003 | $result .= $this->EncodeString($this->Body, $this->Encoding); |
| 1005 | 1004 | $result .= $this->LE.$this->LE; |
| 1006 | 1005 | $result .= $this->EndBoundary($this->boundary[2]); |
@@ -1008,7 +1007,7 @@ discard block |
||
| 1008 | 1007 | break; |
| 1009 | 1008 | } |
| 1010 | 1009 | |
| 1011 | - if($this->IsError()) { |
|
| 1010 | + if ($this->IsError()) { |
|
| 1012 | 1011 | $result = ''; |
| 1013 | 1012 | } else if ($this->sign_key_file) { |
| 1014 | 1013 | $file = tempnam("", "mail"); |
@@ -1021,8 +1020,8 @@ discard block |
||
| 1021 | 1020 | $fp = fopen($signed, "r"); |
| 1022 | 1021 | $result = fread($fp, filesize($this->sign_key_file)); |
| 1023 | 1022 | $result = ''; |
| 1024 | - while(!feof($fp)){ |
|
| 1025 | - $result = $result . fread($fp, 1024); |
|
| 1023 | + while (!feof($fp)) { |
|
| 1024 | + $result = $result.fread($fp, 1024); |
|
| 1026 | 1025 | } |
| 1027 | 1026 | fclose($fp); |
| 1028 | 1027 | } else { |
@@ -1043,16 +1042,16 @@ discard block |
||
| 1043 | 1042 | */ |
| 1044 | 1043 | function GetBoundary($boundary, $charSet, $contentType, $encoding) { |
| 1045 | 1044 | $result = ''; |
| 1046 | - if($charSet == '') { |
|
| 1045 | + if ($charSet == '') { |
|
| 1047 | 1046 | $charSet = $this->CharSet; |
| 1048 | 1047 | } |
| 1049 | - if($contentType == '') { |
|
| 1048 | + if ($contentType == '') { |
|
| 1050 | 1049 | $contentType = $this->ContentType; |
| 1051 | 1050 | } |
| 1052 | - if($encoding == '') { |
|
| 1051 | + if ($encoding == '') { |
|
| 1053 | 1052 | $encoding = $this->Encoding; |
| 1054 | 1053 | } |
| 1055 | - $result .= $this->TextLine('--' . $boundary); |
|
| 1054 | + $result .= $this->TextLine('--'.$boundary); |
|
| 1056 | 1055 | $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet); |
| 1057 | 1056 | $result .= $this->LE; |
| 1058 | 1057 | $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding); |
@@ -1066,7 +1065,7 @@ discard block |
||
| 1066 | 1065 | * @access private |
| 1067 | 1066 | */ |
| 1068 | 1067 | function EndBoundary($boundary) { |
| 1069 | - return $this->LE . '--' . $boundary . '--' . $this->LE; |
|
| 1068 | + return $this->LE.'--'.$boundary.'--'.$this->LE; |
|
| 1070 | 1069 | } |
| 1071 | 1070 | |
| 1072 | 1071 | /** |
@@ -1075,16 +1074,16 @@ discard block |
||
| 1075 | 1074 | * @return void |
| 1076 | 1075 | */ |
| 1077 | 1076 | function SetMessageType() { |
| 1078 | - if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) { |
|
| 1077 | + if (count($this->attachment) < 1 && strlen($this->AltBody) < 1) { |
|
| 1079 | 1078 | $this->message_type = 'plain'; |
| 1080 | 1079 | } else { |
| 1081 | - if(count($this->attachment) > 0) { |
|
| 1080 | + if (count($this->attachment) > 0) { |
|
| 1082 | 1081 | $this->message_type = 'attachments'; |
| 1083 | 1082 | } |
| 1084 | - if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) { |
|
| 1083 | + if (strlen($this->AltBody) > 0 && count($this->attachment) < 1) { |
|
| 1085 | 1084 | $this->message_type = 'alt'; |
| 1086 | 1085 | } |
| 1087 | - if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) { |
|
| 1086 | + if (strlen($this->AltBody) > 0 && count($this->attachment) > 0) { |
|
| 1088 | 1087 | $this->message_type = 'alt_attachments'; |
| 1089 | 1088 | } |
| 1090 | 1089 | } |
@@ -1095,7 +1094,7 @@ discard block |
||
| 1095 | 1094 | * @return string |
| 1096 | 1095 | */ |
| 1097 | 1096 | function HeaderLine($name, $value) { |
| 1098 | - return $name . ': ' . $value . $this->LE; |
|
| 1097 | + return $name.': '.$value.$this->LE; |
|
| 1099 | 1098 | } |
| 1100 | 1099 | |
| 1101 | 1100 | /** |
@@ -1104,7 +1103,7 @@ discard block |
||
| 1104 | 1103 | * @return string |
| 1105 | 1104 | */ |
| 1106 | 1105 | function TextLine($value) { |
| 1107 | - return $value . $this->LE; |
|
| 1106 | + return $value.$this->LE; |
|
| 1108 | 1107 | } |
| 1109 | 1108 | |
| 1110 | 1109 | ///////////////////////////////////////////////// |
@@ -1122,13 +1121,13 @@ discard block |
||
| 1122 | 1121 | * @return bool |
| 1123 | 1122 | */ |
| 1124 | 1123 | function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { |
| 1125 | - if(!@is_file($path)) { |
|
| 1126 | - $this->SetError($this->Lang('file_access') . $path); |
|
| 1124 | + if (!@is_file($path)) { |
|
| 1125 | + $this->SetError($this->Lang('file_access').$path); |
|
| 1127 | 1126 | return false; |
| 1128 | 1127 | } |
| 1129 | 1128 | |
| 1130 | 1129 | $filename = basename($path); |
| 1131 | - if($name == '') { |
|
| 1130 | + if ($name == '') { |
|
| 1132 | 1131 | $name = $filename; |
| 1133 | 1132 | } |
| 1134 | 1133 | |
@@ -1156,7 +1155,7 @@ discard block |
||
| 1156 | 1155 | $mime = array(); |
| 1157 | 1156 | |
| 1158 | 1157 | /* Add all attachments */ |
| 1159 | - for($i = 0; $i < count($this->attachment); $i++) { |
|
| 1158 | + for ($i = 0; $i < count($this->attachment); $i++) { |
|
| 1160 | 1159 | /* Check for string attachment */ |
| 1161 | 1160 | $bString = $this->attachment[$i][5]; |
| 1162 | 1161 | if ($bString) { |
@@ -1176,22 +1175,22 @@ discard block |
||
| 1176 | 1175 | $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE); |
| 1177 | 1176 | $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE); |
| 1178 | 1177 | |
| 1179 | - if($disposition == 'inline') { |
|
| 1178 | + if ($disposition == 'inline') { |
|
| 1180 | 1179 | $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE); |
| 1181 | 1180 | } |
| 1182 | 1181 | |
| 1183 | 1182 | $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE); |
| 1184 | 1183 | |
| 1185 | 1184 | /* Encode as string attachment */ |
| 1186 | - if($bString) { |
|
| 1185 | + if ($bString) { |
|
| 1187 | 1186 | $mime[] = $this->EncodeString($string, $encoding); |
| 1188 | - if($this->IsError()) { |
|
| 1187 | + if ($this->IsError()) { |
|
| 1189 | 1188 | return ''; |
| 1190 | 1189 | } |
| 1191 | 1190 | $mime[] = $this->LE.$this->LE; |
| 1192 | 1191 | } else { |
| 1193 | 1192 | $mime[] = $this->EncodeFile($path, $encoding); |
| 1194 | - if($this->IsError()) { |
|
| 1193 | + if ($this->IsError()) { |
|
| 1195 | 1194 | return ''; |
| 1196 | 1195 | } |
| 1197 | 1196 | $mime[] = $this->LE.$this->LE; |
@@ -1209,9 +1208,9 @@ discard block |
||
| 1209 | 1208 | * @access private |
| 1210 | 1209 | * @return string |
| 1211 | 1210 | */ |
| 1212 | - function EncodeFile ($path, $encoding = 'base64') { |
|
| 1213 | - if(!@$fd = fopen($path, 'rb')) { |
|
| 1214 | - $this->SetError($this->Lang('file_open') . $path); |
|
| 1211 | + function EncodeFile($path, $encoding = 'base64') { |
|
| 1212 | + if (!@$fd = fopen($path, 'rb')) { |
|
| 1213 | + $this->SetError($this->Lang('file_open').$path); |
|
| 1215 | 1214 | return ''; |
| 1216 | 1215 | } |
| 1217 | 1216 | $magic_quotes = get_magic_quotes_runtime(); |
@@ -1230,9 +1229,9 @@ discard block |
||
| 1230 | 1229 | * @access private |
| 1231 | 1230 | * @return string |
| 1232 | 1231 | */ |
| 1233 | - function EncodeString ($str, $encoding = 'base64') { |
|
| 1232 | + function EncodeString($str, $encoding = 'base64') { |
|
| 1234 | 1233 | $encoded = ''; |
| 1235 | - switch(strtolower($encoding)) { |
|
| 1234 | + switch (strtolower($encoding)) { |
|
| 1236 | 1235 | case 'base64': |
| 1237 | 1236 | /* chunk_split is found in PHP >= 3.0.6 */ |
| 1238 | 1237 | $encoded = chunk_split(base64_encode($str), 76, $this->LE); |
@@ -1250,7 +1249,7 @@ discard block |
||
| 1250 | 1249 | $encoded = $this->EncodeQP($str); |
| 1251 | 1250 | break; |
| 1252 | 1251 | default: |
| 1253 | - $this->SetError($this->Lang('encoding') . $encoding); |
|
| 1252 | + $this->SetError($this->Lang('encoding').$encoding); |
|
| 1254 | 1253 | break; |
| 1255 | 1254 | } |
| 1256 | 1255 | return $encoded; |
@@ -1261,7 +1260,7 @@ discard block |
||
| 1261 | 1260 | * @access private |
| 1262 | 1261 | * @return string |
| 1263 | 1262 | */ |
| 1264 | - function EncodeHeader ($str, $position = 'text') { |
|
| 1263 | + function EncodeHeader($str, $position = 'text') { |
|
| 1265 | 1264 | $x = 0; |
| 1266 | 1265 | |
| 1267 | 1266 | switch (strtolower($position)) { |
@@ -1292,7 +1291,7 @@ discard block |
||
| 1292 | 1291 | |
| 1293 | 1292 | $maxlen = 75 - 7 - strlen($this->CharSet); |
| 1294 | 1293 | /* Try to select the encoding which should produce the shortest output */ |
| 1295 | - if (strlen($str)/3 < $x) { |
|
| 1294 | + if (strlen($str) / 3 < $x) { |
|
| 1296 | 1295 | $encoding = 'B'; |
| 1297 | 1296 | if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) { |
| 1298 | 1297 | // Use a custom function which correctly encodes and wraps long |
@@ -1362,7 +1361,7 @@ discard block |
||
| 1362 | 1361 | } |
| 1363 | 1362 | while (strlen($chunk) > $length); |
| 1364 | 1363 | |
| 1365 | - $encoded .= $chunk . $this->LE; |
|
| 1364 | + $encoded .= $chunk.$this->LE; |
|
| 1366 | 1365 | } |
| 1367 | 1366 | |
| 1368 | 1367 | // Chomp the last linefeed |
@@ -1375,37 +1374,37 @@ discard block |
||
| 1375 | 1374 | * @access private |
| 1376 | 1375 | * @return string |
| 1377 | 1376 | */ |
| 1378 | - function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) { |
|
| 1379 | - $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
|
| 1377 | + function EncodeQP($input = '', $line_max = 76, $space_conv = false) { |
|
| 1378 | + $hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
|
| 1380 | 1379 | $lines = preg_split('/(?:\r\n|\r|\n)/', $input); |
| 1381 | 1380 | $eol = "\r\n"; |
| 1382 | 1381 | $escape = '='; |
| 1383 | 1382 | $output = ''; |
| 1384 | - while( list(, $line) = each($lines) ) { |
|
| 1383 | + while (list(, $line) = each($lines)) { |
|
| 1385 | 1384 | $linlen = strlen($line); |
| 1386 | 1385 | $newline = ''; |
| 1387 | - for($i = 0; $i < $linlen; $i++) { |
|
| 1388 | - $c = substr( $line, $i, 1 ); |
|
| 1389 | - $dec = ord( $c ); |
|
| 1390 | - if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E |
|
| 1386 | + for ($i = 0; $i < $linlen; $i++) { |
|
| 1387 | + $c = substr($line, $i, 1); |
|
| 1388 | + $dec = ord($c); |
|
| 1389 | + if (($i == 0) && ($dec == 46)) { // convert first point in the line into =2E |
|
| 1391 | 1390 | $c = '=2E'; |
| 1392 | 1391 | } |
| 1393 | - if ( $dec == 32 ) { |
|
| 1394 | - if ( $i == ( $linlen - 1 ) ) { // convert space at eol only |
|
| 1392 | + if ($dec == 32) { |
|
| 1393 | + if ($i == ($linlen - 1)) { // convert space at eol only |
|
| 1395 | 1394 | $c = '=20'; |
| 1396 | - } else if ( $space_conv ) { |
|
| 1395 | + } else if ($space_conv) { |
|
| 1397 | 1396 | $c = '=20'; |
| 1398 | 1397 | } |
| 1399 | - } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required |
|
| 1400 | - $h2 = floor($dec/16); |
|
| 1401 | - $h1 = floor($dec%16); |
|
| 1398 | + } elseif (($dec == 61) || ($dec < 32) || ($dec > 126)) { // always encode "\t", which is *not* required |
|
| 1399 | + $h2 = floor($dec / 16); |
|
| 1400 | + $h1 = floor($dec % 16); |
|
| 1402 | 1401 | $c = $escape.$hex[$h2].$hex[$h1]; |
| 1403 | 1402 | } |
| 1404 | - if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted |
|
| 1403 | + if ((strlen($newline) + strlen($c)) >= $line_max) { // CRLF is not counted |
|
| 1405 | 1404 | $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay |
| 1406 | 1405 | $newline = ''; |
| 1407 | 1406 | // check if newline first character will be point or not |
| 1408 | - if ( $dec == 46 ) { |
|
| 1407 | + if ($dec == 46) { |
|
| 1409 | 1408 | $c = '=2E'; |
| 1410 | 1409 | } |
| 1411 | 1410 | } |
@@ -1421,7 +1420,7 @@ discard block |
||
| 1421 | 1420 | * @access private |
| 1422 | 1421 | * @return string |
| 1423 | 1422 | */ |
| 1424 | - function EncodeQ ($str, $position = 'text') { |
|
| 1423 | + function EncodeQ($str, $position = 'text') { |
|
| 1425 | 1424 | /* There should not be any EOL in the string */ |
| 1426 | 1425 | $encoded = preg_replace("[\r\n]", '', $str); |
| 1427 | 1426 | |
@@ -1483,13 +1482,13 @@ discard block |
||
| 1483 | 1482 | */ |
| 1484 | 1483 | function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { |
| 1485 | 1484 | |
| 1486 | - if(!@is_file($path)) { |
|
| 1487 | - $this->SetError($this->Lang('file_access') . $path); |
|
| 1485 | + if (!@is_file($path)) { |
|
| 1486 | + $this->SetError($this->Lang('file_access').$path); |
|
| 1488 | 1487 | return false; |
| 1489 | 1488 | } |
| 1490 | 1489 | |
| 1491 | 1490 | $filename = basename($path); |
| 1492 | - if($name == '') { |
|
| 1491 | + if ($name == '') { |
|
| 1493 | 1492 | $name = $filename; |
| 1494 | 1493 | } |
| 1495 | 1494 | |
@@ -1514,8 +1513,8 @@ discard block |
||
| 1514 | 1513 | */ |
| 1515 | 1514 | function InlineImageExists() { |
| 1516 | 1515 | $result = false; |
| 1517 | - for($i = 0; $i < count($this->attachment); $i++) { |
|
| 1518 | - if($this->attachment[$i][6] == 'inline') { |
|
| 1516 | + for ($i = 0; $i < count($this->attachment); $i++) { |
|
| 1517 | + if ($this->attachment[$i][6] == 'inline') { |
|
| 1519 | 1518 | $result = true; |
| 1520 | 1519 | break; |
| 1521 | 1520 | } |
@@ -1612,7 +1611,7 @@ discard block |
||
| 1612 | 1611 | $tz = date('Z'); |
| 1613 | 1612 | $tzs = ($tz < 0) ? '-' : '+'; |
| 1614 | 1613 | $tz = abs($tz); |
| 1615 | - $tz = (int)($tz/3600)*100 + ($tz%3600)/60; |
|
| 1614 | + $tz = (int) ($tz / 3600) * 100 + ($tz % 3600) / 60; |
|
| 1616 | 1615 | $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz); |
| 1617 | 1616 | |
| 1618 | 1617 | return $result; |
@@ -1629,14 +1628,14 @@ discard block |
||
| 1629 | 1628 | global $HTTP_SERVER_VARS; |
| 1630 | 1629 | global $HTTP_ENV_VARS; |
| 1631 | 1630 | |
| 1632 | - if(!isset($_SERVER)) { |
|
| 1631 | + if (!isset($_SERVER)) { |
|
| 1633 | 1632 | $_SERVER = $HTTP_SERVER_VARS; |
| 1634 | - if(!isset($_SERVER['REMOTE_ADDR'])) { |
|
| 1633 | + if (!isset($_SERVER['REMOTE_ADDR'])) { |
|
| 1635 | 1634 | $_SERVER = $HTTP_ENV_VARS; // must be Apache |
| 1636 | 1635 | } |
| 1637 | 1636 | } |
| 1638 | 1637 | |
| 1639 | - if(isset($_SERVER[$varName])) { |
|
| 1638 | + if (isset($_SERVER[$varName])) { |
|
| 1640 | 1639 | return $_SERVER[$varName]; |
| 1641 | 1640 | } else { |
| 1642 | 1641 | return ''; |
@@ -1666,14 +1665,14 @@ discard block |
||
| 1666 | 1665 | * @return string |
| 1667 | 1666 | */ |
| 1668 | 1667 | function Lang($key) { |
| 1669 | - if(count($this->language) < 1) { |
|
| 1668 | + if (count($this->language) < 1) { |
|
| 1670 | 1669 | $this->SetLanguage('en'); // set the default language |
| 1671 | 1670 | } |
| 1672 | 1671 | |
| 1673 | - if(isset($this->language[$key])) { |
|
| 1672 | + if (isset($this->language[$key])) { |
|
| 1674 | 1673 | return $this->language[$key]; |
| 1675 | 1674 | } else { |
| 1676 | - return 'Language string failed to load: ' . $key; |
|
| 1675 | + return 'Language string failed to load: '.$key; |
|
| 1677 | 1676 | } |
| 1678 | 1677 | } |
| 1679 | 1678 | |
@@ -1710,22 +1709,22 @@ discard block |
||
| 1710 | 1709 | * @access public |
| 1711 | 1710 | * @return $message |
| 1712 | 1711 | */ |
| 1713 | - function MsgHTML($message,$basedir='') { |
|
| 1712 | + function MsgHTML($message, $basedir = '') { |
|
| 1714 | 1713 | preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images); |
| 1715 | - if(isset($images[2])) { |
|
| 1716 | - foreach($images[2] as $i => $url) { |
|
| 1714 | + if (isset($images[2])) { |
|
| 1715 | + foreach ($images[2] as $i => $url) { |
|
| 1717 | 1716 | // do not change urls for absolute images (thanks to corvuscorax) |
| 1718 | - if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) { |
|
| 1717 | + if (!preg_match('/^[A-z][A-z]*:\/\//', $url)) { |
|
| 1719 | 1718 | $filename = basename($url); |
| 1720 | 1719 | $directory = dirname($url); |
| 1721 | - ($directory == '.')?$directory='':''; |
|
| 1722 | - $cid = 'cid:' . md5($filename); |
|
| 1720 | + ($directory == '.') ? $directory = '' : ''; |
|
| 1721 | + $cid = 'cid:'.md5($filename); |
|
| 1723 | 1722 | $fileParts = split("\.", $filename); |
| 1724 | 1723 | $ext = $fileParts[1]; |
| 1725 | 1724 | $mimeType = $this->_mime_types($ext); |
| 1726 | - if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; } |
|
| 1727 | - if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; } |
|
| 1728 | - if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) { |
|
| 1725 | + if (strlen($basedir) > 1 && substr($basedir, -1) != '/') { $basedir .= '/'; } |
|
| 1726 | + if (strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; } |
|
| 1727 | + if ($this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType)) { |
|
| 1729 | 1728 | $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message); |
| 1730 | 1729 | } |
| 1731 | 1730 | } |
@@ -1733,12 +1732,12 @@ discard block |
||
| 1733 | 1732 | } |
| 1734 | 1733 | $this->IsHTML(true); |
| 1735 | 1734 | $this->Body = $message; |
| 1736 | - $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message))); |
|
| 1737 | - if ( !empty($textMsg) && empty($this->AltBody) ) { |
|
| 1735 | + $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message))); |
|
| 1736 | + if (!empty($textMsg) && empty($this->AltBody)) { |
|
| 1738 | 1737 | $this->AltBody = html_entity_decode($textMsg); |
| 1739 | 1738 | } |
| 1740 | - if ( empty($this->AltBody) ) { |
|
| 1741 | - $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n"; |
|
| 1739 | + if (empty($this->AltBody)) { |
|
| 1740 | + $this->AltBody = 'To view this email message, open the email in with HTML compatibility!'."\n\n"; |
|
| 1742 | 1741 | } |
| 1743 | 1742 | } |
| 1744 | 1743 | |
@@ -1836,7 +1835,7 @@ discard block |
||
| 1836 | 1835 | 'xsl' => 'text/xml', |
| 1837 | 1836 | 'zip' => 'application/zip' |
| 1838 | 1837 | ); |
| 1839 | - return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; |
|
| 1838 | + return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; |
|
| 1840 | 1839 | } |
| 1841 | 1840 | |
| 1842 | 1841 | /** |
@@ -1850,11 +1849,11 @@ discard block |
||
| 1850 | 1849 | * @param mixed $value Parameter Value |
| 1851 | 1850 | * NOTE: will not work with arrays, there are no arrays to set/reset |
| 1852 | 1851 | */ |
| 1853 | - function set ( $name, $value = '' ) { |
|
| 1854 | - if ( isset($this->$name) ) { |
|
| 1852 | + function set($name, $value = '') { |
|
| 1853 | + if (isset($this->$name)) { |
|
| 1855 | 1854 | $this->$name = $value; |
| 1856 | 1855 | } else { |
| 1857 | - $this->SetError('Cannot set or reset variable ' . $name); |
|
| 1856 | + $this->SetError('Cannot set or reset variable '.$name); |
|
| 1858 | 1857 | return false; |
| 1859 | 1858 | } |
| 1860 | 1859 | } |
@@ -95,6 +95,7 @@ discard block |
||
| 95 | 95 | * SMTP CODE SUCCESS: 220 |
| 96 | 96 | * SMTP CODE FAILURE: 421 |
| 97 | 97 | * @access public |
| 98 | + * @param string $host |
|
| 98 | 99 | * @return bool |
| 99 | 100 | */ |
| 100 | 101 | function Connect($host,$port=0,$tval=30) { |
@@ -156,6 +157,8 @@ discard block |
||
| 156 | 157 | * Performs SMTP authentication. Must be run after running the |
| 157 | 158 | * Hello() method. Returns true if successfully authenticated. |
| 158 | 159 | * @access public |
| 160 | + * @param string $username |
|
| 161 | + * @param string $password |
|
| 159 | 162 | * @return bool |
| 160 | 163 | */ |
| 161 | 164 | function Authenticate($username, $password) { |
@@ -277,6 +280,7 @@ discard block |
||
| 277 | 280 | * SMTP CODE FAILURE: 451,554 |
| 278 | 281 | * SMTP CODE ERROR : 500,501,503,421 |
| 279 | 282 | * @access public |
| 283 | + * @param string $msg_data |
|
| 280 | 284 | * @return bool |
| 281 | 285 | */ |
| 282 | 286 | function Data($msg_data) { |
@@ -499,6 +503,8 @@ discard block |
||
| 499 | 503 | /** |
| 500 | 504 | * Sends a HELO/EHLO command. |
| 501 | 505 | * @access private |
| 506 | + * @param string $hello |
|
| 507 | + * @param string $host |
|
| 502 | 508 | * @return bool |
| 503 | 509 | */ |
| 504 | 510 | function SendHello($hello, $host) { |
@@ -593,6 +599,7 @@ discard block |
||
| 593 | 599 | * SMTP CODE SUCCESS: 552,451,452 |
| 594 | 600 | * SMTP CODE SUCCESS: 500,501,421 |
| 595 | 601 | * @access public |
| 602 | + * @param string $from |
|
| 596 | 603 | * @return bool |
| 597 | 604 | */ |
| 598 | 605 | function Mail($from) { |
@@ -989,7 +996,7 @@ discard block |
||
| 989 | 996 | * SMTP CODE FAILURE: 550,551,553 |
| 990 | 997 | * SMTP CODE ERROR : 500,501,502,421 |
| 991 | 998 | * @access public |
| 992 | - * @return int |
|
| 999 | + * @return false|string |
|
| 993 | 1000 | */ |
| 994 | 1001 | function Verify($name) { |
| 995 | 1002 | $this->error = null; # so no confusion is caused |
@@ -73,11 +73,11 @@ discard block |
||
| 73 | 73 | * @return void |
| 74 | 74 | */ |
| 75 | 75 | function SMTP() { |
| 76 | - $this->smtp_conn = 0; |
|
| 77 | - $this->error = null; |
|
| 78 | - $this->helo_rply = null; |
|
| 76 | + $this->smtp_conn = 0; |
|
| 77 | + $this->error = null; |
|
| 78 | + $this->helo_rply = null; |
|
| 79 | 79 | |
| 80 | - $this->do_debug = 0; |
|
| 80 | + $this->do_debug = 0; |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /************************************************************* |
@@ -98,58 +98,58 @@ discard block |
||
| 98 | 98 | * @return bool |
| 99 | 99 | */ |
| 100 | 100 | function Connect($host,$port=0,$tval=30) { |
| 101 | - # set the error val to null so there is no confusion |
|
| 102 | - $this->error = null; |
|
| 103 | - |
|
| 104 | - # make sure we are __not__ connected |
|
| 105 | - if($this->connected()) { |
|
| 106 | - # ok we are connected! what should we do? |
|
| 107 | - # for now we will just give an error saying we |
|
| 108 | - # are already connected |
|
| 109 | - $this->error = array("error" => "Already connected to a server"); |
|
| 110 | - return false; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - if(empty($port)) { |
|
| 114 | - $port = $this->SMTP_PORT; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - #connect to the smtp server |
|
| 118 | - $this->smtp_conn = fsockopen($host, # the host of the server |
|
| 119 | - $port, # the port to use |
|
| 120 | - $errno, # error number if any |
|
| 121 | - $errstr, # error message if any |
|
| 122 | - $tval); # give up after ? secs |
|
| 123 | - # verify we connected properly |
|
| 124 | - if(empty($this->smtp_conn)) { |
|
| 125 | - $this->error = array("error" => "Failed to connect to server", |
|
| 126 | - "errno" => $errno, |
|
| 127 | - "errstr" => $errstr); |
|
| 128 | - if($this->do_debug >= 1) { |
|
| 129 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 130 | - ": $errstr ($errno)" . $this->CRLF; |
|
| 131 | - } |
|
| 132 | - return false; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - # sometimes the SMTP server takes a little longer to respond |
|
| 136 | - # so we will give it a longer timeout for the first read |
|
| 137 | - // Windows still does not have support for this timeout function |
|
| 138 | - if(substr(PHP_OS, 0, 3) != "WIN") |
|
| 139 | - socket_set_timeout($this->smtp_conn, $tval, 0); |
|
| 140 | - |
|
| 141 | - # get any announcement stuff |
|
| 142 | - $announce = $this->get_lines(); |
|
| 143 | - |
|
| 144 | - # set the timeout of any socket functions at 1/10 of a second |
|
| 145 | - //if(function_exists("socket_set_timeout")) |
|
| 146 | - // socket_set_timeout($this->smtp_conn, 0, 100000); |
|
| 147 | - |
|
| 148 | - if($this->do_debug >= 2) { |
|
| 149 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return true; |
|
| 101 | + # set the error val to null so there is no confusion |
|
| 102 | + $this->error = null; |
|
| 103 | + |
|
| 104 | + # make sure we are __not__ connected |
|
| 105 | + if($this->connected()) { |
|
| 106 | + # ok we are connected! what should we do? |
|
| 107 | + # for now we will just give an error saying we |
|
| 108 | + # are already connected |
|
| 109 | + $this->error = array("error" => "Already connected to a server"); |
|
| 110 | + return false; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + if(empty($port)) { |
|
| 114 | + $port = $this->SMTP_PORT; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + #connect to the smtp server |
|
| 118 | + $this->smtp_conn = fsockopen($host, # the host of the server |
|
| 119 | + $port, # the port to use |
|
| 120 | + $errno, # error number if any |
|
| 121 | + $errstr, # error message if any |
|
| 122 | + $tval); # give up after ? secs |
|
| 123 | + # verify we connected properly |
|
| 124 | + if(empty($this->smtp_conn)) { |
|
| 125 | + $this->error = array("error" => "Failed to connect to server", |
|
| 126 | + "errno" => $errno, |
|
| 127 | + "errstr" => $errstr); |
|
| 128 | + if($this->do_debug >= 1) { |
|
| 129 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 130 | + ": $errstr ($errno)" . $this->CRLF; |
|
| 131 | + } |
|
| 132 | + return false; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + # sometimes the SMTP server takes a little longer to respond |
|
| 136 | + # so we will give it a longer timeout for the first read |
|
| 137 | + // Windows still does not have support for this timeout function |
|
| 138 | + if(substr(PHP_OS, 0, 3) != "WIN") |
|
| 139 | + socket_set_timeout($this->smtp_conn, $tval, 0); |
|
| 140 | + |
|
| 141 | + # get any announcement stuff |
|
| 142 | + $announce = $this->get_lines(); |
|
| 143 | + |
|
| 144 | + # set the timeout of any socket functions at 1/10 of a second |
|
| 145 | + //if(function_exists("socket_set_timeout")) |
|
| 146 | + // socket_set_timeout($this->smtp_conn, 0, 100000); |
|
| 147 | + |
|
| 148 | + if($this->do_debug >= 2) { |
|
| 149 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return true; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -159,61 +159,61 @@ discard block |
||
| 159 | 159 | * @return bool |
| 160 | 160 | */ |
| 161 | 161 | function Authenticate($username, $password) { |
| 162 | - // Start authentication |
|
| 163 | - fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF); |
|
| 164 | - |
|
| 165 | - $rply = $this->get_lines(); |
|
| 166 | - $code = substr($rply,0,3); |
|
| 167 | - |
|
| 168 | - if($code != 334) { |
|
| 169 | - $this->error = |
|
| 170 | - array("error" => "AUTH not accepted from server", |
|
| 171 | - "smtp_code" => $code, |
|
| 172 | - "smtp_msg" => substr($rply,4)); |
|
| 173 | - if($this->do_debug >= 1) { |
|
| 174 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 175 | - ": " . $rply . $this->CRLF; |
|
| 176 | - } |
|
| 177 | - return false; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - // Send encoded username |
|
| 181 | - fputs($this->smtp_conn, base64_encode($username) . $this->CRLF); |
|
| 182 | - |
|
| 183 | - $rply = $this->get_lines(); |
|
| 184 | - $code = substr($rply,0,3); |
|
| 185 | - |
|
| 186 | - if($code != 334) { |
|
| 187 | - $this->error = |
|
| 188 | - array("error" => "Username not accepted from server", |
|
| 189 | - "smtp_code" => $code, |
|
| 190 | - "smtp_msg" => substr($rply,4)); |
|
| 191 | - if($this->do_debug >= 1) { |
|
| 192 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 193 | - ": " . $rply . $this->CRLF; |
|
| 194 | - } |
|
| 195 | - return false; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - // Send encoded password |
|
| 199 | - fputs($this->smtp_conn, base64_encode($password) . $this->CRLF); |
|
| 200 | - |
|
| 201 | - $rply = $this->get_lines(); |
|
| 202 | - $code = substr($rply,0,3); |
|
| 203 | - |
|
| 204 | - if($code != 235) { |
|
| 205 | - $this->error = |
|
| 206 | - array("error" => "Password not accepted from server", |
|
| 207 | - "smtp_code" => $code, |
|
| 208 | - "smtp_msg" => substr($rply,4)); |
|
| 209 | - if($this->do_debug >= 1) { |
|
| 210 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 211 | - ": " . $rply . $this->CRLF; |
|
| 212 | - } |
|
| 213 | - return false; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - return true; |
|
| 162 | + // Start authentication |
|
| 163 | + fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF); |
|
| 164 | + |
|
| 165 | + $rply = $this->get_lines(); |
|
| 166 | + $code = substr($rply,0,3); |
|
| 167 | + |
|
| 168 | + if($code != 334) { |
|
| 169 | + $this->error = |
|
| 170 | + array("error" => "AUTH not accepted from server", |
|
| 171 | + "smtp_code" => $code, |
|
| 172 | + "smtp_msg" => substr($rply,4)); |
|
| 173 | + if($this->do_debug >= 1) { |
|
| 174 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 175 | + ": " . $rply . $this->CRLF; |
|
| 176 | + } |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + // Send encoded username |
|
| 181 | + fputs($this->smtp_conn, base64_encode($username) . $this->CRLF); |
|
| 182 | + |
|
| 183 | + $rply = $this->get_lines(); |
|
| 184 | + $code = substr($rply,0,3); |
|
| 185 | + |
|
| 186 | + if($code != 334) { |
|
| 187 | + $this->error = |
|
| 188 | + array("error" => "Username not accepted from server", |
|
| 189 | + "smtp_code" => $code, |
|
| 190 | + "smtp_msg" => substr($rply,4)); |
|
| 191 | + if($this->do_debug >= 1) { |
|
| 192 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 193 | + ": " . $rply . $this->CRLF; |
|
| 194 | + } |
|
| 195 | + return false; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + // Send encoded password |
|
| 199 | + fputs($this->smtp_conn, base64_encode($password) . $this->CRLF); |
|
| 200 | + |
|
| 201 | + $rply = $this->get_lines(); |
|
| 202 | + $code = substr($rply,0,3); |
|
| 203 | + |
|
| 204 | + if($code != 235) { |
|
| 205 | + $this->error = |
|
| 206 | + array("error" => "Password not accepted from server", |
|
| 207 | + "smtp_code" => $code, |
|
| 208 | + "smtp_msg" => substr($rply,4)); |
|
| 209 | + if($this->do_debug >= 1) { |
|
| 210 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 211 | + ": " . $rply . $this->CRLF; |
|
| 212 | + } |
|
| 213 | + return false; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + return true; |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -222,21 +222,21 @@ discard block |
||
| 222 | 222 | * @return bool |
| 223 | 223 | */ |
| 224 | 224 | function Connected() { |
| 225 | - if(!empty($this->smtp_conn)) { |
|
| 226 | - $sock_status = socket_get_status($this->smtp_conn); |
|
| 227 | - if($sock_status["eof"]) { |
|
| 228 | - # hmm this is an odd situation... the socket is |
|
| 229 | - # valid but we are not connected anymore |
|
| 230 | - if($this->do_debug >= 1) { |
|
| 231 | - echo "SMTP -> NOTICE:" . $this->CRLF . |
|
| 232 | - "EOF caught while checking if connected"; |
|
| 233 | - } |
|
| 234 | - $this->Close(); |
|
| 235 | - return false; |
|
| 236 | - } |
|
| 237 | - return true; # everything looks good |
|
| 238 | - } |
|
| 239 | - return false; |
|
| 225 | + if(!empty($this->smtp_conn)) { |
|
| 226 | + $sock_status = socket_get_status($this->smtp_conn); |
|
| 227 | + if($sock_status["eof"]) { |
|
| 228 | + # hmm this is an odd situation... the socket is |
|
| 229 | + # valid but we are not connected anymore |
|
| 230 | + if($this->do_debug >= 1) { |
|
| 231 | + echo "SMTP -> NOTICE:" . $this->CRLF . |
|
| 232 | + "EOF caught while checking if connected"; |
|
| 233 | + } |
|
| 234 | + $this->Close(); |
|
| 235 | + return false; |
|
| 236 | + } |
|
| 237 | + return true; # everything looks good |
|
| 238 | + } |
|
| 239 | + return false; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -247,13 +247,13 @@ discard block |
||
| 247 | 247 | * @return void |
| 248 | 248 | */ |
| 249 | 249 | function Close() { |
| 250 | - $this->error = null; # so there is no confusion |
|
| 251 | - $this->helo_rply = null; |
|
| 252 | - if(!empty($this->smtp_conn)) { |
|
| 253 | - # close the connection and cleanup |
|
| 254 | - fclose($this->smtp_conn); |
|
| 255 | - $this->smtp_conn = 0; |
|
| 256 | - } |
|
| 250 | + $this->error = null; # so there is no confusion |
|
| 251 | + $this->helo_rply = null; |
|
| 252 | + if(!empty($this->smtp_conn)) { |
|
| 253 | + # close the connection and cleanup |
|
| 254 | + fclose($this->smtp_conn); |
|
| 255 | + $this->smtp_conn = 0; |
|
| 256 | + } |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /*************************************************************** |
@@ -280,126 +280,126 @@ discard block |
||
| 280 | 280 | * @return bool |
| 281 | 281 | */ |
| 282 | 282 | function Data($msg_data) { |
| 283 | - $this->error = null; # so no confusion is caused |
|
| 284 | - |
|
| 285 | - if(!$this->connected()) { |
|
| 286 | - $this->error = array( |
|
| 287 | - "error" => "Called Data() without being connected"); |
|
| 288 | - return false; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - fputs($this->smtp_conn,"DATA" . $this->CRLF); |
|
| 292 | - |
|
| 293 | - $rply = $this->get_lines(); |
|
| 294 | - $code = substr($rply,0,3); |
|
| 295 | - |
|
| 296 | - if($this->do_debug >= 2) { |
|
| 297 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - if($code != 354) { |
|
| 301 | - $this->error = |
|
| 302 | - array("error" => "DATA command not accepted from server", |
|
| 303 | - "smtp_code" => $code, |
|
| 304 | - "smtp_msg" => substr($rply,4)); |
|
| 305 | - if($this->do_debug >= 1) { |
|
| 306 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 307 | - ": " . $rply . $this->CRLF; |
|
| 308 | - } |
|
| 309 | - return false; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - # the server is ready to accept data! |
|
| 313 | - # according to rfc 821 we should not send more than 1000 |
|
| 314 | - # including the CRLF |
|
| 315 | - # characters on a single line so we will break the data up |
|
| 316 | - # into lines by \r and/or \n then if needed we will break |
|
| 317 | - # each of those into smaller lines to fit within the limit. |
|
| 318 | - # in addition we will be looking for lines that start with |
|
| 319 | - # a period '.' and append and additional period '.' to that |
|
| 320 | - # line. NOTE: this does not count towards are limit. |
|
| 321 | - |
|
| 322 | - # normalize the line breaks so we know the explode works |
|
| 323 | - $msg_data = str_replace("\r\n","\n",$msg_data); |
|
| 324 | - $msg_data = str_replace("\r","\n",$msg_data); |
|
| 325 | - $lines = explode("\n",$msg_data); |
|
| 326 | - |
|
| 327 | - # we need to find a good way to determine is headers are |
|
| 328 | - # in the msg_data or if it is a straight msg body |
|
| 329 | - # currently I am assuming rfc 822 definitions of msg headers |
|
| 330 | - # and if the first field of the first line (':' sperated) |
|
| 331 | - # does not contain a space then it _should_ be a header |
|
| 332 | - # and we can process all lines before a blank "" line as |
|
| 333 | - # headers. |
|
| 334 | - $field = substr($lines[0],0,strpos($lines[0],":")); |
|
| 335 | - $in_headers = false; |
|
| 336 | - if(!empty($field) && !strstr($field," ")) { |
|
| 337 | - $in_headers = true; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - $max_line_length = 998; # used below; set here for ease in change |
|
| 341 | - |
|
| 342 | - while(list(,$line) = @each($lines)) { |
|
| 343 | - $lines_out = null; |
|
| 344 | - if($line == "" && $in_headers) { |
|
| 345 | - $in_headers = false; |
|
| 346 | - } |
|
| 347 | - # ok we need to break this line up into several |
|
| 348 | - # smaller lines |
|
| 349 | - while(strlen($line) > $max_line_length) { |
|
| 350 | - $pos = strrpos(substr($line,0,$max_line_length)," "); |
|
| 351 | - |
|
| 352 | - # Patch to fix DOS attack |
|
| 353 | - if(!$pos) { |
|
| 354 | - $pos = $max_line_length - 1; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - $lines_out[] = substr($line,0,$pos); |
|
| 358 | - $line = substr($line,$pos + 1); |
|
| 359 | - # if we are processing headers we need to |
|
| 360 | - # add a LWSP-char to the front of the new line |
|
| 361 | - # rfc 822 on long msg headers |
|
| 362 | - if($in_headers) { |
|
| 363 | - $line = "\t" . $line; |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - $lines_out[] = $line; |
|
| 367 | - |
|
| 368 | - # now send the lines to the server |
|
| 369 | - while(list(,$line_out) = @each($lines_out)) { |
|
| 370 | - if(strlen($line_out) > 0) |
|
| 371 | - { |
|
| 372 | - if(substr($line_out, 0, 1) == ".") { |
|
| 373 | - $line_out = "." . $line_out; |
|
| 374 | - } |
|
| 375 | - } |
|
| 376 | - fputs($this->smtp_conn,$line_out . $this->CRLF); |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - # ok all the message data has been sent so lets get this |
|
| 381 | - # over with aleady |
|
| 382 | - fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF); |
|
| 383 | - |
|
| 384 | - $rply = $this->get_lines(); |
|
| 385 | - $code = substr($rply,0,3); |
|
| 386 | - |
|
| 387 | - if($this->do_debug >= 2) { |
|
| 388 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - if($code != 250) { |
|
| 392 | - $this->error = |
|
| 393 | - array("error" => "DATA not accepted from server", |
|
| 394 | - "smtp_code" => $code, |
|
| 395 | - "smtp_msg" => substr($rply,4)); |
|
| 396 | - if($this->do_debug >= 1) { |
|
| 397 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 398 | - ": " . $rply . $this->CRLF; |
|
| 399 | - } |
|
| 400 | - return false; |
|
| 401 | - } |
|
| 402 | - return true; |
|
| 283 | + $this->error = null; # so no confusion is caused |
|
| 284 | + |
|
| 285 | + if(!$this->connected()) { |
|
| 286 | + $this->error = array( |
|
| 287 | + "error" => "Called Data() without being connected"); |
|
| 288 | + return false; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + fputs($this->smtp_conn,"DATA" . $this->CRLF); |
|
| 292 | + |
|
| 293 | + $rply = $this->get_lines(); |
|
| 294 | + $code = substr($rply,0,3); |
|
| 295 | + |
|
| 296 | + if($this->do_debug >= 2) { |
|
| 297 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + if($code != 354) { |
|
| 301 | + $this->error = |
|
| 302 | + array("error" => "DATA command not accepted from server", |
|
| 303 | + "smtp_code" => $code, |
|
| 304 | + "smtp_msg" => substr($rply,4)); |
|
| 305 | + if($this->do_debug >= 1) { |
|
| 306 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 307 | + ": " . $rply . $this->CRLF; |
|
| 308 | + } |
|
| 309 | + return false; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + # the server is ready to accept data! |
|
| 313 | + # according to rfc 821 we should not send more than 1000 |
|
| 314 | + # including the CRLF |
|
| 315 | + # characters on a single line so we will break the data up |
|
| 316 | + # into lines by \r and/or \n then if needed we will break |
|
| 317 | + # each of those into smaller lines to fit within the limit. |
|
| 318 | + # in addition we will be looking for lines that start with |
|
| 319 | + # a period '.' and append and additional period '.' to that |
|
| 320 | + # line. NOTE: this does not count towards are limit. |
|
| 321 | + |
|
| 322 | + # normalize the line breaks so we know the explode works |
|
| 323 | + $msg_data = str_replace("\r\n","\n",$msg_data); |
|
| 324 | + $msg_data = str_replace("\r","\n",$msg_data); |
|
| 325 | + $lines = explode("\n",$msg_data); |
|
| 326 | + |
|
| 327 | + # we need to find a good way to determine is headers are |
|
| 328 | + # in the msg_data or if it is a straight msg body |
|
| 329 | + # currently I am assuming rfc 822 definitions of msg headers |
|
| 330 | + # and if the first field of the first line (':' sperated) |
|
| 331 | + # does not contain a space then it _should_ be a header |
|
| 332 | + # and we can process all lines before a blank "" line as |
|
| 333 | + # headers. |
|
| 334 | + $field = substr($lines[0],0,strpos($lines[0],":")); |
|
| 335 | + $in_headers = false; |
|
| 336 | + if(!empty($field) && !strstr($field," ")) { |
|
| 337 | + $in_headers = true; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + $max_line_length = 998; # used below; set here for ease in change |
|
| 341 | + |
|
| 342 | + while(list(,$line) = @each($lines)) { |
|
| 343 | + $lines_out = null; |
|
| 344 | + if($line == "" && $in_headers) { |
|
| 345 | + $in_headers = false; |
|
| 346 | + } |
|
| 347 | + # ok we need to break this line up into several |
|
| 348 | + # smaller lines |
|
| 349 | + while(strlen($line) > $max_line_length) { |
|
| 350 | + $pos = strrpos(substr($line,0,$max_line_length)," "); |
|
| 351 | + |
|
| 352 | + # Patch to fix DOS attack |
|
| 353 | + if(!$pos) { |
|
| 354 | + $pos = $max_line_length - 1; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + $lines_out[] = substr($line,0,$pos); |
|
| 358 | + $line = substr($line,$pos + 1); |
|
| 359 | + # if we are processing headers we need to |
|
| 360 | + # add a LWSP-char to the front of the new line |
|
| 361 | + # rfc 822 on long msg headers |
|
| 362 | + if($in_headers) { |
|
| 363 | + $line = "\t" . $line; |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + $lines_out[] = $line; |
|
| 367 | + |
|
| 368 | + # now send the lines to the server |
|
| 369 | + while(list(,$line_out) = @each($lines_out)) { |
|
| 370 | + if(strlen($line_out) > 0) |
|
| 371 | + { |
|
| 372 | + if(substr($line_out, 0, 1) == ".") { |
|
| 373 | + $line_out = "." . $line_out; |
|
| 374 | + } |
|
| 375 | + } |
|
| 376 | + fputs($this->smtp_conn,$line_out . $this->CRLF); |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + # ok all the message data has been sent so lets get this |
|
| 381 | + # over with aleady |
|
| 382 | + fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF); |
|
| 383 | + |
|
| 384 | + $rply = $this->get_lines(); |
|
| 385 | + $code = substr($rply,0,3); |
|
| 386 | + |
|
| 387 | + if($this->do_debug >= 2) { |
|
| 388 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + if($code != 250) { |
|
| 392 | + $this->error = |
|
| 393 | + array("error" => "DATA not accepted from server", |
|
| 394 | + "smtp_code" => $code, |
|
| 395 | + "smtp_msg" => substr($rply,4)); |
|
| 396 | + if($this->do_debug >= 1) { |
|
| 397 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 398 | + ": " . $rply . $this->CRLF; |
|
| 399 | + } |
|
| 400 | + return false; |
|
| 401 | + } |
|
| 402 | + return true; |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -419,42 +419,42 @@ discard block |
||
| 419 | 419 | * @return string array |
| 420 | 420 | */ |
| 421 | 421 | function Expand($name) { |
| 422 | - $this->error = null; # so no confusion is caused |
|
| 423 | - |
|
| 424 | - if(!$this->connected()) { |
|
| 425 | - $this->error = array( |
|
| 426 | - "error" => "Called Expand() without being connected"); |
|
| 427 | - return false; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF); |
|
| 431 | - |
|
| 432 | - $rply = $this->get_lines(); |
|
| 433 | - $code = substr($rply,0,3); |
|
| 434 | - |
|
| 435 | - if($this->do_debug >= 2) { |
|
| 436 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - if($code != 250) { |
|
| 440 | - $this->error = |
|
| 441 | - array("error" => "EXPN not accepted from server", |
|
| 442 | - "smtp_code" => $code, |
|
| 443 | - "smtp_msg" => substr($rply,4)); |
|
| 444 | - if($this->do_debug >= 1) { |
|
| 445 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 446 | - ": " . $rply . $this->CRLF; |
|
| 447 | - } |
|
| 448 | - return false; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - # parse the reply and place in our array to return to user |
|
| 452 | - $entries = explode($this->CRLF,$rply); |
|
| 453 | - while(list(,$l) = @each($entries)) { |
|
| 454 | - $list[] = substr($l,4); |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - return $list; |
|
| 422 | + $this->error = null; # so no confusion is caused |
|
| 423 | + |
|
| 424 | + if(!$this->connected()) { |
|
| 425 | + $this->error = array( |
|
| 426 | + "error" => "Called Expand() without being connected"); |
|
| 427 | + return false; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF); |
|
| 431 | + |
|
| 432 | + $rply = $this->get_lines(); |
|
| 433 | + $code = substr($rply,0,3); |
|
| 434 | + |
|
| 435 | + if($this->do_debug >= 2) { |
|
| 436 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + if($code != 250) { |
|
| 440 | + $this->error = |
|
| 441 | + array("error" => "EXPN not accepted from server", |
|
| 442 | + "smtp_code" => $code, |
|
| 443 | + "smtp_msg" => substr($rply,4)); |
|
| 444 | + if($this->do_debug >= 1) { |
|
| 445 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 446 | + ": " . $rply . $this->CRLF; |
|
| 447 | + } |
|
| 448 | + return false; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + # parse the reply and place in our array to return to user |
|
| 452 | + $entries = explode($this->CRLF,$rply); |
|
| 453 | + while(list(,$l) = @each($entries)) { |
|
| 454 | + $list[] = substr($l,4); |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + return $list; |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | /** |
@@ -470,30 +470,30 @@ discard block |
||
| 470 | 470 | * @return bool |
| 471 | 471 | */ |
| 472 | 472 | function Hello($host="") { |
| 473 | - $this->error = null; # so no confusion is caused |
|
| 474 | - |
|
| 475 | - if(!$this->connected()) { |
|
| 476 | - $this->error = array( |
|
| 477 | - "error" => "Called Hello() without being connected"); |
|
| 478 | - return false; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - # if a hostname for the HELO was not specified determine |
|
| 482 | - # a suitable one to send |
|
| 483 | - if(empty($host)) { |
|
| 484 | - # we need to determine some sort of appopiate default |
|
| 485 | - # to send to the server |
|
| 486 | - $host = "localhost"; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - // Send extended hello first (RFC 2821) |
|
| 490 | - if(!$this->SendHello("EHLO", $host)) |
|
| 491 | - { |
|
| 492 | - if(!$this->SendHello("HELO", $host)) |
|
| 493 | - return false; |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - return true; |
|
| 473 | + $this->error = null; # so no confusion is caused |
|
| 474 | + |
|
| 475 | + if(!$this->connected()) { |
|
| 476 | + $this->error = array( |
|
| 477 | + "error" => "Called Hello() without being connected"); |
|
| 478 | + return false; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + # if a hostname for the HELO was not specified determine |
|
| 482 | + # a suitable one to send |
|
| 483 | + if(empty($host)) { |
|
| 484 | + # we need to determine some sort of appopiate default |
|
| 485 | + # to send to the server |
|
| 486 | + $host = "localhost"; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + // Send extended hello first (RFC 2821) |
|
| 490 | + if(!$this->SendHello("EHLO", $host)) |
|
| 491 | + { |
|
| 492 | + if(!$this->SendHello("HELO", $host)) |
|
| 493 | + return false; |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + return true; |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | /** |
@@ -502,30 +502,30 @@ discard block |
||
| 502 | 502 | * @return bool |
| 503 | 503 | */ |
| 504 | 504 | function SendHello($hello, $host) { |
| 505 | - fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF); |
|
| 506 | - |
|
| 507 | - $rply = $this->get_lines(); |
|
| 508 | - $code = substr($rply,0,3); |
|
| 509 | - |
|
| 510 | - if($this->do_debug >= 2) { |
|
| 511 | - echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply; |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - if($code != 250) { |
|
| 515 | - $this->error = |
|
| 516 | - array("error" => $hello . " not accepted from server", |
|
| 517 | - "smtp_code" => $code, |
|
| 518 | - "smtp_msg" => substr($rply,4)); |
|
| 519 | - if($this->do_debug >= 1) { |
|
| 520 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 521 | - ": " . $rply . $this->CRLF; |
|
| 522 | - } |
|
| 523 | - return false; |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - $this->helo_rply = $rply; |
|
| 527 | - |
|
| 528 | - return true; |
|
| 505 | + fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF); |
|
| 506 | + |
|
| 507 | + $rply = $this->get_lines(); |
|
| 508 | + $code = substr($rply,0,3); |
|
| 509 | + |
|
| 510 | + if($this->do_debug >= 2) { |
|
| 511 | + echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply; |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + if($code != 250) { |
|
| 515 | + $this->error = |
|
| 516 | + array("error" => $hello . " not accepted from server", |
|
| 517 | + "smtp_code" => $code, |
|
| 518 | + "smtp_msg" => substr($rply,4)); |
|
| 519 | + if($this->do_debug >= 1) { |
|
| 520 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 521 | + ": " . $rply . $this->CRLF; |
|
| 522 | + } |
|
| 523 | + return false; |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + $this->helo_rply = $rply; |
|
| 527 | + |
|
| 528 | + return true; |
|
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | /** |
@@ -544,41 +544,41 @@ discard block |
||
| 544 | 544 | * @return string |
| 545 | 545 | */ |
| 546 | 546 | function Help($keyword="") { |
| 547 | - $this->error = null; # to avoid confusion |
|
| 548 | - |
|
| 549 | - if(!$this->connected()) { |
|
| 550 | - $this->error = array( |
|
| 551 | - "error" => "Called Help() without being connected"); |
|
| 552 | - return false; |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - $extra = ""; |
|
| 556 | - if(!empty($keyword)) { |
|
| 557 | - $extra = " " . $keyword; |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF); |
|
| 561 | - |
|
| 562 | - $rply = $this->get_lines(); |
|
| 563 | - $code = substr($rply,0,3); |
|
| 564 | - |
|
| 565 | - if($this->do_debug >= 2) { |
|
| 566 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - if($code != 211 && $code != 214) { |
|
| 570 | - $this->error = |
|
| 571 | - array("error" => "HELP not accepted from server", |
|
| 572 | - "smtp_code" => $code, |
|
| 573 | - "smtp_msg" => substr($rply,4)); |
|
| 574 | - if($this->do_debug >= 1) { |
|
| 575 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 576 | - ": " . $rply . $this->CRLF; |
|
| 577 | - } |
|
| 578 | - return false; |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - return $rply; |
|
| 547 | + $this->error = null; # to avoid confusion |
|
| 548 | + |
|
| 549 | + if(!$this->connected()) { |
|
| 550 | + $this->error = array( |
|
| 551 | + "error" => "Called Help() without being connected"); |
|
| 552 | + return false; |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + $extra = ""; |
|
| 556 | + if(!empty($keyword)) { |
|
| 557 | + $extra = " " . $keyword; |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF); |
|
| 561 | + |
|
| 562 | + $rply = $this->get_lines(); |
|
| 563 | + $code = substr($rply,0,3); |
|
| 564 | + |
|
| 565 | + if($this->do_debug >= 2) { |
|
| 566 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + if($code != 211 && $code != 214) { |
|
| 570 | + $this->error = |
|
| 571 | + array("error" => "HELP not accepted from server", |
|
| 572 | + "smtp_code" => $code, |
|
| 573 | + "smtp_msg" => substr($rply,4)); |
|
| 574 | + if($this->do_debug >= 1) { |
|
| 575 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 576 | + ": " . $rply . $this->CRLF; |
|
| 577 | + } |
|
| 578 | + return false; |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + return $rply; |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | /** |
@@ -596,36 +596,36 @@ discard block |
||
| 596 | 596 | * @return bool |
| 597 | 597 | */ |
| 598 | 598 | function Mail($from) { |
| 599 | - $this->error = null; # so no confusion is caused |
|
| 600 | - |
|
| 601 | - if(!$this->connected()) { |
|
| 602 | - $this->error = array( |
|
| 603 | - "error" => "Called Mail() without being connected"); |
|
| 604 | - return false; |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - $useVerp = ($this->do_verp ? "XVERP" : ""); |
|
| 608 | - fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF); |
|
| 609 | - |
|
| 610 | - $rply = $this->get_lines(); |
|
| 611 | - $code = substr($rply,0,3); |
|
| 612 | - |
|
| 613 | - if($this->do_debug >= 2) { |
|
| 614 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - if($code != 250) { |
|
| 618 | - $this->error = |
|
| 619 | - array("error" => "MAIL not accepted from server", |
|
| 620 | - "smtp_code" => $code, |
|
| 621 | - "smtp_msg" => substr($rply,4)); |
|
| 622 | - if($this->do_debug >= 1) { |
|
| 623 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 624 | - ": " . $rply . $this->CRLF; |
|
| 625 | - } |
|
| 626 | - return false; |
|
| 627 | - } |
|
| 628 | - return true; |
|
| 599 | + $this->error = null; # so no confusion is caused |
|
| 600 | + |
|
| 601 | + if(!$this->connected()) { |
|
| 602 | + $this->error = array( |
|
| 603 | + "error" => "Called Mail() without being connected"); |
|
| 604 | + return false; |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + $useVerp = ($this->do_verp ? "XVERP" : ""); |
|
| 608 | + fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF); |
|
| 609 | + |
|
| 610 | + $rply = $this->get_lines(); |
|
| 611 | + $code = substr($rply,0,3); |
|
| 612 | + |
|
| 613 | + if($this->do_debug >= 2) { |
|
| 614 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + if($code != 250) { |
|
| 618 | + $this->error = |
|
| 619 | + array("error" => "MAIL not accepted from server", |
|
| 620 | + "smtp_code" => $code, |
|
| 621 | + "smtp_msg" => substr($rply,4)); |
|
| 622 | + if($this->do_debug >= 1) { |
|
| 623 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 624 | + ": " . $rply . $this->CRLF; |
|
| 625 | + } |
|
| 626 | + return false; |
|
| 627 | + } |
|
| 628 | + return true; |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | /** |
@@ -639,35 +639,35 @@ discard block |
||
| 639 | 639 | * @return bool |
| 640 | 640 | */ |
| 641 | 641 | function Noop() { |
| 642 | - $this->error = null; # so no confusion is caused |
|
| 643 | - |
|
| 644 | - if(!$this->connected()) { |
|
| 645 | - $this->error = array( |
|
| 646 | - "error" => "Called Noop() without being connected"); |
|
| 647 | - return false; |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - fputs($this->smtp_conn,"NOOP" . $this->CRLF); |
|
| 651 | - |
|
| 652 | - $rply = $this->get_lines(); |
|
| 653 | - $code = substr($rply,0,3); |
|
| 654 | - |
|
| 655 | - if($this->do_debug >= 2) { |
|
| 656 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - if($code != 250) { |
|
| 660 | - $this->error = |
|
| 661 | - array("error" => "NOOP not accepted from server", |
|
| 662 | - "smtp_code" => $code, |
|
| 663 | - "smtp_msg" => substr($rply,4)); |
|
| 664 | - if($this->do_debug >= 1) { |
|
| 665 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 666 | - ": " . $rply . $this->CRLF; |
|
| 667 | - } |
|
| 668 | - return false; |
|
| 669 | - } |
|
| 670 | - return true; |
|
| 642 | + $this->error = null; # so no confusion is caused |
|
| 643 | + |
|
| 644 | + if(!$this->connected()) { |
|
| 645 | + $this->error = array( |
|
| 646 | + "error" => "Called Noop() without being connected"); |
|
| 647 | + return false; |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + fputs($this->smtp_conn,"NOOP" . $this->CRLF); |
|
| 651 | + |
|
| 652 | + $rply = $this->get_lines(); |
|
| 653 | + $code = substr($rply,0,3); |
|
| 654 | + |
|
| 655 | + if($this->do_debug >= 2) { |
|
| 656 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + if($code != 250) { |
|
| 660 | + $this->error = |
|
| 661 | + array("error" => "NOOP not accepted from server", |
|
| 662 | + "smtp_code" => $code, |
|
| 663 | + "smtp_msg" => substr($rply,4)); |
|
| 664 | + if($this->do_debug >= 1) { |
|
| 665 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 666 | + ": " . $rply . $this->CRLF; |
|
| 667 | + } |
|
| 668 | + return false; |
|
| 669 | + } |
|
| 670 | + return true; |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | /** |
@@ -682,45 +682,45 @@ discard block |
||
| 682 | 682 | * @return bool |
| 683 | 683 | */ |
| 684 | 684 | function Quit($close_on_error=true) { |
| 685 | - $this->error = null; # so there is no confusion |
|
| 686 | - |
|
| 687 | - if(!$this->connected()) { |
|
| 688 | - $this->error = array( |
|
| 689 | - "error" => "Called Quit() without being connected"); |
|
| 690 | - return false; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - # send the quit command to the server |
|
| 694 | - fputs($this->smtp_conn,"quit" . $this->CRLF); |
|
| 695 | - |
|
| 696 | - # get any good-bye messages |
|
| 697 | - $byemsg = $this->get_lines(); |
|
| 698 | - |
|
| 699 | - if($this->do_debug >= 2) { |
|
| 700 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg; |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - $rval = true; |
|
| 704 | - $e = null; |
|
| 705 | - |
|
| 706 | - $code = substr($byemsg,0,3); |
|
| 707 | - if($code != 221) { |
|
| 708 | - # use e as a tmp var cause Close will overwrite $this->error |
|
| 709 | - $e = array("error" => "SMTP server rejected quit command", |
|
| 710 | - "smtp_code" => $code, |
|
| 711 | - "smtp_rply" => substr($byemsg,4)); |
|
| 712 | - $rval = false; |
|
| 713 | - if($this->do_debug >= 1) { |
|
| 714 | - echo "SMTP -> ERROR: " . $e["error"] . ": " . |
|
| 715 | - $byemsg . $this->CRLF; |
|
| 716 | - } |
|
| 717 | - } |
|
| 718 | - |
|
| 719 | - if(empty($e) || $close_on_error) { |
|
| 720 | - $this->Close(); |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - return $rval; |
|
| 685 | + $this->error = null; # so there is no confusion |
|
| 686 | + |
|
| 687 | + if(!$this->connected()) { |
|
| 688 | + $this->error = array( |
|
| 689 | + "error" => "Called Quit() without being connected"); |
|
| 690 | + return false; |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + # send the quit command to the server |
|
| 694 | + fputs($this->smtp_conn,"quit" . $this->CRLF); |
|
| 695 | + |
|
| 696 | + # get any good-bye messages |
|
| 697 | + $byemsg = $this->get_lines(); |
|
| 698 | + |
|
| 699 | + if($this->do_debug >= 2) { |
|
| 700 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg; |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + $rval = true; |
|
| 704 | + $e = null; |
|
| 705 | + |
|
| 706 | + $code = substr($byemsg,0,3); |
|
| 707 | + if($code != 221) { |
|
| 708 | + # use e as a tmp var cause Close will overwrite $this->error |
|
| 709 | + $e = array("error" => "SMTP server rejected quit command", |
|
| 710 | + "smtp_code" => $code, |
|
| 711 | + "smtp_rply" => substr($byemsg,4)); |
|
| 712 | + $rval = false; |
|
| 713 | + if($this->do_debug >= 1) { |
|
| 714 | + echo "SMTP -> ERROR: " . $e["error"] . ": " . |
|
| 715 | + $byemsg . $this->CRLF; |
|
| 716 | + } |
|
| 717 | + } |
|
| 718 | + |
|
| 719 | + if(empty($e) || $close_on_error) { |
|
| 720 | + $this->Close(); |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + return $rval; |
|
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | /** |
@@ -736,35 +736,35 @@ discard block |
||
| 736 | 736 | * @return bool |
| 737 | 737 | */ |
| 738 | 738 | function Recipient($to) { |
| 739 | - $this->error = null; # so no confusion is caused |
|
| 740 | - |
|
| 741 | - if(!$this->connected()) { |
|
| 742 | - $this->error = array( |
|
| 743 | - "error" => "Called Recipient() without being connected"); |
|
| 744 | - return false; |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF); |
|
| 748 | - |
|
| 749 | - $rply = $this->get_lines(); |
|
| 750 | - $code = substr($rply,0,3); |
|
| 751 | - |
|
| 752 | - if($this->do_debug >= 2) { |
|
| 753 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - if($code != 250 && $code != 251) { |
|
| 757 | - $this->error = |
|
| 758 | - array("error" => "RCPT not accepted from server", |
|
| 759 | - "smtp_code" => $code, |
|
| 760 | - "smtp_msg" => substr($rply,4)); |
|
| 761 | - if($this->do_debug >= 1) { |
|
| 762 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 763 | - ": " . $rply . $this->CRLF; |
|
| 764 | - } |
|
| 765 | - return false; |
|
| 766 | - } |
|
| 767 | - return true; |
|
| 739 | + $this->error = null; # so no confusion is caused |
|
| 740 | + |
|
| 741 | + if(!$this->connected()) { |
|
| 742 | + $this->error = array( |
|
| 743 | + "error" => "Called Recipient() without being connected"); |
|
| 744 | + return false; |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF); |
|
| 748 | + |
|
| 749 | + $rply = $this->get_lines(); |
|
| 750 | + $code = substr($rply,0,3); |
|
| 751 | + |
|
| 752 | + if($this->do_debug >= 2) { |
|
| 753 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + if($code != 250 && $code != 251) { |
|
| 757 | + $this->error = |
|
| 758 | + array("error" => "RCPT not accepted from server", |
|
| 759 | + "smtp_code" => $code, |
|
| 760 | + "smtp_msg" => substr($rply,4)); |
|
| 761 | + if($this->do_debug >= 1) { |
|
| 762 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 763 | + ": " . $rply . $this->CRLF; |
|
| 764 | + } |
|
| 765 | + return false; |
|
| 766 | + } |
|
| 767 | + return true; |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | /** |
@@ -780,36 +780,36 @@ discard block |
||
| 780 | 780 | * @return bool |
| 781 | 781 | */ |
| 782 | 782 | function Reset() { |
| 783 | - $this->error = null; # so no confusion is caused |
|
| 784 | - |
|
| 785 | - if(!$this->connected()) { |
|
| 786 | - $this->error = array( |
|
| 787 | - "error" => "Called Reset() without being connected"); |
|
| 788 | - return false; |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - fputs($this->smtp_conn,"RSET" . $this->CRLF); |
|
| 792 | - |
|
| 793 | - $rply = $this->get_lines(); |
|
| 794 | - $code = substr($rply,0,3); |
|
| 795 | - |
|
| 796 | - if($this->do_debug >= 2) { |
|
| 797 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 798 | - } |
|
| 799 | - |
|
| 800 | - if($code != 250) { |
|
| 801 | - $this->error = |
|
| 802 | - array("error" => "RSET failed", |
|
| 803 | - "smtp_code" => $code, |
|
| 804 | - "smtp_msg" => substr($rply,4)); |
|
| 805 | - if($this->do_debug >= 1) { |
|
| 806 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 807 | - ": " . $rply . $this->CRLF; |
|
| 808 | - } |
|
| 809 | - return false; |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - return true; |
|
| 783 | + $this->error = null; # so no confusion is caused |
|
| 784 | + |
|
| 785 | + if(!$this->connected()) { |
|
| 786 | + $this->error = array( |
|
| 787 | + "error" => "Called Reset() without being connected"); |
|
| 788 | + return false; |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + fputs($this->smtp_conn,"RSET" . $this->CRLF); |
|
| 792 | + |
|
| 793 | + $rply = $this->get_lines(); |
|
| 794 | + $code = substr($rply,0,3); |
|
| 795 | + |
|
| 796 | + if($this->do_debug >= 2) { |
|
| 797 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 798 | + } |
|
| 799 | + |
|
| 800 | + if($code != 250) { |
|
| 801 | + $this->error = |
|
| 802 | + array("error" => "RSET failed", |
|
| 803 | + "smtp_code" => $code, |
|
| 804 | + "smtp_msg" => substr($rply,4)); |
|
| 805 | + if($this->do_debug >= 1) { |
|
| 806 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 807 | + ": " . $rply . $this->CRLF; |
|
| 808 | + } |
|
| 809 | + return false; |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + return true; |
|
| 813 | 813 | } |
| 814 | 814 | |
| 815 | 815 | /** |
@@ -829,35 +829,35 @@ discard block |
||
| 829 | 829 | * @return bool |
| 830 | 830 | */ |
| 831 | 831 | function Send($from) { |
| 832 | - $this->error = null; # so no confusion is caused |
|
| 833 | - |
|
| 834 | - if(!$this->connected()) { |
|
| 835 | - $this->error = array( |
|
| 836 | - "error" => "Called Send() without being connected"); |
|
| 837 | - return false; |
|
| 838 | - } |
|
| 839 | - |
|
| 840 | - fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF); |
|
| 841 | - |
|
| 842 | - $rply = $this->get_lines(); |
|
| 843 | - $code = substr($rply,0,3); |
|
| 844 | - |
|
| 845 | - if($this->do_debug >= 2) { |
|
| 846 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 847 | - } |
|
| 848 | - |
|
| 849 | - if($code != 250) { |
|
| 850 | - $this->error = |
|
| 851 | - array("error" => "SEND not accepted from server", |
|
| 852 | - "smtp_code" => $code, |
|
| 853 | - "smtp_msg" => substr($rply,4)); |
|
| 854 | - if($this->do_debug >= 1) { |
|
| 855 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 856 | - ": " . $rply . $this->CRLF; |
|
| 857 | - } |
|
| 858 | - return false; |
|
| 859 | - } |
|
| 860 | - return true; |
|
| 832 | + $this->error = null; # so no confusion is caused |
|
| 833 | + |
|
| 834 | + if(!$this->connected()) { |
|
| 835 | + $this->error = array( |
|
| 836 | + "error" => "Called Send() without being connected"); |
|
| 837 | + return false; |
|
| 838 | + } |
|
| 839 | + |
|
| 840 | + fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF); |
|
| 841 | + |
|
| 842 | + $rply = $this->get_lines(); |
|
| 843 | + $code = substr($rply,0,3); |
|
| 844 | + |
|
| 845 | + if($this->do_debug >= 2) { |
|
| 846 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + if($code != 250) { |
|
| 850 | + $this->error = |
|
| 851 | + array("error" => "SEND not accepted from server", |
|
| 852 | + "smtp_code" => $code, |
|
| 853 | + "smtp_msg" => substr($rply,4)); |
|
| 854 | + if($this->do_debug >= 1) { |
|
| 855 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 856 | + ": " . $rply . $this->CRLF; |
|
| 857 | + } |
|
| 858 | + return false; |
|
| 859 | + } |
|
| 860 | + return true; |
|
| 861 | 861 | } |
| 862 | 862 | |
| 863 | 863 | /** |
@@ -877,35 +877,35 @@ discard block |
||
| 877 | 877 | * @return bool |
| 878 | 878 | */ |
| 879 | 879 | function SendAndMail($from) { |
| 880 | - $this->error = null; # so no confusion is caused |
|
| 881 | - |
|
| 882 | - if(!$this->connected()) { |
|
| 883 | - $this->error = array( |
|
| 884 | - "error" => "Called SendAndMail() without being connected"); |
|
| 885 | - return false; |
|
| 886 | - } |
|
| 887 | - |
|
| 888 | - fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF); |
|
| 889 | - |
|
| 890 | - $rply = $this->get_lines(); |
|
| 891 | - $code = substr($rply,0,3); |
|
| 892 | - |
|
| 893 | - if($this->do_debug >= 2) { |
|
| 894 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - if($code != 250) { |
|
| 898 | - $this->error = |
|
| 899 | - array("error" => "SAML not accepted from server", |
|
| 900 | - "smtp_code" => $code, |
|
| 901 | - "smtp_msg" => substr($rply,4)); |
|
| 902 | - if($this->do_debug >= 1) { |
|
| 903 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 904 | - ": " . $rply . $this->CRLF; |
|
| 905 | - } |
|
| 906 | - return false; |
|
| 907 | - } |
|
| 908 | - return true; |
|
| 880 | + $this->error = null; # so no confusion is caused |
|
| 881 | + |
|
| 882 | + if(!$this->connected()) { |
|
| 883 | + $this->error = array( |
|
| 884 | + "error" => "Called SendAndMail() without being connected"); |
|
| 885 | + return false; |
|
| 886 | + } |
|
| 887 | + |
|
| 888 | + fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF); |
|
| 889 | + |
|
| 890 | + $rply = $this->get_lines(); |
|
| 891 | + $code = substr($rply,0,3); |
|
| 892 | + |
|
| 893 | + if($this->do_debug >= 2) { |
|
| 894 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + if($code != 250) { |
|
| 898 | + $this->error = |
|
| 899 | + array("error" => "SAML not accepted from server", |
|
| 900 | + "smtp_code" => $code, |
|
| 901 | + "smtp_msg" => substr($rply,4)); |
|
| 902 | + if($this->do_debug >= 1) { |
|
| 903 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 904 | + ": " . $rply . $this->CRLF; |
|
| 905 | + } |
|
| 906 | + return false; |
|
| 907 | + } |
|
| 908 | + return true; |
|
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | /** |
@@ -925,35 +925,35 @@ discard block |
||
| 925 | 925 | * @return bool |
| 926 | 926 | */ |
| 927 | 927 | function SendOrMail($from) { |
| 928 | - $this->error = null; # so no confusion is caused |
|
| 929 | - |
|
| 930 | - if(!$this->connected()) { |
|
| 931 | - $this->error = array( |
|
| 932 | - "error" => "Called SendOrMail() without being connected"); |
|
| 933 | - return false; |
|
| 934 | - } |
|
| 935 | - |
|
| 936 | - fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF); |
|
| 937 | - |
|
| 938 | - $rply = $this->get_lines(); |
|
| 939 | - $code = substr($rply,0,3); |
|
| 940 | - |
|
| 941 | - if($this->do_debug >= 2) { |
|
| 942 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 943 | - } |
|
| 944 | - |
|
| 945 | - if($code != 250) { |
|
| 946 | - $this->error = |
|
| 947 | - array("error" => "SOML not accepted from server", |
|
| 948 | - "smtp_code" => $code, |
|
| 949 | - "smtp_msg" => substr($rply,4)); |
|
| 950 | - if($this->do_debug >= 1) { |
|
| 951 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 952 | - ": " . $rply . $this->CRLF; |
|
| 953 | - } |
|
| 954 | - return false; |
|
| 955 | - } |
|
| 956 | - return true; |
|
| 928 | + $this->error = null; # so no confusion is caused |
|
| 929 | + |
|
| 930 | + if(!$this->connected()) { |
|
| 931 | + $this->error = array( |
|
| 932 | + "error" => "Called SendOrMail() without being connected"); |
|
| 933 | + return false; |
|
| 934 | + } |
|
| 935 | + |
|
| 936 | + fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF); |
|
| 937 | + |
|
| 938 | + $rply = $this->get_lines(); |
|
| 939 | + $code = substr($rply,0,3); |
|
| 940 | + |
|
| 941 | + if($this->do_debug >= 2) { |
|
| 942 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 943 | + } |
|
| 944 | + |
|
| 945 | + if($code != 250) { |
|
| 946 | + $this->error = |
|
| 947 | + array("error" => "SOML not accepted from server", |
|
| 948 | + "smtp_code" => $code, |
|
| 949 | + "smtp_msg" => substr($rply,4)); |
|
| 950 | + if($this->do_debug >= 1) { |
|
| 951 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 952 | + ": " . $rply . $this->CRLF; |
|
| 953 | + } |
|
| 954 | + return false; |
|
| 955 | + } |
|
| 956 | + return true; |
|
| 957 | 957 | } |
| 958 | 958 | |
| 959 | 959 | /** |
@@ -970,12 +970,12 @@ discard block |
||
| 970 | 970 | * @return bool |
| 971 | 971 | */ |
| 972 | 972 | function Turn() { |
| 973 | - $this->error = array("error" => "This method, TURN, of the SMTP ". |
|
| 974 | - "is not implemented"); |
|
| 975 | - if($this->do_debug >= 1) { |
|
| 976 | - echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF; |
|
| 977 | - } |
|
| 978 | - return false; |
|
| 973 | + $this->error = array("error" => "This method, TURN, of the SMTP ". |
|
| 974 | + "is not implemented"); |
|
| 975 | + if($this->do_debug >= 1) { |
|
| 976 | + echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF; |
|
| 977 | + } |
|
| 978 | + return false; |
|
| 979 | 979 | } |
| 980 | 980 | |
| 981 | 981 | /** |
@@ -992,35 +992,35 @@ discard block |
||
| 992 | 992 | * @return int |
| 993 | 993 | */ |
| 994 | 994 | function Verify($name) { |
| 995 | - $this->error = null; # so no confusion is caused |
|
| 996 | - |
|
| 997 | - if(!$this->connected()) { |
|
| 998 | - $this->error = array( |
|
| 999 | - "error" => "Called Verify() without being connected"); |
|
| 1000 | - return false; |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF); |
|
| 1004 | - |
|
| 1005 | - $rply = $this->get_lines(); |
|
| 1006 | - $code = substr($rply,0,3); |
|
| 1007 | - |
|
| 1008 | - if($this->do_debug >= 2) { |
|
| 1009 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 1010 | - } |
|
| 1011 | - |
|
| 1012 | - if($code != 250 && $code != 251) { |
|
| 1013 | - $this->error = |
|
| 1014 | - array("error" => "VRFY failed on name '$name'", |
|
| 1015 | - "smtp_code" => $code, |
|
| 1016 | - "smtp_msg" => substr($rply,4)); |
|
| 1017 | - if($this->do_debug >= 1) { |
|
| 1018 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 1019 | - ": " . $rply . $this->CRLF; |
|
| 1020 | - } |
|
| 1021 | - return false; |
|
| 1022 | - } |
|
| 1023 | - return $rply; |
|
| 995 | + $this->error = null; # so no confusion is caused |
|
| 996 | + |
|
| 997 | + if(!$this->connected()) { |
|
| 998 | + $this->error = array( |
|
| 999 | + "error" => "Called Verify() without being connected"); |
|
| 1000 | + return false; |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF); |
|
| 1004 | + |
|
| 1005 | + $rply = $this->get_lines(); |
|
| 1006 | + $code = substr($rply,0,3); |
|
| 1007 | + |
|
| 1008 | + if($this->do_debug >= 2) { |
|
| 1009 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 1010 | + } |
|
| 1011 | + |
|
| 1012 | + if($code != 250 && $code != 251) { |
|
| 1013 | + $this->error = |
|
| 1014 | + array("error" => "VRFY failed on name '$name'", |
|
| 1015 | + "smtp_code" => $code, |
|
| 1016 | + "smtp_msg" => substr($rply,4)); |
|
| 1017 | + if($this->do_debug >= 1) { |
|
| 1018 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 1019 | + ": " . $rply . $this->CRLF; |
|
| 1020 | + } |
|
| 1021 | + return false; |
|
| 1022 | + } |
|
| 1023 | + return $rply; |
|
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | /******************************************************************* |
@@ -1037,23 +1037,23 @@ discard block |
||
| 1037 | 1037 | * @return string |
| 1038 | 1038 | */ |
| 1039 | 1039 | function get_lines() { |
| 1040 | - $data = ""; |
|
| 1041 | - while($str = @fgets($this->smtp_conn,515)) { |
|
| 1042 | - if($this->do_debug >= 4) { |
|
| 1043 | - echo "SMTP -> get_lines(): \$data was \"$data\"" . |
|
| 1044 | - $this->CRLF; |
|
| 1045 | - echo "SMTP -> get_lines(): \$str is \"$str\"" . |
|
| 1046 | - $this->CRLF; |
|
| 1047 | - } |
|
| 1048 | - $data .= $str; |
|
| 1049 | - if($this->do_debug >= 4) { |
|
| 1050 | - echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF; |
|
| 1051 | - } |
|
| 1052 | - # if the 4th character is a space then we are done reading |
|
| 1053 | - # so just break the loop |
|
| 1054 | - if(substr($str,3,1) == " ") { break; } |
|
| 1055 | - } |
|
| 1056 | - return $data; |
|
| 1040 | + $data = ""; |
|
| 1041 | + while($str = @fgets($this->smtp_conn,515)) { |
|
| 1042 | + if($this->do_debug >= 4) { |
|
| 1043 | + echo "SMTP -> get_lines(): \$data was \"$data\"" . |
|
| 1044 | + $this->CRLF; |
|
| 1045 | + echo "SMTP -> get_lines(): \$str is \"$str\"" . |
|
| 1046 | + $this->CRLF; |
|
| 1047 | + } |
|
| 1048 | + $data .= $str; |
|
| 1049 | + if($this->do_debug >= 4) { |
|
| 1050 | + echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF; |
|
| 1051 | + } |
|
| 1052 | + # if the 4th character is a space then we are done reading |
|
| 1053 | + # so just break the loop |
|
| 1054 | + if(substr($str,3,1) == " ") { break; } |
|
| 1055 | + } |
|
| 1056 | + return $data; |
|
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | 1059 | } |
@@ -135,8 +135,9 @@ discard block |
||
| 135 | 135 | # sometimes the SMTP server takes a little longer to respond |
| 136 | 136 | # so we will give it a longer timeout for the first read |
| 137 | 137 | // Windows still does not have support for this timeout function |
| 138 | - if(substr(PHP_OS, 0, 3) != "WIN") |
|
| 139 | - socket_set_timeout($this->smtp_conn, $tval, 0); |
|
| 138 | + if(substr(PHP_OS, 0, 3) != "WIN") { |
|
| 139 | + socket_set_timeout($this->smtp_conn, $tval, 0); |
|
| 140 | + } |
|
| 140 | 141 | |
| 141 | 142 | # get any announcement stuff |
| 142 | 143 | $announce = $this->get_lines(); |
@@ -489,8 +490,9 @@ discard block |
||
| 489 | 490 | // Send extended hello first (RFC 2821) |
| 490 | 491 | if(!$this->SendHello("EHLO", $host)) |
| 491 | 492 | { |
| 492 | - if(!$this->SendHello("HELO", $host)) |
|
| 493 | - return false; |
|
| 493 | + if(!$this->SendHello("HELO", $host)) { |
|
| 494 | + return false; |
|
| 495 | + } |
|
| 494 | 496 | } |
| 495 | 497 | |
| 496 | 498 | return true; |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * Sets whether debugging is turned on |
| 52 | 52 | * @var bool |
| 53 | 53 | */ |
| 54 | - var $do_debug; # the level of debug to perform |
|
| 54 | + var $do_debug; # the level of debug to perform |
|
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | 57 | * Sets VERP use on/off (default is off) |
@@ -62,9 +62,9 @@ discard block |
||
| 62 | 62 | /**#@+ |
| 63 | 63 | * @access private |
| 64 | 64 | */ |
| 65 | - var $smtp_conn; # the socket to the server |
|
| 66 | - var $error; # error if any on the last call |
|
| 67 | - var $helo_rply; # the reply the server sent to us for HELO |
|
| 65 | + var $smtp_conn; # the socket to the server |
|
| 66 | + var $error; # error if any on the last call |
|
| 67 | + var $helo_rply; # the reply the server sent to us for HELO |
|
| 68 | 68 | /**#@-*/ |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -97,12 +97,12 @@ discard block |
||
| 97 | 97 | * @access public |
| 98 | 98 | * @return bool |
| 99 | 99 | */ |
| 100 | - function Connect($host,$port=0,$tval=30) { |
|
| 100 | + function Connect($host, $port = 0, $tval = 30) { |
|
| 101 | 101 | # set the error val to null so there is no confusion |
| 102 | 102 | $this->error = null; |
| 103 | 103 | |
| 104 | 104 | # make sure we are __not__ connected |
| 105 | - if($this->connected()) { |
|
| 105 | + if ($this->connected()) { |
|
| 106 | 106 | # ok we are connected! what should we do? |
| 107 | 107 | # for now we will just give an error saying we |
| 108 | 108 | # are already connected |
@@ -110,24 +110,24 @@ discard block |
||
| 110 | 110 | return false; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - if(empty($port)) { |
|
| 113 | + if (empty($port)) { |
|
| 114 | 114 | $port = $this->SMTP_PORT; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | #connect to the smtp server |
| 118 | - $this->smtp_conn = fsockopen($host, # the host of the server |
|
| 119 | - $port, # the port to use |
|
| 120 | - $errno, # error number if any |
|
| 121 | - $errstr, # error message if any |
|
| 122 | - $tval); # give up after ? secs |
|
| 118 | + $this->smtp_conn = fsockopen($host, # the host of the server |
|
| 119 | + $port, # the port to use |
|
| 120 | + $errno, # error number if any |
|
| 121 | + $errstr, # error message if any |
|
| 122 | + $tval); # give up after ? secs |
|
| 123 | 123 | # verify we connected properly |
| 124 | - if(empty($this->smtp_conn)) { |
|
| 124 | + if (empty($this->smtp_conn)) { |
|
| 125 | 125 | $this->error = array("error" => "Failed to connect to server", |
| 126 | 126 | "errno" => $errno, |
| 127 | 127 | "errstr" => $errstr); |
| 128 | - if($this->do_debug >= 1) { |
|
| 129 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 130 | - ": $errstr ($errno)" . $this->CRLF; |
|
| 128 | + if ($this->do_debug >= 1) { |
|
| 129 | + echo "SMTP -> ERROR: ".$this->error["error"]. |
|
| 130 | + ": $errstr ($errno)".$this->CRLF; |
|
| 131 | 131 | } |
| 132 | 132 | return false; |
| 133 | 133 | } |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | # sometimes the SMTP server takes a little longer to respond |
| 136 | 136 | # so we will give it a longer timeout for the first read |
| 137 | 137 | // Windows still does not have support for this timeout function |
| 138 | - if(substr(PHP_OS, 0, 3) != "WIN") |
|
| 138 | + if (substr(PHP_OS, 0, 3) != "WIN") |
|
| 139 | 139 | socket_set_timeout($this->smtp_conn, $tval, 0); |
| 140 | 140 | |
| 141 | 141 | # get any announcement stuff |
@@ -145,8 +145,8 @@ discard block |
||
| 145 | 145 | //if(function_exists("socket_set_timeout")) |
| 146 | 146 | // socket_set_timeout($this->smtp_conn, 0, 100000); |
| 147 | 147 | |
| 148 | - if($this->do_debug >= 2) { |
|
| 149 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce; |
|
| 148 | + if ($this->do_debug >= 2) { |
|
| 149 | + echo "SMTP -> FROM SERVER:".$this->CRLF.$announce; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | return true; |
@@ -160,55 +160,55 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | function Authenticate($username, $password) { |
| 162 | 162 | // Start authentication |
| 163 | - fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF); |
|
| 163 | + fputs($this->smtp_conn, "AUTH LOGIN".$this->CRLF); |
|
| 164 | 164 | |
| 165 | 165 | $rply = $this->get_lines(); |
| 166 | - $code = substr($rply,0,3); |
|
| 166 | + $code = substr($rply, 0, 3); |
|
| 167 | 167 | |
| 168 | - if($code != 334) { |
|
| 168 | + if ($code != 334) { |
|
| 169 | 169 | $this->error = |
| 170 | 170 | array("error" => "AUTH not accepted from server", |
| 171 | 171 | "smtp_code" => $code, |
| 172 | - "smtp_msg" => substr($rply,4)); |
|
| 173 | - if($this->do_debug >= 1) { |
|
| 174 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 175 | - ": " . $rply . $this->CRLF; |
|
| 172 | + "smtp_msg" => substr($rply, 4)); |
|
| 173 | + if ($this->do_debug >= 1) { |
|
| 174 | + echo "SMTP -> ERROR: ".$this->error["error"]. |
|
| 175 | + ": ".$rply.$this->CRLF; |
|
| 176 | 176 | } |
| 177 | 177 | return false; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | // Send encoded username |
| 181 | - fputs($this->smtp_conn, base64_encode($username) . $this->CRLF); |
|
| 181 | + fputs($this->smtp_conn, base64_encode($username).$this->CRLF); |
|
| 182 | 182 | |
| 183 | 183 | $rply = $this->get_lines(); |
| 184 | - $code = substr($rply,0,3); |
|
| 184 | + $code = substr($rply, 0, 3); |
|
| 185 | 185 | |
| 186 | - if($code != 334) { |
|
| 186 | + if ($code != 334) { |
|
| 187 | 187 | $this->error = |
| 188 | 188 | array("error" => "Username not accepted from server", |
| 189 | 189 | "smtp_code" => $code, |
| 190 | - "smtp_msg" => substr($rply,4)); |
|
| 191 | - if($this->do_debug >= 1) { |
|
| 192 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 193 | - ": " . $rply . $this->CRLF; |
|
| 190 | + "smtp_msg" => substr($rply, 4)); |
|
| 191 | + if ($this->do_debug >= 1) { |
|
| 192 | + echo "SMTP -> ERROR: ".$this->error["error"]. |
|
| 193 | + ": ".$rply.$this->CRLF; |
|
| 194 | 194 | } |
| 195 | 195 | return false; |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | // Send encoded password |
| 199 | - fputs($this->smtp_conn, base64_encode($password) . $this->CRLF); |
|
| 199 | + fputs($this->smtp_conn, base64_encode($password).$this->CRLF); |
|
| 200 | 200 | |
| 201 | 201 | $rply = $this->get_lines(); |
| 202 | - $code = substr($rply,0,3); |
|
| 202 | + $code = substr($rply, 0, 3); |
|
| 203 | 203 | |
| 204 | - if($code != 235) { |
|
| 204 | + if ($code != 235) { |
|
| 205 | 205 | $this->error = |
| 206 | 206 | array("error" => "Password not accepted from server", |
| 207 | 207 | "smtp_code" => $code, |
| 208 | - "smtp_msg" => substr($rply,4)); |
|
| 209 | - if($this->do_debug >= 1) { |
|
| 210 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 211 | - ": " . $rply . $this->CRLF; |
|
| 208 | + "smtp_msg" => substr($rply, 4)); |
|
| 209 | + if ($this->do_debug >= 1) { |
|
| 210 | + echo "SMTP -> ERROR: ".$this->error["error"]. |
|
| 211 | + ": ".$rply.$this->CRLF; |
|
| 212 | 212 | } |
| 213 | 213 | return false; |
| 214 | 214 | } |
@@ -222,13 +222,13 @@ discard block |
||
| 222 | 222 | * @return bool |
| 223 | 223 | */ |
| 224 | 224 | function Connected() { |
| 225 | - if(!empty($this->smtp_conn)) { |
|
| 225 | + if (!empty($this->smtp_conn)) { |
|
| 226 | 226 | $sock_status = socket_get_status($this->smtp_conn); |
| 227 | - if($sock_status["eof"]) { |
|
| 227 | + if ($sock_status["eof"]) { |
|
| 228 | 228 | # hmm this is an odd situation... the socket is |
| 229 | 229 | # valid but we are not connected anymore |
| 230 | - if($this->do_debug >= 1) { |
|
| 231 | - echo "SMTP -> NOTICE:" . $this->CRLF . |
|
| 230 | + if ($this->do_debug >= 1) { |
|
| 231 | + echo "SMTP -> NOTICE:".$this->CRLF. |
|
| 232 | 232 | "EOF caught while checking if connected"; |
| 233 | 233 | } |
| 234 | 234 | $this->Close(); |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | function Close() { |
| 250 | 250 | $this->error = null; # so there is no confusion |
| 251 | 251 | $this->helo_rply = null; |
| 252 | - if(!empty($this->smtp_conn)) { |
|
| 252 | + if (!empty($this->smtp_conn)) { |
|
| 253 | 253 | # close the connection and cleanup |
| 254 | 254 | fclose($this->smtp_conn); |
| 255 | 255 | $this->smtp_conn = 0; |
@@ -282,29 +282,29 @@ discard block |
||
| 282 | 282 | function Data($msg_data) { |
| 283 | 283 | $this->error = null; # so no confusion is caused |
| 284 | 284 | |
| 285 | - if(!$this->connected()) { |
|
| 285 | + if (!$this->connected()) { |
|
| 286 | 286 | $this->error = array( |
| 287 | 287 | "error" => "Called Data() without being connected"); |
| 288 | 288 | return false; |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - fputs($this->smtp_conn,"DATA" . $this->CRLF); |
|
| 291 | + fputs($this->smtp_conn, "DATA".$this->CRLF); |
|
| 292 | 292 | |
| 293 | 293 | $rply = $this->get_lines(); |
| 294 | - $code = substr($rply,0,3); |
|
| 294 | + $code = substr($rply, 0, 3); |
|
| 295 | 295 | |
| 296 | - if($this->do_debug >= 2) { |
|
| 297 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 296 | + if ($this->do_debug >= 2) { |
|
| 297 | + echo "SMTP -> FROM SERVER:".$this->CRLF.$rply; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - if($code != 354) { |
|
| 300 | + if ($code != 354) { |
|
| 301 | 301 | $this->error = |
| 302 | 302 | array("error" => "DATA command not accepted from server", |
| 303 | 303 | "smtp_code" => $code, |
| 304 | - "smtp_msg" => substr($rply,4)); |
|
| 305 | - if($this->do_debug >= 1) { |
|
| 306 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 307 | - ": " . $rply . $this->CRLF; |
|
| 304 | + "smtp_msg" => substr($rply, 4)); |
|
| 305 | + if ($this->do_debug >= 1) { |
|
| 306 | + echo "SMTP -> ERROR: ".$this->error["error"]. |
|
| 307 | + ": ".$rply.$this->CRLF; |
|
| 308 | 308 | } |
| 309 | 309 | return false; |
| 310 | 310 | } |
@@ -320,9 +320,9 @@ discard block |
||
| 320 | 320 | # line. NOTE: this does not count towards are limit. |
| 321 | 321 | |
| 322 | 322 | # normalize the line breaks so we know the explode works |
| 323 | - $msg_data = str_replace("\r\n","\n",$msg_data); |
|
| 324 | - $msg_data = str_replace("\r","\n",$msg_data); |
|
| 325 | - $lines = explode("\n",$msg_data); |
|
| 323 | + $msg_data = str_replace("\r\n", "\n", $msg_data); |
|
| 324 | + $msg_data = str_replace("\r", "\n", $msg_data); |
|
| 325 | + $lines = explode("\n", $msg_data); |
|
| 326 | 326 | |
| 327 | 327 | # we need to find a good way to determine is headers are |
| 328 | 328 | # in the msg_data or if it is a straight msg body |
@@ -331,71 +331,71 @@ discard block |
||
| 331 | 331 | # does not contain a space then it _should_ be a header |
| 332 | 332 | # and we can process all lines before a blank "" line as |
| 333 | 333 | # headers. |
| 334 | - $field = substr($lines[0],0,strpos($lines[0],":")); |
|
| 334 | + $field = substr($lines[0], 0, strpos($lines[0], ":")); |
|
| 335 | 335 | $in_headers = false; |
| 336 | - if(!empty($field) && !strstr($field," ")) { |
|
| 336 | + if (!empty($field) && !strstr($field, " ")) { |
|
| 337 | 337 | $in_headers = true; |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | $max_line_length = 998; # used below; set here for ease in change |
| 341 | 341 | |
| 342 | - while(list(,$line) = @each($lines)) { |
|
| 342 | + while (list(,$line) = @each($lines)) { |
|
| 343 | 343 | $lines_out = null; |
| 344 | - if($line == "" && $in_headers) { |
|
| 344 | + if ($line == "" && $in_headers) { |
|
| 345 | 345 | $in_headers = false; |
| 346 | 346 | } |
| 347 | 347 | # ok we need to break this line up into several |
| 348 | 348 | # smaller lines |
| 349 | - while(strlen($line) > $max_line_length) { |
|
| 350 | - $pos = strrpos(substr($line,0,$max_line_length)," "); |
|
| 349 | + while (strlen($line) > $max_line_length) { |
|
| 350 | + $pos = strrpos(substr($line, 0, $max_line_length), " "); |
|
| 351 | 351 | |
| 352 | 352 | # Patch to fix DOS attack |
| 353 | - if(!$pos) { |
|
| 353 | + if (!$pos) { |
|
| 354 | 354 | $pos = $max_line_length - 1; |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - $lines_out[] = substr($line,0,$pos); |
|
| 358 | - $line = substr($line,$pos + 1); |
|
| 357 | + $lines_out[] = substr($line, 0, $pos); |
|
| 358 | + $line = substr($line, $pos + 1); |
|
| 359 | 359 | # if we are processing headers we need to |
| 360 | 360 | # add a LWSP-char to the front of the new line |
| 361 | 361 | # rfc 822 on long msg headers |
| 362 | - if($in_headers) { |
|
| 363 | - $line = "\t" . $line; |
|
| 362 | + if ($in_headers) { |
|
| 363 | + $line = "\t".$line; |
|
| 364 | 364 | } |
| 365 | 365 | } |
| 366 | 366 | $lines_out[] = $line; |
| 367 | 367 | |
| 368 | 368 | # now send the lines to the server |
| 369 | - while(list(,$line_out) = @each($lines_out)) { |
|
| 370 | - if(strlen($line_out) > 0) |
|
| 369 | + while (list(,$line_out) = @each($lines_out)) { |
|
| 370 | + if (strlen($line_out) > 0) |
|
| 371 | 371 | { |
| 372 | - if(substr($line_out, 0, 1) == ".") { |
|
| 373 | - $line_out = "." . $line_out; |
|
| 372 | + if (substr($line_out, 0, 1) == ".") { |
|
| 373 | + $line_out = ".".$line_out; |
|
| 374 | 374 | } |
| 375 | 375 | } |
| 376 | - fputs($this->smtp_conn,$line_out . $this->CRLF); |
|
| 376 | + fputs($this->smtp_conn, $line_out.$this->CRLF); |
|
| 377 | 377 | } |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | # ok all the message data has been sent so lets get this |
| 381 | 381 | # over with aleady |
| 382 | - fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF); |
|
| 382 | + fputs($this->smtp_conn, $this->CRLF.".".$this->CRLF); |
|
| 383 | 383 | |
| 384 | 384 | $rply = $this->get_lines(); |
| 385 | - $code = substr($rply,0,3); |
|
| 385 | + $code = substr($rply, 0, 3); |
|
| 386 | 386 | |
| 387 | - if($this->do_debug >= 2) { |
|
| 388 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 387 | + if ($this->do_debug >= 2) { |
|
| 388 | + echo "SMTP -> FROM SERVER:".$this->CRLF.$rply; |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | - if($code != 250) { |
|
| 391 | + if ($code != 250) { |
|
| 392 | 392 | $this->error = |
| 393 | 393 | array("error" => "DATA not accepted from server", |
| 394 | 394 | "smtp_code" => $code, |
| 395 | - "smtp_msg" => substr($rply,4)); |
|
| 396 | - if($this->do_debug >= 1) { |
|
| 397 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 398 | - ": " . $rply . $this->CRLF; |
|
| 395 | + "smtp_msg" => substr($rply, 4)); |
|
| 396 | + if ($this->do_debug >= 1) { |
|
| 397 | + echo "SMTP -> ERROR: ".$this->error["error"]. |
|
| 398 | + ": ".$rply.$this->CRLF; |
|
| 399 | 399 | } |
| 400 | 400 | return false; |
| 401 | 401 | } |
@@ -421,37 +421,37 @@ discard block |
||
| 421 | 421 | function Expand($name) { |
| 422 | 422 | $this->error = null; # so no confusion is caused |
| 423 | 423 | |
| 424 | - if(!$this->connected()) { |
|
| 424 | + if (!$this->connected()) { |
|
| 425 | 425 | $this->error = array( |
| 426 | 426 | "error" => "Called Expand() without being connected"); |
| 427 | 427 | return false; |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | - fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF); |
|
| 430 | + fputs($this->smtp_conn, "EXPN ".$name.$this->CRLF); |
|
| 431 | 431 | |
| 432 | 432 | $rply = $this->get_lines(); |
| 433 | - $code = substr($rply,0,3); |
|
| 433 | + $code = substr($rply, 0, 3); |
|
| 434 | 434 | |
| 435 | - if($this->do_debug >= 2) { |
|
| 436 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 435 | + if ($this->do_debug >= 2) { |
|
| 436 | + echo "SMTP -> FROM SERVER:".$this->CRLF.$rply; |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | - if($code != 250) { |
|
| 439 | + if ($code != 250) { |
|
| 440 | 440 | $this->error = |
| 441 | 441 | array("error" => "EXPN not accepted from server", |
| 442 | 442 | "smtp_code" => $code, |
| 443 | - "smtp_msg" => substr($rply,4)); |
|
| 444 | - if($this->do_debug >= 1) { |
|
| 445 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 446 | - ": " . $rply . $this->CRLF; |
|
| 443 | + "smtp_msg" => substr($rply, 4)); |
|
| 444 | + if ($this->do_debug >= 1) { |
|
| 445 | + echo "SMTP -> ERROR: ".$this->error["error"]. |
|
| 446 | + ": ".$rply.$this->CRLF; |
|
| 447 | 447 | } |
| 448 | 448 | return false; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | # parse the reply and place in our array to return to user |
| 452 | - $entries = explode($this->CRLF,$rply); |
|
| 453 | - while(list(,$l) = @each($entries)) { |
|
| 454 | - $list[] = substr($l,4); |
|
| 452 | + $entries = explode($this->CRLF, $rply); |
|
| 453 | + while (list(,$l) = @each($entries)) { |
|
| 454 | + $list[] = substr($l, 4); |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | return $list; |
@@ -469,10 +469,10 @@ discard block |
||
| 469 | 469 | * @access public |
| 470 | 470 | * @return bool |
| 471 | 471 | */ |
| 472 | - function Hello($host="") { |
|
| 472 | + function Hello($host = "") { |
|
| 473 | 473 | $this->error = null; # so no confusion is caused |
| 474 | 474 | |
| 475 | - if(!$this->connected()) { |
|
| 475 | + if (!$this->connected()) { |
|
| 476 | 476 | $this->error = array( |
| 477 | 477 | "error" => "Called Hello() without being connected"); |
| 478 | 478 | return false; |
@@ -480,16 +480,16 @@ discard block |
||
| 480 | 480 | |
| 481 | 481 | # if a hostname for the HELO was not specified determine |
| 482 | 482 | # a suitable one to send |
| 483 | - if(empty($host)) { |
|
| 483 | + if (empty($host)) { |
|
| 484 | 484 | # we need to determine some sort of appopiate default |
| 485 | 485 | # to send to the server |
| 486 | 486 | $host = "localhost"; |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | // Send extended hello first (RFC 2821) |
| 490 | - if(!$this->SendHello("EHLO", $host)) |
|
| 490 | + if (!$this->SendHello("EHLO", $host)) |
|
| 491 | 491 | { |
| 492 | - if(!$this->SendHello("HELO", $host)) |
|
| 492 | + if (!$this->SendHello("HELO", $host)) |
|
| 493 | 493 | return false; |
| 494 | 494 | } |
| 495 | 495 | |
@@ -502,23 +502,23 @@ discard block |
||
| 502 | 502 | * @return bool |
| 503 | 503 | */ |
| 504 | 504 | function SendHello($hello, $host) { |
| 505 | - fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF); |
|
| 505 | + fputs($this->smtp_conn, $hello." ".$host.$this->CRLF); |
|
| 506 | 506 | |
| 507 | 507 | $rply = $this->get_lines(); |
| 508 | - $code = substr($rply,0,3); |
|
| 508 | + $code = substr($rply, 0, 3); |
|
| 509 | 509 | |
| 510 | - if($this->do_debug >= 2) { |
|
| 511 | - echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply; |
|
| 510 | + if ($this->do_debug >= 2) { |
|
| 511 | + echo "SMTP -> FROM SERVER: ".$this->CRLF.$rply; |
|
| 512 | 512 | } |
| 513 | 513 | |
| 514 | - if($code != 250) { |
|
| 514 | + if ($code != 250) { |
|
| 515 | 515 | $this->error = |
| 516 | - array("error" => $hello . " not accepted from server", |
|
| 516 | + array("error" => $hello." not accepted from server", |
|
| 517 | 517 | "smtp_code" => $code, |
| 518 | - "smtp_msg" => substr($rply,4)); |
|
| 519 | - if($this->do_debug >= 1) { |
|
| 520 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 521 | - ": " . $rply . $this->CRLF; |
|
| 518 | + "smtp_msg" => substr($rply, 4)); |
|
| 519 | + if ($this->do_debug >= 1) { |
|
| 520 | + echo "SMTP -> ERROR: ".$this->error["error"]. |
|
| 521 | + ": ".$rply.$this->CRLF; |
|
| 522 | 522 | } |
| 523 | 523 | return false; |
| 524 | 524 | } |
@@ -543,37 +543,37 @@ discard block |
||
| 543 | 543 | * @access public |
| 544 | 544 | * @return string |
| 545 | 545 | */ |
| 546 | - function Help($keyword="") { |
|
| 546 | + function Help($keyword = "") { |
|
| 547 | 547 | $this->error = null; # to avoid confusion |
| 548 | 548 | |
| 549 | - if(!$this->connected()) { |
|
| 549 | + if (!$this->connected()) { |
|
| 550 | 550 | $this->error = array( |
| 551 | 551 | "error" => "Called Help() without being connected"); |
| 552 | 552 | return false; |
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | $extra = ""; |
| 556 | - if(!empty($keyword)) { |
|
| 557 | - $extra = " " . $keyword; |
|
| 556 | + if (!empty($keyword)) { |
|
| 557 | + $extra = " ".$keyword; |
|
| 558 | 558 | } |
| 559 | 559 | |
| 560 | - fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF); |
|
| 560 | + fputs($this->smtp_conn, "HELP".$extra.$this->CRLF); |
|
| 561 | 561 | |
| 562 | 562 | $rply = $this->get_lines(); |
| 563 | - $code = substr($rply,0,3); |
|
| 563 | + $code = substr($rply, 0, 3); |
|
| 564 | 564 | |
| 565 | - if($this->do_debug >= 2) { |
|
| 566 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 565 | + if ($this->do_debug >= 2) { |
|
| 566 | + echo "SMTP -> FROM SERVER:".$this->CRLF.$rply; |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | - if($code != 211 && $code != 214) { |
|
| 569 | + if ($code != 211 && $code != 214) { |
|
| 570 | 570 | $this->error = |
| 571 | 571 | array("error" => "HELP not accepted from server", |
| 572 | 572 | "smtp_code" => $code, |
| 573 | - "smtp_msg" => substr($rply,4)); |
|
| 574 | - if($this->do_debug >= 1) { |
|
| 575 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 576 | - ": " . $rply . $this->CRLF; |
|
| 573 | + "smtp_msg" => substr($rply, 4)); |
|
| 574 | + if ($this->do_debug >= 1) { |
|
| 575 | + echo "SMTP -> ERROR: ".$this->error["error"]. |
|
| 576 | + ": ".$rply.$this->CRLF; |
|
| 577 | 577 | } |
| 578 | 578 | return false; |
| 579 | 579 | } |
@@ -598,30 +598,30 @@ discard block |
||
| 598 | 598 | function Mail($from) { |
| 599 | 599 | $this->error = null; # so no confusion is caused |
| 600 | 600 | |
| 601 | - if(!$this->connected()) { |
|
| 601 | + if (!$this->connected()) { |
|
| 602 | 602 | $this->error = array( |
| 603 | 603 | "error" => "Called Mail() without being connected"); |
| 604 | 604 | return false; |
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | $useVerp = ($this->do_verp ? "XVERP" : ""); |
| 608 | - fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF); |
|
| 608 | + fputs($this->smtp_conn, "MAIL FROM:<".$from.">".$useVerp.$this->CRLF); |
|
| 609 | 609 | |
| 610 | 610 | $rply = $this->get_lines(); |
| 611 | - $code = substr($rply,0,3); |
|
| 611 | + $code = substr($rply, 0, 3); |
|
| 612 | 612 | |
| 613 | - if($this->do_debug >= 2) { |
|
| 614 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 613 | + if ($this->do_debug >= 2) { |
|
| 614 | + echo "SMTP -> FROM SERVER:".$this->CRLF.$rply; |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | - if($code != 250) { |
|
| 617 | + if ($code != 250) { |
|
| 618 | 618 | $this->error = |
| 619 | 619 | array("error" => "MAIL not accepted from server", |
| 620 | 620 | "smtp_code" => $code, |
| 621 | - "smtp_msg" => substr($rply,4)); |
|
| 622 | - if($this->do_debug >= 1) { |
|
| 623 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 624 | - ": " . $rply . $this->CRLF; |
|
| 621 | + "smtp_msg" => substr($rply, 4)); |
|
| 622 | + if ($this->do_debug >= 1) { |
|
| 623 | + echo "SMTP -> ERROR: ".$this->error["error"]. |
|
| 624 | + ": ".$rply.$this->CRLF; |
|
| 625 | 625 | } |
| 626 | 626 | return false; |
| 627 | 627 | } |
@@ -641,29 +641,29 @@ discard block |
||
| 641 | 641 | function Noop() { |
| 642 | 642 | $this->error = null; # so no confusion is caused |
| 643 | 643 | |
| 644 | - if(!$this->connected()) { |
|
| 644 | + if (!$this->connected()) { |
|
| 645 | 645 | $this->error = array( |
| 646 | 646 | "error" => "Called Noop() without being connected"); |
| 647 | 647 | return false; |
| 648 | 648 | } |
| 649 | 649 | |
| 650 | - fputs($this->smtp_conn,"NOOP" . $this->CRLF); |
|
| 650 | + fputs($this->smtp_conn, "NOOP".$this->CRLF); |
|
| 651 | 651 | |
| 652 | 652 | $rply = $this->get_lines(); |
| 653 | - $code = substr($rply,0,3); |
|
| 653 | + $code = substr($rply, 0, 3); |
|
| 654 | 654 | |
| 655 | - if($this->do_debug >= 2) { |
|
| 656 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 655 | + if ($this->do_debug >= 2) { |
|
| 656 | + echo "SMTP -> FROM SERVER:".$this->CRLF.$rply; |
|
| 657 | 657 | } |
| 658 | 658 | |
| 659 | - if($code != 250) { |
|
| 659 | + if ($code != 250) { |
|
| 660 | 660 | $this->error = |
| 661 | 661 | array("error" => "NOOP not accepted from server", |
| 662 | 662 | "smtp_code" => $code, |
| 663 | - "smtp_msg" => substr($rply,4)); |
|
| 664 | - if($this->do_debug >= 1) { |
|
| 665 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 666 | - ": " . $rply . $this->CRLF; |
|
| 663 | + "smtp_msg" => substr($rply, 4)); |
|
| 664 | + if ($this->do_debug >= 1) { |
|
| 665 | + echo "SMTP -> ERROR: ".$this->error["error"]. |
|
| 666 | + ": ".$rply.$this->CRLF; |
|
| 667 | 667 | } |
| 668 | 668 | return false; |
| 669 | 669 | } |
@@ -681,42 +681,42 @@ discard block |
||
| 681 | 681 | * @access public |
| 682 | 682 | * @return bool |
| 683 | 683 | */ |
| 684 | - function Quit($close_on_error=true) { |
|
| 684 | + function Quit($close_on_error = true) { |
|
| 685 | 685 | $this->error = null; # so there is no confusion |
| 686 | 686 | |
| 687 | - if(!$this->connected()) { |
|
| 687 | + if (!$this->connected()) { |
|
| 688 | 688 | $this->error = array( |
| 689 | 689 | "error" => "Called Quit() without being connected"); |
| 690 | 690 | return false; |
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | # send the quit command to the server |
| 694 | - fputs($this->smtp_conn,"quit" . $this->CRLF); |
|
| 694 | + fputs($this->smtp_conn, "quit".$this->CRLF); |
|
| 695 | 695 | |
| 696 | 696 | # get any good-bye messages |
| 697 | 697 | $byemsg = $this->get_lines(); |
| 698 | 698 | |
| 699 | - if($this->do_debug >= 2) { |
|
| 700 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg; |
|
| 699 | + if ($this->do_debug >= 2) { |
|
| 700 | + echo "SMTP -> FROM SERVER:".$this->CRLF.$byemsg; |
|
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | $rval = true; |
| 704 | 704 | $e = null; |
| 705 | 705 | |
| 706 | - $code = substr($byemsg,0,3); |
|
| 707 | - if($code != 221) { |
|
| 706 | + $code = substr($byemsg, 0, 3); |
|
| 707 | + if ($code != 221) { |
|
| 708 | 708 | # use e as a tmp var cause Close will overwrite $this->error |
| 709 | 709 | $e = array("error" => "SMTP server rejected quit command", |
| 710 | 710 | "smtp_code" => $code, |
| 711 | - "smtp_rply" => substr($byemsg,4)); |
|
| 711 | + "smtp_rply" => substr($byemsg, 4)); |
|
| 712 | 712 | $rval = false; |
| 713 | - if($this->do_debug >= 1) { |
|
| 714 | - echo "SMTP -> ERROR: " . $e["error"] . ": " . |
|
| 715 | - $byemsg . $this->CRLF; |
|
| 713 | + if ($this->do_debug >= 1) { |
|
| 714 | + echo "SMTP -> ERROR: ".$e["error"].": ". |
|
| 715 | + $byemsg.$this->CRLF; |
|
| 716 | 716 | } |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | - if(empty($e) || $close_on_error) { |
|
| 719 | + if (empty($e) || $close_on_error) { |
|
| 720 | 720 | $this->Close(); |
| 721 | 721 | } |
| 722 | 722 | |
@@ -738,29 +738,29 @@ discard block |
||
| 738 | 738 | function Recipient($to) { |
| 739 | 739 | $this->error = null; # so no confusion is caused |
| 740 | 740 | |
| 741 | - if(!$this->connected()) { |
|
| 741 | + if (!$this->connected()) { |
|
| 742 | 742 | $this->error = array( |
| 743 | 743 | "error" => "Called Recipient() without being connected"); |
| 744 | 744 | return false; |
| 745 | 745 | } |
| 746 | 746 | |
| 747 | - fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF); |
|
| 747 | + fputs($this->smtp_conn, "RCPT TO:<".$to.">".$this->CRLF); |
|
| 748 | 748 | |
| 749 | 749 | $rply = $this->get_lines(); |
| 750 | - $code = substr($rply,0,3); |
|
| 750 | + $code = substr($rply, 0, 3); |
|
| 751 | 751 | |
| 752 | - if($this->do_debug >= 2) { |
|
| 753 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 752 | + if ($this->do_debug >= 2) { |
|
| 753 | + echo "SMTP -> FROM SERVER:".$this->CRLF.$rply; |
|
| 754 | 754 | } |
| 755 | 755 | |
| 756 | - if($code != 250 && $code != 251) { |
|
| 756 | + if ($code != 250 && $code != 251) { |
|
| 757 | 757 | $this->error = |
| 758 | 758 | array("error" => "RCPT not accepted from server", |
| 759 | 759 | "smtp_code" => $code, |
| 760 | - "smtp_msg" => substr($rply,4)); |
|
| 761 | - if($this->do_debug >= 1) { |
|
| 762 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 763 | - ": " . $rply . $this->CRLF; |
|
| 760 | + "smtp_msg" => substr($rply, 4)); |
|
| 761 | + if ($this->do_debug >= 1) { |
|
| 762 | + echo "SMTP -> ERROR: ".$this->error["error"]. |
|
| 763 | + ": ".$rply.$this->CRLF; |
|
| 764 | 764 | } |
| 765 | 765 | return false; |
| 766 | 766 | } |
@@ -782,29 +782,29 @@ discard block |
||
| 782 | 782 | function Reset() { |
| 783 | 783 | $this->error = null; # so no confusion is caused |
| 784 | 784 | |
| 785 | - if(!$this->connected()) { |
|
| 785 | + if (!$this->connected()) { |
|
| 786 | 786 | $this->error = array( |
| 787 | 787 | "error" => "Called Reset() without being connected"); |
| 788 | 788 | return false; |
| 789 | 789 | } |
| 790 | 790 | |
| 791 | - fputs($this->smtp_conn,"RSET" . $this->CRLF); |
|
| 791 | + fputs($this->smtp_conn, "RSET".$this->CRLF); |
|
| 792 | 792 | |
| 793 | 793 | $rply = $this->get_lines(); |
| 794 | - $code = substr($rply,0,3); |
|
| 794 | + $code = substr($rply, 0, 3); |
|
| 795 | 795 | |
| 796 | - if($this->do_debug >= 2) { |
|
| 797 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 796 | + if ($this->do_debug >= 2) { |
|
| 797 | + echo "SMTP -> FROM SERVER:".$this->CRLF.$rply; |
|
| 798 | 798 | } |
| 799 | 799 | |
| 800 | - if($code != 250) { |
|
| 800 | + if ($code != 250) { |
|
| 801 | 801 | $this->error = |
| 802 | 802 | array("error" => "RSET failed", |
| 803 | 803 | "smtp_code" => $code, |
| 804 | - "smtp_msg" => substr($rply,4)); |
|
| 805 | - if($this->do_debug >= 1) { |
|
| 806 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 807 | - ": " . $rply . $this->CRLF; |
|
| 804 | + "smtp_msg" => substr($rply, 4)); |
|
| 805 | + if ($this->do_debug >= 1) { |
|
| 806 | + echo "SMTP -> ERROR: ".$this->error["error"]. |
|
| 807 | + ": ".$rply.$this->CRLF; |
|
| 808 | 808 | } |
| 809 | 809 | return false; |
| 810 | 810 | } |
@@ -831,29 +831,29 @@ discard block |
||
| 831 | 831 | function Send($from) { |
| 832 | 832 | $this->error = null; # so no confusion is caused |
| 833 | 833 | |
| 834 | - if(!$this->connected()) { |
|
| 834 | + if (!$this->connected()) { |
|
| 835 | 835 | $this->error = array( |
| 836 | 836 | "error" => "Called Send() without being connected"); |
| 837 | 837 | return false; |
| 838 | 838 | } |
| 839 | 839 | |
| 840 | - fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF); |
|
| 840 | + fputs($this->smtp_conn, "SEND FROM:".$from.$this->CRLF); |
|
| 841 | 841 | |
| 842 | 842 | $rply = $this->get_lines(); |
| 843 | - $code = substr($rply,0,3); |
|
| 843 | + $code = substr($rply, 0, 3); |
|
| 844 | 844 | |
| 845 | - if($this->do_debug >= 2) { |
|
| 846 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 845 | + if ($this->do_debug >= 2) { |
|
| 846 | + echo "SMTP -> FROM SERVER:".$this->CRLF.$rply; |
|
| 847 | 847 | } |
| 848 | 848 | |
| 849 | - if($code != 250) { |
|
| 849 | + if ($code != 250) { |
|
| 850 | 850 | $this->error = |
| 851 | 851 | array("error" => "SEND not accepted from server", |
| 852 | 852 | "smtp_code" => $code, |
| 853 | - "smtp_msg" => substr($rply,4)); |
|
| 854 | - if($this->do_debug >= 1) { |
|
| 855 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 856 | - ": " . $rply . $this->CRLF; |
|
| 853 | + "smtp_msg" => substr($rply, 4)); |
|
| 854 | + if ($this->do_debug >= 1) { |
|
| 855 | + echo "SMTP -> ERROR: ".$this->error["error"]. |
|
| 856 | + ": ".$rply.$this->CRLF; |
|
| 857 | 857 | } |
| 858 | 858 | return false; |
| 859 | 859 | } |
@@ -879,29 +879,29 @@ discard block |
||
| 879 | 879 | function SendAndMail($from) { |
| 880 | 880 | $this->error = null; # so no confusion is caused |
| 881 | 881 | |
| 882 | - if(!$this->connected()) { |
|
| 882 | + if (!$this->connected()) { |
|
| 883 | 883 | $this->error = array( |
| 884 | 884 | "error" => "Called SendAndMail() without being connected"); |
| 885 | 885 | return false; |
| 886 | 886 | } |
| 887 | 887 | |
| 888 | - fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF); |
|
| 888 | + fputs($this->smtp_conn, "SAML FROM:".$from.$this->CRLF); |
|
| 889 | 889 | |
| 890 | 890 | $rply = $this->get_lines(); |
| 891 | - $code = substr($rply,0,3); |
|
| 891 | + $code = substr($rply, 0, 3); |
|
| 892 | 892 | |
| 893 | - if($this->do_debug >= 2) { |
|
| 894 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 893 | + if ($this->do_debug >= 2) { |
|
| 894 | + echo "SMTP -> FROM SERVER:".$this->CRLF.$rply; |
|
| 895 | 895 | } |
| 896 | 896 | |
| 897 | - if($code != 250) { |
|
| 897 | + if ($code != 250) { |
|
| 898 | 898 | $this->error = |
| 899 | 899 | array("error" => "SAML not accepted from server", |
| 900 | 900 | "smtp_code" => $code, |
| 901 | - "smtp_msg" => substr($rply,4)); |
|
| 902 | - if($this->do_debug >= 1) { |
|
| 903 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 904 | - ": " . $rply . $this->CRLF; |
|
| 901 | + "smtp_msg" => substr($rply, 4)); |
|
| 902 | + if ($this->do_debug >= 1) { |
|
| 903 | + echo "SMTP -> ERROR: ".$this->error["error"]. |
|
| 904 | + ": ".$rply.$this->CRLF; |
|
| 905 | 905 | } |
| 906 | 906 | return false; |
| 907 | 907 | } |
@@ -927,29 +927,29 @@ discard block |
||
| 927 | 927 | function SendOrMail($from) { |
| 928 | 928 | $this->error = null; # so no confusion is caused |
| 929 | 929 | |
| 930 | - if(!$this->connected()) { |
|
| 930 | + if (!$this->connected()) { |
|
| 931 | 931 | $this->error = array( |
| 932 | 932 | "error" => "Called SendOrMail() without being connected"); |
| 933 | 933 | return false; |
| 934 | 934 | } |
| 935 | 935 | |
| 936 | - fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF); |
|
| 936 | + fputs($this->smtp_conn, "SOML FROM:".$from.$this->CRLF); |
|
| 937 | 937 | |
| 938 | 938 | $rply = $this->get_lines(); |
| 939 | - $code = substr($rply,0,3); |
|
| 939 | + $code = substr($rply, 0, 3); |
|
| 940 | 940 | |
| 941 | - if($this->do_debug >= 2) { |
|
| 942 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 941 | + if ($this->do_debug >= 2) { |
|
| 942 | + echo "SMTP -> FROM SERVER:".$this->CRLF.$rply; |
|
| 943 | 943 | } |
| 944 | 944 | |
| 945 | - if($code != 250) { |
|
| 945 | + if ($code != 250) { |
|
| 946 | 946 | $this->error = |
| 947 | 947 | array("error" => "SOML not accepted from server", |
| 948 | 948 | "smtp_code" => $code, |
| 949 | - "smtp_msg" => substr($rply,4)); |
|
| 950 | - if($this->do_debug >= 1) { |
|
| 951 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 952 | - ": " . $rply . $this->CRLF; |
|
| 949 | + "smtp_msg" => substr($rply, 4)); |
|
| 950 | + if ($this->do_debug >= 1) { |
|
| 951 | + echo "SMTP -> ERROR: ".$this->error["error"]. |
|
| 952 | + ": ".$rply.$this->CRLF; |
|
| 953 | 953 | } |
| 954 | 954 | return false; |
| 955 | 955 | } |
@@ -972,8 +972,8 @@ discard block |
||
| 972 | 972 | function Turn() { |
| 973 | 973 | $this->error = array("error" => "This method, TURN, of the SMTP ". |
| 974 | 974 | "is not implemented"); |
| 975 | - if($this->do_debug >= 1) { |
|
| 976 | - echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF; |
|
| 975 | + if ($this->do_debug >= 1) { |
|
| 976 | + echo "SMTP -> NOTICE: ".$this->error["error"].$this->CRLF; |
|
| 977 | 977 | } |
| 978 | 978 | return false; |
| 979 | 979 | } |
@@ -994,29 +994,29 @@ discard block |
||
| 994 | 994 | function Verify($name) { |
| 995 | 995 | $this->error = null; # so no confusion is caused |
| 996 | 996 | |
| 997 | - if(!$this->connected()) { |
|
| 997 | + if (!$this->connected()) { |
|
| 998 | 998 | $this->error = array( |
| 999 | 999 | "error" => "Called Verify() without being connected"); |
| 1000 | 1000 | return false; |
| 1001 | 1001 | } |
| 1002 | 1002 | |
| 1003 | - fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF); |
|
| 1003 | + fputs($this->smtp_conn, "VRFY ".$name.$this->CRLF); |
|
| 1004 | 1004 | |
| 1005 | 1005 | $rply = $this->get_lines(); |
| 1006 | - $code = substr($rply,0,3); |
|
| 1006 | + $code = substr($rply, 0, 3); |
|
| 1007 | 1007 | |
| 1008 | - if($this->do_debug >= 2) { |
|
| 1009 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|
| 1008 | + if ($this->do_debug >= 2) { |
|
| 1009 | + echo "SMTP -> FROM SERVER:".$this->CRLF.$rply; |
|
| 1010 | 1010 | } |
| 1011 | 1011 | |
| 1012 | - if($code != 250 && $code != 251) { |
|
| 1012 | + if ($code != 250 && $code != 251) { |
|
| 1013 | 1013 | $this->error = |
| 1014 | 1014 | array("error" => "VRFY failed on name '$name'", |
| 1015 | 1015 | "smtp_code" => $code, |
| 1016 | - "smtp_msg" => substr($rply,4)); |
|
| 1017 | - if($this->do_debug >= 1) { |
|
| 1018 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|
| 1019 | - ": " . $rply . $this->CRLF; |
|
| 1016 | + "smtp_msg" => substr($rply, 4)); |
|
| 1017 | + if ($this->do_debug >= 1) { |
|
| 1018 | + echo "SMTP -> ERROR: ".$this->error["error"]. |
|
| 1019 | + ": ".$rply.$this->CRLF; |
|
| 1020 | 1020 | } |
| 1021 | 1021 | return false; |
| 1022 | 1022 | } |
@@ -1038,20 +1038,20 @@ discard block |
||
| 1038 | 1038 | */ |
| 1039 | 1039 | function get_lines() { |
| 1040 | 1040 | $data = ""; |
| 1041 | - while($str = @fgets($this->smtp_conn,515)) { |
|
| 1042 | - if($this->do_debug >= 4) { |
|
| 1043 | - echo "SMTP -> get_lines(): \$data was \"$data\"" . |
|
| 1041 | + while ($str = @fgets($this->smtp_conn, 515)) { |
|
| 1042 | + if ($this->do_debug >= 4) { |
|
| 1043 | + echo "SMTP -> get_lines(): \$data was \"$data\"". |
|
| 1044 | 1044 | $this->CRLF; |
| 1045 | - echo "SMTP -> get_lines(): \$str is \"$str\"" . |
|
| 1045 | + echo "SMTP -> get_lines(): \$str is \"$str\"". |
|
| 1046 | 1046 | $this->CRLF; |
| 1047 | 1047 | } |
| 1048 | 1048 | $data .= $str; |
| 1049 | - if($this->do_debug >= 4) { |
|
| 1050 | - echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF; |
|
| 1049 | + if ($this->do_debug >= 4) { |
|
| 1050 | + echo "SMTP -> get_lines(): \$data is \"$data\"".$this->CRLF; |
|
| 1051 | 1051 | } |
| 1052 | 1052 | # if the 4th character is a space then we are done reading |
| 1053 | 1053 | # so just break the loop |
| 1054 | - if(substr($str,3,1) == " ") { break; } |
|
| 1054 | + if (substr($str, 3, 1) == " ") { break; } |
|
| 1055 | 1055 | } |
| 1056 | 1056 | return $data; |
| 1057 | 1057 | } |
@@ -892,6 +892,7 @@ discard block |
||
| 892 | 892 | /** |
| 893 | 893 | * Creates recipient headers. |
| 894 | 894 | * @access public |
| 895 | + * @param string $type |
|
| 895 | 896 | * @return string |
| 896 | 897 | */ |
| 897 | 898 | public function AddrAppend($type, $addr) { |
@@ -1259,6 +1260,9 @@ discard block |
||
| 1259 | 1260 | /** |
| 1260 | 1261 | * Returns the start of a message boundary. |
| 1261 | 1262 | * @access private |
| 1263 | + * @param string $charSet |
|
| 1264 | + * @param string $contentType |
|
| 1265 | + * @param string $encoding |
|
| 1262 | 1266 | */ |
| 1263 | 1267 | private function GetBoundary($boundary, $charSet, $contentType, $encoding) { |
| 1264 | 1268 | $result = ''; |
@@ -1312,6 +1316,7 @@ discard block |
||
| 1312 | 1316 | /** |
| 1313 | 1317 | * Returns a formatted header line. |
| 1314 | 1318 | * @access public |
| 1319 | + * @param string $name |
|
| 1315 | 1320 | * @return string |
| 1316 | 1321 | */ |
| 1317 | 1322 | public function HeaderLine($name, $value) { |
@@ -1321,6 +1326,7 @@ discard block |
||
| 1321 | 1326 | /** |
| 1322 | 1327 | * Returns a formatted mail line. |
| 1323 | 1328 | * @access public |
| 1329 | + * @param string $value |
|
| 1324 | 1330 | * @return string |
| 1325 | 1331 | */ |
| 1326 | 1332 | public function TextLine($value) { |
@@ -1517,6 +1523,7 @@ discard block |
||
| 1517 | 1523 | /** |
| 1518 | 1524 | * Encode a header string to best (shortest) of Q, B, quoted or none. |
| 1519 | 1525 | * @access public |
| 1526 | + * @param string $str |
|
| 1520 | 1527 | * @return string |
| 1521 | 1528 | */ |
| 1522 | 1529 | public function EncodeHeader ($str, $position = 'text') { |
@@ -1902,6 +1909,7 @@ discard block |
||
| 1902 | 1909 | /** |
| 1903 | 1910 | * Adds the error message to the error container. |
| 1904 | 1911 | * @access protected |
| 1912 | + * @param string $msg |
|
| 1905 | 1913 | * @return void |
| 1906 | 1914 | */ |
| 1907 | 1915 | protected function SetError($msg) { |
@@ -1951,6 +1959,7 @@ discard block |
||
| 1951 | 1959 | /** |
| 1952 | 1960 | * Returns a message in the appropriate language. |
| 1953 | 1961 | * @access private |
| 1962 | + * @param string $key |
|
| 1954 | 1963 | * @return string |
| 1955 | 1964 | */ |
| 1956 | 1965 | private function Lang($key) { |
@@ -1998,6 +2007,7 @@ discard block |
||
| 1998 | 2007 | /** |
| 1999 | 2008 | * Evaluates the message and returns modifications for inline images and backgrounds |
| 2000 | 2009 | * @access public |
| 2010 | + * @param string $message |
|
| 2001 | 2011 | * @return $message |
| 2002 | 2012 | */ |
| 2003 | 2013 | public function MsgHTML($message,$basedir='') { |
@@ -38,7 +38,9 @@ discard block |
||
| 38 | 38 | * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License |
| 39 | 39 | */ |
| 40 | 40 | |
| 41 | -if (version_compare(PHP_VERSION, '5.0.0', '<') ) exit("Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n"); |
|
| 41 | +if (version_compare(PHP_VERSION, '5.0.0', '<') ) { |
|
| 42 | + exit("Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n"); |
|
| 43 | +} |
|
| 42 | 44 | |
| 43 | 45 | class PHPMailer { |
| 44 | 46 | |
@@ -1498,8 +1500,9 @@ discard block |
||
| 1498 | 1500 | case '8bit': |
| 1499 | 1501 | $encoded = $this->FixEOL($str); |
| 1500 | 1502 | //Make sure it ends with a line break |
| 1501 | - if (substr($encoded, -(strlen($this->LE))) != $this->LE) |
|
| 1502 | - $encoded .= $this->LE; |
|
| 1503 | + if (substr($encoded, -(strlen($this->LE))) != $this->LE) { |
|
| 1504 | + $encoded .= $this->LE; |
|
| 1505 | + } |
|
| 1503 | 1506 | break; |
| 1504 | 1507 | case 'binary': |
| 1505 | 1508 | $encoded = $str; |
@@ -2249,7 +2252,9 @@ discard block |
||
| 2249 | 2252 | * @param string $body Message Body |
| 2250 | 2253 | */ |
| 2251 | 2254 | public function DKIM_BodyC($body) { |
| 2252 | - if ($body == '') return "\r\n"; |
|
| 2255 | + if ($body == '') { |
|
| 2256 | + return "\r\n"; |
|
| 2257 | + } |
|
| 2253 | 2258 | // stabilize line endings |
| 2254 | 2259 | $body=str_replace("\r\n","\n",$body); |
| 2255 | 2260 | $body=str_replace("\n","\r\n",$body); |
@@ -251,9 +251,9 @@ discard block |
||
| 251 | 251 | public $SingleToArray = array(); |
| 252 | 252 | |
| 253 | 253 | /** |
| 254 | - * Provides the ability to change the line ending |
|
| 255 | - * @var string |
|
| 256 | - */ |
|
| 254 | + * Provides the ability to change the line ending |
|
| 255 | + * @var string |
|
| 256 | + */ |
|
| 257 | 257 | public $LE = "\n"; |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | * @param boolean $exceptions Should we throw external exceptions? |
| 341 | 341 | */ |
| 342 | 342 | public function __construct($exceptions = false) { |
| 343 | - $this->exceptions = ($exceptions == true); |
|
| 343 | + $this->exceptions = ($exceptions == true); |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | /** |
@@ -349,11 +349,11 @@ discard block |
||
| 349 | 349 | * @return void |
| 350 | 350 | */ |
| 351 | 351 | public function IsHTML($ishtml = true) { |
| 352 | - if ($ishtml) { |
|
| 353 | - $this->ContentType = 'text/html'; |
|
| 354 | - } else { |
|
| 355 | - $this->ContentType = 'text/plain'; |
|
| 356 | - } |
|
| 352 | + if ($ishtml) { |
|
| 353 | + $this->ContentType = 'text/html'; |
|
| 354 | + } else { |
|
| 355 | + $this->ContentType = 'text/plain'; |
|
| 356 | + } |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | * @return void |
| 362 | 362 | */ |
| 363 | 363 | public function IsSMTP() { |
| 364 | - $this->Mailer = 'smtp'; |
|
| 364 | + $this->Mailer = 'smtp'; |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | /** |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | * @return void |
| 370 | 370 | */ |
| 371 | 371 | public function IsMail() { |
| 372 | - $this->Mailer = 'mail'; |
|
| 372 | + $this->Mailer = 'mail'; |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
@@ -377,10 +377,10 @@ discard block |
||
| 377 | 377 | * @return void |
| 378 | 378 | */ |
| 379 | 379 | public function IsSendmail() { |
| 380 | - if (!stristr(ini_get('sendmail_path'), 'sendmail')) { |
|
| 381 | - $this->Sendmail = '/var/qmail/bin/sendmail'; |
|
| 382 | - } |
|
| 383 | - $this->Mailer = 'sendmail'; |
|
| 380 | + if (!stristr(ini_get('sendmail_path'), 'sendmail')) { |
|
| 381 | + $this->Sendmail = '/var/qmail/bin/sendmail'; |
|
| 382 | + } |
|
| 383 | + $this->Mailer = 'sendmail'; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | /** |
@@ -388,10 +388,10 @@ discard block |
||
| 388 | 388 | * @return void |
| 389 | 389 | */ |
| 390 | 390 | public function IsQmail() { |
| 391 | - if (stristr(ini_get('sendmail_path'), 'qmail')) { |
|
| 392 | - $this->Sendmail = '/var/qmail/bin/sendmail'; |
|
| 393 | - } |
|
| 394 | - $this->Mailer = 'sendmail'; |
|
| 391 | + if (stristr(ini_get('sendmail_path'), 'qmail')) { |
|
| 392 | + $this->Sendmail = '/var/qmail/bin/sendmail'; |
|
| 393 | + } |
|
| 394 | + $this->Mailer = 'sendmail'; |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | ///////////////////////////////////////////////// |
@@ -405,7 +405,7 @@ discard block |
||
| 405 | 405 | * @return boolean true on success, false if address already used |
| 406 | 406 | */ |
| 407 | 407 | public function AddAddress($address, $name = '') { |
| 408 | - return $this->AddAnAddress('to', $address, $name); |
|
| 408 | + return $this->AddAnAddress('to', $address, $name); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | * @return boolean true on success, false if address already used |
| 417 | 417 | */ |
| 418 | 418 | public function AddCC($address, $name = '') { |
| 419 | - return $this->AddAnAddress('cc', $address, $name); |
|
| 419 | + return $this->AddAnAddress('cc', $address, $name); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | /** |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | * @return boolean true on success, false if address already used |
| 428 | 428 | */ |
| 429 | 429 | public function AddBCC($address, $name = '') { |
| 430 | - return $this->AddAnAddress('bcc', $address, $name); |
|
| 430 | + return $this->AddAnAddress('bcc', $address, $name); |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | /** |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | * @return boolean |
| 438 | 438 | */ |
| 439 | 439 | public function AddReplyTo($address, $name = '') { |
| 440 | - return $this->AddAnAddress('ReplyTo', $address, $name); |
|
| 440 | + return $this->AddAnAddress('ReplyTo', $address, $name); |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | /** |
@@ -450,31 +450,31 @@ discard block |
||
| 450 | 450 | * @access private |
| 451 | 451 | */ |
| 452 | 452 | private function AddAnAddress($kind, $address, $name = '') { |
| 453 | - if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) { |
|
| 454 | - echo 'Invalid recipient array: ' . kind; |
|
| 455 | - return false; |
|
| 456 | - } |
|
| 457 | - $address = trim($address); |
|
| 458 | - $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim |
|
| 459 | - if (!self::ValidateAddress($address)) { |
|
| 460 | - $this->SetError($this->Lang('invalid_address').': '. $address); |
|
| 461 | - if ($this->exceptions) { |
|
| 462 | - throw new phpmailerException($this->Lang('invalid_address').': '.$address); |
|
| 463 | - } |
|
| 464 | - echo $this->Lang('invalid_address').': '.$address; |
|
| 465 | - return false; |
|
| 466 | - } |
|
| 467 | - if ($kind != 'ReplyTo') { |
|
| 468 | - if (!isset($this->all_recipients[strtolower($address)])) { |
|
| 469 | - array_push($this->$kind, array($address, $name)); |
|
| 470 | - $this->all_recipients[strtolower($address)] = true; |
|
| 471 | - return true; |
|
| 472 | - } |
|
| 473 | - } else { |
|
| 474 | - if (!array_key_exists(strtolower($address), $this->ReplyTo)) { |
|
| 475 | - $this->ReplyTo[strtolower($address)] = array($address, $name); |
|
| 476 | - return true; |
|
| 477 | - } |
|
| 453 | + if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) { |
|
| 454 | + echo 'Invalid recipient array: ' . kind; |
|
| 455 | + return false; |
|
| 456 | + } |
|
| 457 | + $address = trim($address); |
|
| 458 | + $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim |
|
| 459 | + if (!self::ValidateAddress($address)) { |
|
| 460 | + $this->SetError($this->Lang('invalid_address').': '. $address); |
|
| 461 | + if ($this->exceptions) { |
|
| 462 | + throw new phpmailerException($this->Lang('invalid_address').': '.$address); |
|
| 463 | + } |
|
| 464 | + echo $this->Lang('invalid_address').': '.$address; |
|
| 465 | + return false; |
|
| 466 | + } |
|
| 467 | + if ($kind != 'ReplyTo') { |
|
| 468 | + if (!isset($this->all_recipients[strtolower($address)])) { |
|
| 469 | + array_push($this->$kind, array($address, $name)); |
|
| 470 | + $this->all_recipients[strtolower($address)] = true; |
|
| 471 | + return true; |
|
| 472 | + } |
|
| 473 | + } else { |
|
| 474 | + if (!array_key_exists(strtolower($address), $this->ReplyTo)) { |
|
| 475 | + $this->ReplyTo[strtolower($address)] = array($address, $name); |
|
| 476 | + return true; |
|
| 477 | + } |
|
| 478 | 478 | } |
| 479 | 479 | return false; |
| 480 | 480 | } |
@@ -486,27 +486,27 @@ discard block |
||
| 486 | 486 | * @return boolean |
| 487 | 487 | */ |
| 488 | 488 | public function SetFrom($address, $name = '',$auto=1) { |
| 489 | - $address = trim($address); |
|
| 490 | - $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim |
|
| 491 | - if (!self::ValidateAddress($address)) { |
|
| 492 | - $this->SetError($this->Lang('invalid_address').': '. $address); |
|
| 493 | - if ($this->exceptions) { |
|
| 494 | - throw new phpmailerException($this->Lang('invalid_address').': '.$address); |
|
| 495 | - } |
|
| 496 | - echo $this->Lang('invalid_address').': '.$address; |
|
| 497 | - return false; |
|
| 498 | - } |
|
| 499 | - $this->From = $address; |
|
| 500 | - $this->FromName = $name; |
|
| 501 | - if ($auto) { |
|
| 502 | - if (empty($this->ReplyTo)) { |
|
| 503 | - $this->AddAnAddress('ReplyTo', $address, $name); |
|
| 504 | - } |
|
| 505 | - if (empty($this->Sender)) { |
|
| 506 | - $this->Sender = $address; |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - return true; |
|
| 489 | + $address = trim($address); |
|
| 490 | + $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim |
|
| 491 | + if (!self::ValidateAddress($address)) { |
|
| 492 | + $this->SetError($this->Lang('invalid_address').': '. $address); |
|
| 493 | + if ($this->exceptions) { |
|
| 494 | + throw new phpmailerException($this->Lang('invalid_address').': '.$address); |
|
| 495 | + } |
|
| 496 | + echo $this->Lang('invalid_address').': '.$address; |
|
| 497 | + return false; |
|
| 498 | + } |
|
| 499 | + $this->From = $address; |
|
| 500 | + $this->FromName = $name; |
|
| 501 | + if ($auto) { |
|
| 502 | + if (empty($this->ReplyTo)) { |
|
| 503 | + $this->AddAnAddress('ReplyTo', $address, $name); |
|
| 504 | + } |
|
| 505 | + if (empty($this->Sender)) { |
|
| 506 | + $this->Sender = $address; |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + return true; |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | /** |
@@ -521,15 +521,15 @@ discard block |
||
| 521 | 521 | * @access public |
| 522 | 522 | */ |
| 523 | 523 | public static function ValidateAddress($address) { |
| 524 | - if (function_exists('filter_var')) { //Introduced in PHP 5.2 |
|
| 525 | - if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) { |
|
| 526 | - return false; |
|
| 527 | - } else { |
|
| 528 | - return true; |
|
| 529 | - } |
|
| 530 | - } else { |
|
| 531 | - return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address); |
|
| 532 | - } |
|
| 524 | + if (function_exists('filter_var')) { //Introduced in PHP 5.2 |
|
| 525 | + if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) { |
|
| 526 | + return false; |
|
| 527 | + } else { |
|
| 528 | + return true; |
|
| 529 | + } |
|
| 530 | + } else { |
|
| 531 | + return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address); |
|
| 532 | + } |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | ///////////////////////////////////////////////// |
@@ -543,49 +543,49 @@ discard block |
||
| 543 | 543 | * @return bool |
| 544 | 544 | */ |
| 545 | 545 | public function Send() { |
| 546 | - try { |
|
| 547 | - if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { |
|
| 548 | - throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL); |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - // Set whether the message is multipart/alternative |
|
| 552 | - if(!empty($this->AltBody)) { |
|
| 553 | - $this->ContentType = 'multipart/alternative'; |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - $this->error_count = 0; // reset errors |
|
| 557 | - $this->SetMessageType(); |
|
| 558 | - $header = $this->CreateHeader(); |
|
| 559 | - $body = $this->CreateBody(); |
|
| 560 | - |
|
| 561 | - if (empty($this->Body)) { |
|
| 562 | - throw new phpmailerException($this->Lang('empty_message'), self::STOP_CRITICAL); |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - // digitally sign with DKIM if enabled |
|
| 566 | - if ($this->DKIM_domain && $this->DKIM_private) { |
|
| 567 | - $header_dkim = $this->DKIM_Add($header,$this->Subject,$body); |
|
| 568 | - $header = str_replace("\r\n","\n",$header_dkim) . $header; |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - // Choose the mailer and send through it |
|
| 572 | - switch($this->Mailer) { |
|
| 573 | - case 'sendmail': |
|
| 574 | - return $this->SendmailSend($header, $body); |
|
| 575 | - case 'smtp': |
|
| 576 | - return $this->SmtpSend($header, $body); |
|
| 577 | - default: |
|
| 578 | - return $this->MailSend($header, $body); |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - } catch (phpmailerException $e) { |
|
| 582 | - $this->SetError($e->getMessage()); |
|
| 583 | - if ($this->exceptions) { |
|
| 584 | - throw $e; |
|
| 585 | - } |
|
| 586 | - echo $e->getMessage()."\n"; |
|
| 587 | - return false; |
|
| 588 | - } |
|
| 546 | + try { |
|
| 547 | + if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { |
|
| 548 | + throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL); |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + // Set whether the message is multipart/alternative |
|
| 552 | + if(!empty($this->AltBody)) { |
|
| 553 | + $this->ContentType = 'multipart/alternative'; |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + $this->error_count = 0; // reset errors |
|
| 557 | + $this->SetMessageType(); |
|
| 558 | + $header = $this->CreateHeader(); |
|
| 559 | + $body = $this->CreateBody(); |
|
| 560 | + |
|
| 561 | + if (empty($this->Body)) { |
|
| 562 | + throw new phpmailerException($this->Lang('empty_message'), self::STOP_CRITICAL); |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + // digitally sign with DKIM if enabled |
|
| 566 | + if ($this->DKIM_domain && $this->DKIM_private) { |
|
| 567 | + $header_dkim = $this->DKIM_Add($header,$this->Subject,$body); |
|
| 568 | + $header = str_replace("\r\n","\n",$header_dkim) . $header; |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + // Choose the mailer and send through it |
|
| 572 | + switch($this->Mailer) { |
|
| 573 | + case 'sendmail': |
|
| 574 | + return $this->SendmailSend($header, $body); |
|
| 575 | + case 'smtp': |
|
| 576 | + return $this->SmtpSend($header, $body); |
|
| 577 | + default: |
|
| 578 | + return $this->MailSend($header, $body); |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + } catch (phpmailerException $e) { |
|
| 582 | + $this->SetError($e->getMessage()); |
|
| 583 | + if ($this->exceptions) { |
|
| 584 | + throw $e; |
|
| 585 | + } |
|
| 586 | + echo $e->getMessage()."\n"; |
|
| 587 | + return false; |
|
| 588 | + } |
|
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | /** |
@@ -596,42 +596,42 @@ discard block |
||
| 596 | 596 | * @return bool |
| 597 | 597 | */ |
| 598 | 598 | protected function SendmailSend($header, $body) { |
| 599 | - if ($this->Sender != '') { |
|
| 600 | - $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender)); |
|
| 601 | - } else { |
|
| 602 | - $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail)); |
|
| 603 | - } |
|
| 604 | - if ($this->SingleTo === true) { |
|
| 605 | - foreach ($this->SingleToArray as $key => $val) { |
|
| 606 | - if(!@$mail = popen($sendmail, 'w')) { |
|
| 607 | - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 608 | - } |
|
| 609 | - fputs($mail, "To: " . $val . "\n"); |
|
| 610 | - fputs($mail, $header); |
|
| 611 | - fputs($mail, $body); |
|
| 612 | - $result = pclose($mail); |
|
| 613 | - // implement call back function if it exists |
|
| 614 | - $isSent = ($result == 0) ? 1 : 0; |
|
| 615 | - $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 616 | - if($result != 0) { |
|
| 617 | - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 618 | - } |
|
| 619 | - } |
|
| 620 | - } else { |
|
| 621 | - if(!@$mail = popen($sendmail, 'w')) { |
|
| 622 | - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 623 | - } |
|
| 624 | - fputs($mail, $header); |
|
| 625 | - fputs($mail, $body); |
|
| 626 | - $result = pclose($mail); |
|
| 627 | - // implement call back function if it exists |
|
| 628 | - $isSent = ($result == 0) ? 1 : 0; |
|
| 629 | - $this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 630 | - if($result != 0) { |
|
| 631 | - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - return true; |
|
| 599 | + if ($this->Sender != '') { |
|
| 600 | + $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender)); |
|
| 601 | + } else { |
|
| 602 | + $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail)); |
|
| 603 | + } |
|
| 604 | + if ($this->SingleTo === true) { |
|
| 605 | + foreach ($this->SingleToArray as $key => $val) { |
|
| 606 | + if(!@$mail = popen($sendmail, 'w')) { |
|
| 607 | + throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 608 | + } |
|
| 609 | + fputs($mail, "To: " . $val . "\n"); |
|
| 610 | + fputs($mail, $header); |
|
| 611 | + fputs($mail, $body); |
|
| 612 | + $result = pclose($mail); |
|
| 613 | + // implement call back function if it exists |
|
| 614 | + $isSent = ($result == 0) ? 1 : 0; |
|
| 615 | + $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 616 | + if($result != 0) { |
|
| 617 | + throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 618 | + } |
|
| 619 | + } |
|
| 620 | + } else { |
|
| 621 | + if(!@$mail = popen($sendmail, 'w')) { |
|
| 622 | + throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 623 | + } |
|
| 624 | + fputs($mail, $header); |
|
| 625 | + fputs($mail, $body); |
|
| 626 | + $result = pclose($mail); |
|
| 627 | + // implement call back function if it exists |
|
| 628 | + $isSent = ($result == 0) ? 1 : 0; |
|
| 629 | + $this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 630 | + if($result != 0) { |
|
| 631 | + throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + return true; |
|
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | /** |
@@ -642,51 +642,51 @@ discard block |
||
| 642 | 642 | * @return bool |
| 643 | 643 | */ |
| 644 | 644 | protected function MailSend($header, $body) { |
| 645 | - $toArr = array(); |
|
| 646 | - foreach($this->to as $t) { |
|
| 647 | - $toArr[] = $this->AddrFormat($t); |
|
| 648 | - } |
|
| 649 | - $to = implode(', ', $toArr); |
|
| 650 | - |
|
| 651 | - $params = sprintf("-oi -f %s", $this->Sender); |
|
| 652 | - if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) { |
|
| 653 | - $old_from = ini_get('sendmail_from'); |
|
| 654 | - ini_set('sendmail_from', $this->Sender); |
|
| 655 | - if ($this->SingleTo === true && count($toArr) > 1) { |
|
| 656 | - foreach ($toArr as $key => $val) { |
|
| 657 | - $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|
| 658 | - // implement call back function if it exists |
|
| 659 | - $isSent = ($rt == 1) ? 1 : 0; |
|
| 660 | - $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 661 | - } |
|
| 662 | - } else { |
|
| 663 | - $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|
| 664 | - // implement call back function if it exists |
|
| 665 | - $isSent = ($rt == 1) ? 1 : 0; |
|
| 666 | - $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 667 | - } |
|
| 668 | - } else { |
|
| 669 | - if ($this->SingleTo === true && count($toArr) > 1) { |
|
| 670 | - foreach ($toArr as $key => $val) { |
|
| 671 | - $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|
| 672 | - // implement call back function if it exists |
|
| 673 | - $isSent = ($rt == 1) ? 1 : 0; |
|
| 674 | - $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 675 | - } |
|
| 676 | - } else { |
|
| 677 | - $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header); |
|
| 678 | - // implement call back function if it exists |
|
| 679 | - $isSent = ($rt == 1) ? 1 : 0; |
|
| 680 | - $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 681 | - } |
|
| 682 | - } |
|
| 683 | - if (isset($old_from)) { |
|
| 684 | - ini_set('sendmail_from', $old_from); |
|
| 685 | - } |
|
| 686 | - if(!$rt) { |
|
| 687 | - throw new phpmailerException($this->Lang('instantiate'), self::STOP_CRITICAL); |
|
| 688 | - } |
|
| 689 | - return true; |
|
| 645 | + $toArr = array(); |
|
| 646 | + foreach($this->to as $t) { |
|
| 647 | + $toArr[] = $this->AddrFormat($t); |
|
| 648 | + } |
|
| 649 | + $to = implode(', ', $toArr); |
|
| 650 | + |
|
| 651 | + $params = sprintf("-oi -f %s", $this->Sender); |
|
| 652 | + if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) { |
|
| 653 | + $old_from = ini_get('sendmail_from'); |
|
| 654 | + ini_set('sendmail_from', $this->Sender); |
|
| 655 | + if ($this->SingleTo === true && count($toArr) > 1) { |
|
| 656 | + foreach ($toArr as $key => $val) { |
|
| 657 | + $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|
| 658 | + // implement call back function if it exists |
|
| 659 | + $isSent = ($rt == 1) ? 1 : 0; |
|
| 660 | + $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 661 | + } |
|
| 662 | + } else { |
|
| 663 | + $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|
| 664 | + // implement call back function if it exists |
|
| 665 | + $isSent = ($rt == 1) ? 1 : 0; |
|
| 666 | + $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 667 | + } |
|
| 668 | + } else { |
|
| 669 | + if ($this->SingleTo === true && count($toArr) > 1) { |
|
| 670 | + foreach ($toArr as $key => $val) { |
|
| 671 | + $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|
| 672 | + // implement call back function if it exists |
|
| 673 | + $isSent = ($rt == 1) ? 1 : 0; |
|
| 674 | + $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 675 | + } |
|
| 676 | + } else { |
|
| 677 | + $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header); |
|
| 678 | + // implement call back function if it exists |
|
| 679 | + $isSent = ($rt == 1) ? 1 : 0; |
|
| 680 | + $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 681 | + } |
|
| 682 | + } |
|
| 683 | + if (isset($old_from)) { |
|
| 684 | + ini_set('sendmail_from', $old_from); |
|
| 685 | + } |
|
| 686 | + if(!$rt) { |
|
| 687 | + throw new phpmailerException($this->Lang('instantiate'), self::STOP_CRITICAL); |
|
| 688 | + } |
|
| 689 | + return true; |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | /** |
@@ -699,67 +699,67 @@ discard block |
||
| 699 | 699 | * @return bool |
| 700 | 700 | */ |
| 701 | 701 | protected function SmtpSend($header, $body) { |
| 702 | - require_once $this->PluginDir . 'smtp.php'; |
|
| 703 | - $bad_rcpt = array(); |
|
| 704 | - |
|
| 705 | - if(!$this->SmtpConnect()) { |
|
| 706 | - throw new phpmailerException($this->Lang('smtp_connect_failed'), self::STOP_CRITICAL); |
|
| 707 | - } |
|
| 708 | - $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender; |
|
| 709 | - if(!$this->smtp->Mail($smtp_from)) { |
|
| 710 | - throw new phpmailerException($this->Lang('from_failed') . $smtp_from, self::STOP_CRITICAL); |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - // Attempt to send attach all recipients |
|
| 714 | - foreach($this->to as $to) { |
|
| 715 | - if (!$this->smtp->Recipient($to[0])) { |
|
| 716 | - $bad_rcpt[] = $to[0]; |
|
| 717 | - // implement call back function if it exists |
|
| 718 | - $isSent = 0; |
|
| 719 | - $this->doCallback($isSent,$to[0],'','',$this->Subject,$body); |
|
| 720 | - } else { |
|
| 721 | - // implement call back function if it exists |
|
| 722 | - $isSent = 1; |
|
| 723 | - $this->doCallback($isSent,$to[0],'','',$this->Subject,$body); |
|
| 724 | - } |
|
| 725 | - } |
|
| 726 | - foreach($this->cc as $cc) { |
|
| 727 | - if (!$this->smtp->Recipient($cc[0])) { |
|
| 728 | - $bad_rcpt[] = $cc[0]; |
|
| 729 | - // implement call back function if it exists |
|
| 730 | - $isSent = 0; |
|
| 731 | - $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body); |
|
| 732 | - } else { |
|
| 733 | - // implement call back function if it exists |
|
| 734 | - $isSent = 1; |
|
| 735 | - $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body); |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - foreach($this->bcc as $bcc) { |
|
| 739 | - if (!$this->smtp->Recipient($bcc[0])) { |
|
| 740 | - $bad_rcpt[] = $bcc[0]; |
|
| 741 | - // implement call back function if it exists |
|
| 742 | - $isSent = 0; |
|
| 743 | - $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body); |
|
| 744 | - } else { |
|
| 745 | - // implement call back function if it exists |
|
| 746 | - $isSent = 1; |
|
| 747 | - $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body); |
|
| 748 | - } |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - |
|
| 752 | - if (count($bad_rcpt) > 0 ) { //Create error message for any bad addresses |
|
| 753 | - $badaddresses = implode(', ', $bad_rcpt); |
|
| 754 | - throw new phpmailerException($this->Lang('recipients_failed') . $badaddresses); |
|
| 755 | - } |
|
| 756 | - if(!$this->smtp->Data($header . $body)) { |
|
| 757 | - throw new phpmailerException($this->Lang('data_not_accepted'), self::STOP_CRITICAL); |
|
| 758 | - } |
|
| 759 | - if($this->SMTPKeepAlive == true) { |
|
| 760 | - $this->smtp->Reset(); |
|
| 761 | - } |
|
| 762 | - return true; |
|
| 702 | + require_once $this->PluginDir . 'smtp.php'; |
|
| 703 | + $bad_rcpt = array(); |
|
| 704 | + |
|
| 705 | + if(!$this->SmtpConnect()) { |
|
| 706 | + throw new phpmailerException($this->Lang('smtp_connect_failed'), self::STOP_CRITICAL); |
|
| 707 | + } |
|
| 708 | + $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender; |
|
| 709 | + if(!$this->smtp->Mail($smtp_from)) { |
|
| 710 | + throw new phpmailerException($this->Lang('from_failed') . $smtp_from, self::STOP_CRITICAL); |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + // Attempt to send attach all recipients |
|
| 714 | + foreach($this->to as $to) { |
|
| 715 | + if (!$this->smtp->Recipient($to[0])) { |
|
| 716 | + $bad_rcpt[] = $to[0]; |
|
| 717 | + // implement call back function if it exists |
|
| 718 | + $isSent = 0; |
|
| 719 | + $this->doCallback($isSent,$to[0],'','',$this->Subject,$body); |
|
| 720 | + } else { |
|
| 721 | + // implement call back function if it exists |
|
| 722 | + $isSent = 1; |
|
| 723 | + $this->doCallback($isSent,$to[0],'','',$this->Subject,$body); |
|
| 724 | + } |
|
| 725 | + } |
|
| 726 | + foreach($this->cc as $cc) { |
|
| 727 | + if (!$this->smtp->Recipient($cc[0])) { |
|
| 728 | + $bad_rcpt[] = $cc[0]; |
|
| 729 | + // implement call back function if it exists |
|
| 730 | + $isSent = 0; |
|
| 731 | + $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body); |
|
| 732 | + } else { |
|
| 733 | + // implement call back function if it exists |
|
| 734 | + $isSent = 1; |
|
| 735 | + $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body); |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + foreach($this->bcc as $bcc) { |
|
| 739 | + if (!$this->smtp->Recipient($bcc[0])) { |
|
| 740 | + $bad_rcpt[] = $bcc[0]; |
|
| 741 | + // implement call back function if it exists |
|
| 742 | + $isSent = 0; |
|
| 743 | + $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body); |
|
| 744 | + } else { |
|
| 745 | + // implement call back function if it exists |
|
| 746 | + $isSent = 1; |
|
| 747 | + $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body); |
|
| 748 | + } |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + |
|
| 752 | + if (count($bad_rcpt) > 0 ) { //Create error message for any bad addresses |
|
| 753 | + $badaddresses = implode(', ', $bad_rcpt); |
|
| 754 | + throw new phpmailerException($this->Lang('recipients_failed') . $badaddresses); |
|
| 755 | + } |
|
| 756 | + if(!$this->smtp->Data($header . $body)) { |
|
| 757 | + throw new phpmailerException($this->Lang('data_not_accepted'), self::STOP_CRITICAL); |
|
| 758 | + } |
|
| 759 | + if($this->SMTPKeepAlive == true) { |
|
| 760 | + $this->smtp->Reset(); |
|
| 761 | + } |
|
| 762 | + return true; |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | /** |
@@ -770,61 +770,61 @@ discard block |
||
| 770 | 770 | * @return bool |
| 771 | 771 | */ |
| 772 | 772 | public function SmtpConnect() { |
| 773 | - if(is_null($this->smtp)) { |
|
| 774 | - $this->smtp = new SMTP(); |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - $this->smtp->do_debug = $this->SMTPDebug; |
|
| 778 | - $hosts = explode(';', $this->Host); |
|
| 779 | - $index = 0; |
|
| 780 | - $connection = $this->smtp->Connected(); |
|
| 781 | - |
|
| 782 | - // Retry while there is no connection |
|
| 783 | - try { |
|
| 784 | - while($index < count($hosts) && !$connection) { |
|
| 785 | - $hostinfo = array(); |
|
| 786 | - if (preg_match('/^(.+):([0-9]+)$/', $hosts[$index], $hostinfo)) { |
|
| 787 | - $host = $hostinfo[1]; |
|
| 788 | - $port = $hostinfo[2]; |
|
| 789 | - } else { |
|
| 790 | - $host = $hosts[$index]; |
|
| 791 | - $port = $this->Port; |
|
| 792 | - } |
|
| 793 | - |
|
| 794 | - $tls = ($this->SMTPSecure == 'tls'); |
|
| 795 | - $ssl = ($this->SMTPSecure == 'ssl'); |
|
| 796 | - |
|
| 797 | - if($this->smtp->Connect(($ssl ? 'ssl://':'').$host, $port, $this->Timeout)) { |
|
| 798 | - |
|
| 799 | - $hello = ($this->Helo != '' ? $this->Helo : $this->ServerHostname()); |
|
| 800 | - $this->smtp->Hello($hello); |
|
| 801 | - |
|
| 802 | - if($tls) { |
|
| 803 | - if(!$this->smtp->StartTLS()) { |
|
| 804 | - throw new phpmailerException($this->Lang('tls')); |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - //We must resend HELO after tls negotiation |
|
| 808 | - $this->smtp->Hello($hello); |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - $connection = true; |
|
| 812 | - if($this->SMTPAuth) { |
|
| 813 | - if(!$this->smtp->Authenticate($this->Username, $this->Password)) { |
|
| 814 | - throw new phpmailerException($this->Lang('authenticate')); |
|
| 815 | - } |
|
| 816 | - } |
|
| 817 | - } |
|
| 818 | - $index++; |
|
| 819 | - if(!$connection) { |
|
| 820 | - throw new phpmailerException($this->Lang('connect_host')); |
|
| 821 | - } |
|
| 822 | - } |
|
| 823 | - } catch (phpmailerException $e) { |
|
| 824 | - $this->smtp->Reset(); |
|
| 825 | - throw $e; |
|
| 826 | - } |
|
| 827 | - return true; |
|
| 773 | + if(is_null($this->smtp)) { |
|
| 774 | + $this->smtp = new SMTP(); |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + $this->smtp->do_debug = $this->SMTPDebug; |
|
| 778 | + $hosts = explode(';', $this->Host); |
|
| 779 | + $index = 0; |
|
| 780 | + $connection = $this->smtp->Connected(); |
|
| 781 | + |
|
| 782 | + // Retry while there is no connection |
|
| 783 | + try { |
|
| 784 | + while($index < count($hosts) && !$connection) { |
|
| 785 | + $hostinfo = array(); |
|
| 786 | + if (preg_match('/^(.+):([0-9]+)$/', $hosts[$index], $hostinfo)) { |
|
| 787 | + $host = $hostinfo[1]; |
|
| 788 | + $port = $hostinfo[2]; |
|
| 789 | + } else { |
|
| 790 | + $host = $hosts[$index]; |
|
| 791 | + $port = $this->Port; |
|
| 792 | + } |
|
| 793 | + |
|
| 794 | + $tls = ($this->SMTPSecure == 'tls'); |
|
| 795 | + $ssl = ($this->SMTPSecure == 'ssl'); |
|
| 796 | + |
|
| 797 | + if($this->smtp->Connect(($ssl ? 'ssl://':'').$host, $port, $this->Timeout)) { |
|
| 798 | + |
|
| 799 | + $hello = ($this->Helo != '' ? $this->Helo : $this->ServerHostname()); |
|
| 800 | + $this->smtp->Hello($hello); |
|
| 801 | + |
|
| 802 | + if($tls) { |
|
| 803 | + if(!$this->smtp->StartTLS()) { |
|
| 804 | + throw new phpmailerException($this->Lang('tls')); |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + //We must resend HELO after tls negotiation |
|
| 808 | + $this->smtp->Hello($hello); |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + $connection = true; |
|
| 812 | + if($this->SMTPAuth) { |
|
| 813 | + if(!$this->smtp->Authenticate($this->Username, $this->Password)) { |
|
| 814 | + throw new phpmailerException($this->Lang('authenticate')); |
|
| 815 | + } |
|
| 816 | + } |
|
| 817 | + } |
|
| 818 | + $index++; |
|
| 819 | + if(!$connection) { |
|
| 820 | + throw new phpmailerException($this->Lang('connect_host')); |
|
| 821 | + } |
|
| 822 | + } |
|
| 823 | + } catch (phpmailerException $e) { |
|
| 824 | + $this->smtp->Reset(); |
|
| 825 | + throw $e; |
|
| 826 | + } |
|
| 827 | + return true; |
|
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | /** |
@@ -832,57 +832,57 @@ discard block |
||
| 832 | 832 | * @return void |
| 833 | 833 | */ |
| 834 | 834 | public function SmtpClose() { |
| 835 | - if(!is_null($this->smtp)) { |
|
| 836 | - if($this->smtp->Connected()) { |
|
| 837 | - $this->smtp->Quit(); |
|
| 838 | - $this->smtp->Close(); |
|
| 839 | - } |
|
| 840 | - } |
|
| 835 | + if(!is_null($this->smtp)) { |
|
| 836 | + if($this->smtp->Connected()) { |
|
| 837 | + $this->smtp->Quit(); |
|
| 838 | + $this->smtp->Close(); |
|
| 839 | + } |
|
| 840 | + } |
|
| 841 | 841 | } |
| 842 | 842 | |
| 843 | 843 | /** |
| 844 | - * Sets the language for all class error messages. |
|
| 845 | - * Returns false if it cannot load the language file. The default language is English. |
|
| 846 | - * @param string $langcode ISO 639-1 2-character language code (e.g. Portuguese: "br") |
|
| 844 | + * Sets the language for all class error messages. |
|
| 845 | + * Returns false if it cannot load the language file. The default language is English. |
|
| 846 | + * @param string $langcode ISO 639-1 2-character language code (e.g. Portuguese: "br") |
|
| 847 | 847 | * @param string $lang_path Path to the language file directory |
| 848 | 848 | * @access public |
| 849 | 849 | */ |
| 850 | 850 | function SetLanguage($langcode = 'en', $lang_path = 'language/') { |
| 851 | - //Define full set of translatable strings |
|
| 852 | - $PHPMAILER_LANG = array( |
|
| 853 | - 'provide_address' => 'You must provide at least one recipient email address.', |
|
| 854 | - 'mailer_not_supported' => ' mailer is not supported.', |
|
| 855 | - 'execute' => 'Could not execute: ', |
|
| 856 | - 'instantiate' => 'Could not instantiate mail function.', |
|
| 857 | - 'authenticate' => 'SMTP Error: Could not authenticate.', |
|
| 858 | - 'from_failed' => 'The following From address failed: ', |
|
| 859 | - 'recipients_failed' => 'SMTP Error: The following recipients failed: ', |
|
| 860 | - 'data_not_accepted' => 'SMTP Error: Data not accepted.', |
|
| 861 | - 'connect_host' => 'SMTP Error: Could not connect to SMTP host.', |
|
| 862 | - 'file_access' => 'Could not access file: ', |
|
| 863 | - 'file_open' => 'File Error: Could not open file: ', |
|
| 864 | - 'encoding' => 'Unknown encoding: ', |
|
| 865 | - 'signing' => 'Signing Error: ', |
|
| 866 | - 'smtp_error' => 'SMTP server error: ', |
|
| 867 | - 'empty_message' => 'Message body empty', |
|
| 868 | - 'invalid_address' => 'Invalid address', |
|
| 869 | - 'variable_set' => 'Cannot set or reset variable: ' |
|
| 870 | - ); |
|
| 871 | - //Overwrite language-specific strings. This way we'll never have missing translations - no more "language string failed to load"! |
|
| 872 | - $l = true; |
|
| 873 | - if ($langcode != 'en') { //There is no English translation file |
|
| 874 | - $l = @include $lang_path.'phpmailer.lang-'.$langcode.'.php'; |
|
| 875 | - } |
|
| 876 | - $this->language = $PHPMAILER_LANG; |
|
| 877 | - return ($l == true); //Returns false if language not found |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - /** |
|
| 881 | - * Return the current array of language strings |
|
| 882 | - * @return array |
|
| 883 | - */ |
|
| 851 | + //Define full set of translatable strings |
|
| 852 | + $PHPMAILER_LANG = array( |
|
| 853 | + 'provide_address' => 'You must provide at least one recipient email address.', |
|
| 854 | + 'mailer_not_supported' => ' mailer is not supported.', |
|
| 855 | + 'execute' => 'Could not execute: ', |
|
| 856 | + 'instantiate' => 'Could not instantiate mail function.', |
|
| 857 | + 'authenticate' => 'SMTP Error: Could not authenticate.', |
|
| 858 | + 'from_failed' => 'The following From address failed: ', |
|
| 859 | + 'recipients_failed' => 'SMTP Error: The following recipients failed: ', |
|
| 860 | + 'data_not_accepted' => 'SMTP Error: Data not accepted.', |
|
| 861 | + 'connect_host' => 'SMTP Error: Could not connect to SMTP host.', |
|
| 862 | + 'file_access' => 'Could not access file: ', |
|
| 863 | + 'file_open' => 'File Error: Could not open file: ', |
|
| 864 | + 'encoding' => 'Unknown encoding: ', |
|
| 865 | + 'signing' => 'Signing Error: ', |
|
| 866 | + 'smtp_error' => 'SMTP server error: ', |
|
| 867 | + 'empty_message' => 'Message body empty', |
|
| 868 | + 'invalid_address' => 'Invalid address', |
|
| 869 | + 'variable_set' => 'Cannot set or reset variable: ' |
|
| 870 | + ); |
|
| 871 | + //Overwrite language-specific strings. This way we'll never have missing translations - no more "language string failed to load"! |
|
| 872 | + $l = true; |
|
| 873 | + if ($langcode != 'en') { //There is no English translation file |
|
| 874 | + $l = @include $lang_path.'phpmailer.lang-'.$langcode.'.php'; |
|
| 875 | + } |
|
| 876 | + $this->language = $PHPMAILER_LANG; |
|
| 877 | + return ($l == true); //Returns false if language not found |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + /** |
|
| 881 | + * Return the current array of language strings |
|
| 882 | + * @return array |
|
| 883 | + */ |
|
| 884 | 884 | public function GetTranslations() { |
| 885 | - return $this->language; |
|
| 885 | + return $this->language; |
|
| 886 | 886 | } |
| 887 | 887 | |
| 888 | 888 | ///////////////////////////////////////////////// |
@@ -895,15 +895,15 @@ discard block |
||
| 895 | 895 | * @return string |
| 896 | 896 | */ |
| 897 | 897 | public function AddrAppend($type, $addr) { |
| 898 | - $addr_str = $type . ': '; |
|
| 899 | - $addresses = array(); |
|
| 900 | - foreach ($addr as $a) { |
|
| 901 | - $addresses[] = $this->AddrFormat($a); |
|
| 902 | - } |
|
| 903 | - $addr_str .= implode(', ', $addresses); |
|
| 904 | - $addr_str .= $this->LE; |
|
| 898 | + $addr_str = $type . ': '; |
|
| 899 | + $addresses = array(); |
|
| 900 | + foreach ($addr as $a) { |
|
| 901 | + $addresses[] = $this->AddrFormat($a); |
|
| 902 | + } |
|
| 903 | + $addr_str .= implode(', ', $addresses); |
|
| 904 | + $addr_str .= $this->LE; |
|
| 905 | 905 | |
| 906 | - return $addr_str; |
|
| 906 | + return $addr_str; |
|
| 907 | 907 | } |
| 908 | 908 | |
| 909 | 909 | /** |
@@ -912,11 +912,11 @@ discard block |
||
| 912 | 912 | * @return string |
| 913 | 913 | */ |
| 914 | 914 | public function AddrFormat($addr) { |
| 915 | - if(empty($addr[1])) { |
|
| 916 | - return $this->SecureHeader($addr[0]); |
|
| 917 | - } else { |
|
| 918 | - return $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">"; |
|
| 919 | - } |
|
| 915 | + if(empty($addr[1])) { |
|
| 916 | + return $this->SecureHeader($addr[0]); |
|
| 917 | + } else { |
|
| 918 | + return $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">"; |
|
| 919 | + } |
|
| 920 | 920 | } |
| 921 | 921 | |
| 922 | 922 | /** |
@@ -930,76 +930,76 @@ discard block |
||
| 930 | 930 | * @return string |
| 931 | 931 | */ |
| 932 | 932 | public function WrapText($message, $length, $qp_mode = false) { |
| 933 | - $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE; |
|
| 934 | - // If utf-8 encoding is used, we will need to make sure we don't |
|
| 935 | - // split multibyte characters when we wrap |
|
| 936 | - $is_utf8 = (strtolower($this->CharSet) == "utf-8"); |
|
| 937 | - |
|
| 938 | - $message = $this->FixEOL($message); |
|
| 939 | - if (substr($message, -1) == $this->LE) { |
|
| 940 | - $message = substr($message, 0, -1); |
|
| 941 | - } |
|
| 942 | - |
|
| 943 | - $line = explode($this->LE, $message); |
|
| 944 | - $message = ''; |
|
| 945 | - for ($i=0 ;$i < count($line); $i++) { |
|
| 946 | - $line_part = explode(' ', $line[$i]); |
|
| 947 | - $buf = ''; |
|
| 948 | - for ($e = 0; $e<count($line_part); $e++) { |
|
| 949 | - $word = $line_part[$e]; |
|
| 950 | - if ($qp_mode and (strlen($word) > $length)) { |
|
| 951 | - $space_left = $length - strlen($buf) - 1; |
|
| 952 | - if ($e != 0) { |
|
| 953 | - if ($space_left > 20) { |
|
| 954 | - $len = $space_left; |
|
| 955 | - if ($is_utf8) { |
|
| 956 | - $len = $this->UTF8CharBoundary($word, $len); |
|
| 957 | - } elseif (substr($word, $len - 1, 1) == "=") { |
|
| 958 | - $len--; |
|
| 959 | - } elseif (substr($word, $len - 2, 1) == "=") { |
|
| 960 | - $len -= 2; |
|
| 961 | - } |
|
| 962 | - $part = substr($word, 0, $len); |
|
| 963 | - $word = substr($word, $len); |
|
| 964 | - $buf .= ' ' . $part; |
|
| 965 | - $message .= $buf . sprintf("=%s", $this->LE); |
|
| 966 | - } else { |
|
| 967 | - $message .= $buf . $soft_break; |
|
| 968 | - } |
|
| 969 | - $buf = ''; |
|
| 970 | - } |
|
| 971 | - while (strlen($word) > 0) { |
|
| 972 | - $len = $length; |
|
| 973 | - if ($is_utf8) { |
|
| 974 | - $len = $this->UTF8CharBoundary($word, $len); |
|
| 975 | - } elseif (substr($word, $len - 1, 1) == "=") { |
|
| 976 | - $len--; |
|
| 977 | - } elseif (substr($word, $len - 2, 1) == "=") { |
|
| 978 | - $len -= 2; |
|
| 979 | - } |
|
| 980 | - $part = substr($word, 0, $len); |
|
| 981 | - $word = substr($word, $len); |
|
| 982 | - |
|
| 983 | - if (strlen($word) > 0) { |
|
| 984 | - $message .= $part . sprintf("=%s", $this->LE); |
|
| 985 | - } else { |
|
| 986 | - $buf = $part; |
|
| 987 | - } |
|
| 988 | - } |
|
| 989 | - } else { |
|
| 990 | - $buf_o = $buf; |
|
| 991 | - $buf .= ($e == 0) ? $word : (' ' . $word); |
|
| 992 | - |
|
| 993 | - if (strlen($buf) > $length and $buf_o != '') { |
|
| 994 | - $message .= $buf_o . $soft_break; |
|
| 995 | - $buf = $word; |
|
| 996 | - } |
|
| 997 | - } |
|
| 998 | - } |
|
| 999 | - $message .= $buf . $this->LE; |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - return $message; |
|
| 933 | + $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE; |
|
| 934 | + // If utf-8 encoding is used, we will need to make sure we don't |
|
| 935 | + // split multibyte characters when we wrap |
|
| 936 | + $is_utf8 = (strtolower($this->CharSet) == "utf-8"); |
|
| 937 | + |
|
| 938 | + $message = $this->FixEOL($message); |
|
| 939 | + if (substr($message, -1) == $this->LE) { |
|
| 940 | + $message = substr($message, 0, -1); |
|
| 941 | + } |
|
| 942 | + |
|
| 943 | + $line = explode($this->LE, $message); |
|
| 944 | + $message = ''; |
|
| 945 | + for ($i=0 ;$i < count($line); $i++) { |
|
| 946 | + $line_part = explode(' ', $line[$i]); |
|
| 947 | + $buf = ''; |
|
| 948 | + for ($e = 0; $e<count($line_part); $e++) { |
|
| 949 | + $word = $line_part[$e]; |
|
| 950 | + if ($qp_mode and (strlen($word) > $length)) { |
|
| 951 | + $space_left = $length - strlen($buf) - 1; |
|
| 952 | + if ($e != 0) { |
|
| 953 | + if ($space_left > 20) { |
|
| 954 | + $len = $space_left; |
|
| 955 | + if ($is_utf8) { |
|
| 956 | + $len = $this->UTF8CharBoundary($word, $len); |
|
| 957 | + } elseif (substr($word, $len - 1, 1) == "=") { |
|
| 958 | + $len--; |
|
| 959 | + } elseif (substr($word, $len - 2, 1) == "=") { |
|
| 960 | + $len -= 2; |
|
| 961 | + } |
|
| 962 | + $part = substr($word, 0, $len); |
|
| 963 | + $word = substr($word, $len); |
|
| 964 | + $buf .= ' ' . $part; |
|
| 965 | + $message .= $buf . sprintf("=%s", $this->LE); |
|
| 966 | + } else { |
|
| 967 | + $message .= $buf . $soft_break; |
|
| 968 | + } |
|
| 969 | + $buf = ''; |
|
| 970 | + } |
|
| 971 | + while (strlen($word) > 0) { |
|
| 972 | + $len = $length; |
|
| 973 | + if ($is_utf8) { |
|
| 974 | + $len = $this->UTF8CharBoundary($word, $len); |
|
| 975 | + } elseif (substr($word, $len - 1, 1) == "=") { |
|
| 976 | + $len--; |
|
| 977 | + } elseif (substr($word, $len - 2, 1) == "=") { |
|
| 978 | + $len -= 2; |
|
| 979 | + } |
|
| 980 | + $part = substr($word, 0, $len); |
|
| 981 | + $word = substr($word, $len); |
|
| 982 | + |
|
| 983 | + if (strlen($word) > 0) { |
|
| 984 | + $message .= $part . sprintf("=%s", $this->LE); |
|
| 985 | + } else { |
|
| 986 | + $buf = $part; |
|
| 987 | + } |
|
| 988 | + } |
|
| 989 | + } else { |
|
| 990 | + $buf_o = $buf; |
|
| 991 | + $buf .= ($e == 0) ? $word : (' ' . $word); |
|
| 992 | + |
|
| 993 | + if (strlen($buf) > $length and $buf_o != '') { |
|
| 994 | + $message .= $buf_o . $soft_break; |
|
| 995 | + $buf = $word; |
|
| 996 | + } |
|
| 997 | + } |
|
| 998 | + } |
|
| 999 | + $message .= $buf . $this->LE; |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + return $message; |
|
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | 1005 | /** |
@@ -1012,35 +1012,35 @@ discard block |
||
| 1012 | 1012 | * @return int |
| 1013 | 1013 | */ |
| 1014 | 1014 | public function UTF8CharBoundary($encodedText, $maxLength) { |
| 1015 | - $foundSplitPos = false; |
|
| 1016 | - $lookBack = 3; |
|
| 1017 | - while (!$foundSplitPos) { |
|
| 1018 | - $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack); |
|
| 1019 | - $encodedCharPos = strpos($lastChunk, "="); |
|
| 1020 | - if ($encodedCharPos !== false) { |
|
| 1021 | - // Found start of encoded character byte within $lookBack block. |
|
| 1022 | - // Check the encoded byte value (the 2 chars after the '=') |
|
| 1023 | - $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2); |
|
| 1024 | - $dec = hexdec($hex); |
|
| 1025 | - if ($dec < 128) { // Single byte character. |
|
| 1026 | - // If the encoded char was found at pos 0, it will fit |
|
| 1027 | - // otherwise reduce maxLength to start of the encoded char |
|
| 1028 | - $maxLength = ($encodedCharPos == 0) ? $maxLength : |
|
| 1029 | - $maxLength - ($lookBack - $encodedCharPos); |
|
| 1030 | - $foundSplitPos = true; |
|
| 1031 | - } elseif ($dec >= 192) { // First byte of a multi byte character |
|
| 1032 | - // Reduce maxLength to split at start of character |
|
| 1033 | - $maxLength = $maxLength - ($lookBack - $encodedCharPos); |
|
| 1034 | - $foundSplitPos = true; |
|
| 1035 | - } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back |
|
| 1036 | - $lookBack += 3; |
|
| 1037 | - } |
|
| 1038 | - } else { |
|
| 1039 | - // No encoded character found |
|
| 1040 | - $foundSplitPos = true; |
|
| 1041 | - } |
|
| 1042 | - } |
|
| 1043 | - return $maxLength; |
|
| 1015 | + $foundSplitPos = false; |
|
| 1016 | + $lookBack = 3; |
|
| 1017 | + while (!$foundSplitPos) { |
|
| 1018 | + $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack); |
|
| 1019 | + $encodedCharPos = strpos($lastChunk, "="); |
|
| 1020 | + if ($encodedCharPos !== false) { |
|
| 1021 | + // Found start of encoded character byte within $lookBack block. |
|
| 1022 | + // Check the encoded byte value (the 2 chars after the '=') |
|
| 1023 | + $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2); |
|
| 1024 | + $dec = hexdec($hex); |
|
| 1025 | + if ($dec < 128) { // Single byte character. |
|
| 1026 | + // If the encoded char was found at pos 0, it will fit |
|
| 1027 | + // otherwise reduce maxLength to start of the encoded char |
|
| 1028 | + $maxLength = ($encodedCharPos == 0) ? $maxLength : |
|
| 1029 | + $maxLength - ($lookBack - $encodedCharPos); |
|
| 1030 | + $foundSplitPos = true; |
|
| 1031 | + } elseif ($dec >= 192) { // First byte of a multi byte character |
|
| 1032 | + // Reduce maxLength to split at start of character |
|
| 1033 | + $maxLength = $maxLength - ($lookBack - $encodedCharPos); |
|
| 1034 | + $foundSplitPos = true; |
|
| 1035 | + } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back |
|
| 1036 | + $lookBack += 3; |
|
| 1037 | + } |
|
| 1038 | + } else { |
|
| 1039 | + // No encoded character found |
|
| 1040 | + $foundSplitPos = true; |
|
| 1041 | + } |
|
| 1042 | + } |
|
| 1043 | + return $maxLength; |
|
| 1044 | 1044 | } |
| 1045 | 1045 | |
| 1046 | 1046 | |
@@ -1050,19 +1050,19 @@ discard block |
||
| 1050 | 1050 | * @return void |
| 1051 | 1051 | */ |
| 1052 | 1052 | public function SetWordWrap() { |
| 1053 | - if($this->WordWrap < 1) { |
|
| 1054 | - return; |
|
| 1055 | - } |
|
| 1053 | + if($this->WordWrap < 1) { |
|
| 1054 | + return; |
|
| 1055 | + } |
|
| 1056 | 1056 | |
| 1057 | - switch($this->message_type) { |
|
| 1058 | - case 'alt': |
|
| 1059 | - case 'alt_attachments': |
|
| 1060 | - $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap); |
|
| 1061 | - break; |
|
| 1062 | - default: |
|
| 1063 | - $this->Body = $this->WrapText($this->Body, $this->WordWrap); |
|
| 1064 | - break; |
|
| 1065 | - } |
|
| 1057 | + switch($this->message_type) { |
|
| 1058 | + case 'alt': |
|
| 1059 | + case 'alt_attachments': |
|
| 1060 | + $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap); |
|
| 1061 | + break; |
|
| 1062 | + default: |
|
| 1063 | + $this->Body = $this->WrapText($this->Body, $this->WordWrap); |
|
| 1064 | + break; |
|
| 1065 | + } |
|
| 1066 | 1066 | } |
| 1067 | 1067 | |
| 1068 | 1068 | /** |
@@ -1071,81 +1071,81 @@ discard block |
||
| 1071 | 1071 | * @return string The assembled header |
| 1072 | 1072 | */ |
| 1073 | 1073 | public function CreateHeader() { |
| 1074 | - $result = ''; |
|
| 1075 | - |
|
| 1076 | - // Set the boundaries |
|
| 1077 | - $uniq_id = md5(uniqid(time())); |
|
| 1078 | - $this->boundary[1] = 'b1_' . $uniq_id; |
|
| 1079 | - $this->boundary[2] = 'b2_' . $uniq_id; |
|
| 1080 | - |
|
| 1081 | - $result .= $this->HeaderLine('Date', self::RFCDate()); |
|
| 1082 | - if($this->Sender == '') { |
|
| 1083 | - $result .= $this->HeaderLine('Return-Path', trim($this->From)); |
|
| 1084 | - } else { |
|
| 1085 | - $result .= $this->HeaderLine('Return-Path', trim($this->Sender)); |
|
| 1086 | - } |
|
| 1087 | - |
|
| 1088 | - // To be created automatically by mail() |
|
| 1089 | - if($this->Mailer != 'mail') { |
|
| 1090 | - if ($this->SingleTo === true) { |
|
| 1091 | - foreach($this->to as $t) { |
|
| 1092 | - $this->SingleToArray[] = $this->AddrFormat($t); |
|
| 1093 | - } |
|
| 1094 | - } else { |
|
| 1095 | - if(count($this->to) > 0) { |
|
| 1096 | - $result .= $this->AddrAppend('To', $this->to); |
|
| 1097 | - } elseif (count($this->cc) == 0) { |
|
| 1098 | - $result .= $this->HeaderLine('To', 'undisclosed-recipients:;'); |
|
| 1099 | - } |
|
| 1100 | - } |
|
| 1101 | - } |
|
| 1102 | - |
|
| 1103 | - $from = array(); |
|
| 1104 | - $from[0][0] = trim($this->From); |
|
| 1105 | - $from[0][1] = $this->FromName; |
|
| 1106 | - $result .= $this->AddrAppend('From', $from); |
|
| 1107 | - |
|
| 1108 | - // sendmail and mail() extract Cc from the header before sending |
|
| 1109 | - if(count($this->cc) > 0) { |
|
| 1110 | - $result .= $this->AddrAppend('Cc', $this->cc); |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - // sendmail and mail() extract Bcc from the header before sending |
|
| 1114 | - if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) { |
|
| 1115 | - $result .= $this->AddrAppend('Bcc', $this->bcc); |
|
| 1116 | - } |
|
| 1117 | - |
|
| 1118 | - if(count($this->ReplyTo) > 0) { |
|
| 1119 | - $result .= $this->AddrAppend('Reply-to', $this->ReplyTo); |
|
| 1120 | - } |
|
| 1121 | - |
|
| 1122 | - // mail() sets the subject itself |
|
| 1123 | - if($this->Mailer != 'mail') { |
|
| 1124 | - $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject))); |
|
| 1125 | - } |
|
| 1126 | - |
|
| 1127 | - if($this->MessageID != '') { |
|
| 1128 | - $result .= $this->HeaderLine('Message-ID',$this->MessageID); |
|
| 1129 | - } else { |
|
| 1130 | - $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); |
|
| 1131 | - } |
|
| 1132 | - $result .= $this->HeaderLine('X-Priority', $this->Priority); |
|
| 1133 | - $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (phpmailer.sourceforge.net)'); |
|
| 1134 | - |
|
| 1135 | - if($this->ConfirmReadingTo != '') { |
|
| 1136 | - $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>'); |
|
| 1137 | - } |
|
| 1138 | - |
|
| 1139 | - // Add custom headers |
|
| 1140 | - for($index = 0; $index < count($this->CustomHeader); $index++) { |
|
| 1141 | - $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1]))); |
|
| 1142 | - } |
|
| 1143 | - if (!$this->sign_key_file) { |
|
| 1144 | - $result .= $this->HeaderLine('MIME-Version', '1.0'); |
|
| 1145 | - $result .= $this->GetMailMIME(); |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - return $result; |
|
| 1074 | + $result = ''; |
|
| 1075 | + |
|
| 1076 | + // Set the boundaries |
|
| 1077 | + $uniq_id = md5(uniqid(time())); |
|
| 1078 | + $this->boundary[1] = 'b1_' . $uniq_id; |
|
| 1079 | + $this->boundary[2] = 'b2_' . $uniq_id; |
|
| 1080 | + |
|
| 1081 | + $result .= $this->HeaderLine('Date', self::RFCDate()); |
|
| 1082 | + if($this->Sender == '') { |
|
| 1083 | + $result .= $this->HeaderLine('Return-Path', trim($this->From)); |
|
| 1084 | + } else { |
|
| 1085 | + $result .= $this->HeaderLine('Return-Path', trim($this->Sender)); |
|
| 1086 | + } |
|
| 1087 | + |
|
| 1088 | + // To be created automatically by mail() |
|
| 1089 | + if($this->Mailer != 'mail') { |
|
| 1090 | + if ($this->SingleTo === true) { |
|
| 1091 | + foreach($this->to as $t) { |
|
| 1092 | + $this->SingleToArray[] = $this->AddrFormat($t); |
|
| 1093 | + } |
|
| 1094 | + } else { |
|
| 1095 | + if(count($this->to) > 0) { |
|
| 1096 | + $result .= $this->AddrAppend('To', $this->to); |
|
| 1097 | + } elseif (count($this->cc) == 0) { |
|
| 1098 | + $result .= $this->HeaderLine('To', 'undisclosed-recipients:;'); |
|
| 1099 | + } |
|
| 1100 | + } |
|
| 1101 | + } |
|
| 1102 | + |
|
| 1103 | + $from = array(); |
|
| 1104 | + $from[0][0] = trim($this->From); |
|
| 1105 | + $from[0][1] = $this->FromName; |
|
| 1106 | + $result .= $this->AddrAppend('From', $from); |
|
| 1107 | + |
|
| 1108 | + // sendmail and mail() extract Cc from the header before sending |
|
| 1109 | + if(count($this->cc) > 0) { |
|
| 1110 | + $result .= $this->AddrAppend('Cc', $this->cc); |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + // sendmail and mail() extract Bcc from the header before sending |
|
| 1114 | + if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) { |
|
| 1115 | + $result .= $this->AddrAppend('Bcc', $this->bcc); |
|
| 1116 | + } |
|
| 1117 | + |
|
| 1118 | + if(count($this->ReplyTo) > 0) { |
|
| 1119 | + $result .= $this->AddrAppend('Reply-to', $this->ReplyTo); |
|
| 1120 | + } |
|
| 1121 | + |
|
| 1122 | + // mail() sets the subject itself |
|
| 1123 | + if($this->Mailer != 'mail') { |
|
| 1124 | + $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject))); |
|
| 1125 | + } |
|
| 1126 | + |
|
| 1127 | + if($this->MessageID != '') { |
|
| 1128 | + $result .= $this->HeaderLine('Message-ID',$this->MessageID); |
|
| 1129 | + } else { |
|
| 1130 | + $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); |
|
| 1131 | + } |
|
| 1132 | + $result .= $this->HeaderLine('X-Priority', $this->Priority); |
|
| 1133 | + $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (phpmailer.sourceforge.net)'); |
|
| 1134 | + |
|
| 1135 | + if($this->ConfirmReadingTo != '') { |
|
| 1136 | + $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>'); |
|
| 1137 | + } |
|
| 1138 | + |
|
| 1139 | + // Add custom headers |
|
| 1140 | + for($index = 0; $index < count($this->CustomHeader); $index++) { |
|
| 1141 | + $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1]))); |
|
| 1142 | + } |
|
| 1143 | + if (!$this->sign_key_file) { |
|
| 1144 | + $result .= $this->HeaderLine('MIME-Version', '1.0'); |
|
| 1145 | + $result .= $this->GetMailMIME(); |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + return $result; |
|
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | 1151 | /** |
@@ -1154,32 +1154,32 @@ discard block |
||
| 1154 | 1154 | * @return string |
| 1155 | 1155 | */ |
| 1156 | 1156 | public function GetMailMIME() { |
| 1157 | - $result = ''; |
|
| 1158 | - switch($this->message_type) { |
|
| 1159 | - case 'plain': |
|
| 1160 | - $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); |
|
| 1161 | - $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet); |
|
| 1162 | - break; |
|
| 1163 | - case 'attachments': |
|
| 1164 | - case 'alt_attachments': |
|
| 1165 | - if($this->InlineImageExists()){ |
|
| 1166 | - $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE); |
|
| 1167 | - } else { |
|
| 1168 | - $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;'); |
|
| 1169 | - $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|
| 1170 | - } |
|
| 1171 | - break; |
|
| 1172 | - case 'alt': |
|
| 1173 | - $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); |
|
| 1174 | - $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|
| 1175 | - break; |
|
| 1176 | - } |
|
| 1177 | - |
|
| 1178 | - if($this->Mailer != 'mail') { |
|
| 1179 | - $result .= $this->LE.$this->LE; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - return $result; |
|
| 1157 | + $result = ''; |
|
| 1158 | + switch($this->message_type) { |
|
| 1159 | + case 'plain': |
|
| 1160 | + $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); |
|
| 1161 | + $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet); |
|
| 1162 | + break; |
|
| 1163 | + case 'attachments': |
|
| 1164 | + case 'alt_attachments': |
|
| 1165 | + if($this->InlineImageExists()){ |
|
| 1166 | + $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE); |
|
| 1167 | + } else { |
|
| 1168 | + $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;'); |
|
| 1169 | + $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|
| 1170 | + } |
|
| 1171 | + break; |
|
| 1172 | + case 'alt': |
|
| 1173 | + $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); |
|
| 1174 | + $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|
| 1175 | + break; |
|
| 1176 | + } |
|
| 1177 | + |
|
| 1178 | + if($this->Mailer != 'mail') { |
|
| 1179 | + $result .= $this->LE.$this->LE; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + return $result; |
|
| 1183 | 1183 | } |
| 1184 | 1184 | |
| 1185 | 1185 | /** |
@@ -1188,72 +1188,72 @@ discard block |
||
| 1188 | 1188 | * @return string The assembled message body |
| 1189 | 1189 | */ |
| 1190 | 1190 | public function CreateBody() { |
| 1191 | - $body = ''; |
|
| 1192 | - |
|
| 1193 | - if ($this->sign_key_file) { |
|
| 1194 | - $body .= $this->GetMailMIME(); |
|
| 1195 | - } |
|
| 1196 | - |
|
| 1197 | - $this->SetWordWrap(); |
|
| 1198 | - |
|
| 1199 | - switch($this->message_type) { |
|
| 1200 | - case 'alt': |
|
| 1201 | - $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', ''); |
|
| 1202 | - $body .= $this->EncodeString($this->AltBody, $this->Encoding); |
|
| 1203 | - $body .= $this->LE.$this->LE; |
|
| 1204 | - $body .= $this->GetBoundary($this->boundary[1], '', 'text/html', ''); |
|
| 1205 | - $body .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1206 | - $body .= $this->LE.$this->LE; |
|
| 1207 | - $body .= $this->EndBoundary($this->boundary[1]); |
|
| 1208 | - break; |
|
| 1209 | - case 'plain': |
|
| 1210 | - $body .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1211 | - break; |
|
| 1212 | - case 'attachments': |
|
| 1213 | - $body .= $this->GetBoundary($this->boundary[1], '', '', ''); |
|
| 1214 | - $body .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1215 | - $body .= $this->LE; |
|
| 1216 | - $body .= $this->AttachAll(); |
|
| 1217 | - break; |
|
| 1218 | - case 'alt_attachments': |
|
| 1219 | - $body .= sprintf("--%s%s", $this->boundary[1], $this->LE); |
|
| 1220 | - $body .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE); |
|
| 1221 | - $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body |
|
| 1222 | - $body .= $this->EncodeString($this->AltBody, $this->Encoding); |
|
| 1223 | - $body .= $this->LE.$this->LE; |
|
| 1224 | - $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body |
|
| 1225 | - $body .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1226 | - $body .= $this->LE.$this->LE; |
|
| 1227 | - $body .= $this->EndBoundary($this->boundary[2]); |
|
| 1228 | - $body .= $this->AttachAll(); |
|
| 1229 | - break; |
|
| 1230 | - } |
|
| 1231 | - |
|
| 1232 | - if($this->IsError()) { |
|
| 1233 | - $body = ''; |
|
| 1234 | - } else if ($this->sign_key_file) { |
|
| 1235 | - try { |
|
| 1236 | - $file = tempnam('', 'mail'); |
|
| 1237 | - file_put_contents($file, $body, LOCK_EX); //TODO check this worked |
|
| 1238 | - $signed = tempnam("", "signed"); |
|
| 1239 | - if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), NULL)) { |
|
| 1240 | - @unlink($file); |
|
| 1241 | - @unlink($signed); |
|
| 1242 | - $body = file_get_contents($signed); |
|
| 1243 | - } else { |
|
| 1244 | - @unlink($file); |
|
| 1245 | - @unlink($signed); |
|
| 1246 | - throw new phpmailerException($this->Lang("signing").openssl_error_string()); |
|
| 1247 | - } |
|
| 1248 | - } catch (phpmailerException $e) { |
|
| 1249 | - $body = ''; |
|
| 1250 | - if ($this->exceptions) { |
|
| 1251 | - throw $e; |
|
| 1252 | - } |
|
| 1253 | - } |
|
| 1254 | - } |
|
| 1255 | - |
|
| 1256 | - return $body; |
|
| 1191 | + $body = ''; |
|
| 1192 | + |
|
| 1193 | + if ($this->sign_key_file) { |
|
| 1194 | + $body .= $this->GetMailMIME(); |
|
| 1195 | + } |
|
| 1196 | + |
|
| 1197 | + $this->SetWordWrap(); |
|
| 1198 | + |
|
| 1199 | + switch($this->message_type) { |
|
| 1200 | + case 'alt': |
|
| 1201 | + $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', ''); |
|
| 1202 | + $body .= $this->EncodeString($this->AltBody, $this->Encoding); |
|
| 1203 | + $body .= $this->LE.$this->LE; |
|
| 1204 | + $body .= $this->GetBoundary($this->boundary[1], '', 'text/html', ''); |
|
| 1205 | + $body .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1206 | + $body .= $this->LE.$this->LE; |
|
| 1207 | + $body .= $this->EndBoundary($this->boundary[1]); |
|
| 1208 | + break; |
|
| 1209 | + case 'plain': |
|
| 1210 | + $body .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1211 | + break; |
|
| 1212 | + case 'attachments': |
|
| 1213 | + $body .= $this->GetBoundary($this->boundary[1], '', '', ''); |
|
| 1214 | + $body .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1215 | + $body .= $this->LE; |
|
| 1216 | + $body .= $this->AttachAll(); |
|
| 1217 | + break; |
|
| 1218 | + case 'alt_attachments': |
|
| 1219 | + $body .= sprintf("--%s%s", $this->boundary[1], $this->LE); |
|
| 1220 | + $body .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE); |
|
| 1221 | + $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body |
|
| 1222 | + $body .= $this->EncodeString($this->AltBody, $this->Encoding); |
|
| 1223 | + $body .= $this->LE.$this->LE; |
|
| 1224 | + $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body |
|
| 1225 | + $body .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1226 | + $body .= $this->LE.$this->LE; |
|
| 1227 | + $body .= $this->EndBoundary($this->boundary[2]); |
|
| 1228 | + $body .= $this->AttachAll(); |
|
| 1229 | + break; |
|
| 1230 | + } |
|
| 1231 | + |
|
| 1232 | + if($this->IsError()) { |
|
| 1233 | + $body = ''; |
|
| 1234 | + } else if ($this->sign_key_file) { |
|
| 1235 | + try { |
|
| 1236 | + $file = tempnam('', 'mail'); |
|
| 1237 | + file_put_contents($file, $body, LOCK_EX); //TODO check this worked |
|
| 1238 | + $signed = tempnam("", "signed"); |
|
| 1239 | + if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), NULL)) { |
|
| 1240 | + @unlink($file); |
|
| 1241 | + @unlink($signed); |
|
| 1242 | + $body = file_get_contents($signed); |
|
| 1243 | + } else { |
|
| 1244 | + @unlink($file); |
|
| 1245 | + @unlink($signed); |
|
| 1246 | + throw new phpmailerException($this->Lang("signing").openssl_error_string()); |
|
| 1247 | + } |
|
| 1248 | + } catch (phpmailerException $e) { |
|
| 1249 | + $body = ''; |
|
| 1250 | + if ($this->exceptions) { |
|
| 1251 | + throw $e; |
|
| 1252 | + } |
|
| 1253 | + } |
|
| 1254 | + } |
|
| 1255 | + |
|
| 1256 | + return $body; |
|
| 1257 | 1257 | } |
| 1258 | 1258 | |
| 1259 | 1259 | /** |
@@ -1261,23 +1261,23 @@ discard block |
||
| 1261 | 1261 | * @access private |
| 1262 | 1262 | */ |
| 1263 | 1263 | private function GetBoundary($boundary, $charSet, $contentType, $encoding) { |
| 1264 | - $result = ''; |
|
| 1265 | - if($charSet == '') { |
|
| 1266 | - $charSet = $this->CharSet; |
|
| 1267 | - } |
|
| 1268 | - if($contentType == '') { |
|
| 1269 | - $contentType = $this->ContentType; |
|
| 1270 | - } |
|
| 1271 | - if($encoding == '') { |
|
| 1272 | - $encoding = $this->Encoding; |
|
| 1273 | - } |
|
| 1274 | - $result .= $this->TextLine('--' . $boundary); |
|
| 1275 | - $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet); |
|
| 1276 | - $result .= $this->LE; |
|
| 1277 | - $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding); |
|
| 1278 | - $result .= $this->LE; |
|
| 1279 | - |
|
| 1280 | - return $result; |
|
| 1264 | + $result = ''; |
|
| 1265 | + if($charSet == '') { |
|
| 1266 | + $charSet = $this->CharSet; |
|
| 1267 | + } |
|
| 1268 | + if($contentType == '') { |
|
| 1269 | + $contentType = $this->ContentType; |
|
| 1270 | + } |
|
| 1271 | + if($encoding == '') { |
|
| 1272 | + $encoding = $this->Encoding; |
|
| 1273 | + } |
|
| 1274 | + $result .= $this->TextLine('--' . $boundary); |
|
| 1275 | + $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet); |
|
| 1276 | + $result .= $this->LE; |
|
| 1277 | + $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding); |
|
| 1278 | + $result .= $this->LE; |
|
| 1279 | + |
|
| 1280 | + return $result; |
|
| 1281 | 1281 | } |
| 1282 | 1282 | |
| 1283 | 1283 | /** |
@@ -1285,7 +1285,7 @@ discard block |
||
| 1285 | 1285 | * @access private |
| 1286 | 1286 | */ |
| 1287 | 1287 | private function EndBoundary($boundary) { |
| 1288 | - return $this->LE . '--' . $boundary . '--' . $this->LE; |
|
| 1288 | + return $this->LE . '--' . $boundary . '--' . $this->LE; |
|
| 1289 | 1289 | } |
| 1290 | 1290 | |
| 1291 | 1291 | /** |
@@ -1294,19 +1294,19 @@ discard block |
||
| 1294 | 1294 | * @return void |
| 1295 | 1295 | */ |
| 1296 | 1296 | private function SetMessageType() { |
| 1297 | - if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) { |
|
| 1298 | - $this->message_type = 'plain'; |
|
| 1299 | - } else { |
|
| 1300 | - if(count($this->attachment) > 0) { |
|
| 1301 | - $this->message_type = 'attachments'; |
|
| 1302 | - } |
|
| 1303 | - if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) { |
|
| 1304 | - $this->message_type = 'alt'; |
|
| 1305 | - } |
|
| 1306 | - if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) { |
|
| 1307 | - $this->message_type = 'alt_attachments'; |
|
| 1308 | - } |
|
| 1309 | - } |
|
| 1297 | + if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) { |
|
| 1298 | + $this->message_type = 'plain'; |
|
| 1299 | + } else { |
|
| 1300 | + if(count($this->attachment) > 0) { |
|
| 1301 | + $this->message_type = 'attachments'; |
|
| 1302 | + } |
|
| 1303 | + if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) { |
|
| 1304 | + $this->message_type = 'alt'; |
|
| 1305 | + } |
|
| 1306 | + if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) { |
|
| 1307 | + $this->message_type = 'alt_attachments'; |
|
| 1308 | + } |
|
| 1309 | + } |
|
| 1310 | 1310 | } |
| 1311 | 1311 | |
| 1312 | 1312 | /** |
@@ -1315,7 +1315,7 @@ discard block |
||
| 1315 | 1315 | * @return string |
| 1316 | 1316 | */ |
| 1317 | 1317 | public function HeaderLine($name, $value) { |
| 1318 | - return $name . ': ' . $value . $this->LE; |
|
| 1318 | + return $name . ': ' . $value . $this->LE; |
|
| 1319 | 1319 | } |
| 1320 | 1320 | |
| 1321 | 1321 | /** |
@@ -1324,7 +1324,7 @@ discard block |
||
| 1324 | 1324 | * @return string |
| 1325 | 1325 | */ |
| 1326 | 1326 | public function TextLine($value) { |
| 1327 | - return $value . $this->LE; |
|
| 1327 | + return $value . $this->LE; |
|
| 1328 | 1328 | } |
| 1329 | 1329 | |
| 1330 | 1330 | ///////////////////////////////////////////////// |
@@ -1342,45 +1342,45 @@ discard block |
||
| 1342 | 1342 | * @return bool |
| 1343 | 1343 | */ |
| 1344 | 1344 | public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { |
| 1345 | - try { |
|
| 1346 | - if(!@is_file($path)) { |
|
| 1347 | - throw new phpmailerException($this->Lang('file_access') . $path, self::STOP_CONTINUE); |
|
| 1348 | - } |
|
| 1349 | - $filename = basename($path); |
|
| 1350 | - if($name == '') { |
|
| 1351 | - $name = $filename; |
|
| 1352 | - } |
|
| 1353 | - |
|
| 1354 | - $this->attachment[] = array( |
|
| 1355 | - 0 => $path, |
|
| 1356 | - 1 => $filename, |
|
| 1357 | - 2 => $name, |
|
| 1358 | - 3 => $encoding, |
|
| 1359 | - 4 => $type, |
|
| 1360 | - 5 => false, // isStringAttachment |
|
| 1361 | - 6 => 'attachment', |
|
| 1362 | - 7 => 0 |
|
| 1363 | - ); |
|
| 1364 | - |
|
| 1365 | - } catch (phpmailerException $e) { |
|
| 1366 | - $this->SetError($e->getMessage()); |
|
| 1367 | - if ($this->exceptions) { |
|
| 1368 | - throw $e; |
|
| 1369 | - } |
|
| 1370 | - echo $e->getMessage()."\n"; |
|
| 1371 | - if ( $e->getCode() == self::STOP_CRITICAL ) { |
|
| 1372 | - return false; |
|
| 1373 | - } |
|
| 1374 | - } |
|
| 1375 | - return true; |
|
| 1376 | - } |
|
| 1377 | - |
|
| 1378 | - /** |
|
| 1379 | - * Return the current array of attachments |
|
| 1380 | - * @return array |
|
| 1381 | - */ |
|
| 1345 | + try { |
|
| 1346 | + if(!@is_file($path)) { |
|
| 1347 | + throw new phpmailerException($this->Lang('file_access') . $path, self::STOP_CONTINUE); |
|
| 1348 | + } |
|
| 1349 | + $filename = basename($path); |
|
| 1350 | + if($name == '') { |
|
| 1351 | + $name = $filename; |
|
| 1352 | + } |
|
| 1353 | + |
|
| 1354 | + $this->attachment[] = array( |
|
| 1355 | + 0 => $path, |
|
| 1356 | + 1 => $filename, |
|
| 1357 | + 2 => $name, |
|
| 1358 | + 3 => $encoding, |
|
| 1359 | + 4 => $type, |
|
| 1360 | + 5 => false, // isStringAttachment |
|
| 1361 | + 6 => 'attachment', |
|
| 1362 | + 7 => 0 |
|
| 1363 | + ); |
|
| 1364 | + |
|
| 1365 | + } catch (phpmailerException $e) { |
|
| 1366 | + $this->SetError($e->getMessage()); |
|
| 1367 | + if ($this->exceptions) { |
|
| 1368 | + throw $e; |
|
| 1369 | + } |
|
| 1370 | + echo $e->getMessage()."\n"; |
|
| 1371 | + if ( $e->getCode() == self::STOP_CRITICAL ) { |
|
| 1372 | + return false; |
|
| 1373 | + } |
|
| 1374 | + } |
|
| 1375 | + return true; |
|
| 1376 | + } |
|
| 1377 | + |
|
| 1378 | + /** |
|
| 1379 | + * Return the current array of attachments |
|
| 1380 | + * @return array |
|
| 1381 | + */ |
|
| 1382 | 1382 | public function GetAttachments() { |
| 1383 | - return $this->attachment; |
|
| 1383 | + return $this->attachment; |
|
| 1384 | 1384 | } |
| 1385 | 1385 | |
| 1386 | 1386 | /** |
@@ -1390,61 +1390,61 @@ discard block |
||
| 1390 | 1390 | * @return string |
| 1391 | 1391 | */ |
| 1392 | 1392 | private function AttachAll() { |
| 1393 | - // Return text of body |
|
| 1394 | - $mime = array(); |
|
| 1395 | - $cidUniq = array(); |
|
| 1396 | - $incl = array(); |
|
| 1397 | - |
|
| 1398 | - // Add all attachments |
|
| 1399 | - foreach ($this->attachment as $attachment) { |
|
| 1400 | - // Check for string attachment |
|
| 1401 | - $bString = $attachment[5]; |
|
| 1402 | - if ($bString) { |
|
| 1403 | - $string = $attachment[0]; |
|
| 1404 | - } else { |
|
| 1405 | - $path = $attachment[0]; |
|
| 1406 | - } |
|
| 1407 | - |
|
| 1408 | - if (in_array($attachment[0], $incl)) { continue; } |
|
| 1409 | - $filename = $attachment[1]; |
|
| 1410 | - $name = $attachment[2]; |
|
| 1411 | - $encoding = $attachment[3]; |
|
| 1412 | - $type = $attachment[4]; |
|
| 1413 | - $disposition = $attachment[6]; |
|
| 1414 | - $cid = $attachment[7]; |
|
| 1415 | - $incl[] = $attachment[0]; |
|
| 1416 | - if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; } |
|
| 1417 | - $cidUniq[$cid] = true; |
|
| 1418 | - |
|
| 1419 | - $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE); |
|
| 1420 | - $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE); |
|
| 1421 | - $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE); |
|
| 1422 | - |
|
| 1423 | - if($disposition == 'inline') { |
|
| 1424 | - $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE); |
|
| 1425 | - } |
|
| 1426 | - |
|
| 1427 | - $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE); |
|
| 1428 | - |
|
| 1429 | - // Encode as string attachment |
|
| 1430 | - if($bString) { |
|
| 1431 | - $mime[] = $this->EncodeString($string, $encoding); |
|
| 1432 | - if($this->IsError()) { |
|
| 1433 | - return ''; |
|
| 1434 | - } |
|
| 1435 | - $mime[] = $this->LE.$this->LE; |
|
| 1436 | - } else { |
|
| 1437 | - $mime[] = $this->EncodeFile($path, $encoding); |
|
| 1438 | - if($this->IsError()) { |
|
| 1439 | - return ''; |
|
| 1440 | - } |
|
| 1441 | - $mime[] = $this->LE.$this->LE; |
|
| 1442 | - } |
|
| 1443 | - } |
|
| 1444 | - |
|
| 1445 | - $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE); |
|
| 1446 | - |
|
| 1447 | - return join('', $mime); |
|
| 1393 | + // Return text of body |
|
| 1394 | + $mime = array(); |
|
| 1395 | + $cidUniq = array(); |
|
| 1396 | + $incl = array(); |
|
| 1397 | + |
|
| 1398 | + // Add all attachments |
|
| 1399 | + foreach ($this->attachment as $attachment) { |
|
| 1400 | + // Check for string attachment |
|
| 1401 | + $bString = $attachment[5]; |
|
| 1402 | + if ($bString) { |
|
| 1403 | + $string = $attachment[0]; |
|
| 1404 | + } else { |
|
| 1405 | + $path = $attachment[0]; |
|
| 1406 | + } |
|
| 1407 | + |
|
| 1408 | + if (in_array($attachment[0], $incl)) { continue; } |
|
| 1409 | + $filename = $attachment[1]; |
|
| 1410 | + $name = $attachment[2]; |
|
| 1411 | + $encoding = $attachment[3]; |
|
| 1412 | + $type = $attachment[4]; |
|
| 1413 | + $disposition = $attachment[6]; |
|
| 1414 | + $cid = $attachment[7]; |
|
| 1415 | + $incl[] = $attachment[0]; |
|
| 1416 | + if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; } |
|
| 1417 | + $cidUniq[$cid] = true; |
|
| 1418 | + |
|
| 1419 | + $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE); |
|
| 1420 | + $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE); |
|
| 1421 | + $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE); |
|
| 1422 | + |
|
| 1423 | + if($disposition == 'inline') { |
|
| 1424 | + $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE); |
|
| 1425 | + } |
|
| 1426 | + |
|
| 1427 | + $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE); |
|
| 1428 | + |
|
| 1429 | + // Encode as string attachment |
|
| 1430 | + if($bString) { |
|
| 1431 | + $mime[] = $this->EncodeString($string, $encoding); |
|
| 1432 | + if($this->IsError()) { |
|
| 1433 | + return ''; |
|
| 1434 | + } |
|
| 1435 | + $mime[] = $this->LE.$this->LE; |
|
| 1436 | + } else { |
|
| 1437 | + $mime[] = $this->EncodeFile($path, $encoding); |
|
| 1438 | + if($this->IsError()) { |
|
| 1439 | + return ''; |
|
| 1440 | + } |
|
| 1441 | + $mime[] = $this->LE.$this->LE; |
|
| 1442 | + } |
|
| 1443 | + } |
|
| 1444 | + |
|
| 1445 | + $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE); |
|
| 1446 | + |
|
| 1447 | + return join('', $mime); |
|
| 1448 | 1448 | } |
| 1449 | 1449 | |
| 1450 | 1450 | /** |
@@ -1457,27 +1457,27 @@ discard block |
||
| 1457 | 1457 | * @return string |
| 1458 | 1458 | */ |
| 1459 | 1459 | private function EncodeFile($path, $encoding = 'base64') { |
| 1460 | - try { |
|
| 1461 | - if (!is_readable($path)) { |
|
| 1462 | - throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE); |
|
| 1463 | - } |
|
| 1464 | - if (function_exists('get_magic_quotes')) { |
|
| 1465 | - function get_magic_quotes() { |
|
| 1466 | - return false; |
|
| 1467 | - } |
|
| 1460 | + try { |
|
| 1461 | + if (!is_readable($path)) { |
|
| 1462 | + throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE); |
|
| 1463 | + } |
|
| 1464 | + if (function_exists('get_magic_quotes')) { |
|
| 1465 | + function get_magic_quotes() { |
|
| 1466 | + return false; |
|
| 1467 | + } |
|
| 1468 | 1468 | } |
| 1469 | - if (PHP_VERSION < 5) { |
|
| 1470 | - $magic_quotes = get_magic_quotes_runtime(); |
|
| 1471 | - set_magic_quotes_runtime(0); |
|
| 1472 | - } |
|
| 1473 | - $file_buffer = file_get_contents($path); |
|
| 1474 | - $file_buffer = $this->EncodeString($file_buffer, $encoding); |
|
| 1475 | - if (PHP_VERSION < 5) { set_magic_quotes_runtime($magic_quotes); } |
|
| 1476 | - return $file_buffer; |
|
| 1477 | - } catch (Exception $e) { |
|
| 1478 | - $this->SetError($e->getMessage()); |
|
| 1479 | - return ''; |
|
| 1480 | - } |
|
| 1469 | + if (PHP_VERSION < 5) { |
|
| 1470 | + $magic_quotes = get_magic_quotes_runtime(); |
|
| 1471 | + set_magic_quotes_runtime(0); |
|
| 1472 | + } |
|
| 1473 | + $file_buffer = file_get_contents($path); |
|
| 1474 | + $file_buffer = $this->EncodeString($file_buffer, $encoding); |
|
| 1475 | + if (PHP_VERSION < 5) { set_magic_quotes_runtime($magic_quotes); } |
|
| 1476 | + return $file_buffer; |
|
| 1477 | + } catch (Exception $e) { |
|
| 1478 | + $this->SetError($e->getMessage()); |
|
| 1479 | + return ''; |
|
| 1480 | + } |
|
| 1481 | 1481 | } |
| 1482 | 1482 | |
| 1483 | 1483 | /** |
@@ -1489,29 +1489,29 @@ discard block |
||
| 1489 | 1489 | * @return string |
| 1490 | 1490 | */ |
| 1491 | 1491 | public function EncodeString ($str, $encoding = 'base64') { |
| 1492 | - $encoded = ''; |
|
| 1493 | - switch(strtolower($encoding)) { |
|
| 1494 | - case 'base64': |
|
| 1495 | - $encoded = chunk_split(base64_encode($str), 76, $this->LE); |
|
| 1496 | - break; |
|
| 1497 | - case '7bit': |
|
| 1498 | - case '8bit': |
|
| 1499 | - $encoded = $this->FixEOL($str); |
|
| 1500 | - //Make sure it ends with a line break |
|
| 1501 | - if (substr($encoded, -(strlen($this->LE))) != $this->LE) |
|
| 1502 | - $encoded .= $this->LE; |
|
| 1503 | - break; |
|
| 1504 | - case 'binary': |
|
| 1505 | - $encoded = $str; |
|
| 1506 | - break; |
|
| 1507 | - case 'quoted-printable': |
|
| 1508 | - $encoded = $this->EncodeQP($str); |
|
| 1509 | - break; |
|
| 1510 | - default: |
|
| 1511 | - $this->SetError($this->Lang('encoding') . $encoding); |
|
| 1512 | - break; |
|
| 1513 | - } |
|
| 1514 | - return $encoded; |
|
| 1492 | + $encoded = ''; |
|
| 1493 | + switch(strtolower($encoding)) { |
|
| 1494 | + case 'base64': |
|
| 1495 | + $encoded = chunk_split(base64_encode($str), 76, $this->LE); |
|
| 1496 | + break; |
|
| 1497 | + case '7bit': |
|
| 1498 | + case '8bit': |
|
| 1499 | + $encoded = $this->FixEOL($str); |
|
| 1500 | + //Make sure it ends with a line break |
|
| 1501 | + if (substr($encoded, -(strlen($this->LE))) != $this->LE) |
|
| 1502 | + $encoded .= $this->LE; |
|
| 1503 | + break; |
|
| 1504 | + case 'binary': |
|
| 1505 | + $encoded = $str; |
|
| 1506 | + break; |
|
| 1507 | + case 'quoted-printable': |
|
| 1508 | + $encoded = $this->EncodeQP($str); |
|
| 1509 | + break; |
|
| 1510 | + default: |
|
| 1511 | + $this->SetError($this->Lang('encoding') . $encoding); |
|
| 1512 | + break; |
|
| 1513 | + } |
|
| 1514 | + return $encoded; |
|
| 1515 | 1515 | } |
| 1516 | 1516 | |
| 1517 | 1517 | /** |
@@ -1520,58 +1520,58 @@ discard block |
||
| 1520 | 1520 | * @return string |
| 1521 | 1521 | */ |
| 1522 | 1522 | public function EncodeHeader ($str, $position = 'text') { |
| 1523 | - $x = 0; |
|
| 1524 | - |
|
| 1525 | - switch (strtolower($position)) { |
|
| 1526 | - case 'phrase': |
|
| 1527 | - if (!preg_match('/[\200-\377]/', $str)) { |
|
| 1528 | - // Can't use addslashes as we don't know what value has magic_quotes_sybase |
|
| 1529 | - $encoded = addcslashes($str, "\0..\37\177\\\""); |
|
| 1530 | - if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) { |
|
| 1531 | - return ($encoded); |
|
| 1532 | - } else { |
|
| 1533 | - return ("\"$encoded\""); |
|
| 1534 | - } |
|
| 1535 | - } |
|
| 1536 | - $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches); |
|
| 1537 | - break; |
|
| 1538 | - case 'comment': |
|
| 1539 | - $x = preg_match_all('/[()"]/', $str, $matches); |
|
| 1540 | - // Fall-through |
|
| 1541 | - case 'text': |
|
| 1542 | - default: |
|
| 1543 | - $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches); |
|
| 1544 | - break; |
|
| 1545 | - } |
|
| 1546 | - |
|
| 1547 | - if ($x == 0) { |
|
| 1548 | - return ($str); |
|
| 1549 | - } |
|
| 1550 | - |
|
| 1551 | - $maxlen = 75 - 7 - strlen($this->CharSet); |
|
| 1552 | - // Try to select the encoding which should produce the shortest output |
|
| 1553 | - if (strlen($str)/3 < $x) { |
|
| 1554 | - $encoding = 'B'; |
|
| 1555 | - if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) { |
|
| 1556 | - // Use a custom function which correctly encodes and wraps long |
|
| 1557 | - // multibyte strings without breaking lines within a character |
|
| 1558 | - $encoded = $this->Base64EncodeWrapMB($str); |
|
| 1559 | - } else { |
|
| 1560 | - $encoded = base64_encode($str); |
|
| 1561 | - $maxlen -= $maxlen % 4; |
|
| 1562 | - $encoded = trim(chunk_split($encoded, $maxlen, "\n")); |
|
| 1563 | - } |
|
| 1564 | - } else { |
|
| 1565 | - $encoding = 'Q'; |
|
| 1566 | - $encoded = $this->EncodeQ($str, $position); |
|
| 1567 | - $encoded = $this->WrapText($encoded, $maxlen, true); |
|
| 1568 | - $encoded = str_replace('='.$this->LE, "\n", trim($encoded)); |
|
| 1569 | - } |
|
| 1570 | - |
|
| 1571 | - $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded); |
|
| 1572 | - $encoded = trim(str_replace("\n", $this->LE, $encoded)); |
|
| 1573 | - |
|
| 1574 | - return $encoded; |
|
| 1523 | + $x = 0; |
|
| 1524 | + |
|
| 1525 | + switch (strtolower($position)) { |
|
| 1526 | + case 'phrase': |
|
| 1527 | + if (!preg_match('/[\200-\377]/', $str)) { |
|
| 1528 | + // Can't use addslashes as we don't know what value has magic_quotes_sybase |
|
| 1529 | + $encoded = addcslashes($str, "\0..\37\177\\\""); |
|
| 1530 | + if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) { |
|
| 1531 | + return ($encoded); |
|
| 1532 | + } else { |
|
| 1533 | + return ("\"$encoded\""); |
|
| 1534 | + } |
|
| 1535 | + } |
|
| 1536 | + $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches); |
|
| 1537 | + break; |
|
| 1538 | + case 'comment': |
|
| 1539 | + $x = preg_match_all('/[()"]/', $str, $matches); |
|
| 1540 | + // Fall-through |
|
| 1541 | + case 'text': |
|
| 1542 | + default: |
|
| 1543 | + $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches); |
|
| 1544 | + break; |
|
| 1545 | + } |
|
| 1546 | + |
|
| 1547 | + if ($x == 0) { |
|
| 1548 | + return ($str); |
|
| 1549 | + } |
|
| 1550 | + |
|
| 1551 | + $maxlen = 75 - 7 - strlen($this->CharSet); |
|
| 1552 | + // Try to select the encoding which should produce the shortest output |
|
| 1553 | + if (strlen($str)/3 < $x) { |
|
| 1554 | + $encoding = 'B'; |
|
| 1555 | + if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) { |
|
| 1556 | + // Use a custom function which correctly encodes and wraps long |
|
| 1557 | + // multibyte strings without breaking lines within a character |
|
| 1558 | + $encoded = $this->Base64EncodeWrapMB($str); |
|
| 1559 | + } else { |
|
| 1560 | + $encoded = base64_encode($str); |
|
| 1561 | + $maxlen -= $maxlen % 4; |
|
| 1562 | + $encoded = trim(chunk_split($encoded, $maxlen, "\n")); |
|
| 1563 | + } |
|
| 1564 | + } else { |
|
| 1565 | + $encoding = 'Q'; |
|
| 1566 | + $encoded = $this->EncodeQ($str, $position); |
|
| 1567 | + $encoded = $this->WrapText($encoded, $maxlen, true); |
|
| 1568 | + $encoded = str_replace('='.$this->LE, "\n", trim($encoded)); |
|
| 1569 | + } |
|
| 1570 | + |
|
| 1571 | + $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded); |
|
| 1572 | + $encoded = trim(str_replace("\n", $this->LE, $encoded)); |
|
| 1573 | + |
|
| 1574 | + return $encoded; |
|
| 1575 | 1575 | } |
| 1576 | 1576 | |
| 1577 | 1577 | /** |
@@ -1581,11 +1581,11 @@ discard block |
||
| 1581 | 1581 | * @return bool |
| 1582 | 1582 | */ |
| 1583 | 1583 | public function HasMultiBytes($str) { |
| 1584 | - if (function_exists('mb_strlen')) { |
|
| 1585 | - return (strlen($str) > mb_strlen($str, $this->CharSet)); |
|
| 1586 | - } else { // Assume no multibytes (we can't handle without mbstring functions anyway) |
|
| 1587 | - return false; |
|
| 1588 | - } |
|
| 1584 | + if (function_exists('mb_strlen')) { |
|
| 1585 | + return (strlen($str) > mb_strlen($str, $this->CharSet)); |
|
| 1586 | + } else { // Assume no multibytes (we can't handle without mbstring functions anyway) |
|
| 1587 | + return false; |
|
| 1588 | + } |
|
| 1589 | 1589 | } |
| 1590 | 1590 | |
| 1591 | 1591 | /** |
@@ -1597,117 +1597,117 @@ discard block |
||
| 1597 | 1597 | * @return string |
| 1598 | 1598 | */ |
| 1599 | 1599 | public function Base64EncodeWrapMB($str) { |
| 1600 | - $start = "=?".$this->CharSet."?B?"; |
|
| 1601 | - $end = "?="; |
|
| 1602 | - $encoded = ""; |
|
| 1603 | - |
|
| 1604 | - $mb_length = mb_strlen($str, $this->CharSet); |
|
| 1605 | - // Each line must have length <= 75, including $start and $end |
|
| 1606 | - $length = 75 - strlen($start) - strlen($end); |
|
| 1607 | - // Average multi-byte ratio |
|
| 1608 | - $ratio = $mb_length / strlen($str); |
|
| 1609 | - // Base64 has a 4:3 ratio |
|
| 1610 | - $offset = $avgLength = floor($length * $ratio * .75); |
|
| 1611 | - |
|
| 1612 | - for ($i = 0; $i < $mb_length; $i += $offset) { |
|
| 1613 | - $lookBack = 0; |
|
| 1614 | - |
|
| 1615 | - do { |
|
| 1616 | - $offset = $avgLength - $lookBack; |
|
| 1617 | - $chunk = mb_substr($str, $i, $offset, $this->CharSet); |
|
| 1618 | - $chunk = base64_encode($chunk); |
|
| 1619 | - $lookBack++; |
|
| 1620 | - } |
|
| 1621 | - while (strlen($chunk) > $length); |
|
| 1622 | - |
|
| 1623 | - $encoded .= $chunk . $this->LE; |
|
| 1624 | - } |
|
| 1625 | - |
|
| 1626 | - // Chomp the last linefeed |
|
| 1627 | - $encoded = substr($encoded, 0, -strlen($this->LE)); |
|
| 1628 | - return $encoded; |
|
| 1629 | - } |
|
| 1630 | - |
|
| 1631 | - /** |
|
| 1632 | - * Encode string to quoted-printable. |
|
| 1633 | - * Only uses standard PHP, slow, but will always work |
|
| 1634 | - * @access public |
|
| 1635 | - * @param string $string the text to encode |
|
| 1636 | - * @param integer $line_max Number of chars allowed on a line before wrapping |
|
| 1637 | - * @return string |
|
| 1638 | - */ |
|
| 1600 | + $start = "=?".$this->CharSet."?B?"; |
|
| 1601 | + $end = "?="; |
|
| 1602 | + $encoded = ""; |
|
| 1603 | + |
|
| 1604 | + $mb_length = mb_strlen($str, $this->CharSet); |
|
| 1605 | + // Each line must have length <= 75, including $start and $end |
|
| 1606 | + $length = 75 - strlen($start) - strlen($end); |
|
| 1607 | + // Average multi-byte ratio |
|
| 1608 | + $ratio = $mb_length / strlen($str); |
|
| 1609 | + // Base64 has a 4:3 ratio |
|
| 1610 | + $offset = $avgLength = floor($length * $ratio * .75); |
|
| 1611 | + |
|
| 1612 | + for ($i = 0; $i < $mb_length; $i += $offset) { |
|
| 1613 | + $lookBack = 0; |
|
| 1614 | + |
|
| 1615 | + do { |
|
| 1616 | + $offset = $avgLength - $lookBack; |
|
| 1617 | + $chunk = mb_substr($str, $i, $offset, $this->CharSet); |
|
| 1618 | + $chunk = base64_encode($chunk); |
|
| 1619 | + $lookBack++; |
|
| 1620 | + } |
|
| 1621 | + while (strlen($chunk) > $length); |
|
| 1622 | + |
|
| 1623 | + $encoded .= $chunk . $this->LE; |
|
| 1624 | + } |
|
| 1625 | + |
|
| 1626 | + // Chomp the last linefeed |
|
| 1627 | + $encoded = substr($encoded, 0, -strlen($this->LE)); |
|
| 1628 | + return $encoded; |
|
| 1629 | + } |
|
| 1630 | + |
|
| 1631 | + /** |
|
| 1632 | + * Encode string to quoted-printable. |
|
| 1633 | + * Only uses standard PHP, slow, but will always work |
|
| 1634 | + * @access public |
|
| 1635 | + * @param string $string the text to encode |
|
| 1636 | + * @param integer $line_max Number of chars allowed on a line before wrapping |
|
| 1637 | + * @return string |
|
| 1638 | + */ |
|
| 1639 | 1639 | public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) { |
| 1640 | - $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
|
| 1641 | - $lines = preg_split('/(?:\r\n|\r|\n)/', $input); |
|
| 1642 | - $eol = "\r\n"; |
|
| 1643 | - $escape = '='; |
|
| 1644 | - $output = ''; |
|
| 1645 | - while( list(, $line) = each($lines) ) { |
|
| 1646 | - $linlen = strlen($line); |
|
| 1647 | - $newline = ''; |
|
| 1648 | - for($i = 0; $i < $linlen; $i++) { |
|
| 1649 | - $c = substr( $line, $i, 1 ); |
|
| 1650 | - $dec = ord( $c ); |
|
| 1651 | - if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E |
|
| 1652 | - $c = '=2E'; |
|
| 1653 | - } |
|
| 1654 | - if ( $dec == 32 ) { |
|
| 1655 | - if ( $i == ( $linlen - 1 ) ) { // convert space at eol only |
|
| 1656 | - $c = '=20'; |
|
| 1657 | - } else if ( $space_conv ) { |
|
| 1658 | - $c = '=20'; |
|
| 1659 | - } |
|
| 1660 | - } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required |
|
| 1661 | - $h2 = floor($dec/16); |
|
| 1662 | - $h1 = floor($dec%16); |
|
| 1663 | - $c = $escape.$hex[$h2].$hex[$h1]; |
|
| 1664 | - } |
|
| 1665 | - if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted |
|
| 1666 | - $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay |
|
| 1667 | - $newline = ''; |
|
| 1668 | - // check if newline first character will be point or not |
|
| 1669 | - if ( $dec == 46 ) { |
|
| 1670 | - $c = '=2E'; |
|
| 1671 | - } |
|
| 1672 | - } |
|
| 1673 | - $newline .= $c; |
|
| 1674 | - } // end of for |
|
| 1675 | - $output .= $newline.$eol; |
|
| 1676 | - } // end of while |
|
| 1677 | - return $output; |
|
| 1678 | - } |
|
| 1679 | - |
|
| 1680 | - /** |
|
| 1681 | - * Encode string to RFC2045 (6.7) quoted-printable format |
|
| 1682 | - * Uses a PHP5 stream filter to do the encoding about 64x faster than the old version |
|
| 1683 | - * Also results in same content as you started with after decoding |
|
| 1684 | - * @see EncodeQPphp() |
|
| 1685 | - * @access public |
|
| 1686 | - * @param string $string the text to encode |
|
| 1687 | - * @param integer $line_max Number of chars allowed on a line before wrapping |
|
| 1688 | - * @param boolean $space_conv Dummy param for compatibility with existing EncodeQP function |
|
| 1689 | - * @return string |
|
| 1690 | - * @author Marcus Bointon |
|
| 1691 | - */ |
|
| 1640 | + $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
|
| 1641 | + $lines = preg_split('/(?:\r\n|\r|\n)/', $input); |
|
| 1642 | + $eol = "\r\n"; |
|
| 1643 | + $escape = '='; |
|
| 1644 | + $output = ''; |
|
| 1645 | + while( list(, $line) = each($lines) ) { |
|
| 1646 | + $linlen = strlen($line); |
|
| 1647 | + $newline = ''; |
|
| 1648 | + for($i = 0; $i < $linlen; $i++) { |
|
| 1649 | + $c = substr( $line, $i, 1 ); |
|
| 1650 | + $dec = ord( $c ); |
|
| 1651 | + if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E |
|
| 1652 | + $c = '=2E'; |
|
| 1653 | + } |
|
| 1654 | + if ( $dec == 32 ) { |
|
| 1655 | + if ( $i == ( $linlen - 1 ) ) { // convert space at eol only |
|
| 1656 | + $c = '=20'; |
|
| 1657 | + } else if ( $space_conv ) { |
|
| 1658 | + $c = '=20'; |
|
| 1659 | + } |
|
| 1660 | + } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required |
|
| 1661 | + $h2 = floor($dec/16); |
|
| 1662 | + $h1 = floor($dec%16); |
|
| 1663 | + $c = $escape.$hex[$h2].$hex[$h1]; |
|
| 1664 | + } |
|
| 1665 | + if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted |
|
| 1666 | + $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay |
|
| 1667 | + $newline = ''; |
|
| 1668 | + // check if newline first character will be point or not |
|
| 1669 | + if ( $dec == 46 ) { |
|
| 1670 | + $c = '=2E'; |
|
| 1671 | + } |
|
| 1672 | + } |
|
| 1673 | + $newline .= $c; |
|
| 1674 | + } // end of for |
|
| 1675 | + $output .= $newline.$eol; |
|
| 1676 | + } // end of while |
|
| 1677 | + return $output; |
|
| 1678 | + } |
|
| 1679 | + |
|
| 1680 | + /** |
|
| 1681 | + * Encode string to RFC2045 (6.7) quoted-printable format |
|
| 1682 | + * Uses a PHP5 stream filter to do the encoding about 64x faster than the old version |
|
| 1683 | + * Also results in same content as you started with after decoding |
|
| 1684 | + * @see EncodeQPphp() |
|
| 1685 | + * @access public |
|
| 1686 | + * @param string $string the text to encode |
|
| 1687 | + * @param integer $line_max Number of chars allowed on a line before wrapping |
|
| 1688 | + * @param boolean $space_conv Dummy param for compatibility with existing EncodeQP function |
|
| 1689 | + * @return string |
|
| 1690 | + * @author Marcus Bointon |
|
| 1691 | + */ |
|
| 1692 | 1692 | public function EncodeQP($string, $line_max = 76, $space_conv = false) { |
| 1693 | - if (function_exists('quoted_printable_encode')) { //Use native function if it's available (>= PHP5.3) |
|
| 1694 | - return quoted_printable_encode($string); |
|
| 1695 | - } |
|
| 1696 | - $filters = stream_get_filters(); |
|
| 1697 | - if (!in_array('convert.*', $filters)) { //Got convert stream filter? |
|
| 1698 | - return $this->EncodeQPphp($string, $line_max, $space_conv); //Fall back to old implementation |
|
| 1699 | - } |
|
| 1700 | - $fp = fopen('php://temp/', 'r+'); |
|
| 1701 | - $string = preg_replace('/\r\n?/', $this->LE, $string); //Normalise line breaks |
|
| 1702 | - $params = array('line-length' => $line_max, 'line-break-chars' => $this->LE); |
|
| 1703 | - $s = stream_filter_append($fp, 'convert.quoted-printable-encode', STREAM_FILTER_READ, $params); |
|
| 1704 | - fputs($fp, $string); |
|
| 1705 | - rewind($fp); |
|
| 1706 | - $out = stream_get_contents($fp); |
|
| 1707 | - stream_filter_remove($s); |
|
| 1708 | - $out = preg_replace('/^\./m', '=2E', $out); //Encode . if it is first char on a line, workaround for bug in Exchange |
|
| 1709 | - fclose($fp); |
|
| 1710 | - return $out; |
|
| 1693 | + if (function_exists('quoted_printable_encode')) { //Use native function if it's available (>= PHP5.3) |
|
| 1694 | + return quoted_printable_encode($string); |
|
| 1695 | + } |
|
| 1696 | + $filters = stream_get_filters(); |
|
| 1697 | + if (!in_array('convert.*', $filters)) { //Got convert stream filter? |
|
| 1698 | + return $this->EncodeQPphp($string, $line_max, $space_conv); //Fall back to old implementation |
|
| 1699 | + } |
|
| 1700 | + $fp = fopen('php://temp/', 'r+'); |
|
| 1701 | + $string = preg_replace('/\r\n?/', $this->LE, $string); //Normalise line breaks |
|
| 1702 | + $params = array('line-length' => $line_max, 'line-break-chars' => $this->LE); |
|
| 1703 | + $s = stream_filter_append($fp, 'convert.quoted-printable-encode', STREAM_FILTER_READ, $params); |
|
| 1704 | + fputs($fp, $string); |
|
| 1705 | + rewind($fp); |
|
| 1706 | + $out = stream_get_contents($fp); |
|
| 1707 | + stream_filter_remove($s); |
|
| 1708 | + $out = preg_replace('/^\./m', '=2E', $out); //Encode . if it is first char on a line, workaround for bug in Exchange |
|
| 1709 | + fclose($fp); |
|
| 1710 | + return $out; |
|
| 1711 | 1711 | } |
| 1712 | 1712 | |
| 1713 | 1713 | /** |
@@ -1719,28 +1719,28 @@ discard block |
||
| 1719 | 1719 | * @return string |
| 1720 | 1720 | */ |
| 1721 | 1721 | public function EncodeQ ($str, $position = 'text') { |
| 1722 | - // There should not be any EOL in the string |
|
| 1723 | - $encoded = preg_replace('/[\r\n]*/', '', $str); |
|
| 1722 | + // There should not be any EOL in the string |
|
| 1723 | + $encoded = preg_replace('/[\r\n]*/', '', $str); |
|
| 1724 | 1724 | |
| 1725 | - switch (strtolower($position)) { |
|
| 1726 | - case 'phrase': |
|
| 1725 | + switch (strtolower($position)) { |
|
| 1726 | + case 'phrase': |
|
| 1727 | 1727 | $encoded = preg_replace_callback('/([^A-Za-z0-9!*+\/ -])/', function($n) { return '='.sprintf('%02X', ord('\\1')); }, $encoded); |
| 1728 | - break; |
|
| 1729 | - case 'comment': |
|
| 1728 | + break; |
|
| 1729 | + case 'comment': |
|
| 1730 | 1730 | $encoded = preg_replace_callback('/([\(\)\"])/', function($n) { return '='.sprintf('%02X', ord('\\1')); }, $encoded); |
| 1731 | - case 'text': |
|
| 1732 | - default: |
|
| 1733 | - // Replace every high ascii, control =, ? and _ characters |
|
| 1734 | - //TODO using /e (equivalent to eval()) is probably not a good idea |
|
| 1735 | - $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e', |
|
| 1736 | - "'='.sprintf('%02X', ord('\\1'))", $encoded); |
|
| 1737 | - break; |
|
| 1738 | - } |
|
| 1731 | + case 'text': |
|
| 1732 | + default: |
|
| 1733 | + // Replace every high ascii, control =, ? and _ characters |
|
| 1734 | + //TODO using /e (equivalent to eval()) is probably not a good idea |
|
| 1735 | + $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e', |
|
| 1736 | + "'='.sprintf('%02X', ord('\\1'))", $encoded); |
|
| 1737 | + break; |
|
| 1738 | + } |
|
| 1739 | 1739 | |
| 1740 | - // Replace every spaces to _ (more readable than =20) |
|
| 1741 | - $encoded = str_replace(' ', '_', $encoded); |
|
| 1740 | + // Replace every spaces to _ (more readable than =20) |
|
| 1741 | + $encoded = str_replace(' ', '_', $encoded); |
|
| 1742 | 1742 | |
| 1743 | - return $encoded; |
|
| 1743 | + return $encoded; |
|
| 1744 | 1744 | } |
| 1745 | 1745 | |
| 1746 | 1746 | /** |
@@ -1754,17 +1754,17 @@ discard block |
||
| 1754 | 1754 | * @return void |
| 1755 | 1755 | */ |
| 1756 | 1756 | public function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') { |
| 1757 | - // Append to $attachment array |
|
| 1758 | - $this->attachment[] = array( |
|
| 1759 | - 0 => $string, |
|
| 1760 | - 1 => $filename, |
|
| 1761 | - 2 => basename($filename), |
|
| 1762 | - 3 => $encoding, |
|
| 1763 | - 4 => $type, |
|
| 1764 | - 5 => true, // isStringAttachment |
|
| 1765 | - 6 => 'attachment', |
|
| 1766 | - 7 => 0 |
|
| 1767 | - ); |
|
| 1757 | + // Append to $attachment array |
|
| 1758 | + $this->attachment[] = array( |
|
| 1759 | + 0 => $string, |
|
| 1760 | + 1 => $filename, |
|
| 1761 | + 2 => basename($filename), |
|
| 1762 | + 3 => $encoding, |
|
| 1763 | + 4 => $type, |
|
| 1764 | + 5 => true, // isStringAttachment |
|
| 1765 | + 6 => 'attachment', |
|
| 1766 | + 7 => 0 |
|
| 1767 | + ); |
|
| 1768 | 1768 | } |
| 1769 | 1769 | |
| 1770 | 1770 | /** |
@@ -1782,29 +1782,29 @@ discard block |
||
| 1782 | 1782 | */ |
| 1783 | 1783 | public function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { |
| 1784 | 1784 | |
| 1785 | - if(!@is_file($path)) { |
|
| 1786 | - $this->SetError($this->Lang('file_access') . $path); |
|
| 1787 | - return false; |
|
| 1788 | - } |
|
| 1785 | + if(!@is_file($path)) { |
|
| 1786 | + $this->SetError($this->Lang('file_access') . $path); |
|
| 1787 | + return false; |
|
| 1788 | + } |
|
| 1789 | 1789 | |
| 1790 | - $filename = basename($path); |
|
| 1791 | - if($name == '') { |
|
| 1792 | - $name = $filename; |
|
| 1793 | - } |
|
| 1790 | + $filename = basename($path); |
|
| 1791 | + if($name == '') { |
|
| 1792 | + $name = $filename; |
|
| 1793 | + } |
|
| 1794 | 1794 | |
| 1795 | - // Append to $attachment array |
|
| 1796 | - $this->attachment[] = array( |
|
| 1797 | - 0 => $path, |
|
| 1798 | - 1 => $filename, |
|
| 1799 | - 2 => $name, |
|
| 1800 | - 3 => $encoding, |
|
| 1801 | - 4 => $type, |
|
| 1802 | - 5 => false, // isStringAttachment |
|
| 1803 | - 6 => 'inline', |
|
| 1804 | - 7 => $cid |
|
| 1805 | - ); |
|
| 1795 | + // Append to $attachment array |
|
| 1796 | + $this->attachment[] = array( |
|
| 1797 | + 0 => $path, |
|
| 1798 | + 1 => $filename, |
|
| 1799 | + 2 => $name, |
|
| 1800 | + 3 => $encoding, |
|
| 1801 | + 4 => $type, |
|
| 1802 | + 5 => false, // isStringAttachment |
|
| 1803 | + 6 => 'inline', |
|
| 1804 | + 7 => $cid |
|
| 1805 | + ); |
|
| 1806 | 1806 | |
| 1807 | - return true; |
|
| 1807 | + return true; |
|
| 1808 | 1808 | } |
| 1809 | 1809 | |
| 1810 | 1810 | /** |
@@ -1813,12 +1813,12 @@ discard block |
||
| 1813 | 1813 | * @return bool |
| 1814 | 1814 | */ |
| 1815 | 1815 | public function InlineImageExists() { |
| 1816 | - foreach($this->attachment as $attachment) { |
|
| 1817 | - if ($attachment[6] == 'inline') { |
|
| 1818 | - return true; |
|
| 1819 | - } |
|
| 1820 | - } |
|
| 1821 | - return false; |
|
| 1816 | + foreach($this->attachment as $attachment) { |
|
| 1817 | + if ($attachment[6] == 'inline') { |
|
| 1818 | + return true; |
|
| 1819 | + } |
|
| 1820 | + } |
|
| 1821 | + return false; |
|
| 1822 | 1822 | } |
| 1823 | 1823 | |
| 1824 | 1824 | ///////////////////////////////////////////////// |
@@ -1830,10 +1830,10 @@ discard block |
||
| 1830 | 1830 | * @return void |
| 1831 | 1831 | */ |
| 1832 | 1832 | public function ClearAddresses() { |
| 1833 | - foreach($this->to as $to) { |
|
| 1834 | - unset($this->all_recipients[strtolower($to[0])]); |
|
| 1835 | - } |
|
| 1836 | - $this->to = array(); |
|
| 1833 | + foreach($this->to as $to) { |
|
| 1834 | + unset($this->all_recipients[strtolower($to[0])]); |
|
| 1835 | + } |
|
| 1836 | + $this->to = array(); |
|
| 1837 | 1837 | } |
| 1838 | 1838 | |
| 1839 | 1839 | /** |
@@ -1841,10 +1841,10 @@ discard block |
||
| 1841 | 1841 | * @return void |
| 1842 | 1842 | */ |
| 1843 | 1843 | public function ClearCCs() { |
| 1844 | - foreach($this->cc as $cc) { |
|
| 1845 | - unset($this->all_recipients[strtolower($cc[0])]); |
|
| 1846 | - } |
|
| 1847 | - $this->cc = array(); |
|
| 1844 | + foreach($this->cc as $cc) { |
|
| 1845 | + unset($this->all_recipients[strtolower($cc[0])]); |
|
| 1846 | + } |
|
| 1847 | + $this->cc = array(); |
|
| 1848 | 1848 | } |
| 1849 | 1849 | |
| 1850 | 1850 | /** |
@@ -1852,10 +1852,10 @@ discard block |
||
| 1852 | 1852 | * @return void |
| 1853 | 1853 | */ |
| 1854 | 1854 | public function ClearBCCs() { |
| 1855 | - foreach($this->bcc as $bcc) { |
|
| 1856 | - unset($this->all_recipients[strtolower($bcc[0])]); |
|
| 1857 | - } |
|
| 1858 | - $this->bcc = array(); |
|
| 1855 | + foreach($this->bcc as $bcc) { |
|
| 1856 | + unset($this->all_recipients[strtolower($bcc[0])]); |
|
| 1857 | + } |
|
| 1858 | + $this->bcc = array(); |
|
| 1859 | 1859 | } |
| 1860 | 1860 | |
| 1861 | 1861 | /** |
@@ -1863,7 +1863,7 @@ discard block |
||
| 1863 | 1863 | * @return void |
| 1864 | 1864 | */ |
| 1865 | 1865 | public function ClearReplyTos() { |
| 1866 | - $this->ReplyTo = array(); |
|
| 1866 | + $this->ReplyTo = array(); |
|
| 1867 | 1867 | } |
| 1868 | 1868 | |
| 1869 | 1869 | /** |
@@ -1872,10 +1872,10 @@ discard block |
||
| 1872 | 1872 | * @return void |
| 1873 | 1873 | */ |
| 1874 | 1874 | public function ClearAllRecipients() { |
| 1875 | - $this->to = array(); |
|
| 1876 | - $this->cc = array(); |
|
| 1877 | - $this->bcc = array(); |
|
| 1878 | - $this->all_recipients = array(); |
|
| 1875 | + $this->to = array(); |
|
| 1876 | + $this->cc = array(); |
|
| 1877 | + $this->bcc = array(); |
|
| 1878 | + $this->all_recipients = array(); |
|
| 1879 | 1879 | } |
| 1880 | 1880 | |
| 1881 | 1881 | /** |
@@ -1884,7 +1884,7 @@ discard block |
||
| 1884 | 1884 | * @return void |
| 1885 | 1885 | */ |
| 1886 | 1886 | public function ClearAttachments() { |
| 1887 | - $this->attachment = array(); |
|
| 1887 | + $this->attachment = array(); |
|
| 1888 | 1888 | } |
| 1889 | 1889 | |
| 1890 | 1890 | /** |
@@ -1892,7 +1892,7 @@ discard block |
||
| 1892 | 1892 | * @return void |
| 1893 | 1893 | */ |
| 1894 | 1894 | public function ClearCustomHeaders() { |
| 1895 | - $this->CustomHeader = array(); |
|
| 1895 | + $this->CustomHeader = array(); |
|
| 1896 | 1896 | } |
| 1897 | 1897 | |
| 1898 | 1898 | ///////////////////////////////////////////////// |
@@ -1905,14 +1905,14 @@ discard block |
||
| 1905 | 1905 | * @return void |
| 1906 | 1906 | */ |
| 1907 | 1907 | protected function SetError($msg) { |
| 1908 | - $this->error_count++; |
|
| 1909 | - if ($this->Mailer == 'smtp' and !is_null($this->smtp)) { |
|
| 1910 | - $lasterror = $this->smtp->getError(); |
|
| 1911 | - if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) { |
|
| 1912 | - $msg .= '<p>' . $this->Lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n"; |
|
| 1913 | - } |
|
| 1914 | - } |
|
| 1915 | - $this->ErrorInfo = $msg; |
|
| 1908 | + $this->error_count++; |
|
| 1909 | + if ($this->Mailer == 'smtp' and !is_null($this->smtp)) { |
|
| 1910 | + $lasterror = $this->smtp->getError(); |
|
| 1911 | + if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) { |
|
| 1912 | + $msg .= '<p>' . $this->Lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n"; |
|
| 1913 | + } |
|
| 1914 | + } |
|
| 1915 | + $this->ErrorInfo = $msg; |
|
| 1916 | 1916 | } |
| 1917 | 1917 | |
| 1918 | 1918 | /** |
@@ -1922,13 +1922,13 @@ discard block |
||
| 1922 | 1922 | * @static |
| 1923 | 1923 | */ |
| 1924 | 1924 | public static function RFCDate() { |
| 1925 | - $tz = date('Z'); |
|
| 1926 | - $tzs = ($tz < 0) ? '-' : '+'; |
|
| 1927 | - $tz = abs($tz); |
|
| 1928 | - $tz = (int)($tz/3600)*100 + ($tz%3600)/60; |
|
| 1929 | - $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz); |
|
| 1925 | + $tz = date('Z'); |
|
| 1926 | + $tzs = ($tz < 0) ? '-' : '+'; |
|
| 1927 | + $tz = abs($tz); |
|
| 1928 | + $tz = (int)($tz/3600)*100 + ($tz%3600)/60; |
|
| 1929 | + $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz); |
|
| 1930 | 1930 | |
| 1931 | - return $result; |
|
| 1931 | + return $result; |
|
| 1932 | 1932 | } |
| 1933 | 1933 | |
| 1934 | 1934 | /** |
@@ -1937,15 +1937,15 @@ discard block |
||
| 1937 | 1937 | * @return string |
| 1938 | 1938 | */ |
| 1939 | 1939 | private function ServerHostname() { |
| 1940 | - if (!empty($this->Hostname)) { |
|
| 1941 | - $result = $this->Hostname; |
|
| 1942 | - } elseif (isset($_SERVER['SERVER_NAME'])) { |
|
| 1943 | - $result = $_SERVER['SERVER_NAME']; |
|
| 1944 | - } else { |
|
| 1945 | - $result = 'localhost.localdomain'; |
|
| 1946 | - } |
|
| 1940 | + if (!empty($this->Hostname)) { |
|
| 1941 | + $result = $this->Hostname; |
|
| 1942 | + } elseif (isset($_SERVER['SERVER_NAME'])) { |
|
| 1943 | + $result = $_SERVER['SERVER_NAME']; |
|
| 1944 | + } else { |
|
| 1945 | + $result = 'localhost.localdomain'; |
|
| 1946 | + } |
|
| 1947 | 1947 | |
| 1948 | - return $result; |
|
| 1948 | + return $result; |
|
| 1949 | 1949 | } |
| 1950 | 1950 | |
| 1951 | 1951 | /** |
@@ -1954,15 +1954,15 @@ discard block |
||
| 1954 | 1954 | * @return string |
| 1955 | 1955 | */ |
| 1956 | 1956 | private function Lang($key) { |
| 1957 | - if(count($this->language) < 1) { |
|
| 1958 | - $this->SetLanguage('en'); // set the default language |
|
| 1959 | - } |
|
| 1957 | + if(count($this->language) < 1) { |
|
| 1958 | + $this->SetLanguage('en'); // set the default language |
|
| 1959 | + } |
|
| 1960 | 1960 | |
| 1961 | - if(isset($this->language[$key])) { |
|
| 1962 | - return $this->language[$key]; |
|
| 1963 | - } else { |
|
| 1964 | - return 'Language string failed to load: ' . $key; |
|
| 1965 | - } |
|
| 1961 | + if(isset($this->language[$key])) { |
|
| 1962 | + return $this->language[$key]; |
|
| 1963 | + } else { |
|
| 1964 | + return 'Language string failed to load: ' . $key; |
|
| 1965 | + } |
|
| 1966 | 1966 | } |
| 1967 | 1967 | |
| 1968 | 1968 | /** |
@@ -1971,7 +1971,7 @@ discard block |
||
| 1971 | 1971 | * @return bool |
| 1972 | 1972 | */ |
| 1973 | 1973 | public function IsError() { |
| 1974 | - return ($this->error_count > 0); |
|
| 1974 | + return ($this->error_count > 0); |
|
| 1975 | 1975 | } |
| 1976 | 1976 | |
| 1977 | 1977 | /** |
@@ -1980,10 +1980,10 @@ discard block |
||
| 1980 | 1980 | * @return string |
| 1981 | 1981 | */ |
| 1982 | 1982 | private function FixEOL($str) { |
| 1983 | - $str = str_replace("\r\n", "\n", $str); |
|
| 1984 | - $str = str_replace("\r", "\n", $str); |
|
| 1985 | - $str = str_replace("\n", $this->LE, $str); |
|
| 1986 | - return $str; |
|
| 1983 | + $str = str_replace("\r\n", "\n", $str); |
|
| 1984 | + $str = str_replace("\r", "\n", $str); |
|
| 1985 | + $str = str_replace("\n", $this->LE, $str); |
|
| 1986 | + return $str; |
|
| 1987 | 1987 | } |
| 1988 | 1988 | |
| 1989 | 1989 | /** |
@@ -1992,7 +1992,7 @@ discard block |
||
| 1992 | 1992 | * @return void |
| 1993 | 1993 | */ |
| 1994 | 1994 | public function AddCustomHeader($custom_header) { |
| 1995 | - $this->CustomHeader[] = explode(':', $custom_header, 2); |
|
| 1995 | + $this->CustomHeader[] = explode(':', $custom_header, 2); |
|
| 1996 | 1996 | } |
| 1997 | 1997 | |
| 1998 | 1998 | /** |
@@ -2001,34 +2001,34 @@ discard block |
||
| 2001 | 2001 | * @return $message |
| 2002 | 2002 | */ |
| 2003 | 2003 | public function MsgHTML($message,$basedir='') { |
| 2004 | - preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images); |
|
| 2005 | - if(isset($images[2])) { |
|
| 2006 | - foreach($images[2] as $i => $url) { |
|
| 2007 | - // do not change urls for absolute images (thanks to corvuscorax) |
|
| 2008 | - if (!preg_match('#^[A-z]+://#',$url)) { |
|
| 2009 | - $filename = basename($url); |
|
| 2010 | - $directory = dirname($url); |
|
| 2011 | - ($directory == '.')?$directory='':''; |
|
| 2012 | - $cid = 'cid:' . md5($filename); |
|
| 2013 | - $ext = pathinfo($filename, PATHINFO_EXTENSION); |
|
| 2014 | - $mimeType = self::_mime_types($ext); |
|
| 2015 | - if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; } |
|
| 2016 | - if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; } |
|
| 2017 | - if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) { |
|
| 2018 | - $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message); |
|
| 2019 | - } |
|
| 2020 | - } |
|
| 2021 | - } |
|
| 2022 | - } |
|
| 2023 | - $this->IsHTML(true); |
|
| 2024 | - $this->Body = $message; |
|
| 2025 | - $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message))); |
|
| 2026 | - if ( !empty($textMsg) && empty($this->AltBody) ) { |
|
| 2027 | - $this->AltBody = html_entity_decode($textMsg); |
|
| 2028 | - } |
|
| 2029 | - if ( empty($this->AltBody) ) { |
|
| 2030 | - $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n"; |
|
| 2031 | - } |
|
| 2004 | + preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images); |
|
| 2005 | + if(isset($images[2])) { |
|
| 2006 | + foreach($images[2] as $i => $url) { |
|
| 2007 | + // do not change urls for absolute images (thanks to corvuscorax) |
|
| 2008 | + if (!preg_match('#^[A-z]+://#',$url)) { |
|
| 2009 | + $filename = basename($url); |
|
| 2010 | + $directory = dirname($url); |
|
| 2011 | + ($directory == '.')?$directory='':''; |
|
| 2012 | + $cid = 'cid:' . md5($filename); |
|
| 2013 | + $ext = pathinfo($filename, PATHINFO_EXTENSION); |
|
| 2014 | + $mimeType = self::_mime_types($ext); |
|
| 2015 | + if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; } |
|
| 2016 | + if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; } |
|
| 2017 | + if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) { |
|
| 2018 | + $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message); |
|
| 2019 | + } |
|
| 2020 | + } |
|
| 2021 | + } |
|
| 2022 | + } |
|
| 2023 | + $this->IsHTML(true); |
|
| 2024 | + $this->Body = $message; |
|
| 2025 | + $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message))); |
|
| 2026 | + if ( !empty($textMsg) && empty($this->AltBody) ) { |
|
| 2027 | + $this->AltBody = html_entity_decode($textMsg); |
|
| 2028 | + } |
|
| 2029 | + if ( empty($this->AltBody) ) { |
|
| 2030 | + $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n"; |
|
| 2031 | + } |
|
| 2032 | 2032 | } |
| 2033 | 2033 | |
| 2034 | 2034 | /** |
@@ -2039,96 +2039,96 @@ discard block |
||
| 2039 | 2039 | * @static |
| 2040 | 2040 | */ |
| 2041 | 2041 | public static function _mime_types($ext = '') { |
| 2042 | - $mimes = array( |
|
| 2043 | - 'hqx' => 'application/mac-binhex40', |
|
| 2044 | - 'cpt' => 'application/mac-compactpro', |
|
| 2045 | - 'doc' => 'application/msword', |
|
| 2046 | - 'bin' => 'application/macbinary', |
|
| 2047 | - 'dms' => 'application/octet-stream', |
|
| 2048 | - 'lha' => 'application/octet-stream', |
|
| 2049 | - 'lzh' => 'application/octet-stream', |
|
| 2050 | - 'exe' => 'application/octet-stream', |
|
| 2051 | - 'class' => 'application/octet-stream', |
|
| 2052 | - 'psd' => 'application/octet-stream', |
|
| 2053 | - 'so' => 'application/octet-stream', |
|
| 2054 | - 'sea' => 'application/octet-stream', |
|
| 2055 | - 'dll' => 'application/octet-stream', |
|
| 2056 | - 'oda' => 'application/oda', |
|
| 2057 | - 'pdf' => 'application/pdf', |
|
| 2058 | - 'ai' => 'application/postscript', |
|
| 2059 | - 'eps' => 'application/postscript', |
|
| 2060 | - 'ps' => 'application/postscript', |
|
| 2061 | - 'smi' => 'application/smil', |
|
| 2062 | - 'smil' => 'application/smil', |
|
| 2063 | - 'mif' => 'application/vnd.mif', |
|
| 2064 | - 'xls' => 'application/vnd.ms-excel', |
|
| 2065 | - 'ppt' => 'application/vnd.ms-powerpoint', |
|
| 2066 | - 'wbxml' => 'application/vnd.wap.wbxml', |
|
| 2067 | - 'wmlc' => 'application/vnd.wap.wmlc', |
|
| 2068 | - 'dcr' => 'application/x-director', |
|
| 2069 | - 'dir' => 'application/x-director', |
|
| 2070 | - 'dxr' => 'application/x-director', |
|
| 2071 | - 'dvi' => 'application/x-dvi', |
|
| 2072 | - 'gtar' => 'application/x-gtar', |
|
| 2073 | - 'php' => 'application/x-httpd-php', |
|
| 2074 | - 'php4' => 'application/x-httpd-php', |
|
| 2075 | - 'php3' => 'application/x-httpd-php', |
|
| 2076 | - 'phtml' => 'application/x-httpd-php', |
|
| 2077 | - 'phps' => 'application/x-httpd-php-source', |
|
| 2078 | - 'js' => 'application/x-javascript', |
|
| 2079 | - 'swf' => 'application/x-shockwave-flash', |
|
| 2080 | - 'sit' => 'application/x-stuffit', |
|
| 2081 | - 'tar' => 'application/x-tar', |
|
| 2082 | - 'tgz' => 'application/x-tar', |
|
| 2083 | - 'xhtml' => 'application/xhtml+xml', |
|
| 2084 | - 'xht' => 'application/xhtml+xml', |
|
| 2085 | - 'zip' => 'application/zip', |
|
| 2086 | - 'mid' => 'audio/midi', |
|
| 2087 | - 'midi' => 'audio/midi', |
|
| 2088 | - 'mpga' => 'audio/mpeg', |
|
| 2089 | - 'mp2' => 'audio/mpeg', |
|
| 2090 | - 'mp3' => 'audio/mpeg', |
|
| 2091 | - 'aif' => 'audio/x-aiff', |
|
| 2092 | - 'aiff' => 'audio/x-aiff', |
|
| 2093 | - 'aifc' => 'audio/x-aiff', |
|
| 2094 | - 'ram' => 'audio/x-pn-realaudio', |
|
| 2095 | - 'rm' => 'audio/x-pn-realaudio', |
|
| 2096 | - 'rpm' => 'audio/x-pn-realaudio-plugin', |
|
| 2097 | - 'ra' => 'audio/x-realaudio', |
|
| 2098 | - 'rv' => 'video/vnd.rn-realvideo', |
|
| 2099 | - 'wav' => 'audio/x-wav', |
|
| 2100 | - 'bmp' => 'image/bmp', |
|
| 2101 | - 'gif' => 'image/gif', |
|
| 2102 | - 'jpeg' => 'image/jpeg', |
|
| 2103 | - 'jpg' => 'image/jpeg', |
|
| 2104 | - 'jpe' => 'image/jpeg', |
|
| 2105 | - 'png' => 'image/png', |
|
| 2106 | - 'tiff' => 'image/tiff', |
|
| 2107 | - 'tif' => 'image/tiff', |
|
| 2108 | - 'css' => 'text/css', |
|
| 2109 | - 'html' => 'text/html', |
|
| 2110 | - 'htm' => 'text/html', |
|
| 2111 | - 'shtml' => 'text/html', |
|
| 2112 | - 'txt' => 'text/plain', |
|
| 2113 | - 'text' => 'text/plain', |
|
| 2114 | - 'log' => 'text/plain', |
|
| 2115 | - 'rtx' => 'text/richtext', |
|
| 2116 | - 'rtf' => 'text/rtf', |
|
| 2117 | - 'xml' => 'text/xml', |
|
| 2118 | - 'xsl' => 'text/xml', |
|
| 2119 | - 'mpeg' => 'video/mpeg', |
|
| 2120 | - 'mpg' => 'video/mpeg', |
|
| 2121 | - 'mpe' => 'video/mpeg', |
|
| 2122 | - 'qt' => 'video/quicktime', |
|
| 2123 | - 'mov' => 'video/quicktime', |
|
| 2124 | - 'avi' => 'video/x-msvideo', |
|
| 2125 | - 'movie' => 'video/x-sgi-movie', |
|
| 2126 | - 'doc' => 'application/msword', |
|
| 2127 | - 'word' => 'application/msword', |
|
| 2128 | - 'xl' => 'application/excel', |
|
| 2129 | - 'eml' => 'message/rfc822' |
|
| 2130 | - ); |
|
| 2131 | - return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; |
|
| 2042 | + $mimes = array( |
|
| 2043 | + 'hqx' => 'application/mac-binhex40', |
|
| 2044 | + 'cpt' => 'application/mac-compactpro', |
|
| 2045 | + 'doc' => 'application/msword', |
|
| 2046 | + 'bin' => 'application/macbinary', |
|
| 2047 | + 'dms' => 'application/octet-stream', |
|
| 2048 | + 'lha' => 'application/octet-stream', |
|
| 2049 | + 'lzh' => 'application/octet-stream', |
|
| 2050 | + 'exe' => 'application/octet-stream', |
|
| 2051 | + 'class' => 'application/octet-stream', |
|
| 2052 | + 'psd' => 'application/octet-stream', |
|
| 2053 | + 'so' => 'application/octet-stream', |
|
| 2054 | + 'sea' => 'application/octet-stream', |
|
| 2055 | + 'dll' => 'application/octet-stream', |
|
| 2056 | + 'oda' => 'application/oda', |
|
| 2057 | + 'pdf' => 'application/pdf', |
|
| 2058 | + 'ai' => 'application/postscript', |
|
| 2059 | + 'eps' => 'application/postscript', |
|
| 2060 | + 'ps' => 'application/postscript', |
|
| 2061 | + 'smi' => 'application/smil', |
|
| 2062 | + 'smil' => 'application/smil', |
|
| 2063 | + 'mif' => 'application/vnd.mif', |
|
| 2064 | + 'xls' => 'application/vnd.ms-excel', |
|
| 2065 | + 'ppt' => 'application/vnd.ms-powerpoint', |
|
| 2066 | + 'wbxml' => 'application/vnd.wap.wbxml', |
|
| 2067 | + 'wmlc' => 'application/vnd.wap.wmlc', |
|
| 2068 | + 'dcr' => 'application/x-director', |
|
| 2069 | + 'dir' => 'application/x-director', |
|
| 2070 | + 'dxr' => 'application/x-director', |
|
| 2071 | + 'dvi' => 'application/x-dvi', |
|
| 2072 | + 'gtar' => 'application/x-gtar', |
|
| 2073 | + 'php' => 'application/x-httpd-php', |
|
| 2074 | + 'php4' => 'application/x-httpd-php', |
|
| 2075 | + 'php3' => 'application/x-httpd-php', |
|
| 2076 | + 'phtml' => 'application/x-httpd-php', |
|
| 2077 | + 'phps' => 'application/x-httpd-php-source', |
|
| 2078 | + 'js' => 'application/x-javascript', |
|
| 2079 | + 'swf' => 'application/x-shockwave-flash', |
|
| 2080 | + 'sit' => 'application/x-stuffit', |
|
| 2081 | + 'tar' => 'application/x-tar', |
|
| 2082 | + 'tgz' => 'application/x-tar', |
|
| 2083 | + 'xhtml' => 'application/xhtml+xml', |
|
| 2084 | + 'xht' => 'application/xhtml+xml', |
|
| 2085 | + 'zip' => 'application/zip', |
|
| 2086 | + 'mid' => 'audio/midi', |
|
| 2087 | + 'midi' => 'audio/midi', |
|
| 2088 | + 'mpga' => 'audio/mpeg', |
|
| 2089 | + 'mp2' => 'audio/mpeg', |
|
| 2090 | + 'mp3' => 'audio/mpeg', |
|
| 2091 | + 'aif' => 'audio/x-aiff', |
|
| 2092 | + 'aiff' => 'audio/x-aiff', |
|
| 2093 | + 'aifc' => 'audio/x-aiff', |
|
| 2094 | + 'ram' => 'audio/x-pn-realaudio', |
|
| 2095 | + 'rm' => 'audio/x-pn-realaudio', |
|
| 2096 | + 'rpm' => 'audio/x-pn-realaudio-plugin', |
|
| 2097 | + 'ra' => 'audio/x-realaudio', |
|
| 2098 | + 'rv' => 'video/vnd.rn-realvideo', |
|
| 2099 | + 'wav' => 'audio/x-wav', |
|
| 2100 | + 'bmp' => 'image/bmp', |
|
| 2101 | + 'gif' => 'image/gif', |
|
| 2102 | + 'jpeg' => 'image/jpeg', |
|
| 2103 | + 'jpg' => 'image/jpeg', |
|
| 2104 | + 'jpe' => 'image/jpeg', |
|
| 2105 | + 'png' => 'image/png', |
|
| 2106 | + 'tiff' => 'image/tiff', |
|
| 2107 | + 'tif' => 'image/tiff', |
|
| 2108 | + 'css' => 'text/css', |
|
| 2109 | + 'html' => 'text/html', |
|
| 2110 | + 'htm' => 'text/html', |
|
| 2111 | + 'shtml' => 'text/html', |
|
| 2112 | + 'txt' => 'text/plain', |
|
| 2113 | + 'text' => 'text/plain', |
|
| 2114 | + 'log' => 'text/plain', |
|
| 2115 | + 'rtx' => 'text/richtext', |
|
| 2116 | + 'rtf' => 'text/rtf', |
|
| 2117 | + 'xml' => 'text/xml', |
|
| 2118 | + 'xsl' => 'text/xml', |
|
| 2119 | + 'mpeg' => 'video/mpeg', |
|
| 2120 | + 'mpg' => 'video/mpeg', |
|
| 2121 | + 'mpe' => 'video/mpeg', |
|
| 2122 | + 'qt' => 'video/quicktime', |
|
| 2123 | + 'mov' => 'video/quicktime', |
|
| 2124 | + 'avi' => 'video/x-msvideo', |
|
| 2125 | + 'movie' => 'video/x-sgi-movie', |
|
| 2126 | + 'doc' => 'application/msword', |
|
| 2127 | + 'word' => 'application/msword', |
|
| 2128 | + 'xl' => 'application/excel', |
|
| 2129 | + 'eml' => 'message/rfc822' |
|
| 2130 | + ); |
|
| 2131 | + return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; |
|
| 2132 | 2132 | } |
| 2133 | 2133 | |
| 2134 | 2134 | /** |
@@ -2141,22 +2141,22 @@ discard block |
||
| 2141 | 2141 | * @param string $name Parameter Name |
| 2142 | 2142 | * @param mixed $value Parameter Value |
| 2143 | 2143 | * NOTE: will not work with arrays, there are no arrays to set/reset |
| 2144 | - * @todo Should this not be using __set() magic function? |
|
| 2144 | + * @todo Should this not be using __set() magic function? |
|
| 2145 | 2145 | */ |
| 2146 | 2146 | public function set ( $name, $value = '' ) { |
| 2147 | - try { |
|
| 2148 | - if ( isset($this->$name) ) { |
|
| 2149 | - $this->$name = $value; |
|
| 2150 | - } else { |
|
| 2151 | - throw new phpmailerException($this->Lang('variable_set') . $name, self::STOP_CRITICAL); |
|
| 2147 | + try { |
|
| 2148 | + if ( isset($this->$name) ) { |
|
| 2149 | + $this->$name = $value; |
|
| 2150 | + } else { |
|
| 2151 | + throw new phpmailerException($this->Lang('variable_set') . $name, self::STOP_CRITICAL); |
|
| 2152 | 2152 | } |
| 2153 | - } catch (Exception $e) { |
|
| 2154 | - $this->SetError($e->getMessage()); |
|
| 2155 | - if ($e->getCode() == self::STOP_CRITICAL) { |
|
| 2156 | - return false; |
|
| 2157 | - } |
|
| 2153 | + } catch (Exception $e) { |
|
| 2154 | + $this->SetError($e->getMessage()); |
|
| 2155 | + if ($e->getCode() == self::STOP_CRITICAL) { |
|
| 2156 | + return false; |
|
| 2157 | + } |
|
| 2158 | 2158 | } |
| 2159 | - return true; |
|
| 2159 | + return true; |
|
| 2160 | 2160 | } |
| 2161 | 2161 | |
| 2162 | 2162 | /** |
@@ -2166,9 +2166,9 @@ discard block |
||
| 2166 | 2166 | * @return string |
| 2167 | 2167 | */ |
| 2168 | 2168 | public function SecureHeader($str) { |
| 2169 | - $str = str_replace("\r", '', $str); |
|
| 2170 | - $str = str_replace("\n", '', $str); |
|
| 2171 | - return trim($str); |
|
| 2169 | + $str = str_replace("\r", '', $str); |
|
| 2170 | + $str = str_replace("\n", '', $str); |
|
| 2171 | + return trim($str); |
|
| 2172 | 2172 | } |
| 2173 | 2173 | |
| 2174 | 2174 | /** |
@@ -2179,9 +2179,9 @@ discard block |
||
| 2179 | 2179 | * @param string $key_pass Password for private key |
| 2180 | 2180 | */ |
| 2181 | 2181 | public function Sign($cert_filename, $key_filename, $key_pass) { |
| 2182 | - $this->sign_cert_file = $cert_filename; |
|
| 2183 | - $this->sign_key_file = $key_filename; |
|
| 2184 | - $this->sign_key_pass = $key_pass; |
|
| 2182 | + $this->sign_cert_file = $cert_filename; |
|
| 2183 | + $this->sign_key_file = $key_filename; |
|
| 2184 | + $this->sign_key_pass = $key_pass; |
|
| 2185 | 2185 | } |
| 2186 | 2186 | |
| 2187 | 2187 | /** |
@@ -2192,17 +2192,17 @@ discard block |
||
| 2192 | 2192 | * @param string $key_pass Password for private key |
| 2193 | 2193 | */ |
| 2194 | 2194 | public function DKIM_QP($txt) { |
| 2195 | - $tmp=""; |
|
| 2196 | - $line=""; |
|
| 2197 | - for ($i=0;$i<strlen($txt);$i++) { |
|
| 2198 | - $ord=ord($txt[$i]); |
|
| 2199 | - if ( ((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)) ) { |
|
| 2200 | - $line.=$txt[$i]; |
|
| 2201 | - } else { |
|
| 2202 | - $line.="=".sprintf("%02X",$ord); |
|
| 2203 | - } |
|
| 2204 | - } |
|
| 2205 | - return $line; |
|
| 2195 | + $tmp=""; |
|
| 2196 | + $line=""; |
|
| 2197 | + for ($i=0;$i<strlen($txt);$i++) { |
|
| 2198 | + $ord=ord($txt[$i]); |
|
| 2199 | + if ( ((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)) ) { |
|
| 2200 | + $line.=$txt[$i]; |
|
| 2201 | + } else { |
|
| 2202 | + $line.="=".sprintf("%02X",$ord); |
|
| 2203 | + } |
|
| 2204 | + } |
|
| 2205 | + return $line; |
|
| 2206 | 2206 | } |
| 2207 | 2207 | |
| 2208 | 2208 | /** |
@@ -2212,15 +2212,15 @@ discard block |
||
| 2212 | 2212 | * @param string $s Header |
| 2213 | 2213 | */ |
| 2214 | 2214 | public function DKIM_Sign($s) { |
| 2215 | - $privKeyStr = file_get_contents($this->DKIM_private); |
|
| 2216 | - if ($this->DKIM_passphrase!='') { |
|
| 2217 | - $privKey = openssl_pkey_get_private($privKeyStr,$this->DKIM_passphrase); |
|
| 2218 | - } else { |
|
| 2219 | - $privKey = $privKeyStr; |
|
| 2220 | - } |
|
| 2221 | - if (openssl_sign($s, $signature, $privKey)) { |
|
| 2222 | - return base64_encode($signature); |
|
| 2223 | - } |
|
| 2215 | + $privKeyStr = file_get_contents($this->DKIM_private); |
|
| 2216 | + if ($this->DKIM_passphrase!='') { |
|
| 2217 | + $privKey = openssl_pkey_get_private($privKeyStr,$this->DKIM_passphrase); |
|
| 2218 | + } else { |
|
| 2219 | + $privKey = $privKeyStr; |
|
| 2220 | + } |
|
| 2221 | + if (openssl_sign($s, $signature, $privKey)) { |
|
| 2222 | + return base64_encode($signature); |
|
| 2223 | + } |
|
| 2224 | 2224 | } |
| 2225 | 2225 | |
| 2226 | 2226 | /** |
@@ -2230,16 +2230,16 @@ discard block |
||
| 2230 | 2230 | * @param string $s Header |
| 2231 | 2231 | */ |
| 2232 | 2232 | public function DKIM_HeaderC($s) { |
| 2233 | - $s=preg_replace("/\r\n\s+/"," ",$s); |
|
| 2234 | - $lines=explode("\r\n",$s); |
|
| 2235 | - foreach ($lines as $key=>$line) { |
|
| 2236 | - list($heading,$value)=explode(":",$line,2); |
|
| 2237 | - $heading=strtolower($heading); |
|
| 2238 | - $value=preg_replace("/\s+/"," ",$value) ; // Compress useless spaces |
|
| 2239 | - $lines[$key]=$heading.":".trim($value) ; // Don't forget to remove WSP around the value |
|
| 2240 | - } |
|
| 2241 | - $s=implode("\r\n",$lines); |
|
| 2242 | - return $s; |
|
| 2233 | + $s=preg_replace("/\r\n\s+/"," ",$s); |
|
| 2234 | + $lines=explode("\r\n",$s); |
|
| 2235 | + foreach ($lines as $key=>$line) { |
|
| 2236 | + list($heading,$value)=explode(":",$line,2); |
|
| 2237 | + $heading=strtolower($heading); |
|
| 2238 | + $value=preg_replace("/\s+/"," ",$value) ; // Compress useless spaces |
|
| 2239 | + $lines[$key]=$heading.":".trim($value) ; // Don't forget to remove WSP around the value |
|
| 2240 | + } |
|
| 2241 | + $s=implode("\r\n",$lines); |
|
| 2242 | + return $s; |
|
| 2243 | 2243 | } |
| 2244 | 2244 | |
| 2245 | 2245 | /** |
@@ -2249,15 +2249,15 @@ discard block |
||
| 2249 | 2249 | * @param string $body Message Body |
| 2250 | 2250 | */ |
| 2251 | 2251 | public function DKIM_BodyC($body) { |
| 2252 | - if ($body == '') return "\r\n"; |
|
| 2253 | - // stabilize line endings |
|
| 2254 | - $body=str_replace("\r\n","\n",$body); |
|
| 2255 | - $body=str_replace("\n","\r\n",$body); |
|
| 2256 | - // END stabilize line endings |
|
| 2257 | - while (substr($body,strlen($body)-4,4) == "\r\n\r\n") { |
|
| 2258 | - $body=substr($body,0,strlen($body)-2); |
|
| 2259 | - } |
|
| 2260 | - return $body; |
|
| 2252 | + if ($body == '') return "\r\n"; |
|
| 2253 | + // stabilize line endings |
|
| 2254 | + $body=str_replace("\r\n","\n",$body); |
|
| 2255 | + $body=str_replace("\n","\r\n",$body); |
|
| 2256 | + // END stabilize line endings |
|
| 2257 | + while (substr($body,strlen($body)-4,4) == "\r\n\r\n") { |
|
| 2258 | + $body=substr($body,0,strlen($body)-2); |
|
| 2259 | + } |
|
| 2260 | + return $body; |
|
| 2261 | 2261 | } |
| 2262 | 2262 | |
| 2263 | 2263 | /** |
@@ -2269,52 +2269,52 @@ discard block |
||
| 2269 | 2269 | * @param string $body Body |
| 2270 | 2270 | */ |
| 2271 | 2271 | public function DKIM_Add($headers_line,$subject,$body) { |
| 2272 | - $DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms |
|
| 2273 | - $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body |
|
| 2274 | - $DKIMquery = 'dns/txt'; // Query method |
|
| 2275 | - $DKIMtime = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone) |
|
| 2276 | - $subject_header = "Subject: $subject"; |
|
| 2277 | - $headers = explode("\r\n",$headers_line); |
|
| 2278 | - foreach($headers as $header) { |
|
| 2279 | - if (strpos($header,'From:') === 0) { |
|
| 2280 | - $from_header=$header; |
|
| 2281 | - } elseif (strpos($header,'To:') === 0) { |
|
| 2282 | - $to_header=$header; |
|
| 2283 | - } |
|
| 2284 | - } |
|
| 2285 | - $from = str_replace('|','=7C',$this->DKIM_QP($from_header)); |
|
| 2286 | - $to = str_replace('|','=7C',$this->DKIM_QP($to_header)); |
|
| 2287 | - $subject = str_replace('|','=7C',$this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable |
|
| 2288 | - $body = $this->DKIM_BodyC($body); |
|
| 2289 | - $DKIMlen = strlen($body) ; // Length of body |
|
| 2290 | - $DKIMb64 = base64_encode(pack("H*", sha1($body))) ; // Base64 of packed binary SHA-1 hash of body |
|
| 2291 | - $ident = ($this->DKIM_identity == '')? '' : " i=" . $this->DKIM_identity . ";"; |
|
| 2292 | - $dkimhdrs = "DKIM-Signature: v=1; a=" . $DKIMsignatureType . "; q=" . $DKIMquery . "; l=" . $DKIMlen . "; s=" . $this->DKIM_selector . ";\r\n". |
|
| 2293 | - "\tt=" . $DKIMtime . "; c=" . $DKIMcanonicalization . ";\r\n". |
|
| 2294 | - "\th=From:To:Subject;\r\n". |
|
| 2295 | - "\td=" . $this->DKIM_domain . ";" . $ident . "\r\n". |
|
| 2296 | - "\tz=$from\r\n". |
|
| 2297 | - "\t|$to\r\n". |
|
| 2298 | - "\t|$subject;\r\n". |
|
| 2299 | - "\tbh=" . $DKIMb64 . ";\r\n". |
|
| 2300 | - "\tb="; |
|
| 2301 | - $toSign = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs); |
|
| 2302 | - $signed = $this->DKIM_Sign($toSign); |
|
| 2303 | - return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n"; |
|
| 2272 | + $DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms |
|
| 2273 | + $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body |
|
| 2274 | + $DKIMquery = 'dns/txt'; // Query method |
|
| 2275 | + $DKIMtime = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone) |
|
| 2276 | + $subject_header = "Subject: $subject"; |
|
| 2277 | + $headers = explode("\r\n",$headers_line); |
|
| 2278 | + foreach($headers as $header) { |
|
| 2279 | + if (strpos($header,'From:') === 0) { |
|
| 2280 | + $from_header=$header; |
|
| 2281 | + } elseif (strpos($header,'To:') === 0) { |
|
| 2282 | + $to_header=$header; |
|
| 2283 | + } |
|
| 2284 | + } |
|
| 2285 | + $from = str_replace('|','=7C',$this->DKIM_QP($from_header)); |
|
| 2286 | + $to = str_replace('|','=7C',$this->DKIM_QP($to_header)); |
|
| 2287 | + $subject = str_replace('|','=7C',$this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable |
|
| 2288 | + $body = $this->DKIM_BodyC($body); |
|
| 2289 | + $DKIMlen = strlen($body) ; // Length of body |
|
| 2290 | + $DKIMb64 = base64_encode(pack("H*", sha1($body))) ; // Base64 of packed binary SHA-1 hash of body |
|
| 2291 | + $ident = ($this->DKIM_identity == '')? '' : " i=" . $this->DKIM_identity . ";"; |
|
| 2292 | + $dkimhdrs = "DKIM-Signature: v=1; a=" . $DKIMsignatureType . "; q=" . $DKIMquery . "; l=" . $DKIMlen . "; s=" . $this->DKIM_selector . ";\r\n". |
|
| 2293 | + "\tt=" . $DKIMtime . "; c=" . $DKIMcanonicalization . ";\r\n". |
|
| 2294 | + "\th=From:To:Subject;\r\n". |
|
| 2295 | + "\td=" . $this->DKIM_domain . ";" . $ident . "\r\n". |
|
| 2296 | + "\tz=$from\r\n". |
|
| 2297 | + "\t|$to\r\n". |
|
| 2298 | + "\t|$subject;\r\n". |
|
| 2299 | + "\tbh=" . $DKIMb64 . ";\r\n". |
|
| 2300 | + "\tb="; |
|
| 2301 | + $toSign = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs); |
|
| 2302 | + $signed = $this->DKIM_Sign($toSign); |
|
| 2303 | + return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n"; |
|
| 2304 | 2304 | } |
| 2305 | 2305 | |
| 2306 | 2306 | protected function doCallback($isSent,$to,$cc,$bcc,$subject,$body) { |
| 2307 | - if (!empty($this->action_function) && function_exists($this->action_function)) { |
|
| 2308 | - $params = array($isSent,$to,$cc,$bcc,$subject,$body); |
|
| 2309 | - call_user_func_array($this->action_function,$params); |
|
| 2310 | - } |
|
| 2307 | + if (!empty($this->action_function) && function_exists($this->action_function)) { |
|
| 2308 | + $params = array($isSent,$to,$cc,$bcc,$subject,$body); |
|
| 2309 | + call_user_func_array($this->action_function,$params); |
|
| 2310 | + } |
|
| 2311 | 2311 | } |
| 2312 | 2312 | } |
| 2313 | 2313 | |
| 2314 | 2314 | class phpmailerException extends Exception { |
| 2315 | 2315 | public function errorMessage() { |
| 2316 | - $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n"; |
|
| 2317 | - return $errorMsg; |
|
| 2316 | + $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n"; |
|
| 2317 | + return $errorMsg; |
|
| 2318 | 2318 | } |
| 2319 | 2319 | } |
| 2320 | 2320 | ?> |
| 2321 | 2321 | \ No newline at end of file |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License |
| 39 | 39 | */ |
| 40 | 40 | |
| 41 | -if (version_compare(PHP_VERSION, '5.0.0', '<') ) exit("Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n"); |
|
| 41 | +if (version_compare(PHP_VERSION, '5.0.0', '<')) exit("Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n"); |
|
| 42 | 42 | |
| 43 | 43 | class PHPMailer { |
| 44 | 44 | |
@@ -50,64 +50,64 @@ discard block |
||
| 50 | 50 | * Email priority (1 = High, 3 = Normal, 5 = low). |
| 51 | 51 | * @var int |
| 52 | 52 | */ |
| 53 | - public $Priority = 3; |
|
| 53 | + public $Priority = 3; |
|
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * Sets the CharSet of the message. |
| 57 | 57 | * @var string |
| 58 | 58 | */ |
| 59 | - public $CharSet = 'utf-8'; |
|
| 59 | + public $CharSet = 'utf-8'; |
|
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | 62 | * Sets the Content-type of the message. |
| 63 | 63 | * @var string |
| 64 | 64 | */ |
| 65 | - public $ContentType = 'text/plain'; |
|
| 65 | + public $ContentType = 'text/plain'; |
|
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * Sets the Encoding of the message. Options for this are |
| 69 | 69 | * "8bit", "7bit", "binary", "base64", and "quoted-printable". |
| 70 | 70 | * @var string |
| 71 | 71 | */ |
| 72 | - public $Encoding = '8bit'; |
|
| 72 | + public $Encoding = '8bit'; |
|
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * Holds the most recent mailer error message. |
| 76 | 76 | * @var string |
| 77 | 77 | */ |
| 78 | - public $ErrorInfo = ''; |
|
| 78 | + public $ErrorInfo = ''; |
|
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | 81 | * Sets the From email address for the message. |
| 82 | 82 | * @var string |
| 83 | 83 | */ |
| 84 | - public $From = 'root@localhost'; |
|
| 84 | + public $From = 'root@localhost'; |
|
| 85 | 85 | |
| 86 | 86 | /** |
| 87 | 87 | * Sets the From name of the message. |
| 88 | 88 | * @var string |
| 89 | 89 | */ |
| 90 | - public $FromName = 'Root User'; |
|
| 90 | + public $FromName = 'Root User'; |
|
| 91 | 91 | |
| 92 | 92 | /** |
| 93 | 93 | * Sets the Sender email (Return-Path) of the message. If not empty, |
| 94 | 94 | * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode. |
| 95 | 95 | * @var string |
| 96 | 96 | */ |
| 97 | - public $Sender = ''; |
|
| 97 | + public $Sender = ''; |
|
| 98 | 98 | |
| 99 | 99 | /** |
| 100 | 100 | * Sets the Subject of the message. |
| 101 | 101 | * @var string |
| 102 | 102 | */ |
| 103 | - public $Subject = ''; |
|
| 103 | + public $Subject = ''; |
|
| 104 | 104 | |
| 105 | 105 | /** |
| 106 | 106 | * Sets the Body of the message. This can be either an HTML or text body. |
| 107 | 107 | * If HTML then run IsHTML(true). |
| 108 | 108 | * @var string |
| 109 | 109 | */ |
| 110 | - public $Body = ''; |
|
| 110 | + public $Body = ''; |
|
| 111 | 111 | |
| 112 | 112 | /** |
| 113 | 113 | * Sets the text-only body of the message. This automatically sets the |
@@ -116,39 +116,39 @@ discard block |
||
| 116 | 116 | * that can read HTML will view the normal Body. |
| 117 | 117 | * @var string |
| 118 | 118 | */ |
| 119 | - public $AltBody = ''; |
|
| 119 | + public $AltBody = ''; |
|
| 120 | 120 | |
| 121 | 121 | /** |
| 122 | 122 | * Sets word wrapping on the body of the message to a given number of |
| 123 | 123 | * characters. |
| 124 | 124 | * @var int |
| 125 | 125 | */ |
| 126 | - public $WordWrap = 0; |
|
| 126 | + public $WordWrap = 0; |
|
| 127 | 127 | |
| 128 | 128 | /** |
| 129 | 129 | * Method to send mail: ("mail", "sendmail", or "smtp"). |
| 130 | 130 | * @var string |
| 131 | 131 | */ |
| 132 | - public $Mailer = 'mail'; |
|
| 132 | + public $Mailer = 'mail'; |
|
| 133 | 133 | |
| 134 | 134 | /** |
| 135 | 135 | * Sets the path of the sendmail program. |
| 136 | 136 | * @var string |
| 137 | 137 | */ |
| 138 | - public $Sendmail = '/usr/sbin/sendmail'; |
|
| 138 | + public $Sendmail = '/usr/sbin/sendmail'; |
|
| 139 | 139 | |
| 140 | 140 | /** |
| 141 | 141 | * Path to PHPMailer plugins. Useful if the SMTP class |
| 142 | 142 | * is in a different directory than the PHP include path. |
| 143 | 143 | * @var string |
| 144 | 144 | */ |
| 145 | - public $PluginDir = ''; |
|
| 145 | + public $PluginDir = ''; |
|
| 146 | 146 | |
| 147 | 147 | /** |
| 148 | 148 | * Sets the email address that a reading confirmation will be sent. |
| 149 | 149 | * @var string |
| 150 | 150 | */ |
| 151 | - public $ConfirmReadingTo = ''; |
|
| 151 | + public $ConfirmReadingTo = ''; |
|
| 152 | 152 | |
| 153 | 153 | /** |
| 154 | 154 | * Sets the hostname to use in Message-Id and Received headers |
@@ -156,14 +156,14 @@ discard block |
||
| 156 | 156 | * by SERVER_NAME is used or 'localhost.localdomain'. |
| 157 | 157 | * @var string |
| 158 | 158 | */ |
| 159 | - public $Hostname = ''; |
|
| 159 | + public $Hostname = ''; |
|
| 160 | 160 | |
| 161 | 161 | /** |
| 162 | 162 | * Sets the message ID to be used in the Message-Id header. |
| 163 | 163 | * If empty, a unique id will be generated. |
| 164 | 164 | * @var string |
| 165 | 165 | */ |
| 166 | - public $MessageID = ''; |
|
| 166 | + public $MessageID = ''; |
|
| 167 | 167 | |
| 168 | 168 | ///////////////////////////////////////////////// |
| 169 | 169 | // PROPERTIES FOR SMTP |
@@ -177,57 +177,57 @@ discard block |
||
| 177 | 177 | * Hosts will be tried in order. |
| 178 | 178 | * @var string |
| 179 | 179 | */ |
| 180 | - public $Host = 'localhost'; |
|
| 180 | + public $Host = 'localhost'; |
|
| 181 | 181 | |
| 182 | 182 | /** |
| 183 | 183 | * Sets the default SMTP server port. |
| 184 | 184 | * @var int |
| 185 | 185 | */ |
| 186 | - public $Port = 25; |
|
| 186 | + public $Port = 25; |
|
| 187 | 187 | |
| 188 | 188 | /** |
| 189 | 189 | * Sets the SMTP HELO of the message (Default is $Hostname). |
| 190 | 190 | * @var string |
| 191 | 191 | */ |
| 192 | - public $Helo = ''; |
|
| 192 | + public $Helo = ''; |
|
| 193 | 193 | |
| 194 | 194 | /** |
| 195 | 195 | * Sets connection prefix. |
| 196 | 196 | * Options are "", "ssl" or "tls" |
| 197 | 197 | * @var string |
| 198 | 198 | */ |
| 199 | - public $SMTPSecure = ''; |
|
| 199 | + public $SMTPSecure = ''; |
|
| 200 | 200 | |
| 201 | 201 | /** |
| 202 | 202 | * Sets SMTP authentication. Utilizes the Username and Password variables. |
| 203 | 203 | * @var bool |
| 204 | 204 | */ |
| 205 | - public $SMTPAuth = false; |
|
| 205 | + public $SMTPAuth = false; |
|
| 206 | 206 | |
| 207 | 207 | /** |
| 208 | 208 | * Sets SMTP username. |
| 209 | 209 | * @var string |
| 210 | 210 | */ |
| 211 | - public $Username = ''; |
|
| 211 | + public $Username = ''; |
|
| 212 | 212 | |
| 213 | 213 | /** |
| 214 | 214 | * Sets SMTP password. |
| 215 | 215 | * @var string |
| 216 | 216 | */ |
| 217 | - public $Password = ''; |
|
| 217 | + public $Password = ''; |
|
| 218 | 218 | |
| 219 | 219 | /** |
| 220 | 220 | * Sets the SMTP server timeout in seconds. |
| 221 | 221 | * This function will not work with the win32 version. |
| 222 | 222 | * @var int |
| 223 | 223 | */ |
| 224 | - public $Timeout = 10; |
|
| 224 | + public $Timeout = 10; |
|
| 225 | 225 | |
| 226 | 226 | /** |
| 227 | 227 | * Sets SMTP class debugging on or off. |
| 228 | 228 | * @var bool |
| 229 | 229 | */ |
| 230 | - public $SMTPDebug = false; |
|
| 230 | + public $SMTPDebug = false; |
|
| 231 | 231 | |
| 232 | 232 | /** |
| 233 | 233 | * Prevents the SMTP connection from being closed after each mail |
@@ -254,34 +254,34 @@ discard block |
||
| 254 | 254 | * Provides the ability to change the line ending |
| 255 | 255 | * @var string |
| 256 | 256 | */ |
| 257 | - public $LE = "\n"; |
|
| 257 | + public $LE = "\n"; |
|
| 258 | 258 | |
| 259 | 259 | /** |
| 260 | 260 | * Used with DKIM DNS Resource Record |
| 261 | 261 | * @var string |
| 262 | 262 | */ |
| 263 | - public $DKIM_selector = 'phpmailer'; |
|
| 263 | + public $DKIM_selector = 'phpmailer'; |
|
| 264 | 264 | |
| 265 | 265 | /** |
| 266 | 266 | * Used with DKIM DNS Resource Record |
| 267 | 267 | * optional, in format of email address '[email protected]' |
| 268 | 268 | * @var string |
| 269 | 269 | */ |
| 270 | - public $DKIM_identity = ''; |
|
| 270 | + public $DKIM_identity = ''; |
|
| 271 | 271 | |
| 272 | 272 | /** |
| 273 | 273 | * Used with DKIM DNS Resource Record |
| 274 | 274 | * optional, in format of email address '[email protected]' |
| 275 | 275 | * @var string |
| 276 | 276 | */ |
| 277 | - public $DKIM_domain = ''; |
|
| 277 | + public $DKIM_domain = ''; |
|
| 278 | 278 | |
| 279 | 279 | /** |
| 280 | 280 | * Used with DKIM DNS Resource Record |
| 281 | 281 | * optional, in format of email address '[email protected]' |
| 282 | 282 | * @var string |
| 283 | 283 | */ |
| 284 | - public $DKIM_private = ''; |
|
| 284 | + public $DKIM_private = ''; |
|
| 285 | 285 | |
| 286 | 286 | /** |
| 287 | 287 | * Callback Action function name |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | * Sets the PHPMailer Version number |
| 301 | 301 | * @var string |
| 302 | 302 | */ |
| 303 | - public $Version = '5.1'; |
|
| 303 | + public $Version = '5.1'; |
|
| 304 | 304 | |
| 305 | 305 | ///////////////////////////////////////////////// |
| 306 | 306 | // PROPERTIES, PRIVATE AND PROTECTED |
@@ -316,12 +316,12 @@ discard block |
||
| 316 | 316 | private $CustomHeader = array(); |
| 317 | 317 | private $message_type = ''; |
| 318 | 318 | private $boundary = array(); |
| 319 | - protected $language = array(); |
|
| 319 | + protected $language = array(); |
|
| 320 | 320 | private $error_count = 0; |
| 321 | 321 | private $sign_cert_file = ""; |
| 322 | 322 | private $sign_key_file = ""; |
| 323 | 323 | private $sign_key_pass = ""; |
| 324 | - private $exceptions = false; |
|
| 324 | + private $exceptions = false; |
|
| 325 | 325 | |
| 326 | 326 | ///////////////////////////////////////////////// |
| 327 | 327 | // CONSTANTS |
@@ -451,13 +451,13 @@ discard block |
||
| 451 | 451 | */ |
| 452 | 452 | private function AddAnAddress($kind, $address, $name = '') { |
| 453 | 453 | if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) { |
| 454 | - echo 'Invalid recipient array: ' . kind; |
|
| 454 | + echo 'Invalid recipient array: '.kind; |
|
| 455 | 455 | return false; |
| 456 | 456 | } |
| 457 | 457 | $address = trim($address); |
| 458 | 458 | $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim |
| 459 | 459 | if (!self::ValidateAddress($address)) { |
| 460 | - $this->SetError($this->Lang('invalid_address').': '. $address); |
|
| 460 | + $this->SetError($this->Lang('invalid_address').': '.$address); |
|
| 461 | 461 | if ($this->exceptions) { |
| 462 | 462 | throw new phpmailerException($this->Lang('invalid_address').': '.$address); |
| 463 | 463 | } |
@@ -485,11 +485,11 @@ discard block |
||
| 485 | 485 | * @param string $name |
| 486 | 486 | * @return boolean |
| 487 | 487 | */ |
| 488 | - public function SetFrom($address, $name = '',$auto=1) { |
|
| 488 | + public function SetFrom($address, $name = '', $auto = 1) { |
|
| 489 | 489 | $address = trim($address); |
| 490 | 490 | $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim |
| 491 | 491 | if (!self::ValidateAddress($address)) { |
| 492 | - $this->SetError($this->Lang('invalid_address').': '. $address); |
|
| 492 | + $this->SetError($this->Lang('invalid_address').': '.$address); |
|
| 493 | 493 | if ($this->exceptions) { |
| 494 | 494 | throw new phpmailerException($this->Lang('invalid_address').': '.$address); |
| 495 | 495 | } |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | */ |
| 523 | 523 | public static function ValidateAddress($address) { |
| 524 | 524 | if (function_exists('filter_var')) { //Introduced in PHP 5.2 |
| 525 | - if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) { |
|
| 525 | + if (filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) { |
|
| 526 | 526 | return false; |
| 527 | 527 | } else { |
| 528 | 528 | return true; |
@@ -544,12 +544,12 @@ discard block |
||
| 544 | 544 | */ |
| 545 | 545 | public function Send() { |
| 546 | 546 | try { |
| 547 | - if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { |
|
| 547 | + if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { |
|
| 548 | 548 | throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL); |
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | // Set whether the message is multipart/alternative |
| 552 | - if(!empty($this->AltBody)) { |
|
| 552 | + if (!empty($this->AltBody)) { |
|
| 553 | 553 | $this->ContentType = 'multipart/alternative'; |
| 554 | 554 | } |
| 555 | 555 | |
@@ -564,12 +564,12 @@ discard block |
||
| 564 | 564 | |
| 565 | 565 | // digitally sign with DKIM if enabled |
| 566 | 566 | if ($this->DKIM_domain && $this->DKIM_private) { |
| 567 | - $header_dkim = $this->DKIM_Add($header,$this->Subject,$body); |
|
| 568 | - $header = str_replace("\r\n","\n",$header_dkim) . $header; |
|
| 567 | + $header_dkim = $this->DKIM_Add($header, $this->Subject, $body); |
|
| 568 | + $header = str_replace("\r\n", "\n", $header_dkim).$header; |
|
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | // Choose the mailer and send through it |
| 572 | - switch($this->Mailer) { |
|
| 572 | + switch ($this->Mailer) { |
|
| 573 | 573 | case 'sendmail': |
| 574 | 574 | return $this->SendmailSend($header, $body); |
| 575 | 575 | case 'smtp': |
@@ -603,32 +603,32 @@ discard block |
||
| 603 | 603 | } |
| 604 | 604 | if ($this->SingleTo === true) { |
| 605 | 605 | foreach ($this->SingleToArray as $key => $val) { |
| 606 | - if(!@$mail = popen($sendmail, 'w')) { |
|
| 607 | - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 606 | + if (!@$mail = popen($sendmail, 'w')) { |
|
| 607 | + throw new phpmailerException($this->Lang('execute').$this->Sendmail, self::STOP_CRITICAL); |
|
| 608 | 608 | } |
| 609 | - fputs($mail, "To: " . $val . "\n"); |
|
| 609 | + fputs($mail, "To: ".$val."\n"); |
|
| 610 | 610 | fputs($mail, $header); |
| 611 | 611 | fputs($mail, $body); |
| 612 | 612 | $result = pclose($mail); |
| 613 | 613 | // implement call back function if it exists |
| 614 | 614 | $isSent = ($result == 0) ? 1 : 0; |
| 615 | - $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 616 | - if($result != 0) { |
|
| 617 | - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 615 | + $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); |
|
| 616 | + if ($result != 0) { |
|
| 617 | + throw new phpmailerException($this->Lang('execute').$this->Sendmail, self::STOP_CRITICAL); |
|
| 618 | 618 | } |
| 619 | 619 | } |
| 620 | 620 | } else { |
| 621 | - if(!@$mail = popen($sendmail, 'w')) { |
|
| 622 | - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 621 | + if (!@$mail = popen($sendmail, 'w')) { |
|
| 622 | + throw new phpmailerException($this->Lang('execute').$this->Sendmail, self::STOP_CRITICAL); |
|
| 623 | 623 | } |
| 624 | 624 | fputs($mail, $header); |
| 625 | 625 | fputs($mail, $body); |
| 626 | 626 | $result = pclose($mail); |
| 627 | 627 | // implement call back function if it exists |
| 628 | 628 | $isSent = ($result == 0) ? 1 : 0; |
| 629 | - $this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 630 | - if($result != 0) { |
|
| 631 | - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 629 | + $this->doCallback($isSent, $this->to, $this->cc, $this->bcc, $this->Subject, $body); |
|
| 630 | + if ($result != 0) { |
|
| 631 | + throw new phpmailerException($this->Lang('execute').$this->Sendmail, self::STOP_CRITICAL); |
|
| 632 | 632 | } |
| 633 | 633 | } |
| 634 | 634 | return true; |
@@ -643,13 +643,13 @@ discard block |
||
| 643 | 643 | */ |
| 644 | 644 | protected function MailSend($header, $body) { |
| 645 | 645 | $toArr = array(); |
| 646 | - foreach($this->to as $t) { |
|
| 646 | + foreach ($this->to as $t) { |
|
| 647 | 647 | $toArr[] = $this->AddrFormat($t); |
| 648 | 648 | } |
| 649 | 649 | $to = implode(', ', $toArr); |
| 650 | 650 | |
| 651 | 651 | $params = sprintf("-oi -f %s", $this->Sender); |
| 652 | - if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) { |
|
| 652 | + if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) { |
|
| 653 | 653 | $old_from = ini_get('sendmail_from'); |
| 654 | 654 | ini_set('sendmail_from', $this->Sender); |
| 655 | 655 | if ($this->SingleTo === true && count($toArr) > 1) { |
@@ -657,13 +657,13 @@ discard block |
||
| 657 | 657 | $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
| 658 | 658 | // implement call back function if it exists |
| 659 | 659 | $isSent = ($rt == 1) ? 1 : 0; |
| 660 | - $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 660 | + $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); |
|
| 661 | 661 | } |
| 662 | 662 | } else { |
| 663 | 663 | $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
| 664 | 664 | // implement call back function if it exists |
| 665 | 665 | $isSent = ($rt == 1) ? 1 : 0; |
| 666 | - $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 666 | + $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body); |
|
| 667 | 667 | } |
| 668 | 668 | } else { |
| 669 | 669 | if ($this->SingleTo === true && count($toArr) > 1) { |
@@ -671,19 +671,19 @@ discard block |
||
| 671 | 671 | $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
| 672 | 672 | // implement call back function if it exists |
| 673 | 673 | $isSent = ($rt == 1) ? 1 : 0; |
| 674 | - $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 674 | + $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); |
|
| 675 | 675 | } |
| 676 | 676 | } else { |
| 677 | 677 | $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header); |
| 678 | 678 | // implement call back function if it exists |
| 679 | 679 | $isSent = ($rt == 1) ? 1 : 0; |
| 680 | - $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 680 | + $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body); |
|
| 681 | 681 | } |
| 682 | 682 | } |
| 683 | 683 | if (isset($old_from)) { |
| 684 | 684 | ini_set('sendmail_from', $old_from); |
| 685 | 685 | } |
| 686 | - if(!$rt) { |
|
| 686 | + if (!$rt) { |
|
| 687 | 687 | throw new phpmailerException($this->Lang('instantiate'), self::STOP_CRITICAL); |
| 688 | 688 | } |
| 689 | 689 | return true; |
@@ -699,64 +699,64 @@ discard block |
||
| 699 | 699 | * @return bool |
| 700 | 700 | */ |
| 701 | 701 | protected function SmtpSend($header, $body) { |
| 702 | - require_once $this->PluginDir . 'smtp.php'; |
|
| 702 | + require_once $this->PluginDir.'smtp.php'; |
|
| 703 | 703 | $bad_rcpt = array(); |
| 704 | 704 | |
| 705 | - if(!$this->SmtpConnect()) { |
|
| 705 | + if (!$this->SmtpConnect()) { |
|
| 706 | 706 | throw new phpmailerException($this->Lang('smtp_connect_failed'), self::STOP_CRITICAL); |
| 707 | 707 | } |
| 708 | 708 | $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender; |
| 709 | - if(!$this->smtp->Mail($smtp_from)) { |
|
| 710 | - throw new phpmailerException($this->Lang('from_failed') . $smtp_from, self::STOP_CRITICAL); |
|
| 709 | + if (!$this->smtp->Mail($smtp_from)) { |
|
| 710 | + throw new phpmailerException($this->Lang('from_failed').$smtp_from, self::STOP_CRITICAL); |
|
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | // Attempt to send attach all recipients |
| 714 | - foreach($this->to as $to) { |
|
| 714 | + foreach ($this->to as $to) { |
|
| 715 | 715 | if (!$this->smtp->Recipient($to[0])) { |
| 716 | 716 | $bad_rcpt[] = $to[0]; |
| 717 | 717 | // implement call back function if it exists |
| 718 | 718 | $isSent = 0; |
| 719 | - $this->doCallback($isSent,$to[0],'','',$this->Subject,$body); |
|
| 719 | + $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body); |
|
| 720 | 720 | } else { |
| 721 | 721 | // implement call back function if it exists |
| 722 | 722 | $isSent = 1; |
| 723 | - $this->doCallback($isSent,$to[0],'','',$this->Subject,$body); |
|
| 723 | + $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body); |
|
| 724 | 724 | } |
| 725 | 725 | } |
| 726 | - foreach($this->cc as $cc) { |
|
| 726 | + foreach ($this->cc as $cc) { |
|
| 727 | 727 | if (!$this->smtp->Recipient($cc[0])) { |
| 728 | 728 | $bad_rcpt[] = $cc[0]; |
| 729 | 729 | // implement call back function if it exists |
| 730 | 730 | $isSent = 0; |
| 731 | - $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body); |
|
| 731 | + $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body); |
|
| 732 | 732 | } else { |
| 733 | 733 | // implement call back function if it exists |
| 734 | 734 | $isSent = 1; |
| 735 | - $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body); |
|
| 735 | + $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body); |
|
| 736 | 736 | } |
| 737 | 737 | } |
| 738 | - foreach($this->bcc as $bcc) { |
|
| 738 | + foreach ($this->bcc as $bcc) { |
|
| 739 | 739 | if (!$this->smtp->Recipient($bcc[0])) { |
| 740 | 740 | $bad_rcpt[] = $bcc[0]; |
| 741 | 741 | // implement call back function if it exists |
| 742 | 742 | $isSent = 0; |
| 743 | - $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body); |
|
| 743 | + $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body); |
|
| 744 | 744 | } else { |
| 745 | 745 | // implement call back function if it exists |
| 746 | 746 | $isSent = 1; |
| 747 | - $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body); |
|
| 747 | + $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body); |
|
| 748 | 748 | } |
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | |
| 752 | - if (count($bad_rcpt) > 0 ) { //Create error message for any bad addresses |
|
| 752 | + if (count($bad_rcpt) > 0) { //Create error message for any bad addresses |
|
| 753 | 753 | $badaddresses = implode(', ', $bad_rcpt); |
| 754 | - throw new phpmailerException($this->Lang('recipients_failed') . $badaddresses); |
|
| 754 | + throw new phpmailerException($this->Lang('recipients_failed').$badaddresses); |
|
| 755 | 755 | } |
| 756 | - if(!$this->smtp->Data($header . $body)) { |
|
| 756 | + if (!$this->smtp->Data($header.$body)) { |
|
| 757 | 757 | throw new phpmailerException($this->Lang('data_not_accepted'), self::STOP_CRITICAL); |
| 758 | 758 | } |
| 759 | - if($this->SMTPKeepAlive == true) { |
|
| 759 | + if ($this->SMTPKeepAlive == true) { |
|
| 760 | 760 | $this->smtp->Reset(); |
| 761 | 761 | } |
| 762 | 762 | return true; |
@@ -770,7 +770,7 @@ discard block |
||
| 770 | 770 | * @return bool |
| 771 | 771 | */ |
| 772 | 772 | public function SmtpConnect() { |
| 773 | - if(is_null($this->smtp)) { |
|
| 773 | + if (is_null($this->smtp)) { |
|
| 774 | 774 | $this->smtp = new SMTP(); |
| 775 | 775 | } |
| 776 | 776 | |
@@ -781,7 +781,7 @@ discard block |
||
| 781 | 781 | |
| 782 | 782 | // Retry while there is no connection |
| 783 | 783 | try { |
| 784 | - while($index < count($hosts) && !$connection) { |
|
| 784 | + while ($index < count($hosts) && !$connection) { |
|
| 785 | 785 | $hostinfo = array(); |
| 786 | 786 | if (preg_match('/^(.+):([0-9]+)$/', $hosts[$index], $hostinfo)) { |
| 787 | 787 | $host = $hostinfo[1]; |
@@ -794,13 +794,13 @@ discard block |
||
| 794 | 794 | $tls = ($this->SMTPSecure == 'tls'); |
| 795 | 795 | $ssl = ($this->SMTPSecure == 'ssl'); |
| 796 | 796 | |
| 797 | - if($this->smtp->Connect(($ssl ? 'ssl://':'').$host, $port, $this->Timeout)) { |
|
| 797 | + if ($this->smtp->Connect(($ssl ? 'ssl://' : '').$host, $port, $this->Timeout)) { |
|
| 798 | 798 | |
| 799 | 799 | $hello = ($this->Helo != '' ? $this->Helo : $this->ServerHostname()); |
| 800 | 800 | $this->smtp->Hello($hello); |
| 801 | 801 | |
| 802 | - if($tls) { |
|
| 803 | - if(!$this->smtp->StartTLS()) { |
|
| 802 | + if ($tls) { |
|
| 803 | + if (!$this->smtp->StartTLS()) { |
|
| 804 | 804 | throw new phpmailerException($this->Lang('tls')); |
| 805 | 805 | } |
| 806 | 806 | |
@@ -809,14 +809,14 @@ discard block |
||
| 809 | 809 | } |
| 810 | 810 | |
| 811 | 811 | $connection = true; |
| 812 | - if($this->SMTPAuth) { |
|
| 813 | - if(!$this->smtp->Authenticate($this->Username, $this->Password)) { |
|
| 812 | + if ($this->SMTPAuth) { |
|
| 813 | + if (!$this->smtp->Authenticate($this->Username, $this->Password)) { |
|
| 814 | 814 | throw new phpmailerException($this->Lang('authenticate')); |
| 815 | 815 | } |
| 816 | 816 | } |
| 817 | 817 | } |
| 818 | 818 | $index++; |
| 819 | - if(!$connection) { |
|
| 819 | + if (!$connection) { |
|
| 820 | 820 | throw new phpmailerException($this->Lang('connect_host')); |
| 821 | 821 | } |
| 822 | 822 | } |
@@ -832,8 +832,8 @@ discard block |
||
| 832 | 832 | * @return void |
| 833 | 833 | */ |
| 834 | 834 | public function SmtpClose() { |
| 835 | - if(!is_null($this->smtp)) { |
|
| 836 | - if($this->smtp->Connected()) { |
|
| 835 | + if (!is_null($this->smtp)) { |
|
| 836 | + if ($this->smtp->Connected()) { |
|
| 837 | 837 | $this->smtp->Quit(); |
| 838 | 838 | $this->smtp->Close(); |
| 839 | 839 | } |
@@ -895,7 +895,7 @@ discard block |
||
| 895 | 895 | * @return string |
| 896 | 896 | */ |
| 897 | 897 | public function AddrAppend($type, $addr) { |
| 898 | - $addr_str = $type . ': '; |
|
| 898 | + $addr_str = $type.': '; |
|
| 899 | 899 | $addresses = array(); |
| 900 | 900 | foreach ($addr as $a) { |
| 901 | 901 | $addresses[] = $this->AddrFormat($a); |
@@ -912,10 +912,10 @@ discard block |
||
| 912 | 912 | * @return string |
| 913 | 913 | */ |
| 914 | 914 | public function AddrFormat($addr) { |
| 915 | - if(empty($addr[1])) { |
|
| 915 | + if (empty($addr[1])) { |
|
| 916 | 916 | return $this->SecureHeader($addr[0]); |
| 917 | 917 | } else { |
| 918 | - return $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">"; |
|
| 918 | + return $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase')." <".$this->SecureHeader($addr[0]).">"; |
|
| 919 | 919 | } |
| 920 | 920 | } |
| 921 | 921 | |
@@ -942,10 +942,10 @@ discard block |
||
| 942 | 942 | |
| 943 | 943 | $line = explode($this->LE, $message); |
| 944 | 944 | $message = ''; |
| 945 | - for ($i=0 ;$i < count($line); $i++) { |
|
| 945 | + for ($i = 0; $i < count($line); $i++) { |
|
| 946 | 946 | $line_part = explode(' ', $line[$i]); |
| 947 | 947 | $buf = ''; |
| 948 | - for ($e = 0; $e<count($line_part); $e++) { |
|
| 948 | + for ($e = 0; $e < count($line_part); $e++) { |
|
| 949 | 949 | $word = $line_part[$e]; |
| 950 | 950 | if ($qp_mode and (strlen($word) > $length)) { |
| 951 | 951 | $space_left = $length - strlen($buf) - 1; |
@@ -961,10 +961,10 @@ discard block |
||
| 961 | 961 | } |
| 962 | 962 | $part = substr($word, 0, $len); |
| 963 | 963 | $word = substr($word, $len); |
| 964 | - $buf .= ' ' . $part; |
|
| 965 | - $message .= $buf . sprintf("=%s", $this->LE); |
|
| 964 | + $buf .= ' '.$part; |
|
| 965 | + $message .= $buf.sprintf("=%s", $this->LE); |
|
| 966 | 966 | } else { |
| 967 | - $message .= $buf . $soft_break; |
|
| 967 | + $message .= $buf.$soft_break; |
|
| 968 | 968 | } |
| 969 | 969 | $buf = ''; |
| 970 | 970 | } |
@@ -981,22 +981,22 @@ discard block |
||
| 981 | 981 | $word = substr($word, $len); |
| 982 | 982 | |
| 983 | 983 | if (strlen($word) > 0) { |
| 984 | - $message .= $part . sprintf("=%s", $this->LE); |
|
| 984 | + $message .= $part.sprintf("=%s", $this->LE); |
|
| 985 | 985 | } else { |
| 986 | 986 | $buf = $part; |
| 987 | 987 | } |
| 988 | 988 | } |
| 989 | 989 | } else { |
| 990 | 990 | $buf_o = $buf; |
| 991 | - $buf .= ($e == 0) ? $word : (' ' . $word); |
|
| 991 | + $buf .= ($e == 0) ? $word : (' '.$word); |
|
| 992 | 992 | |
| 993 | 993 | if (strlen($buf) > $length and $buf_o != '') { |
| 994 | - $message .= $buf_o . $soft_break; |
|
| 994 | + $message .= $buf_o.$soft_break; |
|
| 995 | 995 | $buf = $word; |
| 996 | 996 | } |
| 997 | 997 | } |
| 998 | 998 | } |
| 999 | - $message .= $buf . $this->LE; |
|
| 999 | + $message .= $buf.$this->LE; |
|
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | 1002 | return $message; |
@@ -1025,8 +1025,7 @@ discard block |
||
| 1025 | 1025 | if ($dec < 128) { // Single byte character. |
| 1026 | 1026 | // If the encoded char was found at pos 0, it will fit |
| 1027 | 1027 | // otherwise reduce maxLength to start of the encoded char |
| 1028 | - $maxLength = ($encodedCharPos == 0) ? $maxLength : |
|
| 1029 | - $maxLength - ($lookBack - $encodedCharPos); |
|
| 1028 | + $maxLength = ($encodedCharPos == 0) ? $maxLength : $maxLength - ($lookBack - $encodedCharPos); |
|
| 1030 | 1029 | $foundSplitPos = true; |
| 1031 | 1030 | } elseif ($dec >= 192) { // First byte of a multi byte character |
| 1032 | 1031 | // Reduce maxLength to split at start of character |
@@ -1050,11 +1049,11 @@ discard block |
||
| 1050 | 1049 | * @return void |
| 1051 | 1050 | */ |
| 1052 | 1051 | public function SetWordWrap() { |
| 1053 | - if($this->WordWrap < 1) { |
|
| 1052 | + if ($this->WordWrap < 1) { |
|
| 1054 | 1053 | return; |
| 1055 | 1054 | } |
| 1056 | 1055 | |
| 1057 | - switch($this->message_type) { |
|
| 1056 | + switch ($this->message_type) { |
|
| 1058 | 1057 | case 'alt': |
| 1059 | 1058 | case 'alt_attachments': |
| 1060 | 1059 | $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap); |
@@ -1075,24 +1074,24 @@ discard block |
||
| 1075 | 1074 | |
| 1076 | 1075 | // Set the boundaries |
| 1077 | 1076 | $uniq_id = md5(uniqid(time())); |
| 1078 | - $this->boundary[1] = 'b1_' . $uniq_id; |
|
| 1079 | - $this->boundary[2] = 'b2_' . $uniq_id; |
|
| 1077 | + $this->boundary[1] = 'b1_'.$uniq_id; |
|
| 1078 | + $this->boundary[2] = 'b2_'.$uniq_id; |
|
| 1080 | 1079 | |
| 1081 | 1080 | $result .= $this->HeaderLine('Date', self::RFCDate()); |
| 1082 | - if($this->Sender == '') { |
|
| 1081 | + if ($this->Sender == '') { |
|
| 1083 | 1082 | $result .= $this->HeaderLine('Return-Path', trim($this->From)); |
| 1084 | 1083 | } else { |
| 1085 | 1084 | $result .= $this->HeaderLine('Return-Path', trim($this->Sender)); |
| 1086 | 1085 | } |
| 1087 | 1086 | |
| 1088 | 1087 | // To be created automatically by mail() |
| 1089 | - if($this->Mailer != 'mail') { |
|
| 1088 | + if ($this->Mailer != 'mail') { |
|
| 1090 | 1089 | if ($this->SingleTo === true) { |
| 1091 | - foreach($this->to as $t) { |
|
| 1090 | + foreach ($this->to as $t) { |
|
| 1092 | 1091 | $this->SingleToArray[] = $this->AddrFormat($t); |
| 1093 | 1092 | } |
| 1094 | 1093 | } else { |
| 1095 | - if(count($this->to) > 0) { |
|
| 1094 | + if (count($this->to) > 0) { |
|
| 1096 | 1095 | $result .= $this->AddrAppend('To', $this->to); |
| 1097 | 1096 | } elseif (count($this->cc) == 0) { |
| 1098 | 1097 | $result .= $this->HeaderLine('To', 'undisclosed-recipients:;'); |
@@ -1106,38 +1105,38 @@ discard block |
||
| 1106 | 1105 | $result .= $this->AddrAppend('From', $from); |
| 1107 | 1106 | |
| 1108 | 1107 | // sendmail and mail() extract Cc from the header before sending |
| 1109 | - if(count($this->cc) > 0) { |
|
| 1108 | + if (count($this->cc) > 0) { |
|
| 1110 | 1109 | $result .= $this->AddrAppend('Cc', $this->cc); |
| 1111 | 1110 | } |
| 1112 | 1111 | |
| 1113 | 1112 | // sendmail and mail() extract Bcc from the header before sending |
| 1114 | - if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) { |
|
| 1113 | + if ((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) { |
|
| 1115 | 1114 | $result .= $this->AddrAppend('Bcc', $this->bcc); |
| 1116 | 1115 | } |
| 1117 | 1116 | |
| 1118 | - if(count($this->ReplyTo) > 0) { |
|
| 1117 | + if (count($this->ReplyTo) > 0) { |
|
| 1119 | 1118 | $result .= $this->AddrAppend('Reply-to', $this->ReplyTo); |
| 1120 | 1119 | } |
| 1121 | 1120 | |
| 1122 | 1121 | // mail() sets the subject itself |
| 1123 | - if($this->Mailer != 'mail') { |
|
| 1122 | + if ($this->Mailer != 'mail') { |
|
| 1124 | 1123 | $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject))); |
| 1125 | 1124 | } |
| 1126 | 1125 | |
| 1127 | - if($this->MessageID != '') { |
|
| 1128 | - $result .= $this->HeaderLine('Message-ID',$this->MessageID); |
|
| 1126 | + if ($this->MessageID != '') { |
|
| 1127 | + $result .= $this->HeaderLine('Message-ID', $this->MessageID); |
|
| 1129 | 1128 | } else { |
| 1130 | 1129 | $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); |
| 1131 | 1130 | } |
| 1132 | 1131 | $result .= $this->HeaderLine('X-Priority', $this->Priority); |
| 1133 | 1132 | $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (phpmailer.sourceforge.net)'); |
| 1134 | 1133 | |
| 1135 | - if($this->ConfirmReadingTo != '') { |
|
| 1136 | - $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>'); |
|
| 1134 | + if ($this->ConfirmReadingTo != '') { |
|
| 1135 | + $result .= $this->HeaderLine('Disposition-Notification-To', '<'.trim($this->ConfirmReadingTo).'>'); |
|
| 1137 | 1136 | } |
| 1138 | 1137 | |
| 1139 | 1138 | // Add custom headers |
| 1140 | - for($index = 0; $index < count($this->CustomHeader); $index++) { |
|
| 1139 | + for ($index = 0; $index < count($this->CustomHeader); $index++) { |
|
| 1141 | 1140 | $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1]))); |
| 1142 | 1141 | } |
| 1143 | 1142 | if (!$this->sign_key_file) { |
@@ -1155,27 +1154,27 @@ discard block |
||
| 1155 | 1154 | */ |
| 1156 | 1155 | public function GetMailMIME() { |
| 1157 | 1156 | $result = ''; |
| 1158 | - switch($this->message_type) { |
|
| 1157 | + switch ($this->message_type) { |
|
| 1159 | 1158 | case 'plain': |
| 1160 | 1159 | $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); |
| 1161 | 1160 | $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet); |
| 1162 | 1161 | break; |
| 1163 | 1162 | case 'attachments': |
| 1164 | 1163 | case 'alt_attachments': |
| 1165 | - if($this->InlineImageExists()){ |
|
| 1164 | + if ($this->InlineImageExists()) { |
|
| 1166 | 1165 | $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE); |
| 1167 | 1166 | } else { |
| 1168 | 1167 | $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;'); |
| 1169 | - $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|
| 1168 | + $result .= $this->TextLine("\tboundary=\"".$this->boundary[1].'"'); |
|
| 1170 | 1169 | } |
| 1171 | 1170 | break; |
| 1172 | 1171 | case 'alt': |
| 1173 | 1172 | $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); |
| 1174 | - $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|
| 1173 | + $result .= $this->TextLine("\tboundary=\"".$this->boundary[1].'"'); |
|
| 1175 | 1174 | break; |
| 1176 | 1175 | } |
| 1177 | 1176 | |
| 1178 | - if($this->Mailer != 'mail') { |
|
| 1177 | + if ($this->Mailer != 'mail') { |
|
| 1179 | 1178 | $result .= $this->LE.$this->LE; |
| 1180 | 1179 | } |
| 1181 | 1180 | |
@@ -1196,7 +1195,7 @@ discard block |
||
| 1196 | 1195 | |
| 1197 | 1196 | $this->SetWordWrap(); |
| 1198 | 1197 | |
| 1199 | - switch($this->message_type) { |
|
| 1198 | + switch ($this->message_type) { |
|
| 1200 | 1199 | case 'alt': |
| 1201 | 1200 | $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', ''); |
| 1202 | 1201 | $body .= $this->EncodeString($this->AltBody, $this->Encoding); |
@@ -1217,11 +1216,11 @@ discard block |
||
| 1217 | 1216 | break; |
| 1218 | 1217 | case 'alt_attachments': |
| 1219 | 1218 | $body .= sprintf("--%s%s", $this->boundary[1], $this->LE); |
| 1220 | - $body .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE); |
|
| 1221 | - $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body |
|
| 1219 | + $body .= sprintf("Content-Type: %s;%s"."\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE); |
|
| 1220 | + $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '').$this->LE; // Create text body |
|
| 1222 | 1221 | $body .= $this->EncodeString($this->AltBody, $this->Encoding); |
| 1223 | 1222 | $body .= $this->LE.$this->LE; |
| 1224 | - $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body |
|
| 1223 | + $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '').$this->LE; // Create the HTML body |
|
| 1225 | 1224 | $body .= $this->EncodeString($this->Body, $this->Encoding); |
| 1226 | 1225 | $body .= $this->LE.$this->LE; |
| 1227 | 1226 | $body .= $this->EndBoundary($this->boundary[2]); |
@@ -1229,7 +1228,7 @@ discard block |
||
| 1229 | 1228 | break; |
| 1230 | 1229 | } |
| 1231 | 1230 | |
| 1232 | - if($this->IsError()) { |
|
| 1231 | + if ($this->IsError()) { |
|
| 1233 | 1232 | $body = ''; |
| 1234 | 1233 | } else if ($this->sign_key_file) { |
| 1235 | 1234 | try { |
@@ -1262,16 +1261,16 @@ discard block |
||
| 1262 | 1261 | */ |
| 1263 | 1262 | private function GetBoundary($boundary, $charSet, $contentType, $encoding) { |
| 1264 | 1263 | $result = ''; |
| 1265 | - if($charSet == '') { |
|
| 1264 | + if ($charSet == '') { |
|
| 1266 | 1265 | $charSet = $this->CharSet; |
| 1267 | 1266 | } |
| 1268 | - if($contentType == '') { |
|
| 1267 | + if ($contentType == '') { |
|
| 1269 | 1268 | $contentType = $this->ContentType; |
| 1270 | 1269 | } |
| 1271 | - if($encoding == '') { |
|
| 1270 | + if ($encoding == '') { |
|
| 1272 | 1271 | $encoding = $this->Encoding; |
| 1273 | 1272 | } |
| 1274 | - $result .= $this->TextLine('--' . $boundary); |
|
| 1273 | + $result .= $this->TextLine('--'.$boundary); |
|
| 1275 | 1274 | $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet); |
| 1276 | 1275 | $result .= $this->LE; |
| 1277 | 1276 | $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding); |
@@ -1285,7 +1284,7 @@ discard block |
||
| 1285 | 1284 | * @access private |
| 1286 | 1285 | */ |
| 1287 | 1286 | private function EndBoundary($boundary) { |
| 1288 | - return $this->LE . '--' . $boundary . '--' . $this->LE; |
|
| 1287 | + return $this->LE.'--'.$boundary.'--'.$this->LE; |
|
| 1289 | 1288 | } |
| 1290 | 1289 | |
| 1291 | 1290 | /** |
@@ -1294,16 +1293,16 @@ discard block |
||
| 1294 | 1293 | * @return void |
| 1295 | 1294 | */ |
| 1296 | 1295 | private function SetMessageType() { |
| 1297 | - if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) { |
|
| 1296 | + if (count($this->attachment) < 1 && strlen($this->AltBody) < 1) { |
|
| 1298 | 1297 | $this->message_type = 'plain'; |
| 1299 | 1298 | } else { |
| 1300 | - if(count($this->attachment) > 0) { |
|
| 1299 | + if (count($this->attachment) > 0) { |
|
| 1301 | 1300 | $this->message_type = 'attachments'; |
| 1302 | 1301 | } |
| 1303 | - if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) { |
|
| 1302 | + if (strlen($this->AltBody) > 0 && count($this->attachment) < 1) { |
|
| 1304 | 1303 | $this->message_type = 'alt'; |
| 1305 | 1304 | } |
| 1306 | - if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) { |
|
| 1305 | + if (strlen($this->AltBody) > 0 && count($this->attachment) > 0) { |
|
| 1307 | 1306 | $this->message_type = 'alt_attachments'; |
| 1308 | 1307 | } |
| 1309 | 1308 | } |
@@ -1315,7 +1314,7 @@ discard block |
||
| 1315 | 1314 | * @return string |
| 1316 | 1315 | */ |
| 1317 | 1316 | public function HeaderLine($name, $value) { |
| 1318 | - return $name . ': ' . $value . $this->LE; |
|
| 1317 | + return $name.': '.$value.$this->LE; |
|
| 1319 | 1318 | } |
| 1320 | 1319 | |
| 1321 | 1320 | /** |
@@ -1324,7 +1323,7 @@ discard block |
||
| 1324 | 1323 | * @return string |
| 1325 | 1324 | */ |
| 1326 | 1325 | public function TextLine($value) { |
| 1327 | - return $value . $this->LE; |
|
| 1326 | + return $value.$this->LE; |
|
| 1328 | 1327 | } |
| 1329 | 1328 | |
| 1330 | 1329 | ///////////////////////////////////////////////// |
@@ -1343,11 +1342,11 @@ discard block |
||
| 1343 | 1342 | */ |
| 1344 | 1343 | public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { |
| 1345 | 1344 | try { |
| 1346 | - if(!@is_file($path)) { |
|
| 1347 | - throw new phpmailerException($this->Lang('file_access') . $path, self::STOP_CONTINUE); |
|
| 1345 | + if (!@is_file($path)) { |
|
| 1346 | + throw new phpmailerException($this->Lang('file_access').$path, self::STOP_CONTINUE); |
|
| 1348 | 1347 | } |
| 1349 | 1348 | $filename = basename($path); |
| 1350 | - if($name == '') { |
|
| 1349 | + if ($name == '') { |
|
| 1351 | 1350 | $name = $filename; |
| 1352 | 1351 | } |
| 1353 | 1352 | |
@@ -1357,7 +1356,7 @@ discard block |
||
| 1357 | 1356 | 2 => $name, |
| 1358 | 1357 | 3 => $encoding, |
| 1359 | 1358 | 4 => $type, |
| 1360 | - 5 => false, // isStringAttachment |
|
| 1359 | + 5 => false, // isStringAttachment |
|
| 1361 | 1360 | 6 => 'attachment', |
| 1362 | 1361 | 7 => 0 |
| 1363 | 1362 | ); |
@@ -1368,7 +1367,7 @@ discard block |
||
| 1368 | 1367 | throw $e; |
| 1369 | 1368 | } |
| 1370 | 1369 | echo $e->getMessage()."\n"; |
| 1371 | - if ( $e->getCode() == self::STOP_CRITICAL ) { |
|
| 1370 | + if ($e->getCode() == self::STOP_CRITICAL) { |
|
| 1372 | 1371 | return false; |
| 1373 | 1372 | } |
| 1374 | 1373 | } |
@@ -1413,29 +1412,29 @@ discard block |
||
| 1413 | 1412 | $disposition = $attachment[6]; |
| 1414 | 1413 | $cid = $attachment[7]; |
| 1415 | 1414 | $incl[] = $attachment[0]; |
| 1416 | - if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; } |
|
| 1415 | + if ($disposition == 'inline' && isset($cidUniq[$cid])) { continue; } |
|
| 1417 | 1416 | $cidUniq[$cid] = true; |
| 1418 | 1417 | |
| 1419 | 1418 | $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE); |
| 1420 | 1419 | $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE); |
| 1421 | 1420 | $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE); |
| 1422 | 1421 | |
| 1423 | - if($disposition == 'inline') { |
|
| 1422 | + if ($disposition == 'inline') { |
|
| 1424 | 1423 | $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE); |
| 1425 | 1424 | } |
| 1426 | 1425 | |
| 1427 | 1426 | $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE); |
| 1428 | 1427 | |
| 1429 | 1428 | // Encode as string attachment |
| 1430 | - if($bString) { |
|
| 1429 | + if ($bString) { |
|
| 1431 | 1430 | $mime[] = $this->EncodeString($string, $encoding); |
| 1432 | - if($this->IsError()) { |
|
| 1431 | + if ($this->IsError()) { |
|
| 1433 | 1432 | return ''; |
| 1434 | 1433 | } |
| 1435 | 1434 | $mime[] = $this->LE.$this->LE; |
| 1436 | 1435 | } else { |
| 1437 | 1436 | $mime[] = $this->EncodeFile($path, $encoding); |
| 1438 | - if($this->IsError()) { |
|
| 1437 | + if ($this->IsError()) { |
|
| 1439 | 1438 | return ''; |
| 1440 | 1439 | } |
| 1441 | 1440 | $mime[] = $this->LE.$this->LE; |
@@ -1459,7 +1458,7 @@ discard block |
||
| 1459 | 1458 | private function EncodeFile($path, $encoding = 'base64') { |
| 1460 | 1459 | try { |
| 1461 | 1460 | if (!is_readable($path)) { |
| 1462 | - throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE); |
|
| 1461 | + throw new phpmailerException($this->Lang('file_open').$path, self::STOP_CONTINUE); |
|
| 1463 | 1462 | } |
| 1464 | 1463 | if (function_exists('get_magic_quotes')) { |
| 1465 | 1464 | function get_magic_quotes() { |
@@ -1488,9 +1487,9 @@ discard block |
||
| 1488 | 1487 | * @access public |
| 1489 | 1488 | * @return string |
| 1490 | 1489 | */ |
| 1491 | - public function EncodeString ($str, $encoding = 'base64') { |
|
| 1490 | + public function EncodeString($str, $encoding = 'base64') { |
|
| 1492 | 1491 | $encoded = ''; |
| 1493 | - switch(strtolower($encoding)) { |
|
| 1492 | + switch (strtolower($encoding)) { |
|
| 1494 | 1493 | case 'base64': |
| 1495 | 1494 | $encoded = chunk_split(base64_encode($str), 76, $this->LE); |
| 1496 | 1495 | break; |
@@ -1508,7 +1507,7 @@ discard block |
||
| 1508 | 1507 | $encoded = $this->EncodeQP($str); |
| 1509 | 1508 | break; |
| 1510 | 1509 | default: |
| 1511 | - $this->SetError($this->Lang('encoding') . $encoding); |
|
| 1510 | + $this->SetError($this->Lang('encoding').$encoding); |
|
| 1512 | 1511 | break; |
| 1513 | 1512 | } |
| 1514 | 1513 | return $encoded; |
@@ -1519,7 +1518,7 @@ discard block |
||
| 1519 | 1518 | * @access public |
| 1520 | 1519 | * @return string |
| 1521 | 1520 | */ |
| 1522 | - public function EncodeHeader ($str, $position = 'text') { |
|
| 1521 | + public function EncodeHeader($str, $position = 'text') { |
|
| 1523 | 1522 | $x = 0; |
| 1524 | 1523 | |
| 1525 | 1524 | switch (strtolower($position)) { |
@@ -1550,7 +1549,7 @@ discard block |
||
| 1550 | 1549 | |
| 1551 | 1550 | $maxlen = 75 - 7 - strlen($this->CharSet); |
| 1552 | 1551 | // Try to select the encoding which should produce the shortest output |
| 1553 | - if (strlen($str)/3 < $x) { |
|
| 1552 | + if (strlen($str) / 3 < $x) { |
|
| 1554 | 1553 | $encoding = 'B'; |
| 1555 | 1554 | if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) { |
| 1556 | 1555 | // Use a custom function which correctly encodes and wraps long |
@@ -1620,7 +1619,7 @@ discard block |
||
| 1620 | 1619 | } |
| 1621 | 1620 | while (strlen($chunk) > $length); |
| 1622 | 1621 | |
| 1623 | - $encoded .= $chunk . $this->LE; |
|
| 1622 | + $encoded .= $chunk.$this->LE; |
|
| 1624 | 1623 | } |
| 1625 | 1624 | |
| 1626 | 1625 | // Chomp the last linefeed |
@@ -1636,37 +1635,37 @@ discard block |
||
| 1636 | 1635 | * @param integer $line_max Number of chars allowed on a line before wrapping |
| 1637 | 1636 | * @return string |
| 1638 | 1637 | */ |
| 1639 | - public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) { |
|
| 1640 | - $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
|
| 1638 | + public function EncodeQPphp($input = '', $line_max = 76, $space_conv = false) { |
|
| 1639 | + $hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
|
| 1641 | 1640 | $lines = preg_split('/(?:\r\n|\r|\n)/', $input); |
| 1642 | 1641 | $eol = "\r\n"; |
| 1643 | 1642 | $escape = '='; |
| 1644 | 1643 | $output = ''; |
| 1645 | - while( list(, $line) = each($lines) ) { |
|
| 1644 | + while (list(, $line) = each($lines)) { |
|
| 1646 | 1645 | $linlen = strlen($line); |
| 1647 | 1646 | $newline = ''; |
| 1648 | - for($i = 0; $i < $linlen; $i++) { |
|
| 1649 | - $c = substr( $line, $i, 1 ); |
|
| 1650 | - $dec = ord( $c ); |
|
| 1651 | - if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E |
|
| 1647 | + for ($i = 0; $i < $linlen; $i++) { |
|
| 1648 | + $c = substr($line, $i, 1); |
|
| 1649 | + $dec = ord($c); |
|
| 1650 | + if (($i == 0) && ($dec == 46)) { // convert first point in the line into =2E |
|
| 1652 | 1651 | $c = '=2E'; |
| 1653 | 1652 | } |
| 1654 | - if ( $dec == 32 ) { |
|
| 1655 | - if ( $i == ( $linlen - 1 ) ) { // convert space at eol only |
|
| 1653 | + if ($dec == 32) { |
|
| 1654 | + if ($i == ($linlen - 1)) { // convert space at eol only |
|
| 1656 | 1655 | $c = '=20'; |
| 1657 | - } else if ( $space_conv ) { |
|
| 1656 | + } else if ($space_conv) { |
|
| 1658 | 1657 | $c = '=20'; |
| 1659 | 1658 | } |
| 1660 | - } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required |
|
| 1661 | - $h2 = floor($dec/16); |
|
| 1662 | - $h1 = floor($dec%16); |
|
| 1659 | + } elseif (($dec == 61) || ($dec < 32) || ($dec > 126)) { // always encode "\t", which is *not* required |
|
| 1660 | + $h2 = floor($dec / 16); |
|
| 1661 | + $h1 = floor($dec % 16); |
|
| 1663 | 1662 | $c = $escape.$hex[$h2].$hex[$h1]; |
| 1664 | 1663 | } |
| 1665 | - if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted |
|
| 1664 | + if ((strlen($newline) + strlen($c)) >= $line_max) { // CRLF is not counted |
|
| 1666 | 1665 | $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay |
| 1667 | 1666 | $newline = ''; |
| 1668 | 1667 | // check if newline first character will be point or not |
| 1669 | - if ( $dec == 46 ) { |
|
| 1668 | + if ($dec == 46) { |
|
| 1670 | 1669 | $c = '=2E'; |
| 1671 | 1670 | } |
| 1672 | 1671 | } |
@@ -1718,7 +1717,7 @@ discard block |
||
| 1718 | 1717 | * @access public |
| 1719 | 1718 | * @return string |
| 1720 | 1719 | */ |
| 1721 | - public function EncodeQ ($str, $position = 'text') { |
|
| 1720 | + public function EncodeQ($str, $position = 'text') { |
|
| 1722 | 1721 | // There should not be any EOL in the string |
| 1723 | 1722 | $encoded = preg_replace('/[\r\n]*/', '', $str); |
| 1724 | 1723 | |
@@ -1761,7 +1760,7 @@ discard block |
||
| 1761 | 1760 | 2 => basename($filename), |
| 1762 | 1761 | 3 => $encoding, |
| 1763 | 1762 | 4 => $type, |
| 1764 | - 5 => true, // isStringAttachment |
|
| 1763 | + 5 => true, // isStringAttachment |
|
| 1765 | 1764 | 6 => 'attachment', |
| 1766 | 1765 | 7 => 0 |
| 1767 | 1766 | ); |
@@ -1782,13 +1781,13 @@ discard block |
||
| 1782 | 1781 | */ |
| 1783 | 1782 | public function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { |
| 1784 | 1783 | |
| 1785 | - if(!@is_file($path)) { |
|
| 1786 | - $this->SetError($this->Lang('file_access') . $path); |
|
| 1784 | + if (!@is_file($path)) { |
|
| 1785 | + $this->SetError($this->Lang('file_access').$path); |
|
| 1787 | 1786 | return false; |
| 1788 | 1787 | } |
| 1789 | 1788 | |
| 1790 | 1789 | $filename = basename($path); |
| 1791 | - if($name == '') { |
|
| 1790 | + if ($name == '') { |
|
| 1792 | 1791 | $name = $filename; |
| 1793 | 1792 | } |
| 1794 | 1793 | |
@@ -1799,7 +1798,7 @@ discard block |
||
| 1799 | 1798 | 2 => $name, |
| 1800 | 1799 | 3 => $encoding, |
| 1801 | 1800 | 4 => $type, |
| 1802 | - 5 => false, // isStringAttachment |
|
| 1801 | + 5 => false, // isStringAttachment |
|
| 1803 | 1802 | 6 => 'inline', |
| 1804 | 1803 | 7 => $cid |
| 1805 | 1804 | ); |
@@ -1813,7 +1812,7 @@ discard block |
||
| 1813 | 1812 | * @return bool |
| 1814 | 1813 | */ |
| 1815 | 1814 | public function InlineImageExists() { |
| 1816 | - foreach($this->attachment as $attachment) { |
|
| 1815 | + foreach ($this->attachment as $attachment) { |
|
| 1817 | 1816 | if ($attachment[6] == 'inline') { |
| 1818 | 1817 | return true; |
| 1819 | 1818 | } |
@@ -1830,7 +1829,7 @@ discard block |
||
| 1830 | 1829 | * @return void |
| 1831 | 1830 | */ |
| 1832 | 1831 | public function ClearAddresses() { |
| 1833 | - foreach($this->to as $to) { |
|
| 1832 | + foreach ($this->to as $to) { |
|
| 1834 | 1833 | unset($this->all_recipients[strtolower($to[0])]); |
| 1835 | 1834 | } |
| 1836 | 1835 | $this->to = array(); |
@@ -1841,7 +1840,7 @@ discard block |
||
| 1841 | 1840 | * @return void |
| 1842 | 1841 | */ |
| 1843 | 1842 | public function ClearCCs() { |
| 1844 | - foreach($this->cc as $cc) { |
|
| 1843 | + foreach ($this->cc as $cc) { |
|
| 1845 | 1844 | unset($this->all_recipients[strtolower($cc[0])]); |
| 1846 | 1845 | } |
| 1847 | 1846 | $this->cc = array(); |
@@ -1852,7 +1851,7 @@ discard block |
||
| 1852 | 1851 | * @return void |
| 1853 | 1852 | */ |
| 1854 | 1853 | public function ClearBCCs() { |
| 1855 | - foreach($this->bcc as $bcc) { |
|
| 1854 | + foreach ($this->bcc as $bcc) { |
|
| 1856 | 1855 | unset($this->all_recipients[strtolower($bcc[0])]); |
| 1857 | 1856 | } |
| 1858 | 1857 | $this->bcc = array(); |
@@ -1909,7 +1908,7 @@ discard block |
||
| 1909 | 1908 | if ($this->Mailer == 'smtp' and !is_null($this->smtp)) { |
| 1910 | 1909 | $lasterror = $this->smtp->getError(); |
| 1911 | 1910 | if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) { |
| 1912 | - $msg .= '<p>' . $this->Lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n"; |
|
| 1911 | + $msg .= '<p>'.$this->Lang('smtp_error').$lasterror['smtp_msg']."</p>\n"; |
|
| 1913 | 1912 | } |
| 1914 | 1913 | } |
| 1915 | 1914 | $this->ErrorInfo = $msg; |
@@ -1925,7 +1924,7 @@ discard block |
||
| 1925 | 1924 | $tz = date('Z'); |
| 1926 | 1925 | $tzs = ($tz < 0) ? '-' : '+'; |
| 1927 | 1926 | $tz = abs($tz); |
| 1928 | - $tz = (int)($tz/3600)*100 + ($tz%3600)/60; |
|
| 1927 | + $tz = (int) ($tz / 3600) * 100 + ($tz % 3600) / 60; |
|
| 1929 | 1928 | $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz); |
| 1930 | 1929 | |
| 1931 | 1930 | return $result; |
@@ -1954,14 +1953,14 @@ discard block |
||
| 1954 | 1953 | * @return string |
| 1955 | 1954 | */ |
| 1956 | 1955 | private function Lang($key) { |
| 1957 | - if(count($this->language) < 1) { |
|
| 1956 | + if (count($this->language) < 1) { |
|
| 1958 | 1957 | $this->SetLanguage('en'); // set the default language |
| 1959 | 1958 | } |
| 1960 | 1959 | |
| 1961 | - if(isset($this->language[$key])) { |
|
| 1960 | + if (isset($this->language[$key])) { |
|
| 1962 | 1961 | return $this->language[$key]; |
| 1963 | 1962 | } else { |
| 1964 | - return 'Language string failed to load: ' . $key; |
|
| 1963 | + return 'Language string failed to load: '.$key; |
|
| 1965 | 1964 | } |
| 1966 | 1965 | } |
| 1967 | 1966 | |
@@ -2000,21 +1999,21 @@ discard block |
||
| 2000 | 1999 | * @access public |
| 2001 | 2000 | * @return $message |
| 2002 | 2001 | */ |
| 2003 | - public function MsgHTML($message,$basedir='') { |
|
| 2002 | + public function MsgHTML($message, $basedir = '') { |
|
| 2004 | 2003 | preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images); |
| 2005 | - if(isset($images[2])) { |
|
| 2006 | - foreach($images[2] as $i => $url) { |
|
| 2004 | + if (isset($images[2])) { |
|
| 2005 | + foreach ($images[2] as $i => $url) { |
|
| 2007 | 2006 | // do not change urls for absolute images (thanks to corvuscorax) |
| 2008 | - if (!preg_match('#^[A-z]+://#',$url)) { |
|
| 2007 | + if (!preg_match('#^[A-z]+://#', $url)) { |
|
| 2009 | 2008 | $filename = basename($url); |
| 2010 | 2009 | $directory = dirname($url); |
| 2011 | - ($directory == '.')?$directory='':''; |
|
| 2012 | - $cid = 'cid:' . md5($filename); |
|
| 2010 | + ($directory == '.') ? $directory = '' : ''; |
|
| 2011 | + $cid = 'cid:'.md5($filename); |
|
| 2013 | 2012 | $ext = pathinfo($filename, PATHINFO_EXTENSION); |
| 2014 | - $mimeType = self::_mime_types($ext); |
|
| 2015 | - if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; } |
|
| 2016 | - if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; } |
|
| 2017 | - if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) { |
|
| 2013 | + $mimeType = self::_mime_types($ext); |
|
| 2014 | + if (strlen($basedir) > 1 && substr($basedir, -1) != '/') { $basedir .= '/'; } |
|
| 2015 | + if (strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; } |
|
| 2016 | + if ($this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType)) { |
|
| 2018 | 2017 | $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message); |
| 2019 | 2018 | } |
| 2020 | 2019 | } |
@@ -2022,12 +2021,12 @@ discard block |
||
| 2022 | 2021 | } |
| 2023 | 2022 | $this->IsHTML(true); |
| 2024 | 2023 | $this->Body = $message; |
| 2025 | - $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message))); |
|
| 2026 | - if ( !empty($textMsg) && empty($this->AltBody) ) { |
|
| 2024 | + $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message))); |
|
| 2025 | + if (!empty($textMsg) && empty($this->AltBody)) { |
|
| 2027 | 2026 | $this->AltBody = html_entity_decode($textMsg); |
| 2028 | 2027 | } |
| 2029 | - if ( empty($this->AltBody) ) { |
|
| 2030 | - $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n"; |
|
| 2028 | + if (empty($this->AltBody)) { |
|
| 2029 | + $this->AltBody = 'To view this email message, open it in a program that understands HTML!'."\n\n"; |
|
| 2031 | 2030 | } |
| 2032 | 2031 | } |
| 2033 | 2032 | |
@@ -2128,7 +2127,7 @@ discard block |
||
| 2128 | 2127 | 'xl' => 'application/excel', |
| 2129 | 2128 | 'eml' => 'message/rfc822' |
| 2130 | 2129 | ); |
| 2131 | - return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; |
|
| 2130 | + return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; |
|
| 2132 | 2131 | } |
| 2133 | 2132 | |
| 2134 | 2133 | /** |
@@ -2143,12 +2142,12 @@ discard block |
||
| 2143 | 2142 | * NOTE: will not work with arrays, there are no arrays to set/reset |
| 2144 | 2143 | * @todo Should this not be using __set() magic function? |
| 2145 | 2144 | */ |
| 2146 | - public function set ( $name, $value = '' ) { |
|
| 2145 | + public function set($name, $value = '') { |
|
| 2147 | 2146 | try { |
| 2148 | - if ( isset($this->$name) ) { |
|
| 2147 | + if (isset($this->$name)) { |
|
| 2149 | 2148 | $this->$name = $value; |
| 2150 | 2149 | } else { |
| 2151 | - throw new phpmailerException($this->Lang('variable_set') . $name, self::STOP_CRITICAL); |
|
| 2150 | + throw new phpmailerException($this->Lang('variable_set').$name, self::STOP_CRITICAL); |
|
| 2152 | 2151 | } |
| 2153 | 2152 | } catch (Exception $e) { |
| 2154 | 2153 | $this->SetError($e->getMessage()); |
@@ -2192,14 +2191,14 @@ discard block |
||
| 2192 | 2191 | * @param string $key_pass Password for private key |
| 2193 | 2192 | */ |
| 2194 | 2193 | public function DKIM_QP($txt) { |
| 2195 | - $tmp=""; |
|
| 2196 | - $line=""; |
|
| 2197 | - for ($i=0;$i<strlen($txt);$i++) { |
|
| 2198 | - $ord=ord($txt[$i]); |
|
| 2199 | - if ( ((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)) ) { |
|
| 2200 | - $line.=$txt[$i]; |
|
| 2194 | + $tmp = ""; |
|
| 2195 | + $line = ""; |
|
| 2196 | + for ($i = 0; $i < strlen($txt); $i++) { |
|
| 2197 | + $ord = ord($txt[$i]); |
|
| 2198 | + if (((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E))) { |
|
| 2199 | + $line .= $txt[$i]; |
|
| 2201 | 2200 | } else { |
| 2202 | - $line.="=".sprintf("%02X",$ord); |
|
| 2201 | + $line .= "=".sprintf("%02X", $ord); |
|
| 2203 | 2202 | } |
| 2204 | 2203 | } |
| 2205 | 2204 | return $line; |
@@ -2213,8 +2212,8 @@ discard block |
||
| 2213 | 2212 | */ |
| 2214 | 2213 | public function DKIM_Sign($s) { |
| 2215 | 2214 | $privKeyStr = file_get_contents($this->DKIM_private); |
| 2216 | - if ($this->DKIM_passphrase!='') { |
|
| 2217 | - $privKey = openssl_pkey_get_private($privKeyStr,$this->DKIM_passphrase); |
|
| 2215 | + if ($this->DKIM_passphrase != '') { |
|
| 2216 | + $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase); |
|
| 2218 | 2217 | } else { |
| 2219 | 2218 | $privKey = $privKeyStr; |
| 2220 | 2219 | } |
@@ -2230,15 +2229,15 @@ discard block |
||
| 2230 | 2229 | * @param string $s Header |
| 2231 | 2230 | */ |
| 2232 | 2231 | public function DKIM_HeaderC($s) { |
| 2233 | - $s=preg_replace("/\r\n\s+/"," ",$s); |
|
| 2234 | - $lines=explode("\r\n",$s); |
|
| 2232 | + $s = preg_replace("/\r\n\s+/", " ", $s); |
|
| 2233 | + $lines = explode("\r\n", $s); |
|
| 2235 | 2234 | foreach ($lines as $key=>$line) { |
| 2236 | - list($heading,$value)=explode(":",$line,2); |
|
| 2237 | - $heading=strtolower($heading); |
|
| 2238 | - $value=preg_replace("/\s+/"," ",$value) ; // Compress useless spaces |
|
| 2239 | - $lines[$key]=$heading.":".trim($value) ; // Don't forget to remove WSP around the value |
|
| 2235 | + list($heading, $value) = explode(":", $line, 2); |
|
| 2236 | + $heading = strtolower($heading); |
|
| 2237 | + $value = preg_replace("/\s+/", " ", $value); // Compress useless spaces |
|
| 2238 | + $lines[$key] = $heading.":".trim($value); // Don't forget to remove WSP around the value |
|
| 2240 | 2239 | } |
| 2241 | - $s=implode("\r\n",$lines); |
|
| 2240 | + $s = implode("\r\n", $lines); |
|
| 2242 | 2241 | return $s; |
| 2243 | 2242 | } |
| 2244 | 2243 | |
@@ -2251,11 +2250,11 @@ discard block |
||
| 2251 | 2250 | public function DKIM_BodyC($body) { |
| 2252 | 2251 | if ($body == '') return "\r\n"; |
| 2253 | 2252 | // stabilize line endings |
| 2254 | - $body=str_replace("\r\n","\n",$body); |
|
| 2255 | - $body=str_replace("\n","\r\n",$body); |
|
| 2253 | + $body = str_replace("\r\n", "\n", $body); |
|
| 2254 | + $body = str_replace("\n", "\r\n", $body); |
|
| 2256 | 2255 | // END stabilize line endings |
| 2257 | - while (substr($body,strlen($body)-4,4) == "\r\n\r\n") { |
|
| 2258 | - $body=substr($body,0,strlen($body)-2); |
|
| 2256 | + while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") { |
|
| 2257 | + $body = substr($body, 0, strlen($body) - 2); |
|
| 2259 | 2258 | } |
| 2260 | 2259 | return $body; |
| 2261 | 2260 | } |
@@ -2268,52 +2267,52 @@ discard block |
||
| 2268 | 2267 | * @param string $subject Subject |
| 2269 | 2268 | * @param string $body Body |
| 2270 | 2269 | */ |
| 2271 | - public function DKIM_Add($headers_line,$subject,$body) { |
|
| 2270 | + public function DKIM_Add($headers_line, $subject, $body) { |
|
| 2272 | 2271 | $DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms |
| 2273 | 2272 | $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body |
| 2274 | 2273 | $DKIMquery = 'dns/txt'; // Query method |
| 2275 | - $DKIMtime = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone) |
|
| 2274 | + $DKIMtime = time(); // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone) |
|
| 2276 | 2275 | $subject_header = "Subject: $subject"; |
| 2277 | - $headers = explode("\r\n",$headers_line); |
|
| 2278 | - foreach($headers as $header) { |
|
| 2279 | - if (strpos($header,'From:') === 0) { |
|
| 2280 | - $from_header=$header; |
|
| 2281 | - } elseif (strpos($header,'To:') === 0) { |
|
| 2282 | - $to_header=$header; |
|
| 2276 | + $headers = explode("\r\n", $headers_line); |
|
| 2277 | + foreach ($headers as $header) { |
|
| 2278 | + if (strpos($header, 'From:') === 0) { |
|
| 2279 | + $from_header = $header; |
|
| 2280 | + } elseif (strpos($header, 'To:') === 0) { |
|
| 2281 | + $to_header = $header; |
|
| 2283 | 2282 | } |
| 2284 | 2283 | } |
| 2285 | - $from = str_replace('|','=7C',$this->DKIM_QP($from_header)); |
|
| 2286 | - $to = str_replace('|','=7C',$this->DKIM_QP($to_header)); |
|
| 2287 | - $subject = str_replace('|','=7C',$this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable |
|
| 2284 | + $from = str_replace('|', '=7C', $this->DKIM_QP($from_header)); |
|
| 2285 | + $to = str_replace('|', '=7C', $this->DKIM_QP($to_header)); |
|
| 2286 | + $subject = str_replace('|', '=7C', $this->DKIM_QP($subject_header)); // Copied header fields (dkim-quoted-printable |
|
| 2288 | 2287 | $body = $this->DKIM_BodyC($body); |
| 2289 | - $DKIMlen = strlen($body) ; // Length of body |
|
| 2290 | - $DKIMb64 = base64_encode(pack("H*", sha1($body))) ; // Base64 of packed binary SHA-1 hash of body |
|
| 2291 | - $ident = ($this->DKIM_identity == '')? '' : " i=" . $this->DKIM_identity . ";"; |
|
| 2292 | - $dkimhdrs = "DKIM-Signature: v=1; a=" . $DKIMsignatureType . "; q=" . $DKIMquery . "; l=" . $DKIMlen . "; s=" . $this->DKIM_selector . ";\r\n". |
|
| 2293 | - "\tt=" . $DKIMtime . "; c=" . $DKIMcanonicalization . ";\r\n". |
|
| 2288 | + $DKIMlen = strlen($body); // Length of body |
|
| 2289 | + $DKIMb64 = base64_encode(pack("H*", sha1($body))); // Base64 of packed binary SHA-1 hash of body |
|
| 2290 | + $ident = ($this->DKIM_identity == '') ? '' : " i=".$this->DKIM_identity.";"; |
|
| 2291 | + $dkimhdrs = "DKIM-Signature: v=1; a=".$DKIMsignatureType."; q=".$DKIMquery."; l=".$DKIMlen."; s=".$this->DKIM_selector.";\r\n". |
|
| 2292 | + "\tt=".$DKIMtime."; c=".$DKIMcanonicalization.";\r\n". |
|
| 2294 | 2293 | "\th=From:To:Subject;\r\n". |
| 2295 | - "\td=" . $this->DKIM_domain . ";" . $ident . "\r\n". |
|
| 2294 | + "\td=".$this->DKIM_domain.";".$ident."\r\n". |
|
| 2296 | 2295 | "\tz=$from\r\n". |
| 2297 | 2296 | "\t|$to\r\n". |
| 2298 | 2297 | "\t|$subject;\r\n". |
| 2299 | - "\tbh=" . $DKIMb64 . ";\r\n". |
|
| 2298 | + "\tbh=".$DKIMb64.";\r\n". |
|
| 2300 | 2299 | "\tb="; |
| 2301 | - $toSign = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs); |
|
| 2300 | + $toSign = $this->DKIM_HeaderC($from_header."\r\n".$to_header."\r\n".$subject_header."\r\n".$dkimhdrs); |
|
| 2302 | 2301 | $signed = $this->DKIM_Sign($toSign); |
| 2303 | 2302 | return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n"; |
| 2304 | 2303 | } |
| 2305 | 2304 | |
| 2306 | - protected function doCallback($isSent,$to,$cc,$bcc,$subject,$body) { |
|
| 2305 | + protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body) { |
|
| 2307 | 2306 | if (!empty($this->action_function) && function_exists($this->action_function)) { |
| 2308 | - $params = array($isSent,$to,$cc,$bcc,$subject,$body); |
|
| 2309 | - call_user_func_array($this->action_function,$params); |
|
| 2307 | + $params = array($isSent, $to, $cc, $bcc, $subject, $body); |
|
| 2308 | + call_user_func_array($this->action_function, $params); |
|
| 2310 | 2309 | } |
| 2311 | 2310 | } |
| 2312 | 2311 | } |
| 2313 | 2312 | |
| 2314 | 2313 | class phpmailerException extends Exception { |
| 2315 | 2314 | public function errorMessage() { |
| 2316 | - $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n"; |
|
| 2315 | + $errorMsg = '<strong>'.$this->getMessage()."</strong><br />\n"; |
|
| 2317 | 2316 | return $errorMsg; |
| 2318 | 2317 | } |
| 2319 | 2318 | } |
@@ -107,6 +107,7 @@ discard block |
||
| 107 | 107 | * SMTP CODE SUCCESS: 220 |
| 108 | 108 | * SMTP CODE FAILURE: 421 |
| 109 | 109 | * @access public |
| 110 | + * @param string $host |
|
| 110 | 111 | * @return bool |
| 111 | 112 | */ |
| 112 | 113 | public function Connect($host,$port=0,$tval=30) { |
@@ -205,6 +206,8 @@ discard block |
||
| 205 | 206 | * Performs SMTP authentication. Must be run after running the |
| 206 | 207 | * Hello() method. Returns true if successfully authenticated. |
| 207 | 208 | * @access public |
| 209 | + * @param string $username |
|
| 210 | + * @param string $password |
|
| 208 | 211 | * @return bool |
| 209 | 212 | */ |
| 210 | 213 | public function Authenticate($username, $password) { |
@@ -321,6 +324,7 @@ discard block |
||
| 321 | 324 | * SMTP CODE FAILURE: 451,554 |
| 322 | 325 | * SMTP CODE ERROR : 500,501,503,421 |
| 323 | 326 | * @access public |
| 327 | + * @param string $msg_data |
|
| 324 | 328 | * @return bool |
| 325 | 329 | */ |
| 326 | 330 | public function Data($msg_data) { |
@@ -489,6 +493,8 @@ discard block |
||
| 489 | 493 | /** |
| 490 | 494 | * Sends a HELO/EHLO command. |
| 491 | 495 | * @access private |
| 496 | + * @param string $hello |
|
| 497 | + * @param string $host |
|
| 492 | 498 | * @return bool |
| 493 | 499 | */ |
| 494 | 500 | private function SendHello($hello, $host) { |
@@ -529,6 +535,7 @@ discard block |
||
| 529 | 535 | * SMTP CODE SUCCESS: 552,451,452 |
| 530 | 536 | * SMTP CODE SUCCESS: 500,501,421 |
| 531 | 537 | * @access public |
| 538 | + * @param string $from |
|
| 532 | 539 | * @return bool |
| 533 | 540 | */ |
| 534 | 541 | public function Mail($from) { |
@@ -85,11 +85,11 @@ discard block |
||
| 85 | 85 | * @return void |
| 86 | 86 | */ |
| 87 | 87 | public function __construct() { |
| 88 | - $this->smtp_conn = 0; |
|
| 89 | - $this->error = null; |
|
| 90 | - $this->helo_rply = null; |
|
| 88 | + $this->smtp_conn = 0; |
|
| 89 | + $this->error = null; |
|
| 90 | + $this->helo_rply = null; |
|
| 91 | 91 | |
| 92 | - $this->do_debug = 0; |
|
| 92 | + $this->do_debug = 0; |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | ///////////////////////////////////////////////// |
@@ -110,50 +110,50 @@ discard block |
||
| 110 | 110 | * @return bool |
| 111 | 111 | */ |
| 112 | 112 | public function Connect($host,$port=0,$tval=30) { |
| 113 | - // set the error val to null so there is no confusion |
|
| 114 | - $this->error = null; |
|
| 115 | - |
|
| 116 | - // make sure we are __not__ connected |
|
| 117 | - if($this->connected()) { |
|
| 118 | - // already connected, generate error |
|
| 119 | - $this->error = array("error" => "Already connected to a server"); |
|
| 120 | - return false; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - if(empty($port)) { |
|
| 124 | - $port = $this->SMTP_PORT; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - // connect to the smtp server |
|
| 128 | - $this->smtp_conn = @fsockopen($host, // the host of the server |
|
| 129 | - $port, // the port to use |
|
| 130 | - $errno, // error number if any |
|
| 131 | - $errstr, // error message if any |
|
| 132 | - $tval); // give up after ? secs |
|
| 133 | - // verify we connected properly |
|
| 134 | - if(empty($this->smtp_conn)) { |
|
| 135 | - $this->error = array("error" => "Failed to connect to server", |
|
| 136 | - "errno" => $errno, |
|
| 137 | - "errstr" => $errstr); |
|
| 138 | - if($this->do_debug >= 1) { |
|
| 139 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />'; |
|
| 140 | - } |
|
| 141 | - return false; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - // SMTP server can take longer to respond, give longer timeout for first read |
|
| 145 | - // Windows does not have support for this timeout function |
|
| 146 | - if(substr(PHP_OS, 0, 3) != "WIN") |
|
| 147 | - socket_set_timeout($this->smtp_conn, $tval, 0); |
|
| 148 | - |
|
| 149 | - // get any announcement |
|
| 150 | - $announce = $this->get_lines(); |
|
| 151 | - |
|
| 152 | - if($this->do_debug >= 2) { |
|
| 153 | - echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />'; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - return true; |
|
| 113 | + // set the error val to null so there is no confusion |
|
| 114 | + $this->error = null; |
|
| 115 | + |
|
| 116 | + // make sure we are __not__ connected |
|
| 117 | + if($this->connected()) { |
|
| 118 | + // already connected, generate error |
|
| 119 | + $this->error = array("error" => "Already connected to a server"); |
|
| 120 | + return false; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + if(empty($port)) { |
|
| 124 | + $port = $this->SMTP_PORT; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // connect to the smtp server |
|
| 128 | + $this->smtp_conn = @fsockopen($host, // the host of the server |
|
| 129 | + $port, // the port to use |
|
| 130 | + $errno, // error number if any |
|
| 131 | + $errstr, // error message if any |
|
| 132 | + $tval); // give up after ? secs |
|
| 133 | + // verify we connected properly |
|
| 134 | + if(empty($this->smtp_conn)) { |
|
| 135 | + $this->error = array("error" => "Failed to connect to server", |
|
| 136 | + "errno" => $errno, |
|
| 137 | + "errstr" => $errstr); |
|
| 138 | + if($this->do_debug >= 1) { |
|
| 139 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />'; |
|
| 140 | + } |
|
| 141 | + return false; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + // SMTP server can take longer to respond, give longer timeout for first read |
|
| 145 | + // Windows does not have support for this timeout function |
|
| 146 | + if(substr(PHP_OS, 0, 3) != "WIN") |
|
| 147 | + socket_set_timeout($this->smtp_conn, $tval, 0); |
|
| 148 | + |
|
| 149 | + // get any announcement |
|
| 150 | + $announce = $this->get_lines(); |
|
| 151 | + |
|
| 152 | + if($this->do_debug >= 2) { |
|
| 153 | + echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />'; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + return true; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -166,39 +166,39 @@ discard block |
||
| 166 | 166 | * @return bool success |
| 167 | 167 | */ |
| 168 | 168 | public function StartTLS() { |
| 169 | - $this->error = null; # to avoid confusion |
|
| 170 | - |
|
| 171 | - if(!$this->connected()) { |
|
| 172 | - $this->error = array("error" => "Called StartTLS() without being connected"); |
|
| 173 | - return false; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - fputs($this->smtp_conn,"STARTTLS" . $this->CRLF); |
|
| 177 | - |
|
| 178 | - $rply = $this->get_lines(); |
|
| 179 | - $code = substr($rply,0,3); |
|
| 180 | - |
|
| 181 | - if($this->do_debug >= 2) { |
|
| 182 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - if($code != 220) { |
|
| 186 | - $this->error = |
|
| 187 | - array("error" => "STARTTLS not accepted from server", |
|
| 188 | - "smtp_code" => $code, |
|
| 189 | - "smtp_msg" => substr($rply,4)); |
|
| 190 | - if($this->do_debug >= 1) { |
|
| 191 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 192 | - } |
|
| 193 | - return false; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - //Begin encrypted connection |
|
| 197 | - if(!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { |
|
| 198 | - return false; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - return true; |
|
| 169 | + $this->error = null; # to avoid confusion |
|
| 170 | + |
|
| 171 | + if(!$this->connected()) { |
|
| 172 | + $this->error = array("error" => "Called StartTLS() without being connected"); |
|
| 173 | + return false; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + fputs($this->smtp_conn,"STARTTLS" . $this->CRLF); |
|
| 177 | + |
|
| 178 | + $rply = $this->get_lines(); |
|
| 179 | + $code = substr($rply,0,3); |
|
| 180 | + |
|
| 181 | + if($this->do_debug >= 2) { |
|
| 182 | + echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + if($code != 220) { |
|
| 186 | + $this->error = |
|
| 187 | + array("error" => "STARTTLS not accepted from server", |
|
| 188 | + "smtp_code" => $code, |
|
| 189 | + "smtp_msg" => substr($rply,4)); |
|
| 190 | + if($this->do_debug >= 1) { |
|
| 191 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 192 | + } |
|
| 193 | + return false; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + //Begin encrypted connection |
|
| 197 | + if(!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { |
|
| 198 | + return false; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + return true; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -208,58 +208,58 @@ discard block |
||
| 208 | 208 | * @return bool |
| 209 | 209 | */ |
| 210 | 210 | public function Authenticate($username, $password) { |
| 211 | - // Start authentication |
|
| 212 | - fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF); |
|
| 213 | - |
|
| 214 | - $rply = $this->get_lines(); |
|
| 215 | - $code = substr($rply,0,3); |
|
| 216 | - |
|
| 217 | - if($code != 334) { |
|
| 218 | - $this->error = |
|
| 219 | - array("error" => "AUTH not accepted from server", |
|
| 220 | - "smtp_code" => $code, |
|
| 221 | - "smtp_msg" => substr($rply,4)); |
|
| 222 | - if($this->do_debug >= 1) { |
|
| 223 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 224 | - } |
|
| 225 | - return false; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - // Send encoded username |
|
| 229 | - fputs($this->smtp_conn, base64_encode($username) . $this->CRLF); |
|
| 230 | - |
|
| 231 | - $rply = $this->get_lines(); |
|
| 232 | - $code = substr($rply,0,3); |
|
| 233 | - |
|
| 234 | - if($code != 334) { |
|
| 235 | - $this->error = |
|
| 236 | - array("error" => "Username not accepted from server", |
|
| 237 | - "smtp_code" => $code, |
|
| 238 | - "smtp_msg" => substr($rply,4)); |
|
| 239 | - if($this->do_debug >= 1) { |
|
| 240 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 241 | - } |
|
| 242 | - return false; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - // Send encoded password |
|
| 246 | - fputs($this->smtp_conn, base64_encode($password) . $this->CRLF); |
|
| 247 | - |
|
| 248 | - $rply = $this->get_lines(); |
|
| 249 | - $code = substr($rply,0,3); |
|
| 250 | - |
|
| 251 | - if($code != 235) { |
|
| 252 | - $this->error = |
|
| 253 | - array("error" => "Password not accepted from server", |
|
| 254 | - "smtp_code" => $code, |
|
| 255 | - "smtp_msg" => substr($rply,4)); |
|
| 256 | - if($this->do_debug >= 1) { |
|
| 257 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 258 | - } |
|
| 259 | - return false; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - return true; |
|
| 211 | + // Start authentication |
|
| 212 | + fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF); |
|
| 213 | + |
|
| 214 | + $rply = $this->get_lines(); |
|
| 215 | + $code = substr($rply,0,3); |
|
| 216 | + |
|
| 217 | + if($code != 334) { |
|
| 218 | + $this->error = |
|
| 219 | + array("error" => "AUTH not accepted from server", |
|
| 220 | + "smtp_code" => $code, |
|
| 221 | + "smtp_msg" => substr($rply,4)); |
|
| 222 | + if($this->do_debug >= 1) { |
|
| 223 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 224 | + } |
|
| 225 | + return false; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + // Send encoded username |
|
| 229 | + fputs($this->smtp_conn, base64_encode($username) . $this->CRLF); |
|
| 230 | + |
|
| 231 | + $rply = $this->get_lines(); |
|
| 232 | + $code = substr($rply,0,3); |
|
| 233 | + |
|
| 234 | + if($code != 334) { |
|
| 235 | + $this->error = |
|
| 236 | + array("error" => "Username not accepted from server", |
|
| 237 | + "smtp_code" => $code, |
|
| 238 | + "smtp_msg" => substr($rply,4)); |
|
| 239 | + if($this->do_debug >= 1) { |
|
| 240 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 241 | + } |
|
| 242 | + return false; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + // Send encoded password |
|
| 246 | + fputs($this->smtp_conn, base64_encode($password) . $this->CRLF); |
|
| 247 | + |
|
| 248 | + $rply = $this->get_lines(); |
|
| 249 | + $code = substr($rply,0,3); |
|
| 250 | + |
|
| 251 | + if($code != 235) { |
|
| 252 | + $this->error = |
|
| 253 | + array("error" => "Password not accepted from server", |
|
| 254 | + "smtp_code" => $code, |
|
| 255 | + "smtp_msg" => substr($rply,4)); |
|
| 256 | + if($this->do_debug >= 1) { |
|
| 257 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 258 | + } |
|
| 259 | + return false; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + return true; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /** |
@@ -268,19 +268,19 @@ discard block |
||
| 268 | 268 | * @return bool |
| 269 | 269 | */ |
| 270 | 270 | public function Connected() { |
| 271 | - if(!empty($this->smtp_conn)) { |
|
| 272 | - $sock_status = socket_get_status($this->smtp_conn); |
|
| 273 | - if($sock_status["eof"]) { |
|
| 274 | - // the socket is valid but we are not connected |
|
| 275 | - if($this->do_debug >= 1) { |
|
| 276 | - echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected"; |
|
| 277 | - } |
|
| 278 | - $this->Close(); |
|
| 279 | - return false; |
|
| 280 | - } |
|
| 281 | - return true; // everything looks good |
|
| 282 | - } |
|
| 283 | - return false; |
|
| 271 | + if(!empty($this->smtp_conn)) { |
|
| 272 | + $sock_status = socket_get_status($this->smtp_conn); |
|
| 273 | + if($sock_status["eof"]) { |
|
| 274 | + // the socket is valid but we are not connected |
|
| 275 | + if($this->do_debug >= 1) { |
|
| 276 | + echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected"; |
|
| 277 | + } |
|
| 278 | + $this->Close(); |
|
| 279 | + return false; |
|
| 280 | + } |
|
| 281 | + return true; // everything looks good |
|
| 282 | + } |
|
| 283 | + return false; |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -291,13 +291,13 @@ discard block |
||
| 291 | 291 | * @return void |
| 292 | 292 | */ |
| 293 | 293 | public function Close() { |
| 294 | - $this->error = null; // so there is no confusion |
|
| 295 | - $this->helo_rply = null; |
|
| 296 | - if(!empty($this->smtp_conn)) { |
|
| 297 | - // close the connection and cleanup |
|
| 298 | - fclose($this->smtp_conn); |
|
| 299 | - $this->smtp_conn = 0; |
|
| 300 | - } |
|
| 294 | + $this->error = null; // so there is no confusion |
|
| 295 | + $this->helo_rply = null; |
|
| 296 | + if(!empty($this->smtp_conn)) { |
|
| 297 | + // close the connection and cleanup |
|
| 298 | + fclose($this->smtp_conn); |
|
| 299 | + $this->smtp_conn = 0; |
|
| 300 | + } |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | ///////////////////////////////////////////////// |
@@ -324,35 +324,35 @@ discard block |
||
| 324 | 324 | * @return bool |
| 325 | 325 | */ |
| 326 | 326 | public function Data($msg_data) { |
| 327 | - $this->error = null; // so no confusion is caused |
|
| 328 | - |
|
| 329 | - if(!$this->connected()) { |
|
| 330 | - $this->error = array( |
|
| 331 | - "error" => "Called Data() without being connected"); |
|
| 332 | - return false; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - fputs($this->smtp_conn,"DATA" . $this->CRLF); |
|
| 336 | - |
|
| 337 | - $rply = $this->get_lines(); |
|
| 338 | - $code = substr($rply,0,3); |
|
| 339 | - |
|
| 340 | - if($this->do_debug >= 2) { |
|
| 341 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - if($code != 354) { |
|
| 345 | - $this->error = |
|
| 346 | - array("error" => "DATA command not accepted from server", |
|
| 347 | - "smtp_code" => $code, |
|
| 348 | - "smtp_msg" => substr($rply,4)); |
|
| 349 | - if($this->do_debug >= 1) { |
|
| 350 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 351 | - } |
|
| 352 | - return false; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - /* the server is ready to accept data! |
|
| 327 | + $this->error = null; // so no confusion is caused |
|
| 328 | + |
|
| 329 | + if(!$this->connected()) { |
|
| 330 | + $this->error = array( |
|
| 331 | + "error" => "Called Data() without being connected"); |
|
| 332 | + return false; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + fputs($this->smtp_conn,"DATA" . $this->CRLF); |
|
| 336 | + |
|
| 337 | + $rply = $this->get_lines(); |
|
| 338 | + $code = substr($rply,0,3); |
|
| 339 | + |
|
| 340 | + if($this->do_debug >= 2) { |
|
| 341 | + echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + if($code != 354) { |
|
| 345 | + $this->error = |
|
| 346 | + array("error" => "DATA command not accepted from server", |
|
| 347 | + "smtp_code" => $code, |
|
| 348 | + "smtp_msg" => substr($rply,4)); |
|
| 349 | + if($this->do_debug >= 1) { |
|
| 350 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 351 | + } |
|
| 352 | + return false; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + /* the server is ready to accept data! |
|
| 356 | 356 | * according to rfc 821 we should not send more than 1000 |
| 357 | 357 | * including the CRLF |
| 358 | 358 | * characters on a single line so we will break the data up |
@@ -363,12 +363,12 @@ discard block |
||
| 363 | 363 | * line. NOTE: this does not count towards limit. |
| 364 | 364 | */ |
| 365 | 365 | |
| 366 | - // normalize the line breaks so we know the explode works |
|
| 367 | - $msg_data = str_replace("\r\n","\n",$msg_data); |
|
| 368 | - $msg_data = str_replace("\r","\n",$msg_data); |
|
| 369 | - $lines = explode("\n",$msg_data); |
|
| 366 | + // normalize the line breaks so we know the explode works |
|
| 367 | + $msg_data = str_replace("\r\n","\n",$msg_data); |
|
| 368 | + $msg_data = str_replace("\r","\n",$msg_data); |
|
| 369 | + $lines = explode("\n",$msg_data); |
|
| 370 | 370 | |
| 371 | - /* we need to find a good way to determine is headers are |
|
| 371 | + /* we need to find a good way to determine is headers are |
|
| 372 | 372 | * in the msg_data or if it is a straight msg body |
| 373 | 373 | * currently I am assuming rfc 822 definitions of msg headers |
| 374 | 374 | * and if the first field of the first line (':' sperated) |
@@ -377,76 +377,76 @@ discard block |
||
| 377 | 377 | * headers. |
| 378 | 378 | */ |
| 379 | 379 | |
| 380 | - $field = substr($lines[0],0,strpos($lines[0],":")); |
|
| 381 | - $in_headers = false; |
|
| 382 | - if(!empty($field) && !strstr($field," ")) { |
|
| 383 | - $in_headers = true; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - $max_line_length = 998; // used below; set here for ease in change |
|
| 387 | - |
|
| 388 | - while(list(,$line) = @each($lines)) { |
|
| 389 | - $lines_out = null; |
|
| 390 | - if($line == "" && $in_headers) { |
|
| 391 | - $in_headers = false; |
|
| 392 | - } |
|
| 393 | - // ok we need to break this line up into several smaller lines |
|
| 394 | - while(strlen($line) > $max_line_length) { |
|
| 395 | - $pos = strrpos(substr($line,0,$max_line_length)," "); |
|
| 396 | - |
|
| 397 | - // Patch to fix DOS attack |
|
| 398 | - if(!$pos) { |
|
| 399 | - $pos = $max_line_length - 1; |
|
| 400 | - $lines_out[] = substr($line,0,$pos); |
|
| 401 | - $line = substr($line,$pos); |
|
| 402 | - } else { |
|
| 403 | - $lines_out[] = substr($line,0,$pos); |
|
| 404 | - $line = substr($line,$pos + 1); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - /* if we are processing headers we need to |
|
| 380 | + $field = substr($lines[0],0,strpos($lines[0],":")); |
|
| 381 | + $in_headers = false; |
|
| 382 | + if(!empty($field) && !strstr($field," ")) { |
|
| 383 | + $in_headers = true; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + $max_line_length = 998; // used below; set here for ease in change |
|
| 387 | + |
|
| 388 | + while(list(,$line) = @each($lines)) { |
|
| 389 | + $lines_out = null; |
|
| 390 | + if($line == "" && $in_headers) { |
|
| 391 | + $in_headers = false; |
|
| 392 | + } |
|
| 393 | + // ok we need to break this line up into several smaller lines |
|
| 394 | + while(strlen($line) > $max_line_length) { |
|
| 395 | + $pos = strrpos(substr($line,0,$max_line_length)," "); |
|
| 396 | + |
|
| 397 | + // Patch to fix DOS attack |
|
| 398 | + if(!$pos) { |
|
| 399 | + $pos = $max_line_length - 1; |
|
| 400 | + $lines_out[] = substr($line,0,$pos); |
|
| 401 | + $line = substr($line,$pos); |
|
| 402 | + } else { |
|
| 403 | + $lines_out[] = substr($line,0,$pos); |
|
| 404 | + $line = substr($line,$pos + 1); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /* if we are processing headers we need to |
|
| 408 | 408 | * add a LWSP-char to the front of the new line |
| 409 | 409 | * rfc 822 on long msg headers |
| 410 | 410 | */ |
| 411 | - if($in_headers) { |
|
| 412 | - $line = "\t" . $line; |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - $lines_out[] = $line; |
|
| 416 | - |
|
| 417 | - // send the lines to the server |
|
| 418 | - while(list(,$line_out) = @each($lines_out)) { |
|
| 419 | - if(strlen($line_out) > 0) |
|
| 420 | - { |
|
| 421 | - if(substr($line_out, 0, 1) == ".") { |
|
| 422 | - $line_out = "." . $line_out; |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - fputs($this->smtp_conn,$line_out . $this->CRLF); |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - // message data has been sent |
|
| 430 | - fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF); |
|
| 431 | - |
|
| 432 | - $rply = $this->get_lines(); |
|
| 433 | - $code = substr($rply,0,3); |
|
| 434 | - |
|
| 435 | - if($this->do_debug >= 2) { |
|
| 436 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - if($code != 250) { |
|
| 440 | - $this->error = |
|
| 441 | - array("error" => "DATA not accepted from server", |
|
| 442 | - "smtp_code" => $code, |
|
| 443 | - "smtp_msg" => substr($rply,4)); |
|
| 444 | - if($this->do_debug >= 1) { |
|
| 445 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 446 | - } |
|
| 447 | - return false; |
|
| 448 | - } |
|
| 449 | - return true; |
|
| 411 | + if($in_headers) { |
|
| 412 | + $line = "\t" . $line; |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + $lines_out[] = $line; |
|
| 416 | + |
|
| 417 | + // send the lines to the server |
|
| 418 | + while(list(,$line_out) = @each($lines_out)) { |
|
| 419 | + if(strlen($line_out) > 0) |
|
| 420 | + { |
|
| 421 | + if(substr($line_out, 0, 1) == ".") { |
|
| 422 | + $line_out = "." . $line_out; |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + fputs($this->smtp_conn,$line_out . $this->CRLF); |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + // message data has been sent |
|
| 430 | + fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF); |
|
| 431 | + |
|
| 432 | + $rply = $this->get_lines(); |
|
| 433 | + $code = substr($rply,0,3); |
|
| 434 | + |
|
| 435 | + if($this->do_debug >= 2) { |
|
| 436 | + echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + if($code != 250) { |
|
| 440 | + $this->error = |
|
| 441 | + array("error" => "DATA not accepted from server", |
|
| 442 | + "smtp_code" => $code, |
|
| 443 | + "smtp_msg" => substr($rply,4)); |
|
| 444 | + if($this->do_debug >= 1) { |
|
| 445 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 446 | + } |
|
| 447 | + return false; |
|
| 448 | + } |
|
| 449 | + return true; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | /** |
@@ -462,28 +462,28 @@ discard block |
||
| 462 | 462 | * @return bool |
| 463 | 463 | */ |
| 464 | 464 | public function Hello($host = '') { |
| 465 | - $this->error = null; // so no confusion is caused |
|
| 466 | - |
|
| 467 | - if(!$this->connected()) { |
|
| 468 | - $this->error = array( |
|
| 469 | - "error" => "Called Hello() without being connected"); |
|
| 470 | - return false; |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - // if hostname for HELO was not specified send default |
|
| 474 | - if(empty($host)) { |
|
| 475 | - // determine appropriate default to send to server |
|
| 476 | - $host = "localhost"; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - // Send extended hello first (RFC 2821) |
|
| 480 | - if(!$this->SendHello("EHLO", $host)) { |
|
| 481 | - if(!$this->SendHello("HELO", $host)) { |
|
| 482 | - return false; |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - return true; |
|
| 465 | + $this->error = null; // so no confusion is caused |
|
| 466 | + |
|
| 467 | + if(!$this->connected()) { |
|
| 468 | + $this->error = array( |
|
| 469 | + "error" => "Called Hello() without being connected"); |
|
| 470 | + return false; |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + // if hostname for HELO was not specified send default |
|
| 474 | + if(empty($host)) { |
|
| 475 | + // determine appropriate default to send to server |
|
| 476 | + $host = "localhost"; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + // Send extended hello first (RFC 2821) |
|
| 480 | + if(!$this->SendHello("EHLO", $host)) { |
|
| 481 | + if(!$this->SendHello("HELO", $host)) { |
|
| 482 | + return false; |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + return true; |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | /** |
@@ -492,29 +492,29 @@ discard block |
||
| 492 | 492 | * @return bool |
| 493 | 493 | */ |
| 494 | 494 | private function SendHello($hello, $host) { |
| 495 | - fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF); |
|
| 495 | + fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF); |
|
| 496 | 496 | |
| 497 | - $rply = $this->get_lines(); |
|
| 498 | - $code = substr($rply,0,3); |
|
| 497 | + $rply = $this->get_lines(); |
|
| 498 | + $code = substr($rply,0,3); |
|
| 499 | 499 | |
| 500 | - if($this->do_debug >= 2) { |
|
| 501 | - echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />'; |
|
| 502 | - } |
|
| 500 | + if($this->do_debug >= 2) { |
|
| 501 | + echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />'; |
|
| 502 | + } |
|
| 503 | 503 | |
| 504 | - if($code != 250) { |
|
| 505 | - $this->error = |
|
| 506 | - array("error" => $hello . " not accepted from server", |
|
| 507 | - "smtp_code" => $code, |
|
| 508 | - "smtp_msg" => substr($rply,4)); |
|
| 509 | - if($this->do_debug >= 1) { |
|
| 510 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 511 | - } |
|
| 512 | - return false; |
|
| 513 | - } |
|
| 504 | + if($code != 250) { |
|
| 505 | + $this->error = |
|
| 506 | + array("error" => $hello . " not accepted from server", |
|
| 507 | + "smtp_code" => $code, |
|
| 508 | + "smtp_msg" => substr($rply,4)); |
|
| 509 | + if($this->do_debug >= 1) { |
|
| 510 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 511 | + } |
|
| 512 | + return false; |
|
| 513 | + } |
|
| 514 | 514 | |
| 515 | - $this->helo_rply = $rply; |
|
| 515 | + $this->helo_rply = $rply; |
|
| 516 | 516 | |
| 517 | - return true; |
|
| 517 | + return true; |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -532,35 +532,35 @@ discard block |
||
| 532 | 532 | * @return bool |
| 533 | 533 | */ |
| 534 | 534 | public function Mail($from) { |
| 535 | - $this->error = null; // so no confusion is caused |
|
| 536 | - |
|
| 537 | - if(!$this->connected()) { |
|
| 538 | - $this->error = array( |
|
| 539 | - "error" => "Called Mail() without being connected"); |
|
| 540 | - return false; |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - $useVerp = ($this->do_verp ? "XVERP" : ""); |
|
| 544 | - fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF); |
|
| 545 | - |
|
| 546 | - $rply = $this->get_lines(); |
|
| 547 | - $code = substr($rply,0,3); |
|
| 548 | - |
|
| 549 | - if($this->do_debug >= 2) { |
|
| 550 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - if($code != 250) { |
|
| 554 | - $this->error = |
|
| 555 | - array("error" => "MAIL not accepted from server", |
|
| 556 | - "smtp_code" => $code, |
|
| 557 | - "smtp_msg" => substr($rply,4)); |
|
| 558 | - if($this->do_debug >= 1) { |
|
| 559 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 560 | - } |
|
| 561 | - return false; |
|
| 562 | - } |
|
| 563 | - return true; |
|
| 535 | + $this->error = null; // so no confusion is caused |
|
| 536 | + |
|
| 537 | + if(!$this->connected()) { |
|
| 538 | + $this->error = array( |
|
| 539 | + "error" => "Called Mail() without being connected"); |
|
| 540 | + return false; |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + $useVerp = ($this->do_verp ? "XVERP" : ""); |
|
| 544 | + fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF); |
|
| 545 | + |
|
| 546 | + $rply = $this->get_lines(); |
|
| 547 | + $code = substr($rply,0,3); |
|
| 548 | + |
|
| 549 | + if($this->do_debug >= 2) { |
|
| 550 | + echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + if($code != 250) { |
|
| 554 | + $this->error = |
|
| 555 | + array("error" => "MAIL not accepted from server", |
|
| 556 | + "smtp_code" => $code, |
|
| 557 | + "smtp_msg" => substr($rply,4)); |
|
| 558 | + if($this->do_debug >= 1) { |
|
| 559 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 560 | + } |
|
| 561 | + return false; |
|
| 562 | + } |
|
| 563 | + return true; |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | /** |
@@ -575,44 +575,44 @@ discard block |
||
| 575 | 575 | * @return bool |
| 576 | 576 | */ |
| 577 | 577 | public function Quit($close_on_error=true) { |
| 578 | - $this->error = null; // so there is no confusion |
|
| 579 | - |
|
| 580 | - if(!$this->connected()) { |
|
| 581 | - $this->error = array( |
|
| 582 | - "error" => "Called Quit() without being connected"); |
|
| 583 | - return false; |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - // send the quit command to the server |
|
| 587 | - fputs($this->smtp_conn,"quit" . $this->CRLF); |
|
| 588 | - |
|
| 589 | - // get any good-bye messages |
|
| 590 | - $byemsg = $this->get_lines(); |
|
| 591 | - |
|
| 592 | - if($this->do_debug >= 2) { |
|
| 593 | - echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />'; |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - $rval = true; |
|
| 597 | - $e = null; |
|
| 598 | - |
|
| 599 | - $code = substr($byemsg,0,3); |
|
| 600 | - if($code != 221) { |
|
| 601 | - // use e as a tmp var cause Close will overwrite $this->error |
|
| 602 | - $e = array("error" => "SMTP server rejected quit command", |
|
| 603 | - "smtp_code" => $code, |
|
| 604 | - "smtp_rply" => substr($byemsg,4)); |
|
| 605 | - $rval = false; |
|
| 606 | - if($this->do_debug >= 1) { |
|
| 607 | - echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />'; |
|
| 608 | - } |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - if(empty($e) || $close_on_error) { |
|
| 612 | - $this->Close(); |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - return $rval; |
|
| 578 | + $this->error = null; // so there is no confusion |
|
| 579 | + |
|
| 580 | + if(!$this->connected()) { |
|
| 581 | + $this->error = array( |
|
| 582 | + "error" => "Called Quit() without being connected"); |
|
| 583 | + return false; |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + // send the quit command to the server |
|
| 587 | + fputs($this->smtp_conn,"quit" . $this->CRLF); |
|
| 588 | + |
|
| 589 | + // get any good-bye messages |
|
| 590 | + $byemsg = $this->get_lines(); |
|
| 591 | + |
|
| 592 | + if($this->do_debug >= 2) { |
|
| 593 | + echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />'; |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + $rval = true; |
|
| 597 | + $e = null; |
|
| 598 | + |
|
| 599 | + $code = substr($byemsg,0,3); |
|
| 600 | + if($code != 221) { |
|
| 601 | + // use e as a tmp var cause Close will overwrite $this->error |
|
| 602 | + $e = array("error" => "SMTP server rejected quit command", |
|
| 603 | + "smtp_code" => $code, |
|
| 604 | + "smtp_rply" => substr($byemsg,4)); |
|
| 605 | + $rval = false; |
|
| 606 | + if($this->do_debug >= 1) { |
|
| 607 | + echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />'; |
|
| 608 | + } |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + if(empty($e) || $close_on_error) { |
|
| 612 | + $this->Close(); |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + return $rval; |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | /** |
@@ -628,34 +628,34 @@ discard block |
||
| 628 | 628 | * @return bool |
| 629 | 629 | */ |
| 630 | 630 | public function Recipient($to) { |
| 631 | - $this->error = null; // so no confusion is caused |
|
| 632 | - |
|
| 633 | - if(!$this->connected()) { |
|
| 634 | - $this->error = array( |
|
| 635 | - "error" => "Called Recipient() without being connected"); |
|
| 636 | - return false; |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF); |
|
| 640 | - |
|
| 641 | - $rply = $this->get_lines(); |
|
| 642 | - $code = substr($rply,0,3); |
|
| 643 | - |
|
| 644 | - if($this->do_debug >= 2) { |
|
| 645 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - if($code != 250 && $code != 251) { |
|
| 649 | - $this->error = |
|
| 650 | - array("error" => "RCPT not accepted from server", |
|
| 651 | - "smtp_code" => $code, |
|
| 652 | - "smtp_msg" => substr($rply,4)); |
|
| 653 | - if($this->do_debug >= 1) { |
|
| 654 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 655 | - } |
|
| 656 | - return false; |
|
| 657 | - } |
|
| 658 | - return true; |
|
| 631 | + $this->error = null; // so no confusion is caused |
|
| 632 | + |
|
| 633 | + if(!$this->connected()) { |
|
| 634 | + $this->error = array( |
|
| 635 | + "error" => "Called Recipient() without being connected"); |
|
| 636 | + return false; |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF); |
|
| 640 | + |
|
| 641 | + $rply = $this->get_lines(); |
|
| 642 | + $code = substr($rply,0,3); |
|
| 643 | + |
|
| 644 | + if($this->do_debug >= 2) { |
|
| 645 | + echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + if($code != 250 && $code != 251) { |
|
| 649 | + $this->error = |
|
| 650 | + array("error" => "RCPT not accepted from server", |
|
| 651 | + "smtp_code" => $code, |
|
| 652 | + "smtp_msg" => substr($rply,4)); |
|
| 653 | + if($this->do_debug >= 1) { |
|
| 654 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 655 | + } |
|
| 656 | + return false; |
|
| 657 | + } |
|
| 658 | + return true; |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | /** |
@@ -671,35 +671,35 @@ discard block |
||
| 671 | 671 | * @return bool |
| 672 | 672 | */ |
| 673 | 673 | public function Reset() { |
| 674 | - $this->error = null; // so no confusion is caused |
|
| 675 | - |
|
| 676 | - if(!$this->connected()) { |
|
| 677 | - $this->error = array( |
|
| 678 | - "error" => "Called Reset() without being connected"); |
|
| 679 | - return false; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - fputs($this->smtp_conn,"RSET" . $this->CRLF); |
|
| 683 | - |
|
| 684 | - $rply = $this->get_lines(); |
|
| 685 | - $code = substr($rply,0,3); |
|
| 686 | - |
|
| 687 | - if($this->do_debug >= 2) { |
|
| 688 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - if($code != 250) { |
|
| 692 | - $this->error = |
|
| 693 | - array("error" => "RSET failed", |
|
| 694 | - "smtp_code" => $code, |
|
| 695 | - "smtp_msg" => substr($rply,4)); |
|
| 696 | - if($this->do_debug >= 1) { |
|
| 697 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 698 | - } |
|
| 699 | - return false; |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - return true; |
|
| 674 | + $this->error = null; // so no confusion is caused |
|
| 675 | + |
|
| 676 | + if(!$this->connected()) { |
|
| 677 | + $this->error = array( |
|
| 678 | + "error" => "Called Reset() without being connected"); |
|
| 679 | + return false; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + fputs($this->smtp_conn,"RSET" . $this->CRLF); |
|
| 683 | + |
|
| 684 | + $rply = $this->get_lines(); |
|
| 685 | + $code = substr($rply,0,3); |
|
| 686 | + |
|
| 687 | + if($this->do_debug >= 2) { |
|
| 688 | + echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + if($code != 250) { |
|
| 692 | + $this->error = |
|
| 693 | + array("error" => "RSET failed", |
|
| 694 | + "smtp_code" => $code, |
|
| 695 | + "smtp_msg" => substr($rply,4)); |
|
| 696 | + if($this->do_debug >= 1) { |
|
| 697 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 698 | + } |
|
| 699 | + return false; |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + return true; |
|
| 703 | 703 | } |
| 704 | 704 | |
| 705 | 705 | /** |
@@ -719,34 +719,34 @@ discard block |
||
| 719 | 719 | * @return bool |
| 720 | 720 | */ |
| 721 | 721 | public function SendAndMail($from) { |
| 722 | - $this->error = null; // so no confusion is caused |
|
| 723 | - |
|
| 724 | - if(!$this->connected()) { |
|
| 725 | - $this->error = array( |
|
| 726 | - "error" => "Called SendAndMail() without being connected"); |
|
| 727 | - return false; |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF); |
|
| 731 | - |
|
| 732 | - $rply = $this->get_lines(); |
|
| 733 | - $code = substr($rply,0,3); |
|
| 734 | - |
|
| 735 | - if($this->do_debug >= 2) { |
|
| 736 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - if($code != 250) { |
|
| 740 | - $this->error = |
|
| 741 | - array("error" => "SAML not accepted from server", |
|
| 742 | - "smtp_code" => $code, |
|
| 743 | - "smtp_msg" => substr($rply,4)); |
|
| 744 | - if($this->do_debug >= 1) { |
|
| 745 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 746 | - } |
|
| 747 | - return false; |
|
| 748 | - } |
|
| 749 | - return true; |
|
| 722 | + $this->error = null; // so no confusion is caused |
|
| 723 | + |
|
| 724 | + if(!$this->connected()) { |
|
| 725 | + $this->error = array( |
|
| 726 | + "error" => "Called SendAndMail() without being connected"); |
|
| 727 | + return false; |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF); |
|
| 731 | + |
|
| 732 | + $rply = $this->get_lines(); |
|
| 733 | + $code = substr($rply,0,3); |
|
| 734 | + |
|
| 735 | + if($this->do_debug >= 2) { |
|
| 736 | + echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + if($code != 250) { |
|
| 740 | + $this->error = |
|
| 741 | + array("error" => "SAML not accepted from server", |
|
| 742 | + "smtp_code" => $code, |
|
| 743 | + "smtp_msg" => substr($rply,4)); |
|
| 744 | + if($this->do_debug >= 1) { |
|
| 745 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 746 | + } |
|
| 747 | + return false; |
|
| 748 | + } |
|
| 749 | + return true; |
|
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | /** |
@@ -763,22 +763,22 @@ discard block |
||
| 763 | 763 | * @return bool |
| 764 | 764 | */ |
| 765 | 765 | public function Turn() { |
| 766 | - $this->error = array("error" => "This method, TURN, of the SMTP ". |
|
| 767 | - "is not implemented"); |
|
| 768 | - if($this->do_debug >= 1) { |
|
| 769 | - echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />'; |
|
| 770 | - } |
|
| 771 | - return false; |
|
| 766 | + $this->error = array("error" => "This method, TURN, of the SMTP ". |
|
| 767 | + "is not implemented"); |
|
| 768 | + if($this->do_debug >= 1) { |
|
| 769 | + echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />'; |
|
| 770 | + } |
|
| 771 | + return false; |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | /** |
| 775 | - * Get the current error |
|
| 775 | + * Get the current error |
|
| 776 | 776 | * @access public |
| 777 | - * @return array |
|
| 777 | + * @return array |
|
| 778 | 778 | */ |
| 779 | 779 | public function getError() { |
| 780 | - return $this->error; |
|
| 781 | - } |
|
| 780 | + return $this->error; |
|
| 781 | + } |
|
| 782 | 782 | |
| 783 | 783 | ///////////////////////////////////////////////// |
| 784 | 784 | // INTERNAL FUNCTIONS |
@@ -794,20 +794,20 @@ discard block |
||
| 794 | 794 | * @return string |
| 795 | 795 | */ |
| 796 | 796 | private function get_lines() { |
| 797 | - $data = ""; |
|
| 798 | - while($str = @fgets($this->smtp_conn,515)) { |
|
| 799 | - if($this->do_debug >= 4) { |
|
| 800 | - echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />'; |
|
| 801 | - echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />'; |
|
| 802 | - } |
|
| 803 | - $data .= $str; |
|
| 804 | - if($this->do_debug >= 4) { |
|
| 805 | - echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />'; |
|
| 806 | - } |
|
| 807 | - // if 4th character is a space, we are done reading, break the loop |
|
| 808 | - if(substr($str,3,1) == " ") { break; } |
|
| 809 | - } |
|
| 810 | - return $data; |
|
| 797 | + $data = ""; |
|
| 798 | + while($str = @fgets($this->smtp_conn,515)) { |
|
| 799 | + if($this->do_debug >= 4) { |
|
| 800 | + echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />'; |
|
| 801 | + echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />'; |
|
| 802 | + } |
|
| 803 | + $data .= $str; |
|
| 804 | + if($this->do_debug >= 4) { |
|
| 805 | + echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />'; |
|
| 806 | + } |
|
| 807 | + // if 4th character is a space, we are done reading, break the loop |
|
| 808 | + if(substr($str,3,1) == " ") { break; } |
|
| 809 | + } |
|
| 810 | + return $data; |
|
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | } |
@@ -143,8 +143,9 @@ |
||
| 143 | 143 | |
| 144 | 144 | // SMTP server can take longer to respond, give longer timeout for first read |
| 145 | 145 | // Windows does not have support for this timeout function |
| 146 | - if(substr(PHP_OS, 0, 3) != "WIN") |
|
| 147 | - socket_set_timeout($this->smtp_conn, $tval, 0); |
|
| 146 | + if(substr(PHP_OS, 0, 3) != "WIN") { |
|
| 147 | + socket_set_timeout($this->smtp_conn, $tval, 0); |
|
| 148 | + } |
|
| 148 | 149 | |
| 149 | 150 | // get any announcement |
| 150 | 151 | $announce = $this->get_lines(); |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | * Sets whether debugging is turned on |
| 64 | 64 | * @var bool |
| 65 | 65 | */ |
| 66 | - public $do_debug; // the level of debug to perform |
|
| 66 | + public $do_debug; // the level of debug to perform |
|
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * Sets VERP use on/off (default is off) |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | // PROPERTIES, PRIVATE AND PROTECTED |
| 76 | 76 | ///////////////////////////////////////////////// |
| 77 | 77 | |
| 78 | - private $smtp_conn; // the socket to the server |
|
| 79 | - private $error; // error if any on the last call |
|
| 80 | - private $helo_rply; // the reply the server sent to us for HELO |
|
| 78 | + private $smtp_conn; // the socket to the server |
|
| 79 | + private $error; // error if any on the last call |
|
| 80 | + private $helo_rply; // the reply the server sent to us for HELO |
|
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | 83 | * Initialize the class so that the data is in a known state. |
@@ -109,48 +109,48 @@ discard block |
||
| 109 | 109 | * @access public |
| 110 | 110 | * @return bool |
| 111 | 111 | */ |
| 112 | - public function Connect($host,$port=0,$tval=30) { |
|
| 112 | + public function Connect($host, $port = 0, $tval = 30) { |
|
| 113 | 113 | // set the error val to null so there is no confusion |
| 114 | 114 | $this->error = null; |
| 115 | 115 | |
| 116 | 116 | // make sure we are __not__ connected |
| 117 | - if($this->connected()) { |
|
| 117 | + if ($this->connected()) { |
|
| 118 | 118 | // already connected, generate error |
| 119 | 119 | $this->error = array("error" => "Already connected to a server"); |
| 120 | 120 | return false; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - if(empty($port)) { |
|
| 123 | + if (empty($port)) { |
|
| 124 | 124 | $port = $this->SMTP_PORT; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // connect to the smtp server |
| 128 | - $this->smtp_conn = @fsockopen($host, // the host of the server |
|
| 129 | - $port, // the port to use |
|
| 130 | - $errno, // error number if any |
|
| 131 | - $errstr, // error message if any |
|
| 132 | - $tval); // give up after ? secs |
|
| 128 | + $this->smtp_conn = @fsockopen($host, // the host of the server |
|
| 129 | + $port, // the port to use |
|
| 130 | + $errno, // error number if any |
|
| 131 | + $errstr, // error message if any |
|
| 132 | + $tval); // give up after ? secs |
|
| 133 | 133 | // verify we connected properly |
| 134 | - if(empty($this->smtp_conn)) { |
|
| 134 | + if (empty($this->smtp_conn)) { |
|
| 135 | 135 | $this->error = array("error" => "Failed to connect to server", |
| 136 | 136 | "errno" => $errno, |
| 137 | 137 | "errstr" => $errstr); |
| 138 | - if($this->do_debug >= 1) { |
|
| 139 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />'; |
|
| 138 | + if ($this->do_debug >= 1) { |
|
| 139 | + echo "SMTP -> ERROR: ".$this->error["error"].": $errstr ($errno)".$this->CRLF.'<br />'; |
|
| 140 | 140 | } |
| 141 | 141 | return false; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | // SMTP server can take longer to respond, give longer timeout for first read |
| 145 | 145 | // Windows does not have support for this timeout function |
| 146 | - if(substr(PHP_OS, 0, 3) != "WIN") |
|
| 146 | + if (substr(PHP_OS, 0, 3) != "WIN") |
|
| 147 | 147 | socket_set_timeout($this->smtp_conn, $tval, 0); |
| 148 | 148 | |
| 149 | 149 | // get any announcement |
| 150 | 150 | $announce = $this->get_lines(); |
| 151 | 151 | |
| 152 | - if($this->do_debug >= 2) { |
|
| 153 | - echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />'; |
|
| 152 | + if ($this->do_debug >= 2) { |
|
| 153 | + echo "SMTP -> FROM SERVER:".$announce.$this->CRLF.'<br />'; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | return true; |
@@ -168,33 +168,33 @@ discard block |
||
| 168 | 168 | public function StartTLS() { |
| 169 | 169 | $this->error = null; # to avoid confusion |
| 170 | 170 | |
| 171 | - if(!$this->connected()) { |
|
| 171 | + if (!$this->connected()) { |
|
| 172 | 172 | $this->error = array("error" => "Called StartTLS() without being connected"); |
| 173 | 173 | return false; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - fputs($this->smtp_conn,"STARTTLS" . $this->CRLF); |
|
| 176 | + fputs($this->smtp_conn, "STARTTLS".$this->CRLF); |
|
| 177 | 177 | |
| 178 | 178 | $rply = $this->get_lines(); |
| 179 | - $code = substr($rply,0,3); |
|
| 179 | + $code = substr($rply, 0, 3); |
|
| 180 | 180 | |
| 181 | - if($this->do_debug >= 2) { |
|
| 182 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 181 | + if ($this->do_debug >= 2) { |
|
| 182 | + echo "SMTP -> FROM SERVER:".$rply.$this->CRLF.'<br />'; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - if($code != 220) { |
|
| 185 | + if ($code != 220) { |
|
| 186 | 186 | $this->error = |
| 187 | 187 | array("error" => "STARTTLS not accepted from server", |
| 188 | 188 | "smtp_code" => $code, |
| 189 | - "smtp_msg" => substr($rply,4)); |
|
| 190 | - if($this->do_debug >= 1) { |
|
| 191 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 189 | + "smtp_msg" => substr($rply, 4)); |
|
| 190 | + if ($this->do_debug >= 1) { |
|
| 191 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 192 | 192 | } |
| 193 | 193 | return false; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | //Begin encrypted connection |
| 197 | - if(!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { |
|
| 197 | + if (!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { |
|
| 198 | 198 | return false; |
| 199 | 199 | } |
| 200 | 200 | |
@@ -209,52 +209,52 @@ discard block |
||
| 209 | 209 | */ |
| 210 | 210 | public function Authenticate($username, $password) { |
| 211 | 211 | // Start authentication |
| 212 | - fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF); |
|
| 212 | + fputs($this->smtp_conn, "AUTH LOGIN".$this->CRLF); |
|
| 213 | 213 | |
| 214 | 214 | $rply = $this->get_lines(); |
| 215 | - $code = substr($rply,0,3); |
|
| 215 | + $code = substr($rply, 0, 3); |
|
| 216 | 216 | |
| 217 | - if($code != 334) { |
|
| 217 | + if ($code != 334) { |
|
| 218 | 218 | $this->error = |
| 219 | 219 | array("error" => "AUTH not accepted from server", |
| 220 | 220 | "smtp_code" => $code, |
| 221 | - "smtp_msg" => substr($rply,4)); |
|
| 222 | - if($this->do_debug >= 1) { |
|
| 223 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 221 | + "smtp_msg" => substr($rply, 4)); |
|
| 222 | + if ($this->do_debug >= 1) { |
|
| 223 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 224 | 224 | } |
| 225 | 225 | return false; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | // Send encoded username |
| 229 | - fputs($this->smtp_conn, base64_encode($username) . $this->CRLF); |
|
| 229 | + fputs($this->smtp_conn, base64_encode($username).$this->CRLF); |
|
| 230 | 230 | |
| 231 | 231 | $rply = $this->get_lines(); |
| 232 | - $code = substr($rply,0,3); |
|
| 232 | + $code = substr($rply, 0, 3); |
|
| 233 | 233 | |
| 234 | - if($code != 334) { |
|
| 234 | + if ($code != 334) { |
|
| 235 | 235 | $this->error = |
| 236 | 236 | array("error" => "Username not accepted from server", |
| 237 | 237 | "smtp_code" => $code, |
| 238 | - "smtp_msg" => substr($rply,4)); |
|
| 239 | - if($this->do_debug >= 1) { |
|
| 240 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 238 | + "smtp_msg" => substr($rply, 4)); |
|
| 239 | + if ($this->do_debug >= 1) { |
|
| 240 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 241 | 241 | } |
| 242 | 242 | return false; |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | // Send encoded password |
| 246 | - fputs($this->smtp_conn, base64_encode($password) . $this->CRLF); |
|
| 246 | + fputs($this->smtp_conn, base64_encode($password).$this->CRLF); |
|
| 247 | 247 | |
| 248 | 248 | $rply = $this->get_lines(); |
| 249 | - $code = substr($rply,0,3); |
|
| 249 | + $code = substr($rply, 0, 3); |
|
| 250 | 250 | |
| 251 | - if($code != 235) { |
|
| 251 | + if ($code != 235) { |
|
| 252 | 252 | $this->error = |
| 253 | 253 | array("error" => "Password not accepted from server", |
| 254 | 254 | "smtp_code" => $code, |
| 255 | - "smtp_msg" => substr($rply,4)); |
|
| 256 | - if($this->do_debug >= 1) { |
|
| 257 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 255 | + "smtp_msg" => substr($rply, 4)); |
|
| 256 | + if ($this->do_debug >= 1) { |
|
| 257 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 258 | 258 | } |
| 259 | 259 | return false; |
| 260 | 260 | } |
@@ -268,12 +268,12 @@ discard block |
||
| 268 | 268 | * @return bool |
| 269 | 269 | */ |
| 270 | 270 | public function Connected() { |
| 271 | - if(!empty($this->smtp_conn)) { |
|
| 271 | + if (!empty($this->smtp_conn)) { |
|
| 272 | 272 | $sock_status = socket_get_status($this->smtp_conn); |
| 273 | - if($sock_status["eof"]) { |
|
| 273 | + if ($sock_status["eof"]) { |
|
| 274 | 274 | // the socket is valid but we are not connected |
| 275 | - if($this->do_debug >= 1) { |
|
| 276 | - echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected"; |
|
| 275 | + if ($this->do_debug >= 1) { |
|
| 276 | + echo "SMTP -> NOTICE:".$this->CRLF."EOF caught while checking if connected"; |
|
| 277 | 277 | } |
| 278 | 278 | $this->Close(); |
| 279 | 279 | return false; |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | public function Close() { |
| 294 | 294 | $this->error = null; // so there is no confusion |
| 295 | 295 | $this->helo_rply = null; |
| 296 | - if(!empty($this->smtp_conn)) { |
|
| 296 | + if (!empty($this->smtp_conn)) { |
|
| 297 | 297 | // close the connection and cleanup |
| 298 | 298 | fclose($this->smtp_conn); |
| 299 | 299 | $this->smtp_conn = 0; |
@@ -326,28 +326,28 @@ discard block |
||
| 326 | 326 | public function Data($msg_data) { |
| 327 | 327 | $this->error = null; // so no confusion is caused |
| 328 | 328 | |
| 329 | - if(!$this->connected()) { |
|
| 329 | + if (!$this->connected()) { |
|
| 330 | 330 | $this->error = array( |
| 331 | 331 | "error" => "Called Data() without being connected"); |
| 332 | 332 | return false; |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - fputs($this->smtp_conn,"DATA" . $this->CRLF); |
|
| 335 | + fputs($this->smtp_conn, "DATA".$this->CRLF); |
|
| 336 | 336 | |
| 337 | 337 | $rply = $this->get_lines(); |
| 338 | - $code = substr($rply,0,3); |
|
| 338 | + $code = substr($rply, 0, 3); |
|
| 339 | 339 | |
| 340 | - if($this->do_debug >= 2) { |
|
| 341 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 340 | + if ($this->do_debug >= 2) { |
|
| 341 | + echo "SMTP -> FROM SERVER:".$rply.$this->CRLF.'<br />'; |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - if($code != 354) { |
|
| 344 | + if ($code != 354) { |
|
| 345 | 345 | $this->error = |
| 346 | 346 | array("error" => "DATA command not accepted from server", |
| 347 | 347 | "smtp_code" => $code, |
| 348 | - "smtp_msg" => substr($rply,4)); |
|
| 349 | - if($this->do_debug >= 1) { |
|
| 350 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 348 | + "smtp_msg" => substr($rply, 4)); |
|
| 349 | + if ($this->do_debug >= 1) { |
|
| 350 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 351 | 351 | } |
| 352 | 352 | return false; |
| 353 | 353 | } |
@@ -364,9 +364,9 @@ discard block |
||
| 364 | 364 | */ |
| 365 | 365 | |
| 366 | 366 | // normalize the line breaks so we know the explode works |
| 367 | - $msg_data = str_replace("\r\n","\n",$msg_data); |
|
| 368 | - $msg_data = str_replace("\r","\n",$msg_data); |
|
| 369 | - $lines = explode("\n",$msg_data); |
|
| 367 | + $msg_data = str_replace("\r\n", "\n", $msg_data); |
|
| 368 | + $msg_data = str_replace("\r", "\n", $msg_data); |
|
| 369 | + $lines = explode("\n", $msg_data); |
|
| 370 | 370 | |
| 371 | 371 | /* we need to find a good way to determine is headers are |
| 372 | 372 | * in the msg_data or if it is a straight msg body |
@@ -377,72 +377,72 @@ discard block |
||
| 377 | 377 | * headers. |
| 378 | 378 | */ |
| 379 | 379 | |
| 380 | - $field = substr($lines[0],0,strpos($lines[0],":")); |
|
| 380 | + $field = substr($lines[0], 0, strpos($lines[0], ":")); |
|
| 381 | 381 | $in_headers = false; |
| 382 | - if(!empty($field) && !strstr($field," ")) { |
|
| 382 | + if (!empty($field) && !strstr($field, " ")) { |
|
| 383 | 383 | $in_headers = true; |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | $max_line_length = 998; // used below; set here for ease in change |
| 387 | 387 | |
| 388 | - while(list(,$line) = @each($lines)) { |
|
| 388 | + while (list(,$line) = @each($lines)) { |
|
| 389 | 389 | $lines_out = null; |
| 390 | - if($line == "" && $in_headers) { |
|
| 390 | + if ($line == "" && $in_headers) { |
|
| 391 | 391 | $in_headers = false; |
| 392 | 392 | } |
| 393 | 393 | // ok we need to break this line up into several smaller lines |
| 394 | - while(strlen($line) > $max_line_length) { |
|
| 395 | - $pos = strrpos(substr($line,0,$max_line_length)," "); |
|
| 394 | + while (strlen($line) > $max_line_length) { |
|
| 395 | + $pos = strrpos(substr($line, 0, $max_line_length), " "); |
|
| 396 | 396 | |
| 397 | 397 | // Patch to fix DOS attack |
| 398 | - if(!$pos) { |
|
| 398 | + if (!$pos) { |
|
| 399 | 399 | $pos = $max_line_length - 1; |
| 400 | - $lines_out[] = substr($line,0,$pos); |
|
| 401 | - $line = substr($line,$pos); |
|
| 400 | + $lines_out[] = substr($line, 0, $pos); |
|
| 401 | + $line = substr($line, $pos); |
|
| 402 | 402 | } else { |
| 403 | - $lines_out[] = substr($line,0,$pos); |
|
| 404 | - $line = substr($line,$pos + 1); |
|
| 403 | + $lines_out[] = substr($line, 0, $pos); |
|
| 404 | + $line = substr($line, $pos + 1); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | /* if we are processing headers we need to |
| 408 | 408 | * add a LWSP-char to the front of the new line |
| 409 | 409 | * rfc 822 on long msg headers |
| 410 | 410 | */ |
| 411 | - if($in_headers) { |
|
| 412 | - $line = "\t" . $line; |
|
| 411 | + if ($in_headers) { |
|
| 412 | + $line = "\t".$line; |
|
| 413 | 413 | } |
| 414 | 414 | } |
| 415 | 415 | $lines_out[] = $line; |
| 416 | 416 | |
| 417 | 417 | // send the lines to the server |
| 418 | - while(list(,$line_out) = @each($lines_out)) { |
|
| 419 | - if(strlen($line_out) > 0) |
|
| 418 | + while (list(,$line_out) = @each($lines_out)) { |
|
| 419 | + if (strlen($line_out) > 0) |
|
| 420 | 420 | { |
| 421 | - if(substr($line_out, 0, 1) == ".") { |
|
| 422 | - $line_out = "." . $line_out; |
|
| 421 | + if (substr($line_out, 0, 1) == ".") { |
|
| 422 | + $line_out = ".".$line_out; |
|
| 423 | 423 | } |
| 424 | 424 | } |
| 425 | - fputs($this->smtp_conn,$line_out . $this->CRLF); |
|
| 425 | + fputs($this->smtp_conn, $line_out.$this->CRLF); |
|
| 426 | 426 | } |
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | // message data has been sent |
| 430 | - fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF); |
|
| 430 | + fputs($this->smtp_conn, $this->CRLF.".".$this->CRLF); |
|
| 431 | 431 | |
| 432 | 432 | $rply = $this->get_lines(); |
| 433 | - $code = substr($rply,0,3); |
|
| 433 | + $code = substr($rply, 0, 3); |
|
| 434 | 434 | |
| 435 | - if($this->do_debug >= 2) { |
|
| 436 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 435 | + if ($this->do_debug >= 2) { |
|
| 436 | + echo "SMTP -> FROM SERVER:".$rply.$this->CRLF.'<br />'; |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | - if($code != 250) { |
|
| 439 | + if ($code != 250) { |
|
| 440 | 440 | $this->error = |
| 441 | 441 | array("error" => "DATA not accepted from server", |
| 442 | 442 | "smtp_code" => $code, |
| 443 | - "smtp_msg" => substr($rply,4)); |
|
| 444 | - if($this->do_debug >= 1) { |
|
| 445 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 443 | + "smtp_msg" => substr($rply, 4)); |
|
| 444 | + if ($this->do_debug >= 1) { |
|
| 445 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 446 | 446 | } |
| 447 | 447 | return false; |
| 448 | 448 | } |
@@ -464,21 +464,21 @@ discard block |
||
| 464 | 464 | public function Hello($host = '') { |
| 465 | 465 | $this->error = null; // so no confusion is caused |
| 466 | 466 | |
| 467 | - if(!$this->connected()) { |
|
| 467 | + if (!$this->connected()) { |
|
| 468 | 468 | $this->error = array( |
| 469 | 469 | "error" => "Called Hello() without being connected"); |
| 470 | 470 | return false; |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | // if hostname for HELO was not specified send default |
| 474 | - if(empty($host)) { |
|
| 474 | + if (empty($host)) { |
|
| 475 | 475 | // determine appropriate default to send to server |
| 476 | 476 | $host = "localhost"; |
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | // Send extended hello first (RFC 2821) |
| 480 | - if(!$this->SendHello("EHLO", $host)) { |
|
| 481 | - if(!$this->SendHello("HELO", $host)) { |
|
| 480 | + if (!$this->SendHello("EHLO", $host)) { |
|
| 481 | + if (!$this->SendHello("HELO", $host)) { |
|
| 482 | 482 | return false; |
| 483 | 483 | } |
| 484 | 484 | } |
@@ -492,22 +492,22 @@ discard block |
||
| 492 | 492 | * @return bool |
| 493 | 493 | */ |
| 494 | 494 | private function SendHello($hello, $host) { |
| 495 | - fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF); |
|
| 495 | + fputs($this->smtp_conn, $hello." ".$host.$this->CRLF); |
|
| 496 | 496 | |
| 497 | 497 | $rply = $this->get_lines(); |
| 498 | - $code = substr($rply,0,3); |
|
| 498 | + $code = substr($rply, 0, 3); |
|
| 499 | 499 | |
| 500 | - if($this->do_debug >= 2) { |
|
| 501 | - echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />'; |
|
| 500 | + if ($this->do_debug >= 2) { |
|
| 501 | + echo "SMTP -> FROM SERVER: ".$rply.$this->CRLF.'<br />'; |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | - if($code != 250) { |
|
| 504 | + if ($code != 250) { |
|
| 505 | 505 | $this->error = |
| 506 | - array("error" => $hello . " not accepted from server", |
|
| 506 | + array("error" => $hello." not accepted from server", |
|
| 507 | 507 | "smtp_code" => $code, |
| 508 | - "smtp_msg" => substr($rply,4)); |
|
| 509 | - if($this->do_debug >= 1) { |
|
| 510 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 508 | + "smtp_msg" => substr($rply, 4)); |
|
| 509 | + if ($this->do_debug >= 1) { |
|
| 510 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 511 | 511 | } |
| 512 | 512 | return false; |
| 513 | 513 | } |
@@ -534,29 +534,29 @@ discard block |
||
| 534 | 534 | public function Mail($from) { |
| 535 | 535 | $this->error = null; // so no confusion is caused |
| 536 | 536 | |
| 537 | - if(!$this->connected()) { |
|
| 537 | + if (!$this->connected()) { |
|
| 538 | 538 | $this->error = array( |
| 539 | 539 | "error" => "Called Mail() without being connected"); |
| 540 | 540 | return false; |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | $useVerp = ($this->do_verp ? "XVERP" : ""); |
| 544 | - fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF); |
|
| 544 | + fputs($this->smtp_conn, "MAIL FROM:<".$from.">".$useVerp.$this->CRLF); |
|
| 545 | 545 | |
| 546 | 546 | $rply = $this->get_lines(); |
| 547 | - $code = substr($rply,0,3); |
|
| 547 | + $code = substr($rply, 0, 3); |
|
| 548 | 548 | |
| 549 | - if($this->do_debug >= 2) { |
|
| 550 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 549 | + if ($this->do_debug >= 2) { |
|
| 550 | + echo "SMTP -> FROM SERVER:".$rply.$this->CRLF.'<br />'; |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | - if($code != 250) { |
|
| 553 | + if ($code != 250) { |
|
| 554 | 554 | $this->error = |
| 555 | 555 | array("error" => "MAIL not accepted from server", |
| 556 | 556 | "smtp_code" => $code, |
| 557 | - "smtp_msg" => substr($rply,4)); |
|
| 558 | - if($this->do_debug >= 1) { |
|
| 559 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 557 | + "smtp_msg" => substr($rply, 4)); |
|
| 558 | + if ($this->do_debug >= 1) { |
|
| 559 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 560 | 560 | } |
| 561 | 561 | return false; |
| 562 | 562 | } |
@@ -574,41 +574,41 @@ discard block |
||
| 574 | 574 | * @access public |
| 575 | 575 | * @return bool |
| 576 | 576 | */ |
| 577 | - public function Quit($close_on_error=true) { |
|
| 577 | + public function Quit($close_on_error = true) { |
|
| 578 | 578 | $this->error = null; // so there is no confusion |
| 579 | 579 | |
| 580 | - if(!$this->connected()) { |
|
| 580 | + if (!$this->connected()) { |
|
| 581 | 581 | $this->error = array( |
| 582 | 582 | "error" => "Called Quit() without being connected"); |
| 583 | 583 | return false; |
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | // send the quit command to the server |
| 587 | - fputs($this->smtp_conn,"quit" . $this->CRLF); |
|
| 587 | + fputs($this->smtp_conn, "quit".$this->CRLF); |
|
| 588 | 588 | |
| 589 | 589 | // get any good-bye messages |
| 590 | 590 | $byemsg = $this->get_lines(); |
| 591 | 591 | |
| 592 | - if($this->do_debug >= 2) { |
|
| 593 | - echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />'; |
|
| 592 | + if ($this->do_debug >= 2) { |
|
| 593 | + echo "SMTP -> FROM SERVER:".$byemsg.$this->CRLF.'<br />'; |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | $rval = true; |
| 597 | 597 | $e = null; |
| 598 | 598 | |
| 599 | - $code = substr($byemsg,0,3); |
|
| 600 | - if($code != 221) { |
|
| 599 | + $code = substr($byemsg, 0, 3); |
|
| 600 | + if ($code != 221) { |
|
| 601 | 601 | // use e as a tmp var cause Close will overwrite $this->error |
| 602 | 602 | $e = array("error" => "SMTP server rejected quit command", |
| 603 | 603 | "smtp_code" => $code, |
| 604 | - "smtp_rply" => substr($byemsg,4)); |
|
| 604 | + "smtp_rply" => substr($byemsg, 4)); |
|
| 605 | 605 | $rval = false; |
| 606 | - if($this->do_debug >= 1) { |
|
| 607 | - echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />'; |
|
| 606 | + if ($this->do_debug >= 1) { |
|
| 607 | + echo "SMTP -> ERROR: ".$e["error"].": ".$byemsg.$this->CRLF.'<br />'; |
|
| 608 | 608 | } |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | - if(empty($e) || $close_on_error) { |
|
| 611 | + if (empty($e) || $close_on_error) { |
|
| 612 | 612 | $this->Close(); |
| 613 | 613 | } |
| 614 | 614 | |
@@ -630,28 +630,28 @@ discard block |
||
| 630 | 630 | public function Recipient($to) { |
| 631 | 631 | $this->error = null; // so no confusion is caused |
| 632 | 632 | |
| 633 | - if(!$this->connected()) { |
|
| 633 | + if (!$this->connected()) { |
|
| 634 | 634 | $this->error = array( |
| 635 | 635 | "error" => "Called Recipient() without being connected"); |
| 636 | 636 | return false; |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | - fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF); |
|
| 639 | + fputs($this->smtp_conn, "RCPT TO:<".$to.">".$this->CRLF); |
|
| 640 | 640 | |
| 641 | 641 | $rply = $this->get_lines(); |
| 642 | - $code = substr($rply,0,3); |
|
| 642 | + $code = substr($rply, 0, 3); |
|
| 643 | 643 | |
| 644 | - if($this->do_debug >= 2) { |
|
| 645 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 644 | + if ($this->do_debug >= 2) { |
|
| 645 | + echo "SMTP -> FROM SERVER:".$rply.$this->CRLF.'<br />'; |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | - if($code != 250 && $code != 251) { |
|
| 648 | + if ($code != 250 && $code != 251) { |
|
| 649 | 649 | $this->error = |
| 650 | 650 | array("error" => "RCPT not accepted from server", |
| 651 | 651 | "smtp_code" => $code, |
| 652 | - "smtp_msg" => substr($rply,4)); |
|
| 653 | - if($this->do_debug >= 1) { |
|
| 654 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 652 | + "smtp_msg" => substr($rply, 4)); |
|
| 653 | + if ($this->do_debug >= 1) { |
|
| 654 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 655 | 655 | } |
| 656 | 656 | return false; |
| 657 | 657 | } |
@@ -673,28 +673,28 @@ discard block |
||
| 673 | 673 | public function Reset() { |
| 674 | 674 | $this->error = null; // so no confusion is caused |
| 675 | 675 | |
| 676 | - if(!$this->connected()) { |
|
| 676 | + if (!$this->connected()) { |
|
| 677 | 677 | $this->error = array( |
| 678 | 678 | "error" => "Called Reset() without being connected"); |
| 679 | 679 | return false; |
| 680 | 680 | } |
| 681 | 681 | |
| 682 | - fputs($this->smtp_conn,"RSET" . $this->CRLF); |
|
| 682 | + fputs($this->smtp_conn, "RSET".$this->CRLF); |
|
| 683 | 683 | |
| 684 | 684 | $rply = $this->get_lines(); |
| 685 | - $code = substr($rply,0,3); |
|
| 685 | + $code = substr($rply, 0, 3); |
|
| 686 | 686 | |
| 687 | - if($this->do_debug >= 2) { |
|
| 688 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 687 | + if ($this->do_debug >= 2) { |
|
| 688 | + echo "SMTP -> FROM SERVER:".$rply.$this->CRLF.'<br />'; |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | - if($code != 250) { |
|
| 691 | + if ($code != 250) { |
|
| 692 | 692 | $this->error = |
| 693 | 693 | array("error" => "RSET failed", |
| 694 | 694 | "smtp_code" => $code, |
| 695 | - "smtp_msg" => substr($rply,4)); |
|
| 696 | - if($this->do_debug >= 1) { |
|
| 697 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 695 | + "smtp_msg" => substr($rply, 4)); |
|
| 696 | + if ($this->do_debug >= 1) { |
|
| 697 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 698 | 698 | } |
| 699 | 699 | return false; |
| 700 | 700 | } |
@@ -721,28 +721,28 @@ discard block |
||
| 721 | 721 | public function SendAndMail($from) { |
| 722 | 722 | $this->error = null; // so no confusion is caused |
| 723 | 723 | |
| 724 | - if(!$this->connected()) { |
|
| 724 | + if (!$this->connected()) { |
|
| 725 | 725 | $this->error = array( |
| 726 | 726 | "error" => "Called SendAndMail() without being connected"); |
| 727 | 727 | return false; |
| 728 | 728 | } |
| 729 | 729 | |
| 730 | - fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF); |
|
| 730 | + fputs($this->smtp_conn, "SAML FROM:".$from.$this->CRLF); |
|
| 731 | 731 | |
| 732 | 732 | $rply = $this->get_lines(); |
| 733 | - $code = substr($rply,0,3); |
|
| 733 | + $code = substr($rply, 0, 3); |
|
| 734 | 734 | |
| 735 | - if($this->do_debug >= 2) { |
|
| 736 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 735 | + if ($this->do_debug >= 2) { |
|
| 736 | + echo "SMTP -> FROM SERVER:".$rply.$this->CRLF.'<br />'; |
|
| 737 | 737 | } |
| 738 | 738 | |
| 739 | - if($code != 250) { |
|
| 739 | + if ($code != 250) { |
|
| 740 | 740 | $this->error = |
| 741 | 741 | array("error" => "SAML not accepted from server", |
| 742 | 742 | "smtp_code" => $code, |
| 743 | - "smtp_msg" => substr($rply,4)); |
|
| 744 | - if($this->do_debug >= 1) { |
|
| 745 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 743 | + "smtp_msg" => substr($rply, 4)); |
|
| 744 | + if ($this->do_debug >= 1) { |
|
| 745 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 746 | 746 | } |
| 747 | 747 | return false; |
| 748 | 748 | } |
@@ -765,8 +765,8 @@ discard block |
||
| 765 | 765 | public function Turn() { |
| 766 | 766 | $this->error = array("error" => "This method, TURN, of the SMTP ". |
| 767 | 767 | "is not implemented"); |
| 768 | - if($this->do_debug >= 1) { |
|
| 769 | - echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />'; |
|
| 768 | + if ($this->do_debug >= 1) { |
|
| 769 | + echo "SMTP -> NOTICE: ".$this->error["error"].$this->CRLF.'<br />'; |
|
| 770 | 770 | } |
| 771 | 771 | return false; |
| 772 | 772 | } |
@@ -795,17 +795,17 @@ discard block |
||
| 795 | 795 | */ |
| 796 | 796 | private function get_lines() { |
| 797 | 797 | $data = ""; |
| 798 | - while($str = @fgets($this->smtp_conn,515)) { |
|
| 799 | - if($this->do_debug >= 4) { |
|
| 800 | - echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />'; |
|
| 801 | - echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />'; |
|
| 798 | + while ($str = @fgets($this->smtp_conn, 515)) { |
|
| 799 | + if ($this->do_debug >= 4) { |
|
| 800 | + echo "SMTP -> get_lines(): \$data was \"$data\"".$this->CRLF.'<br />'; |
|
| 801 | + echo "SMTP -> get_lines(): \$str is \"$str\"".$this->CRLF.'<br />'; |
|
| 802 | 802 | } |
| 803 | 803 | $data .= $str; |
| 804 | - if($this->do_debug >= 4) { |
|
| 805 | - echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />'; |
|
| 804 | + if ($this->do_debug >= 4) { |
|
| 805 | + echo "SMTP -> get_lines(): \$data is \"$data\"".$this->CRLF.'<br />'; |
|
| 806 | 806 | } |
| 807 | 807 | // if 4th character is a space, we are done reading, break the loop |
| 808 | - if(substr($str,3,1) == " ") { break; } |
|
| 808 | + if (substr($str, 3, 1) == " ") { break; } |
|
| 809 | 809 | } |
| 810 | 810 | return $data; |
| 811 | 811 | } |