GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#1805)
by
unknown
18:31
created
libs/PEAR.1.9/PEAR/Exception.php 4 patches
Doc Comments   +2 added lines patch added patch discarded remove patch
@@ -117,6 +117,8 @@
 block discarded – undo
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
     {
Please login to merge, or discard this patch.
Indentation   +275 added lines, -275 removed lines patch added patch discarded remove patch
@@ -96,296 +96,296 @@
 block discarded – undo
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 .= '&hellip;';
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>&nbsp;</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 .= '&hellip;';
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>&nbsp;</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
 ?>
Please login to merge, or discard this patch.
Spacing   +8 added lines, -10 removed lines patch added patch discarded remove patch
@@ -277,11 +277,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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,7 +323,7 @@  discard block
 block discarded – undo
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 329
                . str_repeat('-', $i) . ' <b>' . $cause['class'] . '</b>: '
@@ -350,24 +348,24 @@  discard block
 block discarded – undo
350 348
                 foreach ($v['args'] as $arg) {
351 349
                     if (is_null($arg)) $args[] = 'null';
352 350
                     elseif (is_array($arg)) $args[] = 'Array';
353
-                    elseif (is_object($arg)) $args[] = 'Object('.get_class($arg).')';
351
+                    elseif (is_object($arg)) $args[] = 'Object(' . get_class($arg) . ')';
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 .= '&hellip;';
360 358
                         $args[] = "'" . $str . "'";
361 359
                     }
362 360
                 }
363 361
             }
364
-            $html .= '(' . implode(', ',$args) . ')'
362
+            $html .= '(' . implode(', ', $args) . ')'
365 363
                    . '</td>'
366 364
                    . '<td>' . (isset($v['file']) ? $v['file'] : 'unknown')
367 365
                    . ':' . (isset($v['line']) ? $v['line'] : 'unknown')
368 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 370
                . '<td>&nbsp;</td></tr>' . "\n"
373 371
                . '</table>';
Please login to merge, or discard this patch.
Braces   +14 added lines, -7 removed lines patch added patch discarded remove patch
@@ -348,15 +348,22 @@
 block discarded – undo
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 .= '&hellip;';
364
+                        if (strlen($arg) > 16) {
365
+                        	$str .= '&hellip;';
366
+                        }
360 367
                         $args[] = "'" . $str . "'";
361 368
                     }
362 369
                 }
Please login to merge, or discard this patch.
libs/PEAR/HTTP/Request.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -1267,6 +1267,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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)
Please login to merge, or discard this patch.
Indentation   +1147 added lines, -1147 removed lines patch added patch discarded remove patch
@@ -1,48 +1,48 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Class for performing HTTP requests
4
- *
5
- * PHP versions 4 and 5
6
- * 
7
- * LICENSE:
8
- *
9
- * Copyright (c) 2002-2007, Richard Heyes
10
- * All rights reserved.
11
- *
12
- * Redistribution and use in source and binary forms, with or without
13
- * modification, are permitted provided that the following conditions
14
- * are met:
15
- *
16
- * o Redistributions of source code must retain the above copyright
17
- *   notice, this list of conditions and the following disclaimer.
18
- * o Redistributions in binary form must reproduce the above copyright
19
- *   notice, this list of conditions and the following disclaimer in the
20
- *   documentation and/or other materials provided with the distribution.
21
- * o The names of the authors may not be used to endorse or promote
22
- *   products derived from this software without specific prior written
23
- *   permission.
24
- *
25
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
- *
37
- * @category    HTTP
38
- * @package     HTTP_Request
39
- * @author      Richard Heyes <[email protected]>
40
- * @author      Alexey Borzov <[email protected]>
41
- * @copyright   2002-2007 Richard Heyes
42
- * @license     http://opensource.org/licenses/bsd-license.php New BSD License
43
- * @version     CVS: $Id: Request.php,v 1.55 2007/05/18 19:20:12 avb Exp $
44
- * @link        http://pear.php.net/package/HTTP_Request/ 
45
- */
3
+	 * Class for performing HTTP requests
4
+	 *
5
+	 * PHP versions 4 and 5
6
+	 * 
7
+	 * LICENSE:
8
+	 *
9
+	 * Copyright (c) 2002-2007, Richard Heyes
10
+	 * All rights reserved.
11
+	 *
12
+	 * Redistribution and use in source and binary forms, with or without
13
+	 * modification, are permitted provided that the following conditions
14
+	 * are met:
15
+	 *
16
+	 * o Redistributions of source code must retain the above copyright
17
+	 *   notice, this list of conditions and the following disclaimer.
18
+	 * o Redistributions in binary form must reproduce the above copyright
19
+	 *   notice, this list of conditions and the following disclaimer in the
20
+	 *   documentation and/or other materials provided with the distribution.
21
+	 * o The names of the authors may not be used to endorse or promote
22
+	 *   products derived from this software without specific prior written
23
+	 *   permission.
24
+	 *
25
+	 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
+	 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
+	 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
+	 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
+	 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
+	 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
+	 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
+	 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
+	 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
+	 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
+	 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
+	 *
37
+	 * @category    HTTP
38
+	 * @package     HTTP_Request
39
+	 * @author      Richard Heyes <[email protected]>
40
+	 * @author      Alexey Borzov <[email protected]>
41
+	 * @copyright   2002-2007 Richard Heyes
42
+	 * @license     http://opensource.org/licenses/bsd-license.php New BSD License
43
+	 * @version     CVS: $Id: Request.php,v 1.55 2007/05/18 19:20:12 avb Exp $
44
+	 * @link        http://pear.php.net/package/HTTP_Request/ 
45
+	 */
46 46
 
47 47
 /**
48 48
  * PEAR and PEAR_Error classes (for error handling)
@@ -80,12 +80,12 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 ?>
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -60,13 +60,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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;
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
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
     /**
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
     */
635 635
     function addCookie($name, $value)
636 636
     {
637
-        $cookies = isset($this->_requestHeaders['cookie']) ? $this->_requestHeaders['cookie']. '; ' : '';
637
+        $cookies = isset($this->_requestHeaders['cookie']) ? $this->_requestHeaders['cookie'] . '; ' : '';
638 638
         $this->addHeader('Cookie', $cookies . $name . '=' . $value);
639 639
     }
640 640
     
@@ -699,11 +699,11 @@  discard block
 block discarded – undo
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());
@@ -730,7 +730,7 @@  discard block
 block discarded – undo
730 730
                     if (isset($this->_response->_headers['connection'])) {
731 731
                         $keepAlive = strtolower($this->_response->_headers['connection']) == 'keep-alive';
732 732
                     } else {
733
-                        $keepAlive = 'HTTP/'.HTTP_REQUEST_HTTP_VER_1_1 == $this->_response->_protocol;
733
+                        $keepAlive = 'HTTP/' . HTTP_REQUEST_HTTP_VER_1_1 == $this->_response->_protocol;
734 734
                     }
735 735
                 }
736 736
             }
@@ -746,11 +746,11 @@  discard block
 block discarded – undo
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
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
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;
@@ -935,7 +935,7 @@  discard block
 block discarded – undo
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,7 +945,7 @@  discard block
 block discarded – undo
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 950
                         $postdata .= '--' . $boundary . "\r\n";
951 951
                         $postdata .= 'Content-Disposition: form-data; name="' . $varname . '"; filename="' . $basename . '"';
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
                 $postdata .= '--' . $boundary . "--\r\n";
957 957
             }
958 958
             $request .= 'Content-Length: ' .
959
-                        (HTTP_REQUEST_MBSTRING? mb_strlen($postdata, 'iso-8859-1'): strlen($postdata)) .
959
+                        (HTTP_REQUEST_MBSTRING ? mb_strlen($postdata, 'iso-8859-1') : strlen($postdata)) .
960 960
                         "\r\n\r\n";
961 961
             $request .= $postdata;
962 962
 
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
         } elseif (!empty($this->_body)) {
965 965
 
966 966
             $request .= 'Content-Length: ' .
967
-                        (HTTP_REQUEST_MBSTRING? mb_strlen($this->_body, 'iso-8859-1'): strlen($this->_body)) .
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
         }
@@ -1026,7 +1026,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
@@ -1204,7 +1204,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
         }
@@ -1336,7 +1336,7 @@  discard block
 block discarded – undo
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
         }
Please login to merge, or discard this patch.
libs/PEAR/Net/URL.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -340,7 +340,7 @@
 block discarded – undo
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)
Please login to merge, or discard this patch.
Indentation   +367 added lines, -367 removed lines patch added patch discarded remove patch
@@ -38,373 +38,373 @@
 block discarded – undo
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
 ?>
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
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
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
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
 
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
libs/phpmailer/class.phpmailer.php 4 patches
Doc Comments   +27 added lines, -5 removed lines patch added patch discarded remove patch
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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(
Please login to merge, or discard this patch.
Indentation   +1070 added lines, -1070 removed lines patch added patch discarded remove patch
@@ -271,11 +271,11 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +166 added lines, -167 removed lines patch added patch discarded remove patch
@@ -41,64 +41,64 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,7 +435,7 @@  discard block
 block discarded – undo
435 435
       $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
436 436
     }
437 437
 
438
-    if(!@$mail = popen($sendmail, 'w')) {
438
+    if (!@$mail = popen($sendmail, 'w')) {
439 439
       $this->SetError($this->Lang('execute') . $this->Sendmail);
440 440
       return false;
441 441
     }
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
     if (version_compare(phpversion(), '4.2.3') == -1) {
448 448
       $result = $result >> 8 & 0xFF;
449 449
     }
450
-    if($result != 0) {
450
+    if ($result != 0) {
451 451
       $this->SetError($this->Lang('execute') . $this->Sendmail);
452 452
       return false;
453 453
     }
@@ -462,8 +462,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
     }
@@ -514,12 +514,12 @@  discard block
 block discarded – undo
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)) {
522
+    if (!$this->smtp->Mail($smtp_from)) {
523 523
       $error = $this->Lang('from_failed') . $smtp_from;
524 524
       $this->SetError($error);
525 525
       $this->smtp->Reset();
@@ -527,25 +527,25 @@  discard block
 block discarded – undo
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];
@@ -556,12 +556,12 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,10 +645,10 @@  discard block
 block discarded – undo
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');
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 652
     } else {
653 653
       $PHPMAILER_LANG = array();
654 654
       $PHPMAILER_LANG["provide_address"]      = 'You must provide at least one ' .
@@ -682,8 +682,8 @@  discard block
 block discarded – undo
682 682
   function AddrAppend($type, $addr) {
683 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++) {
685
+    if (count($addr) > 1) {
686
+      for ($i = 1; $i < count($addr); $i++) {
687 687
         $addr_str .= ', ' . $this->AddrFormat($addr[$i]);
688 688
       }
689 689
     }
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
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 704
       $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
@@ -727,10 +727,10 @@  discard block
 block discarded – undo
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;
@@ -810,8 +810,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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':
@@ -864,15 +863,15 @@  discard block
 block discarded – undo
864 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
 block discarded – undo
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 911
     $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version ' . $this->Version . ']');
913 912
 
914
-    if($this->ConfirmReadingTo != '') {
913
+    if ($this->ConfirmReadingTo != '') {
915 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
 block discarded – undo
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,7 +941,7 @@  discard block
 block discarded – undo
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;');
@@ -955,8 +954,8 @@  discard block
 block discarded – undo
955 954
         break;
956 955
     }
957 956
 
958
-    if($this->Mailer != 'mail') {
959
-      $result .= $this->LE.$this->LE;
957
+    if ($this->Mailer != 'mail') {
958
+      $result .= $this->LE . $this->LE;
960 959
     }
961 960
 
962 961
     return $result;
@@ -975,14 +974,14 @@  discard block
 block discarded – undo
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);
982
-        $result .= $this->LE.$this->LE;
981
+        $result .= $this->LE . $this->LE;
983 982
         $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
984 983
         $result .= $this->EncodeString($this->Body, $this->Encoding);
985
-        $result .= $this->LE.$this->LE;
984
+        $result .= $this->LE . $this->LE;
986 985
         $result .= $this->EndBoundary($this->boundary[1]);
987 986
         break;
988 987
       case 'plain':
@@ -996,19 +995,19 @@  discard block
 block discarded – undo
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);
998
+        $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE . $this->LE);
1000 999
         $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
1001 1000
         $result .= $this->EncodeString($this->AltBody, $this->Encoding);
1002
-        $result .= $this->LE.$this->LE;
1001
+        $result .= $this->LE . $this->LE;
1003 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
-        $result .= $this->LE.$this->LE;
1004
+        $result .= $this->LE . $this->LE;
1006 1005
         $result .= $this->EndBoundary($this->boundary[2]);
1007 1006
         $result .= $this->AttachAll();
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");
@@ -1017,16 +1016,16 @@  discard block
 block discarded – undo
1017 1016
       fclose($fp);
1018 1017
       $signed = tempnam("", "signed");
1019 1018
 
1020
-      if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), null)) {
1019
+      if (@openssl_pkcs7_sign($file, $signed, "file://" . $this->sign_cert_file, array("file://" . $this->sign_key_file, $this->sign_key_pass), null)) {
1021 1020
         $fp = fopen($signed, "r");
1022 1021
         $result = fread($fp, filesize($this->sign_key_file));
1023 1022
         $result = '';
1024
-        while(!feof($fp)){
1023
+        while (!feof($fp)) {
1025 1024
           $result = $result . fread($fp, 1024);
1026 1025
         }
1027 1026
         fclose($fp);
1028 1027
       } else {
1029
-        $this->SetError($this->Lang("signing").openssl_error_string());
1028
+        $this->SetError($this->Lang("signing") . openssl_error_string());
1030 1029
         $result = '';
1031 1030
       }
1032 1031
 
@@ -1043,13 +1042,13 @@  discard block
 block discarded – undo
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 1054
     $result .= $this->TextLine('--' . $boundary);
@@ -1075,16 +1074,16 @@  discard block
 block discarded – undo
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
     }
@@ -1122,13 +1121,13 @@  discard block
 block discarded – undo
1122 1121
    * @return bool
1123 1122
    */
1124 1123
   function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
1125
-    if(!@is_file($path)) {
1124
+    if (!@is_file($path)) {
1126 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
 block discarded – undo
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,25 +1175,25 @@  discard block
 block discarded – undo
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
-      $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
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
-        $mime[] = $this->LE.$this->LE;
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
-        $mime[] = $this->LE.$this->LE;
1196
+        $mime[] = $this->LE . $this->LE;
1198 1197
       }
1199 1198
     }
1200 1199
 
@@ -1209,8 +1208,8 @@  discard block
 block discarded – undo
1209 1208
    * @access private
1210 1209
    * @return string
1211 1210
    */
1212
-  function EncodeFile ($path, $encoding = 'base64') {
1213
-    if(!@$fd = fopen($path, 'rb')) {
1211
+  function EncodeFile($path, $encoding = 'base64') {
1212
+    if (!@$fd = fopen($path, 'rb')) {
1214 1213
       $this->SetError($this->Lang('file_open') . $path);
1215 1214
       return '';
1216 1215
     }
@@ -1230,9 +1229,9 @@  discard block
 block discarded – undo
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);
@@ -1261,7 +1260,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
@@ -1307,10 +1306,10 @@  discard block
 block discarded – undo
1307 1306
       $encoding = 'Q';
1308 1307
       $encoded = $this->EncodeQ($str, $position);
1309 1308
       $encoded = $this->WrapText($encoded, $maxlen, true);
1310
-      $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
1309
+      $encoded = str_replace('=' . $this->LE, "\n", trim($encoded));
1311 1310
     }
1312 1311
 
1313
-    $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
1312
+    $encoded = preg_replace('/^(.*)$/m', " =?" . $this->CharSet . "?$encoding?\\1?=", $encoded);
1314 1313
     $encoded = trim(str_replace("\n", $this->LE, $encoded));
1315 1314
 
1316 1315
     return $encoded;
@@ -1339,7 +1338,7 @@  discard block
 block discarded – undo
1339 1338
    * @return string
1340 1339
    */
1341 1340
   function Base64EncodeWrapMB($str) {
1342
-    $start = "=?".$this->CharSet."?B?";
1341
+    $start = "=?" . $this->CharSet . "?B?";
1343 1342
     $end = "?=";
1344 1343
     $encoded = "";
1345 1344
 
@@ -1375,43 +1374,43 @@  discard block
 block discarded – undo
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);
1402
-          $c = $escape.$hex[$h2].$hex[$h1];
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);
1401
+          $c = $escape . $hex[$h2] . $hex[$h1];
1403 1402
         }
1404
-        if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
1405
-          $output .= $newline.$escape.$eol; //  soft line break; " =\r\n" is okay
1403
+        if ((strlen($newline) + strlen($c)) >= $line_max) { // CRLF is not counted
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
         }
1412 1411
         $newline .= $c;
1413 1412
       } // end of for
1414
-      $output .= $newline.$eol;
1413
+      $output .= $newline . $eol;
1415 1414
     } // end of while
1416 1415
     return $output;
1417 1416
   }
@@ -1421,7 +1420,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
1483 1482
    */
1484 1483
   function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
1485 1484
 
1486
-    if(!@is_file($path)) {
1485
+    if (!@is_file($path)) {
1487 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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,11 +1665,11 @@  discard block
 block discarded – undo
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 1675
       return 'Language string failed to load: ' . $key;
@@ -1710,34 +1709,34 @@  discard block
 block discarded – undo
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='':'';
1720
+          ($directory == '.') ? $directory = '' : '';
1722 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) ) {
1729
-            $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
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)) {
1728
+            $message = preg_replace("/" . $images[1][$i] . "=\"" . preg_quote($url, '/') . "\"/Ui", $images[1][$i] . "=\"" . $cid . "\"", $message);
1730 1729
           }
1731 1730
         }
1732 1731
       }
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) ) {
1739
+    if (empty($this->AltBody)) {
1741 1740
       $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n";
1742 1741
     }
1743 1742
   }
@@ -1836,7 +1835,7 @@  discard block
 block discarded – undo
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,8 +1849,8 @@  discard block
 block discarded – undo
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 1856
       $this->SetError('Cannot set or reset variable ' . $name);
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1240,8 +1240,9 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.
libs/phpmailer/class.smtp.php 4 patches
Doc Comments   +8 added lines, -1 removed lines patch added patch discarded remove patch
@@ -95,6 +95,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
Indentation   +668 added lines, -668 removed lines patch added patch discarded remove patch
@@ -73,11 +73,11 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,22 +110,22 @@  discard block
 block discarded – undo
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) {
128
+      if ($this->do_debug >= 1) {
129 129
         echo "SMTP -> ERROR: " . $this->error["error"] .
130 130
                  ": $errstr ($errno)" . $this->CRLF;
131 131
       }
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
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,7 +145,7 @@  discard block
 block discarded – undo
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) {
148
+    if ($this->do_debug >= 2) {
149 149
       echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
150 150
     }
151 151
 
@@ -160,17 +160,17 @@  discard block
 block discarded – undo
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) {
172
+              "smtp_msg" => substr($rply, 4));
173
+      if ($this->do_debug >= 1) {
174 174
         echo "SMTP -> ERROR: " . $this->error["error"] .
175 175
                  ": " . $rply . $this->CRLF;
176 176
       }
@@ -181,14 +181,14 @@  discard block
 block discarded – undo
181 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) {
190
+              "smtp_msg" => substr($rply, 4));
191
+      if ($this->do_debug >= 1) {
192 192
         echo "SMTP -> ERROR: " . $this->error["error"] .
193 193
                  ": " . $rply . $this->CRLF;
194 194
       }
@@ -199,14 +199,14 @@  discard block
 block discarded – undo
199 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) {
208
+              "smtp_msg" => substr($rply, 4));
209
+      if ($this->do_debug >= 1) {
210 210
         echo "SMTP -> ERROR: " . $this->error["error"] .
211 211
                  ": " . $rply . $this->CRLF;
212 212
       }
@@ -222,12 +222,12 @@  discard block
 block discarded – undo
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) {
230
+        if ($this->do_debug >= 1) {
231 231
             echo "SMTP -> NOTICE:" . $this->CRLF .
232 232
                  "EOF caught while checking if connected";
233 233
         }
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
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,27 +282,27 @@  discard block
 block discarded – undo
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) {
296
+    if ($this->do_debug >= 2) {
297 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) {
304
+              "smtp_msg" => substr($rply, 4));
305
+      if ($this->do_debug >= 1) {
306 306
         echo "SMTP -> ERROR: " . $this->error["error"] .
307 307
                  ": " . $rply . $this->CRLF;
308 308
       }
@@ -320,9 +320,9 @@  discard block
 block discarded – undo
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,49 +331,49 @@  discard block
 block discarded – undo
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) {
362
+        if ($in_headers) {
363 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) == ".") {
372
+          if (substr($line_out, 0, 1) == ".") {
373 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
 
@@ -382,18 +382,18 @@  discard block
 block discarded – undo
382 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) {
387
+    if ($this->do_debug >= 2) {
388 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) {
395
+              "smtp_msg" => substr($rply, 4));
396
+      if ($this->do_debug >= 1) {
397 397
         echo "SMTP -> ERROR: " . $this->error["error"] .
398 398
                  ": " . $rply . $this->CRLF;
399 399
       }
@@ -421,27 +421,27 @@  discard block
 block discarded – undo
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) {
435
+    if ($this->do_debug >= 2) {
436 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) {
443
+              "smtp_msg" => substr($rply, 4));
444
+      if ($this->do_debug >= 1) {
445 445
         echo "SMTP -> ERROR: " . $this->error["error"] .
446 446
                  ": " . $rply . $this->CRLF;
447 447
       }
@@ -449,9 +449,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
@@ -505,18 +505,18 @@  discard block
 block discarded – undo
505 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) {
510
+    if ($this->do_debug >= 2) {
511 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 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) {
518
+              "smtp_msg" => substr($rply, 4));
519
+      if ($this->do_debug >= 1) {
520 520
         echo "SMTP -> ERROR: " . $this->error["error"] .
521 521
                  ": " . $rply . $this->CRLF;
522 522
       }
@@ -543,35 +543,35 @@  discard block
 block discarded – undo
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)) {
556
+    if (!empty($keyword)) {
557 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) {
565
+    if ($this->do_debug >= 2) {
566 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) {
573
+              "smtp_msg" => substr($rply, 4));
574
+      if ($this->do_debug >= 1) {
575 575
         echo "SMTP -> ERROR: " . $this->error["error"] .
576 576
                  ": " . $rply . $this->CRLF;
577 577
       }
@@ -598,28 +598,28 @@  discard block
 block discarded – undo
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) {
613
+    if ($this->do_debug >= 2) {
614 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) {
621
+              "smtp_msg" => substr($rply, 4));
622
+      if ($this->do_debug >= 1) {
623 623
         echo "SMTP -> ERROR: " . $this->error["error"] .
624 624
                  ": " . $rply . $this->CRLF;
625 625
       }
@@ -641,27 +641,27 @@  discard block
 block discarded – undo
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) {
655
+    if ($this->do_debug >= 2) {
656 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) {
663
+              "smtp_msg" => substr($rply, 4));
664
+      if ($this->do_debug >= 1) {
665 665
         echo "SMTP -> ERROR: " . $this->error["error"] .
666 666
                  ": " . $rply . $this->CRLF;
667 667
       }
@@ -681,42 +681,42 @@  discard block
 block discarded – undo
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) {
699
+    if ($this->do_debug >= 2) {
700 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) {
713
+      if ($this->do_debug >= 1) {
714 714
         echo "SMTP -> ERROR: " . $e["error"] . ": " .
715 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,27 +738,27 @@  discard block
 block discarded – undo
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) {
752
+    if ($this->do_debug >= 2) {
753 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) {
760
+              "smtp_msg" => substr($rply, 4));
761
+      if ($this->do_debug >= 1) {
762 762
         echo "SMTP -> ERROR: " . $this->error["error"] .
763 763
                  ": " . $rply . $this->CRLF;
764 764
       }
@@ -782,27 +782,27 @@  discard block
 block discarded – undo
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) {
796
+    if ($this->do_debug >= 2) {
797 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) {
804
+              "smtp_msg" => substr($rply, 4));
805
+      if ($this->do_debug >= 1) {
806 806
         echo "SMTP -> ERROR: " . $this->error["error"] .
807 807
                  ": " . $rply . $this->CRLF;
808 808
       }
@@ -831,27 +831,27 @@  discard block
 block discarded – undo
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) {
845
+    if ($this->do_debug >= 2) {
846 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) {
853
+              "smtp_msg" => substr($rply, 4));
854
+      if ($this->do_debug >= 1) {
855 855
         echo "SMTP -> ERROR: " . $this->error["error"] .
856 856
                  ": " . $rply . $this->CRLF;
857 857
       }
@@ -879,27 +879,27 @@  discard block
 block discarded – undo
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) {
893
+    if ($this->do_debug >= 2) {
894 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) {
901
+              "smtp_msg" => substr($rply, 4));
902
+      if ($this->do_debug >= 1) {
903 903
         echo "SMTP -> ERROR: " . $this->error["error"] .
904 904
                  ": " . $rply . $this->CRLF;
905 905
       }
@@ -927,27 +927,27 @@  discard block
 block discarded – undo
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) {
941
+    if ($this->do_debug >= 2) {
942 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) {
949
+              "smtp_msg" => substr($rply, 4));
950
+      if ($this->do_debug >= 1) {
951 951
         echo "SMTP -> ERROR: " . $this->error["error"] .
952 952
                  ": " . $rply . $this->CRLF;
953 953
       }
@@ -970,9 +970,9 @@  discard block
 block discarded – undo
970 970
    * @return bool
971 971
    */
972 972
   function Turn() {
973
-    $this->error = array("error" => "This method, TURN, of the SMTP ".
973
+    $this->error = array("error" => "This method, TURN, of the SMTP " .
974 974
                                     "is not implemented");
975
-    if($this->do_debug >= 1) {
975
+    if ($this->do_debug >= 1) {
976 976
       echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF;
977 977
     }
978 978
     return false;
@@ -994,27 +994,27 @@  discard block
 block discarded – undo
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) {
1008
+    if ($this->do_debug >= 2) {
1009 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) {
1016
+              "smtp_msg" => substr($rply, 4));
1017
+      if ($this->do_debug >= 1) {
1018 1018
         echo "SMTP -> ERROR: " . $this->error["error"] .
1019 1019
                  ": " . $rply . $this->CRLF;
1020 1020
       }
@@ -1038,20 +1038,20 @@  discard block
 block discarded – undo
1038 1038
    */
1039 1039
   function get_lines() {
1040 1040
     $data = "";
1041
-    while($str = @fgets($this->smtp_conn,515)) {
1042
-      if($this->do_debug >= 4) {
1041
+    while ($str = @fgets($this->smtp_conn, 515)) {
1042
+      if ($this->do_debug >= 4) {
1043 1043
         echo "SMTP -> get_lines(): \$data was \"$data\"" .
1044 1044
                  $this->CRLF;
1045 1045
         echo "SMTP -> get_lines(): \$str is \"$str\"" .
1046 1046
                  $this->CRLF;
1047 1047
       }
1048 1048
       $data .= $str;
1049
-      if($this->do_debug >= 4) {
1049
+      if ($this->do_debug >= 4) {
1050 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
   }
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -135,8 +135,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
libs/phpmailer/phpmailer.php 4 patches
Doc Comments   +10 added lines patch added patch discarded remove patch
@@ -892,6 +892,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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='') {
Please login to merge, or discard this patch.
Indentation   +1311 added lines, -1311 removed lines patch added patch discarded remove patch
@@ -251,9 +251,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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':
1727
-        $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
1728
-        break;
1729
-      case 'comment':
1730
-        $encoded = preg_replace("/([\(\)\"])/e", "'='.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
-    }
1725
+	switch (strtolower($position)) {
1726
+	  case 'phrase':
1727
+		$encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
1728
+		break;
1729
+	  case 'comment':
1730
+		$encoded = preg_replace("/([\(\)\"])/e", "'='.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
+	}
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
Spacing   +239 added lines, -240 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
@@ -457,11 +457,11 @@  discard block
 block discarded – undo
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
-        throw new phpmailerException($this->Lang('invalid_address').': '.$address);
462
+        throw new phpmailerException($this->Lang('invalid_address') . ': ' . $address);
463 463
       }
464
-      echo $this->Lang('invalid_address').': '.$address;
464
+      echo $this->Lang('invalid_address') . ': ' . $address;
465 465
       return false;
466 466
     }
467 467
     if ($kind != 'ReplyTo') {
@@ -485,15 +485,15 @@  discard block
 block discarded – undo
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
-        throw new phpmailerException($this->Lang('invalid_address').': '.$address);
494
+        throw new phpmailerException($this->Lang('invalid_address') . ': ' . $address);
495 495
       }
496
-      echo $this->Lang('invalid_address').': '.$address;
496
+      echo $this->Lang('invalid_address') . ': ' . $address;
497 497
       return false;
498 498
     }
499 499
     $this->From = $address;
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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':
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
       if ($this->exceptions) {
584 584
         throw $e;
585 585
       }
586
-      echo $e->getMessage()."\n";
586
+      echo $e->getMessage() . "\n";
587 587
       return false;
588 588
     }
589 589
   }
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
     }
604 604
     if ($this->SingleTo === true) {
605 605
       foreach ($this->SingleToArray as $key => $val) {
606
-    if(!@$mail = popen($sendmail, 'w')) {
606
+    if (!@$mail = popen($sendmail, 'w')) {
607 607
           throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
608 608
     }
609 609
         fputs($mail, "To: " . $val . "\n");
@@ -612,13 +612,13 @@  discard block
 block discarded – undo
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) {
615
+        $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
616
+        if ($result != 0) {
617 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')) {
621
+      if (!@$mail = popen($sendmail, 'w')) {
622 622
         throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
623 623
     }
624 624
       fputs($mail, $header);
@@ -626,8 +626,8 @@  discard block
 block discarded – undo
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) {
629
+      $this->doCallback($isSent, $this->to, $this->cc, $this->bcc, $this->Subject, $body);
630
+    if ($result != 0) {
631 631
         throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
632 632
       }
633 633
     }
@@ -643,13 +643,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
@@ -702,61 +702,61 @@  discard block
 block discarded – undo
702 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)) {
709
+    if (!$this->smtp->Mail($smtp_from)) {
710 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 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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
       }
@@ -871,7 +871,7 @@  discard block
 block discarded – undo
871 871
     //Overwrite language-specific strings. This way we'll never have missing translations - no more "language string failed to load"!
872 872
     $l = true;
873 873
     if ($langcode != 'en') { //There is no English translation file
874
-      $l = @include $lang_path.'phpmailer.lang-'.$langcode.'.php';
874
+      $l = @include $lang_path . 'phpmailer.lang-' . $langcode . '.php';
875 875
     }
876 876
     $this->language = $PHPMAILER_LANG;
877 877
     return ($l == true); //Returns false if language not found
@@ -912,7 +912,7 @@  discard block
 block discarded – undo
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 918
       return $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
@@ -942,10 +942,10 @@  discard block
 block discarded – undo
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;
@@ -1025,8 +1025,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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);
@@ -1079,20 +1078,20 @@  discard block
 block discarded – undo
1079 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
 block discarded – undo
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
-    $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (phpmailer.sourceforge.net)');
1132
+    $result .= $this->HeaderLine('X-Mailer', 'PHPMailer ' . $this->Version . ' (phpmailer.sourceforge.net)');
1134 1133
 
1135
-    if($this->ConfirmReadingTo != '') {
1134
+    if ($this->ConfirmReadingTo != '') {
1136 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,14 +1154,14 @@  discard block
 block discarded – undo
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;');
@@ -1175,8 +1174,8 @@  discard block
 block discarded – undo
1175 1174
         break;
1176 1175
     }
1177 1176
 
1178
-    if($this->Mailer != 'mail') {
1179
-      $result .= $this->LE.$this->LE;
1177
+    if ($this->Mailer != 'mail') {
1178
+      $result .= $this->LE . $this->LE;
1180 1179
     }
1181 1180
 
1182 1181
     return $result;
@@ -1196,14 +1195,14 @@  discard block
 block discarded – undo
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);
1203
-        $body .= $this->LE.$this->LE;
1202
+        $body .= $this->LE . $this->LE;
1204 1203
         $body .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
1205 1204
         $body .= $this->EncodeString($this->Body, $this->Encoding);
1206
-        $body .= $this->LE.$this->LE;
1205
+        $body .= $this->LE . $this->LE;
1207 1206
         $body .= $this->EndBoundary($this->boundary[1]);
1208 1207
         break;
1209 1208
       case 'plain':
@@ -1217,33 +1216,33 @@  discard block
 block discarded – undo
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);
1219
+        $body .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE . $this->LE);
1221 1220
         $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
1222 1221
         $body .= $this->EncodeString($this->AltBody, $this->Encoding);
1223
-        $body .= $this->LE.$this->LE;
1222
+        $body .= $this->LE . $this->LE;
1224 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
-        $body .= $this->LE.$this->LE;
1225
+        $body .= $this->LE . $this->LE;
1227 1226
         $body .= $this->EndBoundary($this->boundary[2]);
1228 1227
         $body .= $this->AttachAll();
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 {
1236 1235
         $file = tempnam('', 'mail');
1237 1236
         file_put_contents($file, $body, LOCK_EX); //TODO check this worked
1238 1237
       $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)) {
1238
+        if (@openssl_pkcs7_sign($file, $signed, "file://" . $this->sign_cert_file, array("file://" . $this->sign_key_file, $this->sign_key_pass), NULL)) {
1240 1239
           @unlink($file);
1241 1240
           @unlink($signed);
1242 1241
           $body = file_get_contents($signed);
1243 1242
       } else {
1244 1243
           @unlink($file);
1245 1244
           @unlink($signed);
1246
-          throw new phpmailerException($this->Lang("signing").openssl_error_string());
1245
+          throw new phpmailerException($this->Lang("signing") . openssl_error_string());
1247 1246
         }
1248 1247
       } catch (phpmailerException $e) {
1249 1248
         $body = '';
@@ -1262,13 +1261,13 @@  discard block
 block discarded – undo
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 1273
     $result .= $this->TextLine('--' . $boundary);
@@ -1294,16 +1293,16 @@  discard block
 block discarded – undo
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
     }
@@ -1343,11 +1342,11 @@  discard block
 block discarded – undo
1343 1342
    */
1344 1343
   public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
1345 1344
     try {
1346
-    if(!@is_file($path)) {
1345
+    if (!@is_file($path)) {
1347 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
 block discarded – undo
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
       );
@@ -1367,8 +1366,8 @@  discard block
 block discarded – undo
1367 1366
       if ($this->exceptions) {
1368 1367
         throw $e;
1369 1368
       }
1370
-      echo $e->getMessage()."\n";
1371
-      if ( $e->getCode() == self::STOP_CRITICAL ) {
1369
+      echo $e->getMessage() . "\n";
1370
+      if ($e->getCode() == self::STOP_CRITICAL) {
1372 1371
         return false;
1373 1372
       }
1374 1373
     }
@@ -1413,32 +1412,32 @@  discard block
 block discarded – undo
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
-      $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
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
-        $mime[] = $this->LE.$this->LE;
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
-        $mime[] = $this->LE.$this->LE;
1440
+        $mime[] = $this->LE . $this->LE;
1442 1441
       }
1443 1442
     }
1444 1443
 
@@ -1488,9 +1487,9 @@  discard block
 block discarded – undo
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;
@@ -1519,7 +1518,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
@@ -1565,10 +1564,10 @@  discard block
 block discarded – undo
1565 1564
       $encoding = 'Q';
1566 1565
       $encoded = $this->EncodeQ($str, $position);
1567 1566
       $encoded = $this->WrapText($encoded, $maxlen, true);
1568
-      $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
1567
+      $encoded = str_replace('=' . $this->LE, "\n", trim($encoded));
1569 1568
     }
1570 1569
 
1571
-    $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
1570
+    $encoded = preg_replace('/^(.*)$/m', " =?" . $this->CharSet . "?$encoding?\\1?=", $encoded);
1572 1571
     $encoded = trim(str_replace("\n", $this->LE, $encoded));
1573 1572
 
1574 1573
     return $encoded;
@@ -1597,7 +1596,7 @@  discard block
 block discarded – undo
1597 1596
    * @return string
1598 1597
    */
1599 1598
   public function Base64EncodeWrapMB($str) {
1600
-    $start = "=?".$this->CharSet."?B?";
1599
+    $start = "=?" . $this->CharSet . "?B?";
1601 1600
     $end = "?=";
1602 1601
     $encoded = "";
1603 1602
 
@@ -1636,43 +1635,43 @@  discard block
 block discarded – undo
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);
1663
-          $c = $escape.$hex[$h2].$hex[$h1];
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);
1662
+          $c = $escape . $hex[$h2] . $hex[$h1];
1664 1663
         }
1665
-        if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
1666
-          $output .= $newline.$escape.$eol; //  soft line break; " =\r\n" is okay
1664
+        if ((strlen($newline) + strlen($c)) >= $line_max) { // CRLF is not counted
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
         }
1673 1672
         $newline .= $c;
1674 1673
       } // end of for
1675
-      $output .= $newline.$eol;
1674
+      $output .= $newline . $eol;
1676 1675
     } // end of while
1677 1676
     return $output;
1678 1677
   }
@@ -1718,7 +1717,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
1782 1781
    */
1783 1782
   public function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
1784 1783
 
1785
-    if(!@is_file($path)) {
1784
+    if (!@is_file($path)) {
1786 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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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();
@@ -1925,7 +1924,7 @@  discard block
 block discarded – undo
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,11 +1953,11 @@  discard block
 block discarded – undo
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 1963
       return 'Language string failed to load: ' . $key;
@@ -2000,33 +1999,33 @@  discard block
 block discarded – undo
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='':'';
2010
+          ($directory == '.') ? $directory = '' : '';
2012 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) ) {
2018
-            $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
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)) {
2017
+            $message = preg_replace("/" . $images[1][$i] . "=\"" . preg_quote($url, '/') . "\"/Ui", $images[1][$i] . "=\"" . $cid . "\"", $message);
2019 2018
           }
2020 2019
         }
2021 2020
       }
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) ) {
2028
+    if (empty($this->AltBody)) {
2030 2029
       $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n";
2031 2030
     }
2032 2031
   }
@@ -2128,7 +2127,7 @@  discard block
 block discarded – undo
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,9 +2142,9 @@  discard block
 block discarded – undo
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 2150
         throw new phpmailerException($this->Lang('variable_set') . $name, self::STOP_CRITICAL);
@@ -2192,14 +2191,14 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,45 +2267,45 @@  discard block
 block discarded – undo
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".
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".
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" .
2293
+                "\th=From:To:Subject;\r\n" .
2294
+                "\td=" . $this->DKIM_domain . ";" . $ident . "\r\n" .
2295
+                "\tz=$from\r\n" .
2296
+                "\t|$to\r\n" .
2297
+                "\t|$subject;\r\n" .
2298
+                "\tbh=" . $DKIMb64 . ";\r\n" .
2300 2299
                 "\tb=";
2301 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
-    return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n";
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
 }
Please login to merge, or discard this patch.
Braces   +9 added lines, -4 removed lines patch added patch discarded remove patch
@@ -38,7 +38,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.
libs/phpmailer/smtp.php 4 patches
Doc Comments   +7 added lines patch added patch discarded remove patch
@@ -107,6 +107,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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) {
Please login to merge, or discard this patch.
Indentation   +470 added lines, -470 removed lines patch added patch discarded remove patch
@@ -85,11 +85,11 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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,33 +109,33 @@  discard block
 block discarded – undo
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) {
138
+      if ($this->do_debug >= 1) {
139 139
         echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />';
140 140
       }
141 141
       return false;
@@ -143,13 +143,13 @@  discard block
 block discarded – undo
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) {
152
+    if ($this->do_debug >= 2) {
153 153
       echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />';
154 154
     }
155 155
 
@@ -168,33 +168,33 @@  discard block
 block discarded – undo
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) {
181
+    if ($this->do_debug >= 2) {
182 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) {
189
+               "smtp_msg"  => substr($rply, 4));
190
+      if ($this->do_debug >= 1) {
191 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,17 +209,17 @@  discard block
 block discarded – undo
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) {
221
+              "smtp_msg" => substr($rply, 4));
222
+      if ($this->do_debug >= 1) {
223 223
         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
224 224
       }
225 225
       return false;
@@ -229,14 +229,14 @@  discard block
 block discarded – undo
229 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) {
238
+              "smtp_msg" => substr($rply, 4));
239
+      if ($this->do_debug >= 1) {
240 240
         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
241 241
       }
242 242
       return false;
@@ -246,14 +246,14 @@  discard block
 block discarded – undo
246 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) {
255
+              "smtp_msg" => substr($rply, 4));
256
+      if ($this->do_debug >= 1) {
257 257
         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
258 258
       }
259 259
       return false;
@@ -268,11 +268,11 @@  discard block
 block discarded – undo
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) {
275
+        if ($this->do_debug >= 1) {
276 276
             echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected";
277 277
         }
278 278
         $this->Close();
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
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,27 +326,27 @@  discard block
 block discarded – undo
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) {
340
+    if ($this->do_debug >= 2) {
341 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) {
348
+              "smtp_msg" => substr($rply, 4));
349
+      if ($this->do_debug >= 1) {
350 350
         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
351 351
       }
352 352
       return false;
@@ -364,9 +364,9 @@  discard block
 block discarded – undo
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,52 +377,52 @@  discard block
 block discarded – undo
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) {
411
+        if ($in_headers) {
412 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) == ".") {
421
+          if (substr($line_out, 0, 1) == ".") {
422 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
 
@@ -430,18 +430,18 @@  discard block
 block discarded – undo
430 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) {
435
+    if ($this->do_debug >= 2) {
436 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) {
443
+              "smtp_msg" => substr($rply, 4));
444
+      if ($this->do_debug >= 1) {
445 445
         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
446 446
       }
447 447
       return false;
@@ -464,21 +464,21 @@  discard block
 block discarded – undo
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
     }
@@ -495,18 +495,18 @@  discard block
 block discarded – undo
495 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) {
500
+    if ($this->do_debug >= 2) {
501 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 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) {
508
+              "smtp_msg" => substr($rply, 4));
509
+      if ($this->do_debug >= 1) {
510 510
         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
511 511
       }
512 512
       return false;
@@ -534,28 +534,28 @@  discard block
 block discarded – undo
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) {
549
+    if ($this->do_debug >= 2) {
550 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) {
557
+              "smtp_msg" => substr($rply, 4));
558
+      if ($this->do_debug >= 1) {
559 559
         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
560 560
       }
561 561
       return false;
@@ -574,41 +574,41 @@  discard block
 block discarded – undo
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) {
592
+    if ($this->do_debug >= 2) {
593 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) {
606
+      if ($this->do_debug >= 1) {
607 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,27 +630,27 @@  discard block
 block discarded – undo
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) {
644
+    if ($this->do_debug >= 2) {
645 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) {
652
+              "smtp_msg" => substr($rply, 4));
653
+      if ($this->do_debug >= 1) {
654 654
         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
655 655
       }
656 656
       return false;
@@ -673,27 +673,27 @@  discard block
 block discarded – undo
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) {
687
+    if ($this->do_debug >= 2) {
688 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) {
695
+              "smtp_msg" => substr($rply, 4));
696
+      if ($this->do_debug >= 1) {
697 697
         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
698 698
       }
699 699
       return false;
@@ -721,27 +721,27 @@  discard block
 block discarded – undo
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) {
735
+    if ($this->do_debug >= 2) {
736 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) {
743
+              "smtp_msg" => substr($rply, 4));
744
+      if ($this->do_debug >= 1) {
745 745
         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
746 746
       }
747 747
       return false;
@@ -763,9 +763,9 @@  discard block
 block discarded – undo
763 763
    * @return bool
764 764
    */
765 765
   public function Turn() {
766
-    $this->error = array("error" => "This method, TURN, of the SMTP ".
766
+    $this->error = array("error" => "This method, TURN, of the SMTP " .
767 767
                                     "is not implemented");
768
-    if($this->do_debug >= 1) {
768
+    if ($this->do_debug >= 1) {
769 769
       echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />';
770 770
     }
771 771
     return false;
@@ -795,17 +795,17 @@  discard block
 block discarded – undo
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) {
798
+    while ($str = @fgets($this->smtp_conn, 515)) {
799
+      if ($this->do_debug >= 4) {
800 800
         echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />';
801 801
         echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />';
802 802
       }
803 803
       $data .= $str;
804
-      if($this->do_debug >= 4) {
804
+      if ($this->do_debug >= 4) {
805 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
   }
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -143,8 +143,9 @@
 block discarded – undo
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();
Please login to merge, or discard this patch.
libs/tar.class.php 4 patches
Doc Comments   +24 added lines patch added patch discarded remove patch
@@ -84,6 +84,10 @@  discard block
 block discarded – undo
84 84
     // Computes the unsigned Checksum of a file's header
85 85
     // to try to ensure valid file
86 86
     // PRIVATE ACCESS FUNCTION
87
+
88
+    /**
89
+     * @param string $bytestring
90
+     */
87 91
     function __computeUnsignedChecksum($bytestring) {
88 92
         for($i=0; $i<512; $i++)
89 93
             $unsigned_chksum += ord($bytestring[$i]);
@@ -97,6 +101,10 @@  discard block
 block discarded – undo
97 101
 
98 102
     // Converts a NULL padded string to a non-NULL padded string
99 103
     // PRIVATE ACCESS FUNCTION
104
+
105
+    /**
106
+     * @param string $string
107
+     */
100 108
     function __parseNullPaddedString($string) {
101 109
         $position = strpos($string,chr(0));
102 110
 		if(!$position)
@@ -357,6 +365,10 @@  discard block
 block discarded – undo
357 365
 
358 366
 
359 367
     // Open a TAR file
368
+
369
+    /**
370
+     * @param string $filename
371
+     */
360 372
     function openTAR($filename) {
361 373
         // Clear any values from previous tar archives
362 374
         unset($this->filename);
@@ -393,6 +405,10 @@  discard block
 block discarded – undo
393 405
 
394 406
 
395 407
     // Retrieves information about a file in the current tar archive
408
+
409
+    /**
410
+     * @param string $filename
411
+     */
396 412
     function getFile($filename) {
397 413
         if($this->numFiles > 0) {
398 414
             foreach($this->files as $key => $information) {
@@ -467,6 +483,10 @@  discard block
 block discarded – undo
467 483
 
468 484
 
469 485
     // Add a file to the tar archive
486
+
487
+    /**
488
+     * @param string $filename
489
+     */
470 490
     function addFile($filename,$from=null,$to=null) {
471 491
         // Make sure the file we are adding exists!
472 492
         if(!file_exists($filename))
@@ -555,6 +575,10 @@  discard block
 block discarded – undo
555 575
 
556 576
 
557 577
     // Saves tar archive to a different file than the current file
578
+
579
+    /**
580
+     * @param boolean $useGzip
581
+     */
558 582
     function toTar($filename,$useGzip) {
559 583
         if(!$filename)
560 584
             return false;
Please login to merge, or discard this patch.
Indentation   +431 added lines, -431 removed lines patch added patch discarded remove patch
@@ -63,99 +63,99 @@  discard block
 block discarded – undo
63 63
 */
64 64
 
65 65
 class tar {
66
-    // Unprocessed Archive Information
67
-    var $filename;
68
-    var $isGzipped;
69
-    var $tar_file;
70
-
71
-    // Processed Archive Information
72
-    var $files;
73
-    var $directories;
74
-    var $numFiles;
75
-    var $numDirectories;
76
-
77
-
78
-    // Class Constructor -- Does nothing...
79
-    function tar() {
80
-        return true;
81
-    }
82
-
83
-
84
-    // Computes the unsigned Checksum of a file's header
85
-    // to try to ensure valid file
86
-    // PRIVATE ACCESS FUNCTION
87
-    function __computeUnsignedChecksum($bytestring) {
88
-        for($i=0; $i<512; $i++)
89
-            $unsigned_chksum += ord($bytestring[$i]);
90
-        for($i=0; $i<8; $i++)
91
-            $unsigned_chksum -= ord($bytestring[148 + $i]);
92
-        $unsigned_chksum += ord(" ") * 8;
93
-
94
-        return $unsigned_chksum;
95
-    }
96
-
97
-
98
-    // Converts a NULL padded string to a non-NULL padded string
99
-    // PRIVATE ACCESS FUNCTION
100
-    function __parseNullPaddedString($string) {
101
-        $position = strpos($string,chr(0));
66
+	// Unprocessed Archive Information
67
+	var $filename;
68
+	var $isGzipped;
69
+	var $tar_file;
70
+
71
+	// Processed Archive Information
72
+	var $files;
73
+	var $directories;
74
+	var $numFiles;
75
+	var $numDirectories;
76
+
77
+
78
+	// Class Constructor -- Does nothing...
79
+	function tar() {
80
+		return true;
81
+	}
82
+
83
+
84
+	// Computes the unsigned Checksum of a file's header
85
+	// to try to ensure valid file
86
+	// PRIVATE ACCESS FUNCTION
87
+	function __computeUnsignedChecksum($bytestring) {
88
+		for($i=0; $i<512; $i++)
89
+			$unsigned_chksum += ord($bytestring[$i]);
90
+		for($i=0; $i<8; $i++)
91
+			$unsigned_chksum -= ord($bytestring[148 + $i]);
92
+		$unsigned_chksum += ord(" ") * 8;
93
+
94
+		return $unsigned_chksum;
95
+	}
96
+
97
+
98
+	// Converts a NULL padded string to a non-NULL padded string
99
+	// PRIVATE ACCESS FUNCTION
100
+	function __parseNullPaddedString($string) {
101
+		$position = strpos($string,chr(0));
102 102
 		if(!$position)
103 103
 		{
104 104
 			$position = strlen($string);
105 105
 		}
106
-        return substr($string,0,$position);
107
-    }
106
+		return substr($string,0,$position);
107
+	}
108 108
 
109 109
 
110
-    // This function parses the current TAR file
111
-    // PRIVATE ACCESS FUNCTION
112
-    function __parseTar() {
113
-        // Read Files from archive
114
-        $tar_length = strlen($this->tar_file);
115
-        $main_offset = 0;
110
+	// This function parses the current TAR file
111
+	// PRIVATE ACCESS FUNCTION
112
+	function __parseTar() {
113
+		// Read Files from archive
114
+		$tar_length = strlen($this->tar_file);
115
+		$main_offset = 0;
116 116
 		$flag_longlink = false;
117
-        while($main_offset < $tar_length) {
118
-            // If we read a block of 512 nulls, we are at the end of the archive
119
-            if(substr($this->tar_file,$main_offset,512) == str_repeat(chr(0),512))
120
-                break;
117
+		while($main_offset < $tar_length) {
118
+			// If we read a block of 512 nulls, we are at the end of the archive
119
+			if(substr($this->tar_file,$main_offset,512) == str_repeat(chr(0),512))
120
+				break;
121 121
 
122
-            // Parse file name
123
-            $file_name      = $this->__parseNullPaddedString(substr($this->tar_file,$main_offset,100));
122
+			// Parse file name
123
+			$file_name      = $this->__parseNullPaddedString(substr($this->tar_file,$main_offset,100));
124 124
 
125
-            // Parse the file mode
126
-            $file_mode      = substr($this->tar_file,$main_offset + 100,8);
125
+			// Parse the file mode
126
+			$file_mode      = substr($this->tar_file,$main_offset + 100,8);
127 127
 
128
-            // Parse the file user ID
129
-            $file_uid       = octdec(substr($this->tar_file,$main_offset + 108,8));
128
+			// Parse the file user ID
129
+			$file_uid       = octdec(substr($this->tar_file,$main_offset + 108,8));
130 130
 
131
-            // Parse the file group ID
132
-            $file_gid       = octdec(substr($this->tar_file,$main_offset + 116,8));
131
+			// Parse the file group ID
132
+			$file_gid       = octdec(substr($this->tar_file,$main_offset + 116,8));
133 133
 
134
-            // Parse the file size
135
-            $file_size      = octdec(substr($this->tar_file,$main_offset + 124,12));
134
+			// Parse the file size
135
+			$file_size      = octdec(substr($this->tar_file,$main_offset + 124,12));
136 136
 
137
-            // Parse the file update time - unix timestamp format
138
-            $file_time      = octdec(substr($this->tar_file,$main_offset + 136,12));
137
+			// Parse the file update time - unix timestamp format
138
+			$file_time      = octdec(substr($this->tar_file,$main_offset + 136,12));
139 139
 
140
-            // Parse Checksum
141
-            $file_chksum        = octdec(substr($this->tar_file,$main_offset + 148,6));
140
+			// Parse Checksum
141
+			$file_chksum        = octdec(substr($this->tar_file,$main_offset + 148,6));
142 142
 
143
-            // Parse user name
144
-            $file_uname     = $this->__parseNullPaddedString(substr($this->tar_file,$main_offset + 265,32));
143
+			// Parse user name
144
+			$file_uname     = $this->__parseNullPaddedString(substr($this->tar_file,$main_offset + 265,32));
145 145
 
146
-            // Parse Group name
147
-            $file_gname     = $this->__parseNullPaddedString(substr($this->tar_file,$main_offset + 297,32));
146
+			// Parse Group name
147
+			$file_gname     = $this->__parseNullPaddedString(substr($this->tar_file,$main_offset + 297,32));
148 148
 
149
-            $file_type = substr($this->tar_file,$main_offset + 156,1);
149
+			$file_type = substr($this->tar_file,$main_offset + 156,1);
150 150
 
151
-            // Make sure our file is valid
152
-            if($this->__computeUnsignedChecksum(substr($this->tar_file,$main_offset,512)) != $file_chksum)
153
-                return false;
151
+			// Make sure our file is valid
152
+			if($this->__computeUnsignedChecksum(substr($this->tar_file,$main_offset,512)) != $file_chksum)
153
+				return false;
154 154
 
155
-            // Parse File Contents
156
-            $file_contents      = substr($this->tar_file,$main_offset + 512,$file_size);
155
+			// Parse File Contents
156
+			$file_contents      = substr($this->tar_file,$main_offset + 512,$file_size);
157 157
 
158
-            /*  ### Unused Header Information ###
158
+			/*  ### Unused Header Information ###
159 159
                 $activeFile["typeflag"]     = substr($this->tar_file,$main_offset + 156,1);
160 160
                 $activeFile["linkname"]     = substr($this->tar_file,$main_offset + 157,100);
161 161
                 $activeFile["magic"]        = substr($this->tar_file,$main_offset + 257,6);
@@ -228,363 +228,363 @@  discard block
 block discarded – undo
228 228
 				$flag_longlink = false;
229 229
 			}
230 230
 
231
-            // Move our offset the number of blocks we have processed
232
-            $main_offset += 512 + (ceil($file_size / 512) * 512);
233
-        }
234
-
235
-        return true;
236
-    }
237
-
238
-
239
-    // Read a non gzipped tar file in for processing
240
-    // PRIVATE ACCESS FUNCTION
241
-    function __readTar($filename='') {
242
-        // Set the filename to load
243
-        if(!$filename)
244
-            $filename = $this->filename;
245
-
246
-        // Read in the TAR file
247
-        $fp = fopen($filename,"rb");
248
-        $this->tar_file = fread($fp,filesize($filename));
249
-        fclose($fp);
250
-
251
-        if($this->tar_file[0] == chr(31) && $this->tar_file[1] == chr(139) && $this->tar_file[2] == chr(8)) {
252
-            if(!function_exists("gzinflate"))
253
-                return false;
254
-
255
-            $this->isGzipped = TRUE;
256
-
257
-            $this->tar_file = gzinflate(substr($this->tar_file,10,-4));
258
-        }
259
-
260
-        // Parse the TAR file
261
-        $this->__parseTar();
262
-
263
-        return true;
264
-    }
265
-
266
-
267
-    // Generates a TAR file from the processed data
268
-    // PRIVATE ACCESS FUNCTION
269
-    function __generateTAR() {
270
-        // Clear any data currently in $this->tar_file
271
-        unset($this->tar_file);
272
-
273
-        // Generate Records for each directory, if we have directories
274
-        if($this->numDirectories > 0) {
275
-            foreach($this->directories as $key => $information) {
276
-                unset($header);
277
-
278
-                // Generate tar header for this directory
279
-                // Filename, Permissions, UID, GID, size, Time, checksum, typeflag, linkname, magic, version, user name, group name, devmajor, devminor, prefix, end
280
-                $header .= str_pad($information["name"],100,chr(0));
281
-                $header .= str_pad(decoct($information["mode"]),7,"0",STR_PAD_LEFT) . chr(0);
282
-                $header .= str_pad(decoct($information["user_id"]),7,"0",STR_PAD_LEFT) . chr(0);
283
-                $header .= str_pad(decoct($information["group_id"]),7,"0",STR_PAD_LEFT) . chr(0);
284
-                $header .= str_pad(decoct(0),11,"0",STR_PAD_LEFT) . chr(0);
285
-                $header .= str_pad(decoct($information["time"]),11,"0",STR_PAD_LEFT) . chr(0);
286
-                $header .= str_repeat(" ",8);
287
-                $header .= "5";
288
-                $header .= str_repeat(chr(0),100);
289
-                $header .= str_pad("ustar",6,chr(32));
290
-                $header .= chr(32) . chr(0);
291
-                $header .= str_pad("",32,chr(0));
292
-                $header .= str_pad("",32,chr(0));
293
-                $header .= str_repeat(chr(0),8);
294
-                $header .= str_repeat(chr(0),8);
295
-                $header .= str_repeat(chr(0),155);
296
-                $header .= str_repeat(chr(0),12);
297
-
298
-                // Compute header checksum
299
-                $checksum = str_pad(decoct($this->__computeUnsignedChecksum($header)),6,"0",STR_PAD_LEFT);
300
-                for($i=0; $i<6; $i++) {
301
-                    $header[(148 + $i)] = substr($checksum,$i,1);
302
-                }
303
-                $header[154] = chr(0);
304
-                $header[155] = chr(32);
305
-
306
-                // Add new tar formatted data to tar file contents
307
-                $this->tar_file .= $header;
308
-            }
309
-        }
310
-
311
-        // Generate Records for each file, if we have files (We should...)
312
-        if($this->numFiles > 0) {
313
-            foreach($this->files as $key => $information) {
314
-                unset($header);
315
-
316
-                // Generate the TAR header for this file
317
-                // Filename, Permissions, UID, GID, size, Time, checksum, typeflag, linkname, magic, version, user name, group name, devmajor, devminor, prefix, end
318
-                $header .= str_pad($information["name"],100,chr(0));
319
-                $header .= str_pad(decoct($information["mode"]),7,"0",STR_PAD_LEFT) . chr(0);
320
-                $header .= str_pad(decoct($information["user_id"]),7,"0",STR_PAD_LEFT) . chr(0);
321
-                $header .= str_pad(decoct($information["group_id"]),7,"0",STR_PAD_LEFT) . chr(0);
322
-                $header .= str_pad(decoct($information["size"]),11,"0",STR_PAD_LEFT) . chr(0);
323
-                $header .= str_pad(decoct($information["time"]),11,"0",STR_PAD_LEFT) . chr(0);
324
-                $header .= str_repeat(" ",8);
325
-                $header .= "0";
326
-                $header .= str_repeat(chr(0),100);
327
-                $header .= str_pad("ustar",6,chr(32));
328
-                $header .= chr(32) . chr(0);
329
-                $header .= str_pad($information["user_name"],32,chr(0));    // How do I get a file's user name from PHP?
330
-                $header .= str_pad($information["group_name"],32,chr(0));   // How do I get a file's group name from PHP?
331
-                $header .= str_repeat(chr(0),8);
332
-                $header .= str_repeat(chr(0),8);
333
-                $header .= str_repeat(chr(0),155);
334
-                $header .= str_repeat(chr(0),12);
335
-
336
-                // Compute header checksum
337
-                $checksum = str_pad(decoct($this->__computeUnsignedChecksum($header)),6,"0",STR_PAD_LEFT);
338
-                for($i=0; $i<6; $i++) {
339
-                    $header[(148 + $i)] = substr($checksum,$i,1);
340
-                }
341
-                $header[154] = chr(0);
342
-                $header[155] = chr(32);
343
-
344
-                // Pad file contents to byte count divisible by 512
345
-                $file_contents = str_pad($information["file"],(ceil($information["size"] / 512) * 512),chr(0));
346
-
347
-                // Add new tar formatted data to tar file contents
348
-                $this->tar_file .= $header . $file_contents;
349
-            }
350
-        }
351
-
352
-        // Add 512 bytes of NULLs to designate EOF
353
-        $this->tar_file .= str_repeat(chr(0),512);
354
-
355
-        return true;
356
-    }
357
-
358
-
359
-    // Open a TAR file
360
-    function openTAR($filename) {
361
-        // Clear any values from previous tar archives
362
-        unset($this->filename);
363
-        unset($this->isGzipped);
364
-        unset($this->tar_file);
365
-        unset($this->files);
366
-        unset($this->directories);
367
-        unset($this->numFiles);
368
-        unset($this->numDirectories);
369
-
370
-        // If the tar file doesn't exist...
371
-        if(!file_exists($filename))
372
-            return false;
373
-
374
-        $this->filename = $filename;
375
-
376
-        // Parse this file
377
-        $this->__readTar();
378
-
379
-        return true;
380
-    }
381
-
382
-
383
-    // Appends a tar file to the end of the currently opened tar file
384
-    function appendTar($filename) {
385
-        // If the tar file doesn't exist...
386
-        if(!file_exists($filename))
387
-            return false;
388
-
389
-        $this->__readTar($filename);
390
-
391
-        return true;
392
-    }
393
-
394
-
395
-    // Retrieves information about a file in the current tar archive
396
-    function getFile($filename) {
397
-        if($this->numFiles > 0) {
398
-            foreach($this->files as $key => $information) {
399
-                if($information["name"] == $filename)
400
-                    return $information;
401
-            }
402
-        }
403
-
404
-        return false;
405
-    }
406
-
407
-
408
-    // Retrieves information about a directory in the current tar archive
409
-    function getDirectory($dirname) {
410
-        if($this->numDirectories > 0) {
411
-            foreach($this->directories as $key => $information) {
412
-                if($information["name"] == $dirname)
413
-                    return $information;
414
-            }
415
-        }
416
-
417
-        return false;
418
-    }
419
-
420
-
421
-    // Check if this tar archive contains a specific file
422
-    function containsFile($filename) {
423
-        if($this->numFiles > 0) {
424
-            foreach($this->files as $key => $information) {
425
-                if($information["name"] == $filename)
426
-                    return true;
427
-            }
428
-        }
429
-
430
-        return false;
431
-    }
432
-
433
-
434
-    // Check if this tar archive contains a specific directory
435
-    function containsDirectory($dirname) {
436
-        if($this->numDirectories > 0) {
437
-            foreach($this->directories as $key => $information) {
438
-                if($information["name"] == $dirname)
439
-                    return true;
440
-            }
441
-        }
442
-
443
-        return false;
444
-    }
445
-
446
-
447
-    // Add a directory to this tar archive
448
-    function addDirectory($dirname) {
449
-        if(!file_exists($dirname))
450
-            return false;
451
-
452
-        // Get directory information
453
-        $file_information = stat($dirname);
454
-
455
-        // Add directory to processed data
456
-        $this->numDirectories++;
457
-        $activeDir      = &$this->directories[];
458
-        $activeDir["name"]  = $dirname;
459
-        $activeDir["mode"]  = $file_information["mode"];
460
-        $activeDir["time"]  = $file_information["time"];
461
-        $activeDir["user_id"]   = $file_information["uid"];
462
-        $activeDir["group_id"]  = $file_information["gid"];
463
-        $activeDir["checksum"]  = $checksum;
464
-
465
-        return true;
466
-    }
467
-
468
-
469
-    // Add a file to the tar archive
470
-    function addFile($filename,$from=null,$to=null) {
471
-        // Make sure the file we are adding exists!
472
-        if(!file_exists($filename))
473
-            return false;
474
-
475
-        if(filesize($filename)==0)
476
-            return false;
477
-
478
-        // Make sure there are no other files in the archive that have this same filename
479
-        if($this->containsFile($filename))
480
-            return false;
481
-
482
-        // Get file information
483
-        $file_information = stat($filename);
484
-
485
-        // Read in the file's contents
486
-        $fp = fopen($filename,"rb");
487
-        $file_contents = fread($fp,filesize($filename));
488
-        fclose($fp);
489
-
490
-        if($from && $to){
491
-            $file_contents = str_replace($from,$to,$file_contents);
492
-            $file_information["size"] = strlen($file_contents);
493
-        }
494
-
495
-        // Add file to processed data
496
-        $this->numFiles++;
497
-        $activeFile         = &$this->files[];
498
-        $activeFile["name"]     = $filename;
499
-        $activeFile["mode"]     = $file_information["mode"];
500
-        $activeFile["user_id"]      = $file_information["uid"];
501
-        $activeFile["group_id"]     = $file_information["gid"];
502
-        $activeFile["size"]     = $file_information["size"];
503
-        $activeFile["time"]     = $file_information["mtime"];
504
-        $activeFile["checksum"]     = $checksum;
505
-        $activeFile["user_name"]    = "";
506
-        $activeFile["group_name"]   = "";
507
-        $activeFile["file"]     = $file_contents;
508
-
509
-        return true;
510
-    }
511
-
512
-
513
-    // Remove a file from the tar archive
514
-    function removeFile($filename) {
515
-        if($this->numFiles > 0) {
516
-            foreach($this->files as $key => $information) {
517
-                if($information["name"] == $filename) {
518
-                    $this->numFiles--;
519
-                    unset($this->files[$key]);
520
-                    return true;
521
-                }
522
-            }
523
-        }
524
-
525
-        return false;
526
-    }
527
-
528
-
529
-    // Remove a directory from the tar archive
530
-    function removeDirectory($dirname) {
531
-        if($this->numDirectories > 0) {
532
-            foreach($this->directories as $key => $information) {
533
-                if($information["name"] == $dirname) {
534
-                    $this->numDirectories--;
535
-                    unset($this->directories[$key]);
536
-                    return true;
537
-                }
538
-            }
539
-        }
540
-
541
-        return false;
542
-    }
543
-
544
-
545
-    // Write the currently loaded tar archive to disk
546
-    function saveTar() {
547
-        if(!$this->filename)
548
-            return false;
549
-
550
-        // Write tar to current file using specified gzip compression
551
-        $this->toTar($this->filename,$this->isGzipped);
552
-
553
-        return true;
554
-    }
555
-
556
-
557
-    // Saves tar archive to a different file than the current file
558
-    function toTar($filename,$useGzip) {
559
-        if(!$filename)
560
-            return false;
561
-
562
-        // Encode processed files into TAR file format
563
-        $this->__generateTar();
564
-
565
-        // GZ Compress the data if we need to
566
-        if($useGzip) {
567
-            // Make sure we have gzip support
568
-            if(!function_exists("gzencode"))
569
-                return false;
570
-
571
-            $file = gzencode($this->tar_file);
572
-        } else {
573
-            $file = $this->tar_file;
574
-        }
575
-
576
-        // Write the TAR file
577
-        $fp = fopen($filename,"wb");
578
-        fwrite($fp,$file);
579
-        fclose($fp);
580
-
581
-        return true;
582
-    }
583
-
584
-
585
-    function toTarStream() {
586
-        $this->__generateTar();
587
-        return $this->tar_file;
588
-    }
231
+			// Move our offset the number of blocks we have processed
232
+			$main_offset += 512 + (ceil($file_size / 512) * 512);
233
+		}
234
+
235
+		return true;
236
+	}
237
+
238
+
239
+	// Read a non gzipped tar file in for processing
240
+	// PRIVATE ACCESS FUNCTION
241
+	function __readTar($filename='') {
242
+		// Set the filename to load
243
+		if(!$filename)
244
+			$filename = $this->filename;
245
+
246
+		// Read in the TAR file
247
+		$fp = fopen($filename,"rb");
248
+		$this->tar_file = fread($fp,filesize($filename));
249
+		fclose($fp);
250
+
251
+		if($this->tar_file[0] == chr(31) && $this->tar_file[1] == chr(139) && $this->tar_file[2] == chr(8)) {
252
+			if(!function_exists("gzinflate"))
253
+				return false;
254
+
255
+			$this->isGzipped = TRUE;
256
+
257
+			$this->tar_file = gzinflate(substr($this->tar_file,10,-4));
258
+		}
259
+
260
+		// Parse the TAR file
261
+		$this->__parseTar();
262
+
263
+		return true;
264
+	}
265
+
266
+
267
+	// Generates a TAR file from the processed data
268
+	// PRIVATE ACCESS FUNCTION
269
+	function __generateTAR() {
270
+		// Clear any data currently in $this->tar_file
271
+		unset($this->tar_file);
272
+
273
+		// Generate Records for each directory, if we have directories
274
+		if($this->numDirectories > 0) {
275
+			foreach($this->directories as $key => $information) {
276
+				unset($header);
277
+
278
+				// Generate tar header for this directory
279
+				// Filename, Permissions, UID, GID, size, Time, checksum, typeflag, linkname, magic, version, user name, group name, devmajor, devminor, prefix, end
280
+				$header .= str_pad($information["name"],100,chr(0));
281
+				$header .= str_pad(decoct($information["mode"]),7,"0",STR_PAD_LEFT) . chr(0);
282
+				$header .= str_pad(decoct($information["user_id"]),7,"0",STR_PAD_LEFT) . chr(0);
283
+				$header .= str_pad(decoct($information["group_id"]),7,"0",STR_PAD_LEFT) . chr(0);
284
+				$header .= str_pad(decoct(0),11,"0",STR_PAD_LEFT) . chr(0);
285
+				$header .= str_pad(decoct($information["time"]),11,"0",STR_PAD_LEFT) . chr(0);
286
+				$header .= str_repeat(" ",8);
287
+				$header .= "5";
288
+				$header .= str_repeat(chr(0),100);
289
+				$header .= str_pad("ustar",6,chr(32));
290
+				$header .= chr(32) . chr(0);
291
+				$header .= str_pad("",32,chr(0));
292
+				$header .= str_pad("",32,chr(0));
293
+				$header .= str_repeat(chr(0),8);
294
+				$header .= str_repeat(chr(0),8);
295
+				$header .= str_repeat(chr(0),155);
296
+				$header .= str_repeat(chr(0),12);
297
+
298
+				// Compute header checksum
299
+				$checksum = str_pad(decoct($this->__computeUnsignedChecksum($header)),6,"0",STR_PAD_LEFT);
300
+				for($i=0; $i<6; $i++) {
301
+					$header[(148 + $i)] = substr($checksum,$i,1);
302
+				}
303
+				$header[154] = chr(0);
304
+				$header[155] = chr(32);
305
+
306
+				// Add new tar formatted data to tar file contents
307
+				$this->tar_file .= $header;
308
+			}
309
+		}
310
+
311
+		// Generate Records for each file, if we have files (We should...)
312
+		if($this->numFiles > 0) {
313
+			foreach($this->files as $key => $information) {
314
+				unset($header);
315
+
316
+				// Generate the TAR header for this file
317
+				// Filename, Permissions, UID, GID, size, Time, checksum, typeflag, linkname, magic, version, user name, group name, devmajor, devminor, prefix, end
318
+				$header .= str_pad($information["name"],100,chr(0));
319
+				$header .= str_pad(decoct($information["mode"]),7,"0",STR_PAD_LEFT) . chr(0);
320
+				$header .= str_pad(decoct($information["user_id"]),7,"0",STR_PAD_LEFT) . chr(0);
321
+				$header .= str_pad(decoct($information["group_id"]),7,"0",STR_PAD_LEFT) . chr(0);
322
+				$header .= str_pad(decoct($information["size"]),11,"0",STR_PAD_LEFT) . chr(0);
323
+				$header .= str_pad(decoct($information["time"]),11,"0",STR_PAD_LEFT) . chr(0);
324
+				$header .= str_repeat(" ",8);
325
+				$header .= "0";
326
+				$header .= str_repeat(chr(0),100);
327
+				$header .= str_pad("ustar",6,chr(32));
328
+				$header .= chr(32) . chr(0);
329
+				$header .= str_pad($information["user_name"],32,chr(0));    // How do I get a file's user name from PHP?
330
+				$header .= str_pad($information["group_name"],32,chr(0));   // How do I get a file's group name from PHP?
331
+				$header .= str_repeat(chr(0),8);
332
+				$header .= str_repeat(chr(0),8);
333
+				$header .= str_repeat(chr(0),155);
334
+				$header .= str_repeat(chr(0),12);
335
+
336
+				// Compute header checksum
337
+				$checksum = str_pad(decoct($this->__computeUnsignedChecksum($header)),6,"0",STR_PAD_LEFT);
338
+				for($i=0; $i<6; $i++) {
339
+					$header[(148 + $i)] = substr($checksum,$i,1);
340
+				}
341
+				$header[154] = chr(0);
342
+				$header[155] = chr(32);
343
+
344
+				// Pad file contents to byte count divisible by 512
345
+				$file_contents = str_pad($information["file"],(ceil($information["size"] / 512) * 512),chr(0));
346
+
347
+				// Add new tar formatted data to tar file contents
348
+				$this->tar_file .= $header . $file_contents;
349
+			}
350
+		}
351
+
352
+		// Add 512 bytes of NULLs to designate EOF
353
+		$this->tar_file .= str_repeat(chr(0),512);
354
+
355
+		return true;
356
+	}
357
+
358
+
359
+	// Open a TAR file
360
+	function openTAR($filename) {
361
+		// Clear any values from previous tar archives
362
+		unset($this->filename);
363
+		unset($this->isGzipped);
364
+		unset($this->tar_file);
365
+		unset($this->files);
366
+		unset($this->directories);
367
+		unset($this->numFiles);
368
+		unset($this->numDirectories);
369
+
370
+		// If the tar file doesn't exist...
371
+		if(!file_exists($filename))
372
+			return false;
373
+
374
+		$this->filename = $filename;
375
+
376
+		// Parse this file
377
+		$this->__readTar();
378
+
379
+		return true;
380
+	}
381
+
382
+
383
+	// Appends a tar file to the end of the currently opened tar file
384
+	function appendTar($filename) {
385
+		// If the tar file doesn't exist...
386
+		if(!file_exists($filename))
387
+			return false;
388
+
389
+		$this->__readTar($filename);
390
+
391
+		return true;
392
+	}
393
+
394
+
395
+	// Retrieves information about a file in the current tar archive
396
+	function getFile($filename) {
397
+		if($this->numFiles > 0) {
398
+			foreach($this->files as $key => $information) {
399
+				if($information["name"] == $filename)
400
+					return $information;
401
+			}
402
+		}
403
+
404
+		return false;
405
+	}
406
+
407
+
408
+	// Retrieves information about a directory in the current tar archive
409
+	function getDirectory($dirname) {
410
+		if($this->numDirectories > 0) {
411
+			foreach($this->directories as $key => $information) {
412
+				if($information["name"] == $dirname)
413
+					return $information;
414
+			}
415
+		}
416
+
417
+		return false;
418
+	}
419
+
420
+
421
+	// Check if this tar archive contains a specific file
422
+	function containsFile($filename) {
423
+		if($this->numFiles > 0) {
424
+			foreach($this->files as $key => $information) {
425
+				if($information["name"] == $filename)
426
+					return true;
427
+			}
428
+		}
429
+
430
+		return false;
431
+	}
432
+
433
+
434
+	// Check if this tar archive contains a specific directory
435
+	function containsDirectory($dirname) {
436
+		if($this->numDirectories > 0) {
437
+			foreach($this->directories as $key => $information) {
438
+				if($information["name"] == $dirname)
439
+					return true;
440
+			}
441
+		}
442
+
443
+		return false;
444
+	}
445
+
446
+
447
+	// Add a directory to this tar archive
448
+	function addDirectory($dirname) {
449
+		if(!file_exists($dirname))
450
+			return false;
451
+
452
+		// Get directory information
453
+		$file_information = stat($dirname);
454
+
455
+		// Add directory to processed data
456
+		$this->numDirectories++;
457
+		$activeDir      = &$this->directories[];
458
+		$activeDir["name"]  = $dirname;
459
+		$activeDir["mode"]  = $file_information["mode"];
460
+		$activeDir["time"]  = $file_information["time"];
461
+		$activeDir["user_id"]   = $file_information["uid"];
462
+		$activeDir["group_id"]  = $file_information["gid"];
463
+		$activeDir["checksum"]  = $checksum;
464
+
465
+		return true;
466
+	}
467
+
468
+
469
+	// Add a file to the tar archive
470
+	function addFile($filename,$from=null,$to=null) {
471
+		// Make sure the file we are adding exists!
472
+		if(!file_exists($filename))
473
+			return false;
474
+
475
+		if(filesize($filename)==0)
476
+			return false;
477
+
478
+		// Make sure there are no other files in the archive that have this same filename
479
+		if($this->containsFile($filename))
480
+			return false;
481
+
482
+		// Get file information
483
+		$file_information = stat($filename);
484
+
485
+		// Read in the file's contents
486
+		$fp = fopen($filename,"rb");
487
+		$file_contents = fread($fp,filesize($filename));
488
+		fclose($fp);
489
+
490
+		if($from && $to){
491
+			$file_contents = str_replace($from,$to,$file_contents);
492
+			$file_information["size"] = strlen($file_contents);
493
+		}
494
+
495
+		// Add file to processed data
496
+		$this->numFiles++;
497
+		$activeFile         = &$this->files[];
498
+		$activeFile["name"]     = $filename;
499
+		$activeFile["mode"]     = $file_information["mode"];
500
+		$activeFile["user_id"]      = $file_information["uid"];
501
+		$activeFile["group_id"]     = $file_information["gid"];
502
+		$activeFile["size"]     = $file_information["size"];
503
+		$activeFile["time"]     = $file_information["mtime"];
504
+		$activeFile["checksum"]     = $checksum;
505
+		$activeFile["user_name"]    = "";
506
+		$activeFile["group_name"]   = "";
507
+		$activeFile["file"]     = $file_contents;
508
+
509
+		return true;
510
+	}
511
+
512
+
513
+	// Remove a file from the tar archive
514
+	function removeFile($filename) {
515
+		if($this->numFiles > 0) {
516
+			foreach($this->files as $key => $information) {
517
+				if($information["name"] == $filename) {
518
+					$this->numFiles--;
519
+					unset($this->files[$key]);
520
+					return true;
521
+				}
522
+			}
523
+		}
524
+
525
+		return false;
526
+	}
527
+
528
+
529
+	// Remove a directory from the tar archive
530
+	function removeDirectory($dirname) {
531
+		if($this->numDirectories > 0) {
532
+			foreach($this->directories as $key => $information) {
533
+				if($information["name"] == $dirname) {
534
+					$this->numDirectories--;
535
+					unset($this->directories[$key]);
536
+					return true;
537
+				}
538
+			}
539
+		}
540
+
541
+		return false;
542
+	}
543
+
544
+
545
+	// Write the currently loaded tar archive to disk
546
+	function saveTar() {
547
+		if(!$this->filename)
548
+			return false;
549
+
550
+		// Write tar to current file using specified gzip compression
551
+		$this->toTar($this->filename,$this->isGzipped);
552
+
553
+		return true;
554
+	}
555
+
556
+
557
+	// Saves tar archive to a different file than the current file
558
+	function toTar($filename,$useGzip) {
559
+		if(!$filename)
560
+			return false;
561
+
562
+		// Encode processed files into TAR file format
563
+		$this->__generateTar();
564
+
565
+		// GZ Compress the data if we need to
566
+		if($useGzip) {
567
+			// Make sure we have gzip support
568
+			if(!function_exists("gzencode"))
569
+				return false;
570
+
571
+			$file = gzencode($this->tar_file);
572
+		} else {
573
+			$file = $this->tar_file;
574
+		}
575
+
576
+		// Write the TAR file
577
+		$fp = fopen($filename,"wb");
578
+		fwrite($fp,$file);
579
+		fclose($fp);
580
+
581
+		return true;
582
+	}
583
+
584
+
585
+	function toTarStream() {
586
+		$this->__generateTar();
587
+		return $this->tar_file;
588
+	}
589 589
 }
590 590
 ?>
Please login to merge, or discard this patch.
Spacing   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
     // to try to ensure valid file
86 86
     // PRIVATE ACCESS FUNCTION
87 87
     function __computeUnsignedChecksum($bytestring) {
88
-        for($i=0; $i<512; $i++)
88
+        for ($i = 0; $i < 512; $i++)
89 89
             $unsigned_chksum += ord($bytestring[$i]);
90
-        for($i=0; $i<8; $i++)
90
+        for ($i = 0; $i < 8; $i++)
91 91
             $unsigned_chksum -= ord($bytestring[148 + $i]);
92 92
         $unsigned_chksum += ord(" ") * 8;
93 93
 
@@ -98,12 +98,12 @@  discard block
 block discarded – undo
98 98
     // Converts a NULL padded string to a non-NULL padded string
99 99
     // PRIVATE ACCESS FUNCTION
100 100
     function __parseNullPaddedString($string) {
101
-        $position = strpos($string,chr(0));
102
-		if(!$position)
101
+        $position = strpos($string, chr(0));
102
+		if (!$position)
103 103
 		{
104 104
 			$position = strlen($string);
105 105
 		}
106
-        return substr($string,0,$position);
106
+        return substr($string, 0, $position);
107 107
     }
108 108
 
109 109
 
@@ -114,46 +114,46 @@  discard block
 block discarded – undo
114 114
         $tar_length = strlen($this->tar_file);
115 115
         $main_offset = 0;
116 116
 		$flag_longlink = false;
117
-        while($main_offset < $tar_length) {
117
+        while ($main_offset < $tar_length) {
118 118
             // If we read a block of 512 nulls, we are at the end of the archive
119
-            if(substr($this->tar_file,$main_offset,512) == str_repeat(chr(0),512))
119
+            if (substr($this->tar_file, $main_offset, 512) == str_repeat(chr(0), 512))
120 120
                 break;
121 121
 
122 122
             // Parse file name
123
-            $file_name      = $this->__parseNullPaddedString(substr($this->tar_file,$main_offset,100));
123
+            $file_name      = $this->__parseNullPaddedString(substr($this->tar_file, $main_offset, 100));
124 124
 
125 125
             // Parse the file mode
126
-            $file_mode      = substr($this->tar_file,$main_offset + 100,8);
126
+            $file_mode      = substr($this->tar_file, $main_offset + 100, 8);
127 127
 
128 128
             // Parse the file user ID
129
-            $file_uid       = octdec(substr($this->tar_file,$main_offset + 108,8));
129
+            $file_uid       = octdec(substr($this->tar_file, $main_offset + 108, 8));
130 130
 
131 131
             // Parse the file group ID
132
-            $file_gid       = octdec(substr($this->tar_file,$main_offset + 116,8));
132
+            $file_gid       = octdec(substr($this->tar_file, $main_offset + 116, 8));
133 133
 
134 134
             // Parse the file size
135
-            $file_size      = octdec(substr($this->tar_file,$main_offset + 124,12));
135
+            $file_size      = octdec(substr($this->tar_file, $main_offset + 124, 12));
136 136
 
137 137
             // Parse the file update time - unix timestamp format
138
-            $file_time      = octdec(substr($this->tar_file,$main_offset + 136,12));
138
+            $file_time      = octdec(substr($this->tar_file, $main_offset + 136, 12));
139 139
 
140 140
             // Parse Checksum
141
-            $file_chksum        = octdec(substr($this->tar_file,$main_offset + 148,6));
141
+            $file_chksum = octdec(substr($this->tar_file, $main_offset + 148, 6));
142 142
 
143 143
             // Parse user name
144
-            $file_uname     = $this->__parseNullPaddedString(substr($this->tar_file,$main_offset + 265,32));
144
+            $file_uname     = $this->__parseNullPaddedString(substr($this->tar_file, $main_offset + 265, 32));
145 145
 
146 146
             // Parse Group name
147
-            $file_gname     = $this->__parseNullPaddedString(substr($this->tar_file,$main_offset + 297,32));
147
+            $file_gname     = $this->__parseNullPaddedString(substr($this->tar_file, $main_offset + 297, 32));
148 148
 
149
-            $file_type = substr($this->tar_file,$main_offset + 156,1);
149
+            $file_type = substr($this->tar_file, $main_offset + 156, 1);
150 150
 
151 151
             // Make sure our file is valid
152
-            if($this->__computeUnsignedChecksum(substr($this->tar_file,$main_offset,512)) != $file_chksum)
152
+            if ($this->__computeUnsignedChecksum(substr($this->tar_file, $main_offset, 512)) != $file_chksum)
153 153
                 return false;
154 154
 
155 155
             // Parse File Contents
156
-            $file_contents      = substr($this->tar_file,$main_offset + 512,$file_size);
156
+            $file_contents = substr($this->tar_file, $main_offset + 512, $file_size);
157 157
 
158 158
             /*  ### Unused Header Information ###
159 159
                 $activeFile["typeflag"]     = substr($this->tar_file,$main_offset + 156,1);
@@ -166,12 +166,12 @@  discard block
 block discarded – undo
166 166
                 $activeFile["endheader"]    = substr($this->tar_file,$main_offset + 500,12);
167 167
             */
168 168
 
169
-			if(strtolower($file_type) == 'l' || $file_name == '././@LongLink')
169
+			if (strtolower($file_type) == 'l' || $file_name == '././@LongLink')
170 170
 			{
171 171
 				$flag_longlink = true;
172 172
 				$longlink_name = $this->__parseNullPaddedString($file_contents);
173 173
 			}
174
-			elseif($file_type == '0') {
174
+			elseif ($file_type == '0') {
175 175
 				// Increment number of files
176 176
 				$this->numFiles++;
177 177
 
@@ -179,13 +179,13 @@  discard block
 block discarded – undo
179 179
 				$activeFile = &$this->files[];
180 180
 
181 181
 				// Asign Values
182
-				if($flag_longlink)
182
+				if ($flag_longlink)
183 183
 				{
184
-					$activeFile["name"]     = $longlink_name;
184
+					$activeFile["name"] = $longlink_name;
185 185
 				}
186 186
 				else
187 187
 				{
188
-					$activeFile["name"]     = $file_name;
188
+					$activeFile["name"] = $file_name;
189 189
 				}
190 190
 				$activeFile["type"]     = $file_type;
191 191
 				$activeFile["mode"]     = $file_mode;
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
 				$activeFile["user_name"]    = $file_uname;
197 197
 				$activeFile["group_name"]   = $file_gname;
198 198
 				$activeFile["checksum"]     = $file_chksum;
199
-				$activeFile["file"]     = $file_contents;
199
+				$activeFile["file"] = $file_contents;
200 200
 
201 201
 				$flag_longlink = false;
202 202
 
203
-			} elseif($file_type == '5') {
203
+			} elseif ($file_type == '5') {
204 204
 				// Increment number of directories
205 205
 				$this->numDirectories++;
206 206
 
@@ -208,9 +208,9 @@  discard block
 block discarded – undo
208 208
 				$activeDir = &$this->directories[];
209 209
 
210 210
 				// Assign values
211
-				if($flag_longlink)
211
+				if ($flag_longlink)
212 212
 				{
213
-					$activeDir["name"]     = $longlink_name;
213
+					$activeDir["name"] = $longlink_name;
214 214
 				}
215 215
 				else
216 216
 				{
@@ -238,23 +238,23 @@  discard block
 block discarded – undo
238 238
 
239 239
     // Read a non gzipped tar file in for processing
240 240
     // PRIVATE ACCESS FUNCTION
241
-    function __readTar($filename='') {
241
+    function __readTar($filename = '') {
242 242
         // Set the filename to load
243
-        if(!$filename)
243
+        if (!$filename)
244 244
             $filename = $this->filename;
245 245
 
246 246
         // Read in the TAR file
247
-        $fp = fopen($filename,"rb");
248
-        $this->tar_file = fread($fp,filesize($filename));
247
+        $fp = fopen($filename, "rb");
248
+        $this->tar_file = fread($fp, filesize($filename));
249 249
         fclose($fp);
250 250
 
251
-        if($this->tar_file[0] == chr(31) && $this->tar_file[1] == chr(139) && $this->tar_file[2] == chr(8)) {
252
-            if(!function_exists("gzinflate"))
251
+        if ($this->tar_file[0] == chr(31) && $this->tar_file[1] == chr(139) && $this->tar_file[2] == chr(8)) {
252
+            if (!function_exists("gzinflate"))
253 253
                 return false;
254 254
 
255 255
             $this->isGzipped = TRUE;
256 256
 
257
-            $this->tar_file = gzinflate(substr($this->tar_file,10,-4));
257
+            $this->tar_file = gzinflate(substr($this->tar_file, 10, -4));
258 258
         }
259 259
 
260 260
         // Parse the TAR file
@@ -271,34 +271,34 @@  discard block
 block discarded – undo
271 271
         unset($this->tar_file);
272 272
 
273 273
         // Generate Records for each directory, if we have directories
274
-        if($this->numDirectories > 0) {
275
-            foreach($this->directories as $key => $information) {
274
+        if ($this->numDirectories > 0) {
275
+            foreach ($this->directories as $key => $information) {
276 276
                 unset($header);
277 277
 
278 278
                 // Generate tar header for this directory
279 279
                 // Filename, Permissions, UID, GID, size, Time, checksum, typeflag, linkname, magic, version, user name, group name, devmajor, devminor, prefix, end
280
-                $header .= str_pad($information["name"],100,chr(0));
281
-                $header .= str_pad(decoct($information["mode"]),7,"0",STR_PAD_LEFT) . chr(0);
282
-                $header .= str_pad(decoct($information["user_id"]),7,"0",STR_PAD_LEFT) . chr(0);
283
-                $header .= str_pad(decoct($information["group_id"]),7,"0",STR_PAD_LEFT) . chr(0);
284
-                $header .= str_pad(decoct(0),11,"0",STR_PAD_LEFT) . chr(0);
285
-                $header .= str_pad(decoct($information["time"]),11,"0",STR_PAD_LEFT) . chr(0);
286
-                $header .= str_repeat(" ",8);
280
+                $header .= str_pad($information["name"], 100, chr(0));
281
+                $header .= str_pad(decoct($information["mode"]), 7, "0", STR_PAD_LEFT) . chr(0);
282
+                $header .= str_pad(decoct($information["user_id"]), 7, "0", STR_PAD_LEFT) . chr(0);
283
+                $header .= str_pad(decoct($information["group_id"]), 7, "0", STR_PAD_LEFT) . chr(0);
284
+                $header .= str_pad(decoct(0), 11, "0", STR_PAD_LEFT) . chr(0);
285
+                $header .= str_pad(decoct($information["time"]), 11, "0", STR_PAD_LEFT) . chr(0);
286
+                $header .= str_repeat(" ", 8);
287 287
                 $header .= "5";
288
-                $header .= str_repeat(chr(0),100);
289
-                $header .= str_pad("ustar",6,chr(32));
288
+                $header .= str_repeat(chr(0), 100);
289
+                $header .= str_pad("ustar", 6, chr(32));
290 290
                 $header .= chr(32) . chr(0);
291
-                $header .= str_pad("",32,chr(0));
292
-                $header .= str_pad("",32,chr(0));
293
-                $header .= str_repeat(chr(0),8);
294
-                $header .= str_repeat(chr(0),8);
295
-                $header .= str_repeat(chr(0),155);
296
-                $header .= str_repeat(chr(0),12);
291
+                $header .= str_pad("", 32, chr(0));
292
+                $header .= str_pad("", 32, chr(0));
293
+                $header .= str_repeat(chr(0), 8);
294
+                $header .= str_repeat(chr(0), 8);
295
+                $header .= str_repeat(chr(0), 155);
296
+                $header .= str_repeat(chr(0), 12);
297 297
 
298 298
                 // Compute header checksum
299
-                $checksum = str_pad(decoct($this->__computeUnsignedChecksum($header)),6,"0",STR_PAD_LEFT);
300
-                for($i=0; $i<6; $i++) {
301
-                    $header[(148 + $i)] = substr($checksum,$i,1);
299
+                $checksum = str_pad(decoct($this->__computeUnsignedChecksum($header)), 6, "0", STR_PAD_LEFT);
300
+                for ($i = 0; $i < 6; $i++) {
301
+                    $header[(148 + $i)] = substr($checksum, $i, 1);
302 302
                 }
303 303
                 $header[154] = chr(0);
304 304
                 $header[155] = chr(32);
@@ -309,40 +309,40 @@  discard block
 block discarded – undo
309 309
         }
310 310
 
311 311
         // Generate Records for each file, if we have files (We should...)
312
-        if($this->numFiles > 0) {
313
-            foreach($this->files as $key => $information) {
312
+        if ($this->numFiles > 0) {
313
+            foreach ($this->files as $key => $information) {
314 314
                 unset($header);
315 315
 
316 316
                 // Generate the TAR header for this file
317 317
                 // Filename, Permissions, UID, GID, size, Time, checksum, typeflag, linkname, magic, version, user name, group name, devmajor, devminor, prefix, end
318
-                $header .= str_pad($information["name"],100,chr(0));
319
-                $header .= str_pad(decoct($information["mode"]),7,"0",STR_PAD_LEFT) . chr(0);
320
-                $header .= str_pad(decoct($information["user_id"]),7,"0",STR_PAD_LEFT) . chr(0);
321
-                $header .= str_pad(decoct($information["group_id"]),7,"0",STR_PAD_LEFT) . chr(0);
322
-                $header .= str_pad(decoct($information["size"]),11,"0",STR_PAD_LEFT) . chr(0);
323
-                $header .= str_pad(decoct($information["time"]),11,"0",STR_PAD_LEFT) . chr(0);
324
-                $header .= str_repeat(" ",8);
318
+                $header .= str_pad($information["name"], 100, chr(0));
319
+                $header .= str_pad(decoct($information["mode"]), 7, "0", STR_PAD_LEFT) . chr(0);
320
+                $header .= str_pad(decoct($information["user_id"]), 7, "0", STR_PAD_LEFT) . chr(0);
321
+                $header .= str_pad(decoct($information["group_id"]), 7, "0", STR_PAD_LEFT) . chr(0);
322
+                $header .= str_pad(decoct($information["size"]), 11, "0", STR_PAD_LEFT) . chr(0);
323
+                $header .= str_pad(decoct($information["time"]), 11, "0", STR_PAD_LEFT) . chr(0);
324
+                $header .= str_repeat(" ", 8);
325 325
                 $header .= "0";
326
-                $header .= str_repeat(chr(0),100);
327
-                $header .= str_pad("ustar",6,chr(32));
326
+                $header .= str_repeat(chr(0), 100);
327
+                $header .= str_pad("ustar", 6, chr(32));
328 328
                 $header .= chr(32) . chr(0);
329
-                $header .= str_pad($information["user_name"],32,chr(0));    // How do I get a file's user name from PHP?
330
-                $header .= str_pad($information["group_name"],32,chr(0));   // How do I get a file's group name from PHP?
331
-                $header .= str_repeat(chr(0),8);
332
-                $header .= str_repeat(chr(0),8);
333
-                $header .= str_repeat(chr(0),155);
334
-                $header .= str_repeat(chr(0),12);
329
+                $header .= str_pad($information["user_name"], 32, chr(0)); // How do I get a file's user name from PHP?
330
+                $header .= str_pad($information["group_name"], 32, chr(0)); // How do I get a file's group name from PHP?
331
+                $header .= str_repeat(chr(0), 8);
332
+                $header .= str_repeat(chr(0), 8);
333
+                $header .= str_repeat(chr(0), 155);
334
+                $header .= str_repeat(chr(0), 12);
335 335
 
336 336
                 // Compute header checksum
337
-                $checksum = str_pad(decoct($this->__computeUnsignedChecksum($header)),6,"0",STR_PAD_LEFT);
338
-                for($i=0; $i<6; $i++) {
339
-                    $header[(148 + $i)] = substr($checksum,$i,1);
337
+                $checksum = str_pad(decoct($this->__computeUnsignedChecksum($header)), 6, "0", STR_PAD_LEFT);
338
+                for ($i = 0; $i < 6; $i++) {
339
+                    $header[(148 + $i)] = substr($checksum, $i, 1);
340 340
                 }
341 341
                 $header[154] = chr(0);
342 342
                 $header[155] = chr(32);
343 343
 
344 344
                 // Pad file contents to byte count divisible by 512
345
-                $file_contents = str_pad($information["file"],(ceil($information["size"] / 512) * 512),chr(0));
345
+                $file_contents = str_pad($information["file"], (ceil($information["size"] / 512) * 512), chr(0));
346 346
 
347 347
                 // Add new tar formatted data to tar file contents
348 348
                 $this->tar_file .= $header . $file_contents;
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
         }
351 351
 
352 352
         // Add 512 bytes of NULLs to designate EOF
353
-        $this->tar_file .= str_repeat(chr(0),512);
353
+        $this->tar_file .= str_repeat(chr(0), 512);
354 354
 
355 355
         return true;
356 356
     }
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
         unset($this->numDirectories);
369 369
 
370 370
         // If the tar file doesn't exist...
371
-        if(!file_exists($filename))
371
+        if (!file_exists($filename))
372 372
             return false;
373 373
 
374 374
         $this->filename = $filename;
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
     // Appends a tar file to the end of the currently opened tar file
384 384
     function appendTar($filename) {
385 385
         // If the tar file doesn't exist...
386
-        if(!file_exists($filename))
386
+        if (!file_exists($filename))
387 387
             return false;
388 388
 
389 389
         $this->__readTar($filename);
@@ -394,9 +394,9 @@  discard block
 block discarded – undo
394 394
 
395 395
     // Retrieves information about a file in the current tar archive
396 396
     function getFile($filename) {
397
-        if($this->numFiles > 0) {
398
-            foreach($this->files as $key => $information) {
399
-                if($information["name"] == $filename)
397
+        if ($this->numFiles > 0) {
398
+            foreach ($this->files as $key => $information) {
399
+                if ($information["name"] == $filename)
400 400
                     return $information;
401 401
             }
402 402
         }
@@ -407,9 +407,9 @@  discard block
 block discarded – undo
407 407
 
408 408
     // Retrieves information about a directory in the current tar archive
409 409
     function getDirectory($dirname) {
410
-        if($this->numDirectories > 0) {
411
-            foreach($this->directories as $key => $information) {
412
-                if($information["name"] == $dirname)
410
+        if ($this->numDirectories > 0) {
411
+            foreach ($this->directories as $key => $information) {
412
+                if ($information["name"] == $dirname)
413 413
                     return $information;
414 414
             }
415 415
         }
@@ -420,9 +420,9 @@  discard block
 block discarded – undo
420 420
 
421 421
     // Check if this tar archive contains a specific file
422 422
     function containsFile($filename) {
423
-        if($this->numFiles > 0) {
424
-            foreach($this->files as $key => $information) {
425
-                if($information["name"] == $filename)
423
+        if ($this->numFiles > 0) {
424
+            foreach ($this->files as $key => $information) {
425
+                if ($information["name"] == $filename)
426 426
                     return true;
427 427
             }
428 428
         }
@@ -433,9 +433,9 @@  discard block
 block discarded – undo
433 433
 
434 434
     // Check if this tar archive contains a specific directory
435 435
     function containsDirectory($dirname) {
436
-        if($this->numDirectories > 0) {
437
-            foreach($this->directories as $key => $information) {
438
-                if($information["name"] == $dirname)
436
+        if ($this->numDirectories > 0) {
437
+            foreach ($this->directories as $key => $information) {
438
+                if ($information["name"] == $dirname)
439 439
                     return true;
440 440
             }
441 441
         }
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 
447 447
     // Add a directory to this tar archive
448 448
     function addDirectory($dirname) {
449
-        if(!file_exists($dirname))
449
+        if (!file_exists($dirname))
450 450
             return false;
451 451
 
452 452
         // Get directory information
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 
455 455
         // Add directory to processed data
456 456
         $this->numDirectories++;
457
-        $activeDir      = &$this->directories[];
457
+        $activeDir = &$this->directories[];
458 458
         $activeDir["name"]  = $dirname;
459 459
         $activeDir["mode"]  = $file_information["mode"];
460 460
         $activeDir["time"]  = $file_information["time"];
@@ -467,34 +467,34 @@  discard block
 block discarded – undo
467 467
 
468 468
 
469 469
     // Add a file to the tar archive
470
-    function addFile($filename,$from=null,$to=null) {
470
+    function addFile($filename, $from = null, $to = null) {
471 471
         // Make sure the file we are adding exists!
472
-        if(!file_exists($filename))
472
+        if (!file_exists($filename))
473 473
             return false;
474 474
 
475
-        if(filesize($filename)==0)
475
+        if (filesize($filename) == 0)
476 476
             return false;
477 477
 
478 478
         // Make sure there are no other files in the archive that have this same filename
479
-        if($this->containsFile($filename))
479
+        if ($this->containsFile($filename))
480 480
             return false;
481 481
 
482 482
         // Get file information
483 483
         $file_information = stat($filename);
484 484
 
485 485
         // Read in the file's contents
486
-        $fp = fopen($filename,"rb");
487
-        $file_contents = fread($fp,filesize($filename));
486
+        $fp = fopen($filename, "rb");
487
+        $file_contents = fread($fp, filesize($filename));
488 488
         fclose($fp);
489 489
 
490
-        if($from && $to){
491
-            $file_contents = str_replace($from,$to,$file_contents);
490
+        if ($from && $to) {
491
+            $file_contents = str_replace($from, $to, $file_contents);
492 492
             $file_information["size"] = strlen($file_contents);
493 493
         }
494 494
 
495 495
         // Add file to processed data
496 496
         $this->numFiles++;
497
-        $activeFile         = &$this->files[];
497
+        $activeFile = &$this->files[];
498 498
         $activeFile["name"]     = $filename;
499 499
         $activeFile["mode"]     = $file_information["mode"];
500 500
         $activeFile["user_id"]      = $file_information["uid"];
@@ -504,7 +504,7 @@  discard block
 block discarded – undo
504 504
         $activeFile["checksum"]     = $checksum;
505 505
         $activeFile["user_name"]    = "";
506 506
         $activeFile["group_name"]   = "";
507
-        $activeFile["file"]     = $file_contents;
507
+        $activeFile["file"] = $file_contents;
508 508
 
509 509
         return true;
510 510
     }
@@ -512,9 +512,9 @@  discard block
 block discarded – undo
512 512
 
513 513
     // Remove a file from the tar archive
514 514
     function removeFile($filename) {
515
-        if($this->numFiles > 0) {
516
-            foreach($this->files as $key => $information) {
517
-                if($information["name"] == $filename) {
515
+        if ($this->numFiles > 0) {
516
+            foreach ($this->files as $key => $information) {
517
+                if ($information["name"] == $filename) {
518 518
                     $this->numFiles--;
519 519
                     unset($this->files[$key]);
520 520
                     return true;
@@ -528,9 +528,9 @@  discard block
 block discarded – undo
528 528
 
529 529
     // Remove a directory from the tar archive
530 530
     function removeDirectory($dirname) {
531
-        if($this->numDirectories > 0) {
532
-            foreach($this->directories as $key => $information) {
533
-                if($information["name"] == $dirname) {
531
+        if ($this->numDirectories > 0) {
532
+            foreach ($this->directories as $key => $information) {
533
+                if ($information["name"] == $dirname) {
534 534
                     $this->numDirectories--;
535 535
                     unset($this->directories[$key]);
536 536
                     return true;
@@ -544,28 +544,28 @@  discard block
 block discarded – undo
544 544
 
545 545
     // Write the currently loaded tar archive to disk
546 546
     function saveTar() {
547
-        if(!$this->filename)
547
+        if (!$this->filename)
548 548
             return false;
549 549
 
550 550
         // Write tar to current file using specified gzip compression
551
-        $this->toTar($this->filename,$this->isGzipped);
551
+        $this->toTar($this->filename, $this->isGzipped);
552 552
 
553 553
         return true;
554 554
     }
555 555
 
556 556
 
557 557
     // Saves tar archive to a different file than the current file
558
-    function toTar($filename,$useGzip) {
559
-        if(!$filename)
558
+    function toTar($filename, $useGzip) {
559
+        if (!$filename)
560 560
             return false;
561 561
 
562 562
         // Encode processed files into TAR file format
563 563
         $this->__generateTar();
564 564
 
565 565
         // GZ Compress the data if we need to
566
-        if($useGzip) {
566
+        if ($useGzip) {
567 567
             // Make sure we have gzip support
568
-            if(!function_exists("gzencode"))
568
+            if (!function_exists("gzencode"))
569 569
                 return false;
570 570
 
571 571
             $file = gzencode($this->tar_file);
@@ -574,8 +574,8 @@  discard block
 block discarded – undo
574 574
         }
575 575
 
576 576
         // Write the TAR file
577
-        $fp = fopen($filename,"wb");
578
-        fwrite($fp,$file);
577
+        $fp = fopen($filename, "wb");
578
+        fwrite($fp, $file);
579 579
         fclose($fp);
580 580
 
581 581
         return true;
Please login to merge, or discard this patch.
Braces   +60 added lines, -44 removed lines patch added patch discarded remove patch
@@ -85,10 +85,12 @@  discard block
 block discarded – undo
85 85
     // to try to ensure valid file
86 86
     // PRIVATE ACCESS FUNCTION
87 87
     function __computeUnsignedChecksum($bytestring) {
88
-        for($i=0; $i<512; $i++)
89
-            $unsigned_chksum += ord($bytestring[$i]);
90
-        for($i=0; $i<8; $i++)
91
-            $unsigned_chksum -= ord($bytestring[148 + $i]);
88
+        for($i=0; $i<512; $i++) {
89
+                    $unsigned_chksum += ord($bytestring[$i]);
90
+        }
91
+        for($i=0; $i<8; $i++) {
92
+                    $unsigned_chksum -= ord($bytestring[148 + $i]);
93
+        }
92 94
         $unsigned_chksum += ord(" ") * 8;
93 95
 
94 96
         return $unsigned_chksum;
@@ -116,8 +118,9 @@  discard block
 block discarded – undo
116 118
 		$flag_longlink = false;
117 119
         while($main_offset < $tar_length) {
118 120
             // If we read a block of 512 nulls, we are at the end of the archive
119
-            if(substr($this->tar_file,$main_offset,512) == str_repeat(chr(0),512))
120
-                break;
121
+            if(substr($this->tar_file,$main_offset,512) == str_repeat(chr(0),512)) {
122
+                            break;
123
+            }
121 124
 
122 125
             // Parse file name
123 126
             $file_name      = $this->__parseNullPaddedString(substr($this->tar_file,$main_offset,100));
@@ -149,8 +152,9 @@  discard block
 block discarded – undo
149 152
             $file_type = substr($this->tar_file,$main_offset + 156,1);
150 153
 
151 154
             // Make sure our file is valid
152
-            if($this->__computeUnsignedChecksum(substr($this->tar_file,$main_offset,512)) != $file_chksum)
153
-                return false;
155
+            if($this->__computeUnsignedChecksum(substr($this->tar_file,$main_offset,512)) != $file_chksum) {
156
+                            return false;
157
+            }
154 158
 
155 159
             // Parse File Contents
156 160
             $file_contents      = substr($this->tar_file,$main_offset + 512,$file_size);
@@ -170,8 +174,7 @@  discard block
 block discarded – undo
170 174
 			{
171 175
 				$flag_longlink = true;
172 176
 				$longlink_name = $this->__parseNullPaddedString($file_contents);
173
-			}
174
-			elseif($file_type == '0') {
177
+			} elseif($file_type == '0') {
175 178
 				// Increment number of files
176 179
 				$this->numFiles++;
177 180
 
@@ -182,8 +185,7 @@  discard block
 block discarded – undo
182 185
 				if($flag_longlink)
183 186
 				{
184 187
 					$activeFile["name"]     = $longlink_name;
185
-				}
186
-				else
188
+				} else
187 189
 				{
188 190
 					$activeFile["name"]     = $file_name;
189 191
 				}
@@ -211,8 +213,7 @@  discard block
 block discarded – undo
211 213
 				if($flag_longlink)
212 214
 				{
213 215
 					$activeDir["name"]     = $longlink_name;
214
-				}
215
-				else
216
+				} else
216 217
 				{
217 218
 					$activeDir["name"]     = $file_name;
218 219
 				}
@@ -240,8 +241,9 @@  discard block
 block discarded – undo
240 241
     // PRIVATE ACCESS FUNCTION
241 242
     function __readTar($filename='') {
242 243
         // Set the filename to load
243
-        if(!$filename)
244
-            $filename = $this->filename;
244
+        if(!$filename) {
245
+                    $filename = $this->filename;
246
+        }
245 247
 
246 248
         // Read in the TAR file
247 249
         $fp = fopen($filename,"rb");
@@ -249,8 +251,9 @@  discard block
 block discarded – undo
249 251
         fclose($fp);
250 252
 
251 253
         if($this->tar_file[0] == chr(31) && $this->tar_file[1] == chr(139) && $this->tar_file[2] == chr(8)) {
252
-            if(!function_exists("gzinflate"))
253
-                return false;
254
+            if(!function_exists("gzinflate")) {
255
+                            return false;
256
+            }
254 257
 
255 258
             $this->isGzipped = TRUE;
256 259
 
@@ -368,8 +371,9 @@  discard block
 block discarded – undo
368 371
         unset($this->numDirectories);
369 372
 
370 373
         // If the tar file doesn't exist...
371
-        if(!file_exists($filename))
372
-            return false;
374
+        if(!file_exists($filename)) {
375
+                    return false;
376
+        }
373 377
 
374 378
         $this->filename = $filename;
375 379
 
@@ -383,8 +387,9 @@  discard block
 block discarded – undo
383 387
     // Appends a tar file to the end of the currently opened tar file
384 388
     function appendTar($filename) {
385 389
         // If the tar file doesn't exist...
386
-        if(!file_exists($filename))
387
-            return false;
390
+        if(!file_exists($filename)) {
391
+                    return false;
392
+        }
388 393
 
389 394
         $this->__readTar($filename);
390 395
 
@@ -396,8 +401,9 @@  discard block
 block discarded – undo
396 401
     function getFile($filename) {
397 402
         if($this->numFiles > 0) {
398 403
             foreach($this->files as $key => $information) {
399
-                if($information["name"] == $filename)
400
-                    return $information;
404
+                if($information["name"] == $filename) {
405
+                                    return $information;
406
+                }
401 407
             }
402 408
         }
403 409
 
@@ -409,8 +415,9 @@  discard block
 block discarded – undo
409 415
     function getDirectory($dirname) {
410 416
         if($this->numDirectories > 0) {
411 417
             foreach($this->directories as $key => $information) {
412
-                if($information["name"] == $dirname)
413
-                    return $information;
418
+                if($information["name"] == $dirname) {
419
+                                    return $information;
420
+                }
414 421
             }
415 422
         }
416 423
 
@@ -422,8 +429,9 @@  discard block
 block discarded – undo
422 429
     function containsFile($filename) {
423 430
         if($this->numFiles > 0) {
424 431
             foreach($this->files as $key => $information) {
425
-                if($information["name"] == $filename)
426
-                    return true;
432
+                if($information["name"] == $filename) {
433
+                                    return true;
434
+                }
427 435
             }
428 436
         }
429 437
 
@@ -435,8 +443,9 @@  discard block
 block discarded – undo
435 443
     function containsDirectory($dirname) {
436 444
         if($this->numDirectories > 0) {
437 445
             foreach($this->directories as $key => $information) {
438
-                if($information["name"] == $dirname)
439
-                    return true;
446
+                if($information["name"] == $dirname) {
447
+                                    return true;
448
+                }
440 449
             }
441 450
         }
442 451
 
@@ -446,8 +455,9 @@  discard block
 block discarded – undo
446 455
 
447 456
     // Add a directory to this tar archive
448 457
     function addDirectory($dirname) {
449
-        if(!file_exists($dirname))
450
-            return false;
458
+        if(!file_exists($dirname)) {
459
+                    return false;
460
+        }
451 461
 
452 462
         // Get directory information
453 463
         $file_information = stat($dirname);
@@ -469,15 +479,18 @@  discard block
 block discarded – undo
469 479
     // Add a file to the tar archive
470 480
     function addFile($filename,$from=null,$to=null) {
471 481
         // Make sure the file we are adding exists!
472
-        if(!file_exists($filename))
473
-            return false;
482
+        if(!file_exists($filename)) {
483
+                    return false;
484
+        }
474 485
 
475
-        if(filesize($filename)==0)
476
-            return false;
486
+        if(filesize($filename)==0) {
487
+                    return false;
488
+        }
477 489
 
478 490
         // Make sure there are no other files in the archive that have this same filename
479
-        if($this->containsFile($filename))
480
-            return false;
491
+        if($this->containsFile($filename)) {
492
+                    return false;
493
+        }
481 494
 
482 495
         // Get file information
483 496
         $file_information = stat($filename);
@@ -544,8 +557,9 @@  discard block
 block discarded – undo
544 557
 
545 558
     // Write the currently loaded tar archive to disk
546 559
     function saveTar() {
547
-        if(!$this->filename)
548
-            return false;
560
+        if(!$this->filename) {
561
+                    return false;
562
+        }
549 563
 
550 564
         // Write tar to current file using specified gzip compression
551 565
         $this->toTar($this->filename,$this->isGzipped);
@@ -556,8 +570,9 @@  discard block
 block discarded – undo
556 570
 
557 571
     // Saves tar archive to a different file than the current file
558 572
     function toTar($filename,$useGzip) {
559
-        if(!$filename)
560
-            return false;
573
+        if(!$filename) {
574
+                    return false;
575
+        }
561 576
 
562 577
         // Encode processed files into TAR file format
563 578
         $this->__generateTar();
@@ -565,8 +580,9 @@  discard block
 block discarded – undo
565 580
         // GZ Compress the data if we need to
566 581
         if($useGzip) {
567 582
             // Make sure we have gzip support
568
-            if(!function_exists("gzencode"))
569
-                return false;
583
+            if(!function_exists("gzencode")) {
584
+                            return false;
585
+            }
570 586
 
571 587
             $file = gzencode($this->tar_file);
572 588
         } else {
Please login to merge, or discard this patch.
modules/addon/addon.admin.model.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -141,7 +141,7 @@
 block discarded – undo
141 141
 	 * @param string $addon Name to get information
142 142
 	 * @param int $site_srl Site srl
143 143
 	 * @param string $gtype site or global
144
-	 * @return object Returns a information
144
+	 * @return null|stdClass Returns a information
145 145
 	 */
146 146
 	function getAddonInfoXml($addon, $site_srl = 0, $gtype = 'site')
147 147
 	{
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	function getAddonPath($addon_name)
28 28
 	{
29 29
 		$class_path = sprintf('./addons/%s/', $addon_name);
30
-		if(is_dir($class_path))
30
+		if (is_dir($class_path))
31 31
 		{
32 32
 			return $class_path;
33 33
 		}
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 		$addonList = $this->getAddonList(0, 'site');
45 45
 
46 46
 		$oAutoinstallModel = getModel('autoinstall');
47
-		foreach($addonList as $key => $addon)
47
+		foreach ($addonList as $key => $addon)
48 48
 		{
49 49
 			// get easyinstall remove url
50 50
 			$packageSrl = $oAutoinstallModel->getPackageSrlByPath($addon->path);
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 			$addonList[$key]->need_update = $package[$packageSrl]->need_update;
56 56
 
57 57
 			// get easyinstall update url
58
-			if($addonList[$key]->need_update == 'Y')
58
+			if ($addonList[$key]->need_update == 'Y')
59 59
 			{
60 60
 				$addonList[$key]->update_url = $oAutoinstallModel->getUpdateUrlByPackageSrl($packageSrl);
61 61
 			}
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 		// Downloaded and installed add-on to the list of Wanted
79 79
 		$searched_list = FileHandler::readDir('./addons', '/^([a-zA-Z0-9-_]+)$/');
80 80
 		$searched_count = count($searched_list);
81
-		if(!$searched_count)
81
+		if (!$searched_count)
82 82
 		{
83 83
 			return;
84 84
 		}
@@ -87,11 +87,11 @@  discard block
 block discarded – undo
87 87
 
88 88
 		$oAddonAdminController = getAdminController('addon');
89 89
 
90
-		for($i = 0; $i < $searched_count; $i++)
90
+		for ($i = 0; $i < $searched_count; $i++)
91 91
 		{
92 92
 			// Add the name of
93 93
 			$addon_name = $searched_list[$i];
94
-			if($addon_name == "smartphone")
94
+			if ($addon_name == "smartphone")
95 95
 			{
96 96
 				continue;
97 97
 			}
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 			// Wanted information on the add-on
101 101
 			$info = $this->getAddonInfoXml($addon_name, $site_srl, $gtype);
102 102
 			
103
-			if(!$info) $info = new stdClass();
103
+			if (!$info) $info = new stdClass();
104 104
 
105 105
 			$info->addon = $addon_name;
106 106
 			$info->path = $path;
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 			$info->mactivated = FALSE;
109 109
 			$info->fixed = FALSE;
110 110
 			// Check if a permossion is granted entered in DB
111
-			if(!in_array($addon_name, array_keys($inserted_addons)))
111
+			if (!in_array($addon_name, array_keys($inserted_addons)))
112 112
 			{
113 113
 				// If not, type in the DB type (model, perhaps because of the hate doing this haneungeo .. ㅡ. ㅜ)
114 114
 				$oAddonAdminController->doInsert($addon_name, $site_srl, $type);
@@ -116,15 +116,15 @@  discard block
 block discarded – undo
116 116
 			}
117 117
 			else
118 118
 			{
119
-				if($inserted_addons[$addon_name]->is_used == 'Y')
119
+				if ($inserted_addons[$addon_name]->is_used == 'Y')
120 120
 				{
121 121
 					$info->activated = TRUE;
122 122
 				}
123
-				if($inserted_addons[$addon_name]->is_used_m == 'Y')
123
+				if ($inserted_addons[$addon_name]->is_used_m == 'Y')
124 124
 				{
125 125
 					$info->mactivated = TRUE;
126 126
 				}
127
-				if($gtype == 'global' && $inserted_addons[$addon_name]->is_fixed == 'Y')
127
+				if ($gtype == 'global' && $inserted_addons[$addon_name]->is_fixed == 'Y')
128 128
 				{
129 129
 					$info->fixed = TRUE;
130 130
 				}
@@ -147,14 +147,14 @@  discard block
 block discarded – undo
147 147
 	{
148 148
 		// Get a path of the requested module. Return if not exists.
149 149
 		$addon_path = $this->getAddonPath($addon);
150
-		if(!$addon_path)
150
+		if (!$addon_path)
151 151
 		{
152 152
 			return;
153 153
 		}
154 154
 
155 155
 		// Read the xml file for module skin information
156 156
 		$xml_file = sprintf("%sconf/info.xml", FileHandler::getRealpath($addon_path));
157
-		if(!file_exists($xml_file))
157
+		if (!file_exists($xml_file))
158 158
 		{
159 159
 			return;
160 160
 		}
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 		$tmp_xml_obj = $oXmlParser->loadXmlFile($xml_file);
164 164
 		$xml_obj = $tmp_xml_obj->addon;
165 165
 
166
-		if(!$xml_obj)
166
+		if (!$xml_obj)
167 167
 		{
168 168
 			return;
169 169
 		}
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 		// DB is set to bring history
172 172
 		$db_args = new stdClass();
173 173
 		$db_args->addon = $addon;
174
-		if($gtype == 'global')
174
+		if ($gtype == 'global')
175 175
 		{
176 176
 			$output = executeQuery('addon.getAddonInfo', $db_args);
177 177
 		}
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 		$extra_vals = unserialize($output->data->extra_vars);
184 184
 
185 185
 		$addon_info = new stdClass();
186
-		if($extra_vals->mid_list)
186
+		if ($extra_vals->mid_list)
187 187
 		{
188 188
 			$addon_info->mid_list = $extra_vals->mid_list;
189 189
 		}
@@ -192,13 +192,13 @@  discard block
 block discarded – undo
192 192
 			$addon_info->mid_list = array();
193 193
 		}
194 194
 
195
-		if($extra_vals->xe_run_method)
195
+		if ($extra_vals->xe_run_method)
196 196
 		{
197 197
 			$addon_info->xe_run_method = $extra_vals->xe_run_method;
198 198
 		}
199 199
 
200 200
 		// Add information
201
-		if($xml_obj->version && $xml_obj->attrs->version == '0.2')
201
+		if ($xml_obj->version && $xml_obj->attrs->version == '0.2')
202 202
 		{
203 203
 			// addon format v0.2
204 204
 			$date_obj = new stdClass();
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 			$addon_info->license = $xml_obj->license->body;
214 214
 			$addon_info->license_link = $xml_obj->license->attrs->link;
215 215
 
216
-			if(!is_array($xml_obj->author))
216
+			if (!is_array($xml_obj->author))
217 217
 			{
218 218
 				$author_list = array();
219 219
 				$author_list[] = $xml_obj->author;
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 			}
225 225
 
226 226
 			$addon_info->author = array();
227
-			foreach($author_list as $author)
227
+			foreach ($author_list as $author)
228 228
 			{
229 229
 				$author_obj = new stdClass();
230 230
 				$author_obj->name = $author->name->body;
@@ -234,39 +234,39 @@  discard block
 block discarded – undo
234 234
 			}
235 235
 
236 236
 			// Expand the variable order
237
-			if($xml_obj->extra_vars)
237
+			if ($xml_obj->extra_vars)
238 238
 			{
239 239
 				$extra_var_groups = $xml_obj->extra_vars->group;
240
-				if(!$extra_var_groups)
240
+				if (!$extra_var_groups)
241 241
 				{
242 242
 					$extra_var_groups = $xml_obj->extra_vars;
243 243
 				}
244
-				if(!is_array($extra_var_groups))
244
+				if (!is_array($extra_var_groups))
245 245
 				{
246 246
 					$extra_var_groups = array($extra_var_groups);
247 247
 				}
248 248
 
249
-				foreach($extra_var_groups as $group)
249
+				foreach ($extra_var_groups as $group)
250 250
 				{
251 251
 					$extra_vars = $group->var;
252
-					if(!is_array($group->var))
252
+					if (!is_array($group->var))
253 253
 					{
254 254
 						$extra_vars = array($group->var);
255 255
 					}
256 256
 
257
-					foreach($extra_vars as $key => $val)
257
+					foreach ($extra_vars as $key => $val)
258 258
 					{
259
-						if(!$val)
259
+						if (!$val)
260 260
 						{
261 261
 							continue;
262 262
 						}
263 263
 
264 264
 						$obj = new stdClass();
265
-						if(!$val->attrs)
265
+						if (!$val->attrs)
266 266
 						{
267 267
 							$val->attrs = new stdClass();
268 268
 						}
269
-						if(!$val->attrs->type)
269
+						if (!$val->attrs->type)
270 270
 						{
271 271
 							$val->attrs->type = 'text';
272 272
 						}
@@ -276,26 +276,26 @@  discard block
 block discarded – undo
276 276
 						$obj->title = $val->title->body;
277 277
 						$obj->type = $val->attrs->type;
278 278
 						$obj->description = $val->description->body;
279
-						if($obj->name)
279
+						if ($obj->name)
280 280
 						{
281 281
 							$obj->value = $extra_vals->{$obj->name};
282 282
 						}
283
-						if(strpos($obj->value, '|@|') != FALSE)
283
+						if (strpos($obj->value, '|@|') != FALSE)
284 284
 						{
285 285
 							$obj->value = explode('|@|', $obj->value);
286 286
 						}
287
-						if($obj->type == 'mid_list' && !is_array($obj->value))
287
+						if ($obj->type == 'mid_list' && !is_array($obj->value))
288 288
 						{
289 289
 							$obj->value = array($obj->value);
290 290
 						}
291 291
 
292 292
 						// 'Select'type obtained from the option list.
293
-						if($val->options && !is_array($val->options))
293
+						if ($val->options && !is_array($val->options))
294 294
 						{
295 295
 							$val->options = array($val->options);
296 296
 						}
297 297
 
298
-						for($i = 0, $c = count($val->options); $i < $c; $i++)
298
+						for ($i = 0, $c = count($val->options); $i < $c; $i++)
299 299
 						{
300 300
 							$obj->options[$i] = new stdClass();
301 301
 							$obj->options[$i]->title = $val->options[$i]->title->body;
@@ -328,30 +328,30 @@  discard block
 block discarded – undo
328 328
 			$addon_info->author = array();
329 329
 			$addon_info->author[] = $author_obj;
330 330
 
331
-			if($xml_obj->extra_vars)
331
+			if ($xml_obj->extra_vars)
332 332
 			{
333 333
 				// Expand the variable order
334 334
 				$extra_var_groups = $xml_obj->extra_vars->group;
335
-				if(!$extra_var_groups)
335
+				if (!$extra_var_groups)
336 336
 				{
337 337
 					$extra_var_groups = $xml_obj->extra_vars;
338 338
 				}
339
-				if(!is_array($extra_var_groups))
339
+				if (!is_array($extra_var_groups))
340 340
 				{
341 341
 					$extra_var_groups = array($extra_var_groups);
342 342
 				}
343
-				foreach($extra_var_groups as $group)
343
+				foreach ($extra_var_groups as $group)
344 344
 				{
345 345
 					$extra_vars = $group->var;
346
-					if(!is_array($group->var))
346
+					if (!is_array($group->var))
347 347
 					{
348 348
 						$extra_vars = array($group->var);
349 349
 					}
350 350
 
351 351
 					$addon_info->extra_vars = array();
352
-					foreach($extra_vars as $key => $val)
352
+					foreach ($extra_vars as $key => $val)
353 353
 					{
354
-						if(!$val)
354
+						if (!$val)
355 355
 						{
356 356
 							continue;
357 357
 						}
@@ -363,26 +363,26 @@  discard block
 block discarded – undo
363 363
 						$obj->title = $val->title->body;
364 364
 						$obj->type = $val->type->body ? $val->type->body : 'text';
365 365
 						$obj->description = $val->description->body;
366
-						if($obj->name)
366
+						if ($obj->name)
367 367
 						{
368 368
 							$obj->value = $extra_vals->{$obj->name};
369 369
 						}
370
-						if(strpos($obj->value, '|@|') != false)
370
+						if (strpos($obj->value, '|@|') != false)
371 371
 						{
372 372
 							$obj->value = explode('|@|', $obj->value);
373 373
 						}
374
-						if($obj->type == 'mid_list' && !is_array($obj->value))
374
+						if ($obj->type == 'mid_list' && !is_array($obj->value))
375 375
 						{
376 376
 							$obj->value = array($obj->value);
377 377
 						}
378 378
 						// 'Select'type obtained from the option list.
379
-						if($val->options && !is_array($val->options))
379
+						if ($val->options && !is_array($val->options))
380 380
 						{
381 381
 							$val->options = array($val->options);
382 382
 						}
383 383
 
384 384
 						$obj->options = array();
385
-						for($i = 0, $c = count($val->options); $i < $c; $i++)
385
+						for ($i = 0, $c = count($val->options); $i < $c; $i++)
386 386
 						{
387 387
 							$obj->options[$i]->title = $val->options[$i]->title->body;
388 388
 							$obj->options[$i]->value = $val->options[$i]->value->body;
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
 	{
407 407
 		$args = new stdClass();
408 408
 		$args->list_order = 'addon';
409
-		if($gtype == 'global')
409
+		if ($gtype == 'global')
410 410
 		{
411 411
 			$output = executeQueryArray('addon.getAddons', $args);
412 412
 		}
@@ -415,14 +415,14 @@  discard block
 block discarded – undo
415 415
 			$args->site_srl = $site_srl;
416 416
 			$output = executeQueryArray('addon.getSiteAddons', $args);
417 417
 		}
418
-		if(!$output->data)
418
+		if (!$output->data)
419 419
 		{
420 420
 			return array();
421 421
 		}
422 422
 
423 423
 		$activated_count = count($output->data);
424 424
 		$addon_list = array();
425
-		for($i = 0; $i < $activated_count; $i++)
425
+		for ($i = 0; $i < $activated_count; $i++)
426 426
 		{
427 427
 			$addon = $output->data[$i];
428 428
 			$addon_list[$addon->addon] = $addon;
@@ -443,9 +443,9 @@  discard block
 block discarded – undo
443 443
 	{
444 444
 		$args = new stdClass();
445 445
 		$args->addon = $addon;
446
-		if($gtype == 'global')
446
+		if ($gtype == 'global')
447 447
 		{
448
-			if($type == "pc")
448
+			if ($type == "pc")
449 449
 			{
450 450
 				$output = executeQuery('addon.getAddonIsActivated', $args);
451 451
 			}
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
 		else
458 458
 		{
459 459
 			$args->site_srl = $site_srl;
460
-			if($type == "pc")
460
+			if ($type == "pc")
461 461
 			{
462 462
 				$output = executeQuery('addon.getSiteAddonIsActivated', $args);
463 463
 			}
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
 				$output = executeQuery('addon.getSiteMAddonIsActivated', $args);
467 467
 			}
468 468
 		}
469
-		if($output->data->count > 0)
469
+		if ($output->data->count > 0)
470 470
 		{
471 471
 			return TRUE;
472 472
 		}
Please login to merge, or discard this patch.
Braces   +12 added lines, -19 removed lines patch added patch discarded remove patch
@@ -100,7 +100,9 @@  discard block
 block discarded – undo
100 100
 			// Wanted information on the add-on
101 101
 			$info = $this->getAddonInfoXml($addon_name, $site_srl, $gtype);
102 102
 			
103
-			if(!$info) $info = new stdClass();
103
+			if(!$info) {
104
+				$info = new stdClass();
105
+			}
104 106
 
105 107
 			$info->addon = $addon_name;
106 108
 			$info->path = $path;
@@ -113,8 +115,7 @@  discard block
 block discarded – undo
113 115
 				// If not, type in the DB type (model, perhaps because of the hate doing this haneungeo .. ㅡ. ㅜ)
114 116
 				$oAddonAdminController->doInsert($addon_name, $site_srl, $type);
115 117
 				// Is activated
116
-			}
117
-			else
118
+			} else
118 119
 			{
119 120
 				if($inserted_addons[$addon_name]->is_used == 'Y')
120 121
 				{
@@ -174,8 +175,7 @@  discard block
 block discarded – undo
174 175
 		if($gtype == 'global')
175 176
 		{
176 177
 			$output = executeQuery('addon.getAddonInfo', $db_args);
177
-		}
178
-		else
178
+		} else
179 179
 		{
180 180
 			$db_args->site_srl = $site_srl;
181 181
 			$output = executeQuery('addon.getSiteAddonInfo', $db_args);
@@ -186,8 +186,7 @@  discard block
 block discarded – undo
186 186
 		if($extra_vals->mid_list)
187 187
 		{
188 188
 			$addon_info->mid_list = $extra_vals->mid_list;
189
-		}
190
-		else
189
+		} else
191 190
 		{
192 191
 			$addon_info->mid_list = array();
193 192
 		}
@@ -217,8 +216,7 @@  discard block
 block discarded – undo
217 216
 			{
218 217
 				$author_list = array();
219 218
 				$author_list[] = $xml_obj->author;
220
-			}
221
-			else
219
+			} else
222 220
 			{
223 221
 				$author_list = $xml_obj->author;
224 222
 			}
@@ -306,8 +304,7 @@  discard block
 block discarded – undo
306 304
 					}
307 305
 				}
308 306
 			}
309
-		}
310
-		else
307
+		} else
311 308
 		{
312 309
 			// addon format 0.1
313 310
 			$addon_info = new stdClass();
@@ -409,8 +406,7 @@  discard block
 block discarded – undo
409 406
 		if($gtype == 'global')
410 407
 		{
411 408
 			$output = executeQueryArray('addon.getAddons', $args);
412
-		}
413
-		else
409
+		} else
414 410
 		{
415 411
 			$args->site_srl = $site_srl;
416 412
 			$output = executeQueryArray('addon.getSiteAddons', $args);
@@ -448,20 +444,17 @@  discard block
 block discarded – undo
448 444
 			if($type == "pc")
449 445
 			{
450 446
 				$output = executeQuery('addon.getAddonIsActivated', $args);
451
-			}
452
-			else
447
+			} else
453 448
 			{
454 449
 				$output = executeQuery('addon.getMAddonIsActivated', $args);
455 450
 			}
456
-		}
457
-		else
451
+		} else
458 452
 		{
459 453
 			$args->site_srl = $site_srl;
460 454
 			if($type == "pc")
461 455
 			{
462 456
 				$output = executeQuery('addon.getSiteAddonIsActivated', $args);
463
-			}
464
-			else
457
+			} else
465 458
 			{
466 459
 				$output = executeQuery('addon.getSiteMAddonIsActivated', $args);
467 460
 			}
Please login to merge, or discard this patch.