Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/upstream/master' into autotls
Browse files Browse the repository at this point in the history
  • Loading branch information
Synchro committed Apr 29, 2015
2 parents e427427 + a6cd574 commit 1befef0
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 12 deletions.
5 changes: 5 additions & 0 deletions changelog.md
@@ -1,5 +1,7 @@
# ChangeLog

## Version 5.2.10 (April 29th 2015)
* Add custom header getter
* Use `application/javascript` for .js attachments
* Improve RFC2821 compliance for timelimits, especially for end-of-data
* Add Azerbaijani translations (Thanks to @mirjalal)
Expand Down Expand Up @@ -27,6 +29,9 @@
* Enable TLS encryption automatically if the server offers it
* Provide detailed errors when individual recipients fail
* Report more errors when connecting
* Add extras classes to composer classmap
* Expose stream_context_create options via new SMTPOptions property
* Automatic encoding switch to quoted-printable if message lines are too long

## Version 5.2.9 (Sept 25th 2014)
* **Important: The autoloader is no longer autoloaded by the PHPMailer class**
Expand Down
73 changes: 64 additions & 9 deletions class.phpmailer.php
Expand Up @@ -263,6 +263,12 @@ class PHPMailer
*/
public $SMTPAuth = false;

/**
* Options array passed to stream_context_create when connecting via SMTP.
* @type array
*/
public $SMTPOptions = array();

/**
* SMTP username.
* @type string
Expand Down Expand Up @@ -566,6 +572,13 @@ class PHPMailer
*/
protected $exceptions = false;

/**
* Unique ID used for message ID and boundaries.
* @type string
* @access protected
*/
protected $uniqueid = '';

/**
* Error severity: message only, continue processing.
*/
Expand All @@ -586,6 +599,12 @@ class PHPMailer
*/
const CRLF = "\r\n";

/**
* The maximum line length allowed by RFC 2822 section 2.1.1
* @type integer
*/
const MAX_LINE_LENGTH = 998;

/**
* Constructor.
* @param boolean $exceptions Should we throw external exceptions?
Expand Down Expand Up @@ -1018,8 +1037,9 @@ public function preSend()
throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
}

$this->MIMEHeader = $this->createHeader();
//Create body before headers in case body makes changes to headers (e.g. altering transfer encoding)
$this->MIMEBody = $this->createBody();
$this->MIMEHeader = $this->createHeader();

// To capture the complete message when using mail(), create
// an extra header list which createHeader() doesn't fold in
Expand Down Expand Up @@ -1228,7 +1248,7 @@ public function getSMTPInstance()
protected function smtpSend($header, $body)
{
$bad_rcpt = array();
if (!$this->smtpConnect()) {
if (!$this->smtpConnect($this->SMTPOptions)) {
throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
}
if ('' == $this->Sender) {
Expand Down Expand Up @@ -1693,12 +1713,6 @@ public function createHeader()
{
$result = '';

// Set the boundaries
$uniq_id = md5(uniqid(time()));
$this->boundary[1] = 'b1_' . $uniq_id;
$this->boundary[2] = 'b2_' . $uniq_id;
$this->boundary[3] = 'b3_' . $uniq_id;

if ($this->MessageDate == '') {
$this->MessageDate = self::rfcDate();
}
Expand Down Expand Up @@ -1750,7 +1764,7 @@ public function createHeader()
if ($this->MessageID != '') {
$this->lastMessageID = $this->MessageID;
} else {
$this->lastMessageID = sprintf('<%s@%s>', $uniq_id, $this->ServerHostname());
$this->lastMessageID = sprintf('<%s@%s>', $this->uniqueid, $this->ServerHostname());
}
$result .= $this->headerLine('Message-ID', $this->lastMessageID);
$result .= $this->headerLine('X-Priority', $this->Priority);
Expand Down Expand Up @@ -1860,6 +1874,11 @@ public function getSentMIMEMessage()
public function createBody()
{
$body = '';
//Create unique IDs and preset boundaries
$this->uniqueid = md5(uniqid(time()));
$this->boundary[1] = 'b1_' . $this->uniqueid;
$this->boundary[2] = 'b2_' . $this->uniqueid;
$this->boundary[3] = 'b3_' . $this->uniqueid;

if ($this->sign_key_file) {
$body .= $this->getMailMIME() . $this->LE;
Expand All @@ -1869,16 +1888,30 @@ public function createBody()

$bodyEncoding = $this->Encoding;
$bodyCharSet = $this->CharSet;
//Can we do a 7-bit downgrade?
if ($bodyEncoding == '8bit' and !$this->has8bitChars($this->Body)) {
$bodyEncoding = '7bit';
$bodyCharSet = 'us-ascii';
}
//If lines are too long, change to quoted-printable transfer encoding
if (self::hasLineLongerThanMax($this->Body)) {
$this->Encoding = 'quoted-printable';
$bodyEncoding = 'quoted-printable';
$bodyCharSet = 'us-ascii'; //qp always fits into ascii
}

$altBodyEncoding = $this->Encoding;
$altBodyCharSet = $this->CharSet;
//Can we do a 7-bit downgrade?
if ($altBodyEncoding == '8bit' and !$this->has8bitChars($this->AltBody)) {
$altBodyEncoding = '7bit';
$altBodyCharSet = 'us-ascii';
}
//If lines are too long, change to quoted-printable transfer encoding
if (self::hasLineLongerThanMax($this->AltBody)) {
$altBodyEncoding = 'quoted-printable';
$altBodyCharSet = 'us-ascii';
}
//Use this as a preamble in all multipart message types
$mimepre = "This is a multi-part message in MIME format." . $this->LE . $this->LE;
switch ($this->message_type) {
Expand Down Expand Up @@ -2968,6 +3001,16 @@ public function addCustomHeader($name, $value = null)
}
}

/**
* Returns all custom headers
*
* @return array
*/
public function getCustomHeaders()
{
return $this->CustomHeader;
}

/**
* Create a message from an HTML string.
* Automatically makes modifications for inline images and backgrounds
Expand Down Expand Up @@ -3471,6 +3514,18 @@ public function DKIM_Add($headers_line, $subject, $body)
return $dkimhdrs . $signed . "\r\n";
}

/**
* Detect if a string contains a line longer than the maximum line length allowed.
* @param string $str
* @return boolean
* @static
*/
public static function hasLineLongerThanMax($str)
{
//+2 to include CRLF line break for a 1000 total
return (boolean)preg_match('/^(.{'.(self::MAX_LINE_LENGTH + 2).',})/m', $str);
}

/**
* Allows for public read access to 'to' property.
* @access public
Expand Down
2 changes: 1 addition & 1 deletion class.smtp.php
Expand Up @@ -265,7 +265,7 @@ public function connect($host, $port = null, $timeout = 30, $options = array())
}
// Connect to the SMTP server
$this->edebug(
"Connection: opening to $host:$port, t=$timeout, opt=".var_export($options, true),
"Connection: opening to $host:$port, timeout=$timeout, options=".var_export($options, true),
self::DEBUG_CONNECTION
);
$errno = 0;
Expand Down
8 changes: 7 additions & 1 deletion composer.json
Expand Up @@ -27,7 +27,13 @@
"phpunit/phpunit": "4.3.*"
},
"autoload": {
"classmap": ["class.phpmailer.php", "class.pop3.php", "class.smtp.php"]
"classmap": [
"class.phpmailer.php",
"class.smtp.php",
"class.pop3.php",
"extras/EasyPeasyICS.php",
"extras/ntlm_sasl_client.php"
]
},
"license": "LGPL-2.1"
}
74 changes: 74 additions & 0 deletions examples/ssl_options.phps
@@ -0,0 +1,74 @@
<?php
/**
* This example shows settings to use when sending over SMTP with TLS and custom connection options.
*/

//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');

require '../PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer;

//Tell PHPMailer to use SMTP
$mail->isSMTP();

//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;

//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';

//Set the hostname of the mail server
$mail->Host = 'smtp.example.com';

//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;

//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';

//Custom connection options
$mail->SMTPOptions = array (
'ssl' => array(
'verify_peer' => true,
'verify_depth' => 3,
'allow_self_signed' => true,
'peer_name' => 'smtp.example.com',
'cafile' => '/etc/ssl/ca_cert.pem',
)
);

//Whether to use SMTP authentication
$mail->SMTPAuth = true;

//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "username@example.com";

//Password to use for SMTP authentication
$mail->Password = "yourpassword";

//Set who the message is to be sent from
$mail->setFrom('from@example.com', 'First Last');

//Set who the message is to be sent to
$mail->addAddress('whoto@example.com', 'John Doe');

//Set the subject line
$mail->Subject = 'PHPMailer SMTP options test';

//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));

//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
26 changes: 26 additions & 0 deletions language/phpmailer.lang-ko.php
@@ -0,0 +1,26 @@
<?php
/**
* Korean PHPMailer language file: refer to English translation for definitive list
* @package PHPMailer
* @author ChalkPE <amato0617@gmail.com>
*/

$PHPMAILER_LANG['authenticate'] = 'SMTP 오류: 인증할 수 없습니다.';
$PHPMAILER_LANG['connect_host'] = 'SMTP 오류: SMTP 호스트에 접속할 수 없습니다.';
$PHPMAILER_LANG['data_not_accepted'] = 'SMTP 오류: 데이터가 받아들여지지 않았습니다.';
$PHPMAILER_LANG['empty_message'] = '메세지 내용이 없습니다';
$PHPMAILER_LANG['encoding'] = '알 수 없는 인코딩: ';
$PHPMAILER_LANG['execute'] = '실행 불가: ';
$PHPMAILER_LANG['file_access'] = '파일 접근 불가: ';
$PHPMAILER_LANG['file_open'] = '파일 오류: 파일을 열 수 없습니다: ';
$PHPMAILER_LANG['from_failed'] = '다음 From 주소에서 오류가 발생했습니다: ';
$PHPMAILER_LANG['instantiate'] = 'mail 함수를 인스턴스화할 수 없습니다';
$PHPMAILER_LANG['invalid_address'] = '잘못된 주소';
$PHPMAILER_LANG['mailer_not_supported'] = ' 메일러는 지원되지 않습니다.';
$PHPMAILER_LANG['provide_address'] = '적어도 한 개 이상의 수신자 메일 주소를 제공해야 합니다.';
$PHPMAILER_LANG['recipients_failed'] = 'SMTP 오류: 다음 수신자에서 오류가 발생했습니다: ';
$PHPMAILER_LANG['signing'] = '서명 오류: ';
$PHPMAILER_LANG['smtp_connect_failed'] = 'SMTP 연결을 실패하였습니다.';
$PHPMAILER_LANG['smtp_error'] = 'SMTP 서버 오류: ';
$PHPMAILER_LANG['variable_set'] = '변수 설정 및 초기화 불가: ';
$PHPMAILER_LANG['extension_missing'] = '확장자 없음: ';

0 comments on commit 1befef0

Please sign in to comment.