Subversion-Projekte lars-tiefland.ci

Revision

Revision 68 | Revision 2049 | Zur aktuellen Revision | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 68 Revision 1257
Zeile 372... Zeile 372...
372
		3 => '3 (Normal)',
372
		3 => '3 (Normal)',
373
		4 => '4 (Low)',
373
		4 => '4 (Low)',
374
		5 => '5 (Lowest)'
374
		5 => '5 (Lowest)'
375
	);
375
	);
Zeile -... Zeile 376...
-
 
376
 
-
 
377
	/**
-
 
378
	 * mbstring.func_override flag
-
 
379
	 *
-
 
380
	 * @var	bool
-
 
381
	 */
-
 
382
	protected static $func_override;
376
 
383
 
Zeile 377... Zeile 384...
377
	// --------------------------------------------------------------------
384
	// --------------------------------------------------------------------
378
 
385
 
379
	/**
386
	/**
Zeile 388... Zeile 395...
388
	{
395
	{
389
		$this->charset = config_item('charset');
396
		$this->charset = config_item('charset');
390
		$this->initialize($config);
397
		$this->initialize($config);
391
		$this->_safe_mode = ( ! is_php('5.4') && ini_get('safe_mode'));
398
		$this->_safe_mode = ( ! is_php('5.4') && ini_get('safe_mode'));
Zeile -... Zeile 399...
-
 
399
 
-
 
400
		isset(self::$func_override) OR self::$func_override = (extension_loaded('mbstring') && ini_get('mbstring.func_override'));
392
 
401
 
393
		log_message('info', 'Email Class Initialized');
402
		log_message('info', 'Email Class Initialized');
Zeile 394... Zeile 403...
394
	}
403
	}
Zeile 1035... Zeile 1044...
1035
	 */
1044
	 */
1036
	public function valid_email($email)
1045
	public function valid_email($email)
1037
	{
1046
	{
1038
		if (function_exists('idn_to_ascii') && $atpos = strpos($email, '@'))
1047
		if (function_exists('idn_to_ascii') && $atpos = strpos($email, '@'))
1039
		{
1048
		{
1040
			$email = substr($email, 0, ++$atpos).idn_to_ascii(substr($email, $atpos));
1049
			$email = self::substr($email, 0, ++$atpos).idn_to_ascii(self::substr($email, $atpos));
1041
		}
1050
		}
Zeile 1042... Zeile 1051...
1042
 
1051
 
1043
		return (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
1052
		return (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
Zeile 1152... Zeile 1161...
1152
		$output = '';
1161
		$output = '';
1153
		foreach (explode("\n", $str) as $line)
1162
		foreach (explode("\n", $str) as $line)
1154
		{
1163
		{
1155
			// Is the line within the allowed character count?
1164
			// Is the line within the allowed character count?
1156
			// If so we'll join it to the output and continue
1165
			// If so we'll join it to the output and continue
1157
			if (mb_strlen($line) <= $charlim)
1166
			if (self::strlen($line) <= $charlim)
1158
			{
1167
			{
1159
				$output .= $line.$this->newline;
1168
				$output .= $line.$this->newline;
1160
				continue;
1169
				continue;
1161
			}
1170
			}
Zeile 1168... Zeile 1177...
1168
				{
1177
				{
1169
					break;
1178
					break;
1170
				}
1179
				}
Zeile 1171... Zeile 1180...
1171
 
1180
 
1172
				// Trim the word down
1181
				// Trim the word down
1173
				$temp .= mb_substr($line, 0, $charlim - 1);
1182
				$temp .= self::substr($line, 0, $charlim - 1);
1174
				$line = mb_substr($line, $charlim - 1);
1183
				$line = self::substr($line, $charlim - 1);
1175
			}
1184
			}
Zeile 1176... Zeile 1185...
1176
			while (mb_strlen($line) > $charlim);
1185
			while (self::strlen($line) > $charlim);
1177
 
1186
 
1178
			// If $temp contains data it means we had to split up an over-length
1187
			// If $temp contains data it means we had to split up an over-length
1179
			// word into smaller chunks so we'll add it back to our current line
1188
			// word into smaller chunks so we'll add it back to our current line
Zeile 1200... Zeile 1209...
1200
	// --------------------------------------------------------------------
1209
	// --------------------------------------------------------------------
Zeile 1201... Zeile 1210...
1201
 
1210
 
1202
	/**
1211
	/**
1203
	 * Build final headers
1212
	 * Build final headers
1204
	 *
1213
	 *
1205
	 * @return	string
1214
	 * @return	void
1206
	 */
1215
	 */
1207
	protected function _build_headers()
1216
	protected function _build_headers()
1208
	{
1217
	{
1209
		$this->set_header('X-Sender', $this->clean_email($this->_headers['From']));
1218
		$this->set_header('X-Sender', $this->clean_email($this->_headers['From']));
Zeile 1383... Zeile 1392...
1383
				if ($this->_get_protocol() === 'mail')
1392
				if ($this->_get_protocol() === 'mail')
1384
				{
1393
				{
1385
					$this->_header_str .= $hdr;
1394
					$this->_header_str .= $hdr;
1386
				}
1395
				}
Zeile 1387... Zeile 1396...
1387
 
1396
 
1388
				strlen($body) && $body .= $this->newline.$this->newline;
1397
				self::strlen($body) && $body .= $this->newline.$this->newline;
1389
				$body .= $this->_get_mime_message().$this->newline.$this->newline
1398
				$body .= $this->_get_mime_message().$this->newline.$this->newline
Zeile 1390... Zeile 1399...
1390
					.'--'.$last_boundary.$this->newline
1399
					.'--'.$last_boundary.$this->newline
1391
 
1400
 
Zeile 1466... Zeile 1475...
1466
 
1475
 
1467
			$body .= '--'.$boundary.$this->newline
1476
			$body .= '--'.$boundary.$this->newline
1468
				.'Content-Type: '.$this->_attachments[$i]['type'].'; name="'.$name.'"'.$this->newline
1477
				.'Content-Type: '.$this->_attachments[$i]['type'].'; name="'.$name.'"'.$this->newline
1469
				.'Content-Disposition: '.$this->_attachments[$i]['disposition'].';'.$this->newline
1478
				.'Content-Disposition: '.$this->_attachments[$i]['disposition'].';'.$this->newline
1470
				.'Content-Transfer-Encoding: base64'.$this->newline
1479
				.'Content-Transfer-Encoding: base64'.$this->newline
-
 
1480
				.(empty($this->_attachments[$i]['cid']) ? '' : 'Content-ID: <'.$this->_attachments[$i]['cid'].'>'.$this->newline)
1471
				.(empty($this->_attachments[$i]['cid']) ? '' : 'Content-ID: <'.$this->_attachments[$i]['cid'].'>'.$this->newline.$this->newline)
1481
				.$this->newline
1472
				.$this->_attachments[$i]['content'].$this->newline;
1482
				.$this->_attachments[$i]['content'].$this->newline;
Zeile 1473... Zeile 1483...
1473
		}
1483
		}
1474
 
1484
 
Zeile 1512... Zeile 1522...
1512
		// However, many developers choose to override that and violate
1522
		// However, many developers choose to override that and violate
1513
		// the RFC rules due to (apparently) a bug in MS Exchange,
1523
		// the RFC rules due to (apparently) a bug in MS Exchange,
1514
		// which only works with "\n".
1524
		// which only works with "\n".
1515
		if ($this->crlf === "\r\n")
1525
		if ($this->crlf === "\r\n")
1516
		{
1526
		{
1517
			if (is_php('5.3'))
-
 
1518
			{
-
 
1519
				return quoted_printable_encode($str);
1527
			return quoted_printable_encode($str);
1520
			}
-
 
1521
			elseif (function_exists('imap_8bit'))
-
 
1522
			{
-
 
1523
				return imap_8bit($str);
-
 
1524
			}
-
 
1525
		}
1528
		}
Zeile 1526... Zeile 1529...
1526
 
1529
 
1527
		// Reduce multiple spaces & remove nulls
1530
		// Reduce multiple spaces & remove nulls
Zeile 1536... Zeile 1539...
1536
		$escape = '=';
1539
		$escape = '=';
1537
		$output = '';
1540
		$output = '';
Zeile 1538... Zeile 1541...
1538
 
1541
 
1539
		foreach (explode("\n", $str) as $line)
1542
		foreach (explode("\n", $str) as $line)
1540
		{
1543
		{
1541
			$length = strlen($line);
1544
			$length = self::strlen($line);
Zeile 1542... Zeile 1545...
1542
			$temp = '';
1545
			$temp = '';
1543
 
1546
 
1544
			// Loop through each character in the line to add soft-wrap
1547
			// Loop through each character in the line to add soft-wrap
Zeile 1571... Zeile 1574...
1571
					$char = $escape.strtoupper(sprintf('%02s', dechex($ascii)));
1574
					$char = $escape.strtoupper(sprintf('%02s', dechex($ascii)));
1572
				}
1575
				}
Zeile 1573... Zeile 1576...
1573
 
1576
 
1574
				// If we're at the character limit, add the line to the output,
1577
				// If we're at the character limit, add the line to the output,
1575
				// reset our temp variable, and keep on chuggin'
1578
				// reset our temp variable, and keep on chuggin'
1576
				if ((strlen($temp) + strlen($char)) >= 76)
1579
				if ((self::strlen($temp) + self::strlen($char)) >= 76)
1577
				{
1580
				{
1578
					$output .= $temp.$escape.$this->crlf;
1581
					$output .= $temp.$escape.$this->crlf;
1579
					$temp = '';
1582
					$temp = '';
Zeile 1586... Zeile 1589...
1586
			// Add our completed line to the output
1589
			// Add our completed line to the output
1587
			$output .= $temp.$this->crlf;
1590
			$output .= $temp.$this->crlf;
1588
		}
1591
		}
Zeile 1589... Zeile 1592...
1589
 
1592
 
1590
		// get rid of extra CRLF tacked onto the end
1593
		// get rid of extra CRLF tacked onto the end
1591
		return substr($output, 0, strlen($this->crlf) * -1);
1594
		return self::substr($output, 0, self::strlen($this->crlf) * -1);
Zeile 1592... Zeile 1595...
1592
	}
1595
	}
Zeile 1593... Zeile 1596...
1593
 
1596
 
Zeile 1628... Zeile 1631...
1628
				if ($output !== FALSE)
1631
				if ($output !== FALSE)
1629
				{
1632
				{
1630
					// iconv_mime_encode() will always put a header field name.
1633
					// iconv_mime_encode() will always put a header field name.
1631
					// We've passed it an empty one, but it still prepends our
1634
					// We've passed it an empty one, but it still prepends our
1632
					// encoded string with ': ', so we need to strip it.
1635
					// encoded string with ': ', so we need to strip it.
1633
					return substr($output, 2);
1636
					return self::substr($output, 2);
1634
				}
1637
				}
Zeile 1635... Zeile 1638...
1635
 
1638
 
1636
				$chars = iconv_strlen($str, 'UTF-8');
1639
				$chars = iconv_strlen($str, 'UTF-8');
1637
			}
1640
			}
Zeile 1640... Zeile 1643...
1640
				$chars = mb_strlen($str, 'UTF-8');
1643
				$chars = mb_strlen($str, 'UTF-8');
1641
			}
1644
			}
1642
		}
1645
		}
Zeile 1643... Zeile 1646...
1643
 
1646
 
1644
		// We might already have this set for UTF-8
1647
		// We might already have this set for UTF-8
Zeile 1645... Zeile 1648...
1645
		isset($chars) OR $chars = strlen($str);
1648
		isset($chars) OR $chars = self::strlen($str);
1646
 
1649
 
1647
		$output = '=?'.$this->charset.'?Q?';
1650
		$output = '=?'.$this->charset.'?Q?';
1648
		for ($i = 0, $length = strlen($output); $i < $chars; $i++)
1651
		for ($i = 0, $length = self::strlen($output); $i < $chars; $i++)
1649
		{
1652
		{
1650
			$chr = ($this->charset === 'UTF-8' && ICONV_ENABLED === TRUE)
1653
			$chr = ($this->charset === 'UTF-8' && ICONV_ENABLED === TRUE)
Zeile 1651... Zeile 1654...
1651
				? '='.implode('=', str_split(strtoupper(bin2hex(iconv_substr($str, $i, 1, $this->charset))), 2))
1654
				? '='.implode('=', str_split(strtoupper(bin2hex(iconv_substr($str, $i, 1, $this->charset))), 2))
1652
				: '='.strtoupper(bin2hex($str[$i]));
1655
				: '='.strtoupper(bin2hex($str[$i]));
1653
 
1656
 
1654
			// RFC 2045 sets a limit of 76 characters per line.
1657
			// RFC 2045 sets a limit of 76 characters per line.
1655
			// We'll append ?= to the end of each line though.
1658
			// We'll append ?= to the end of each line though.
1656
			if ($length + ($l = strlen($chr)) > 74)
1659
			if ($length + ($l = self::strlen($chr)) > 74)
1657
			{
1660
			{
1658
				$output .= '?='.$this->crlf // EOL
1661
				$output .= '?='.$this->crlf // EOL
1659
					.' =?'.$this->charset.'?Q?'.$chr; // New line
1662
					.' =?'.$this->charset.'?Q?'.$chr; // New line
1660
				$length = 6 + strlen($this->charset) + $l; // Reset the length for the new line
1663
				$length = 6 + self::strlen($this->charset) + $l; // Reset the length for the new line
1661
			}
1664
			}
1662
			else
1665
			else
Zeile 1748... Zeile 1751...
1748
				$set .= ', '.$this->_bcc_array[$i];
1751
				$set .= ', '.$this->_bcc_array[$i];
1749
			}
1752
			}
Zeile 1750... Zeile 1753...
1750
 
1753
 
1751
			if ($i === $float)
1754
			if ($i === $float)
1752
			{
1755
			{
1753
				$chunk[] = substr($set, 1);
1756
				$chunk[] = self::substr($set, 1);
1754
				$float += $this->bcc_batch_size;
1757
				$float += $this->bcc_batch_size;
1755
				$set = '';
1758
				$set = '';
Zeile 1756... Zeile 1759...
1756
			}
1759
			}
1757
 
1760
 
1758
			if ($i === $c-1)
1761
			if ($i === $c-1)
1759
			{
1762
			{
1760
				$chunk[] = substr($set, 1);
1763
				$chunk[] = self::substr($set, 1);
Zeile 1761... Zeile 1764...
1761
			}
1764
			}
1762
		}
1765
		}
Zeile 2050... Zeile 2053...
2050
	/**
2053
	/**
2051
	 * Send SMTP command
2054
	 * Send SMTP command
2052
	 *
2055
	 *
2053
	 * @param	string
2056
	 * @param	string
2054
	 * @param	string
2057
	 * @param	string
2055
	 * @return	string
2058
	 * @return	bool
2056
	 */
2059
	 */
2057
	protected function _send_command($cmd, $data = '')
2060
	protected function _send_command($cmd, $data = '')
2058
	{
2061
	{
2059
		switch ($cmd)
2062
		switch ($cmd)
2060
		{
2063
		{
Zeile 2113... Zeile 2116...
2113
 
2116
 
Zeile 2114... Zeile 2117...
2114
		$reply = $this->_get_smtp_data();
2117
		$reply = $this->_get_smtp_data();
Zeile 2115... Zeile 2118...
2115
 
2118
 
2116
		$this->_debug_msg[] = '<pre>'.$cmd.': '.$reply.'</pre>';
2119
		$this->_debug_msg[] = '<pre>'.$cmd.': '.$reply.'</pre>';
2117
 
2120
 
2118
		if ((int) substr($reply, 0, 3) !== $resp)
2121
		if ((int) self::substr($reply, 0, 3) !== $resp)
2119
		{
2122
		{
Zeile 2200... Zeile 2203...
2200
	 * @return	bool
2203
	 * @return	bool
2201
	 */
2204
	 */
2202
	protected function _send_data($data)
2205
	protected function _send_data($data)
2203
	{
2206
	{
2204
		$data .= $this->newline;
2207
		$data .= $this->newline;
2205
		for ($written = $timestamp = 0, $length = strlen($data); $written < $length; $written += $result)
2208
		for ($written = $timestamp = 0, $length = self::strlen($data); $written < $length; $written += $result)
2206
		{
2209
		{
2207
			if (($result = fwrite($this->_smtp_connect, substr($data, $written))) === FALSE)
2210
			if (($result = fwrite($this->_smtp_connect, self::substr($data, $written))) === FALSE)
2208
			{
2211
			{
2209
				break;
2212
				break;
2210
			}
2213
			}
2211
			// See https://bugs.php.net/bug.php?id=39598 and http://php.net/manual/en/function.fwrite.php#96951
2214
			// See https://bugs.php.net/bug.php?id=39598 and http://php.net/manual/en/function.fwrite.php#96951
2212
			elseif ($result === 0)
2215
			elseif ($result === 0)
Zeile 2386... Zeile 2389...
2386
	 */
2389
	 */
2387
	public function __destruct()
2390
	public function __destruct()
2388
	{
2391
	{
2389
		is_resource($this->_smtp_connect) && $this->_send_command('quit');
2392
		is_resource($this->_smtp_connect) && $this->_send_command('quit');
2390
	}
2393
	}
-
 
2394
 
-
 
2395
	// --------------------------------------------------------------------
-
 
2396
 
-
 
2397
	/**
-
 
2398
	 * Byte-safe strlen()
-
 
2399
	 *
-
 
2400
	 * @param	string	$str
-
 
2401
	 * @return	int
-
 
2402
	 */
-
 
2403
	protected static function strlen($str)
-
 
2404
	{
-
 
2405
		return (self::$func_override)
-
 
2406
			? mb_strlen($str, '8bit')
-
 
2407
			: strlen($str);
-
 
2408
	}
-
 
2409
 
-
 
2410
	// --------------------------------------------------------------------
-
 
2411
 
-
 
2412
	/**
-
 
2413
	 * Byte-safe substr()
-
 
2414
	 *
-
 
2415
	 * @param	string	$str
-
 
2416
	 * @param	int	$start
-
 
2417
	 * @param	int	$length
-
 
2418
	 * @return	string
-
 
2419
	 */
-
 
2420
	protected static function substr($str, $start, $length = NULL)
-
 
2421
	{
-
 
2422
		if (self::$func_override)
-
 
2423
		{
-
 
2424
			// mb_substr($str, $start, null, '8bit') returns an empty
-
 
2425
			// string on PHP 5.3
-
 
2426
			isset($length) OR $length = ($start >= 0 ? self::strlen($str) - $start : -$start);
-
 
2427
			return mb_substr($str, $start, $length, '8bit');
-
 
2428
		}
-
 
2429
 
-
 
2430
		return isset($length)
-
 
2431
			? substr($str, $start, $length)
-
 
2432
			: substr($str, $start);
-
 
2433
	}
2391
}
2434
}