Skip to content

Commit

Permalink
Increase default timelimit to match RFC, make data command wait longe…
Browse files Browse the repository at this point in the history
…r, see PHPMailer#293
  • Loading branch information
Synchro committed Oct 13, 2014
1 parent 74bdf93 commit 093405d
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions class.smtp.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,11 @@ class SMTP
public $Timeout = 300;

/**
* The SMTP timelimit value for reads, in seconds.
* How long to wait for commands to complete, in seconds.
* Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
* @type integer
*/
public $Timelimit = 30;
public $Timelimit = 300;

/**
* The socket for the server connection.
Expand Down Expand Up @@ -537,9 +538,11 @@ public function close()
*/
public function data($msg_data)
{
//This will use the standard timelimit
if (!$this->sendCommand('DATA', 'DATA', 354)) {
return false;
}

/* The server is ready to accept data!
* According to rfc821 we should not send more than 1000 characters on a single line (including the CRLF)
* so we will break the data up into lines by \r and/or \n then if needed we will break each of those into
Expand Down Expand Up @@ -567,7 +570,7 @@ public function data($msg_data)
if ($in_headers and $line == '') {
$in_headers = false;
}
// ok we need to break this line up into several smaller lines
//We need to break this line up into several smaller lines
//This is a small micro-optimisation: isset($str[$len]) is equivalent to (strlen($str) > $len)
while (isset($line[self::MAX_LINE_LENGTH])) {
//Working backwards, try to find a space within the last MAX_LINE_LENGTH chars of the line to break on
Expand All @@ -584,16 +587,14 @@ public function data($msg_data)
//Move along by the amount we dealt with
$line = substr($line, $pos + 1);
}
/* If processing headers add a LWSP-char to the front of new line
* RFC822 section 3.1.1
*/
//If processing headers add a LWSP-char to the front of new line RFC822 section 3.1.1
if ($in_headers) {
$line = "\t" . $line;
}
}
$lines_out[] = $line;

// Send the lines to the server
//Send the lines to the server
foreach ($lines_out as $line_out) {
//RFC2821 section 4.5.2
if (!empty($line_out) and $line_out[0] == '.') {
Expand All @@ -603,8 +604,14 @@ public function data($msg_data)
}
}

// Message data has been sent, complete the command
return $this->sendCommand('DATA END', '.', 250);
//Message data has been sent, complete the command
//Increase timelimit for end of DATA command
$savetimelimit = $this->Timelimit;
$this->Timelimit = $this->Timelimit * 2;
$r = $this->sendCommand('DATA END', '.', 250);
//Restore timelimit
$this->Timelimit = $savetimelimit;
return $r;
}

/**
Expand All @@ -619,7 +626,7 @@ public function data($msg_data)
*/
public function hello($host = '')
{
// Try extended hello first (RFC 2821)
//Try extended hello first (RFC 2821)
return (boolean)($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host));
}

Expand Down

0 comments on commit 093405d

Please sign in to comment.