Skip to content

Commit 6a949ef

Browse files
committed
Fix size calculation when headers are provided
When headers are provided to data(), we include their size in the initial data size calculation. However, because the headers are sent separately in that case, we need to remove them from $size before sending the remaining data. Fixes #27
1 parent de9f5f8 commit 6a949ef

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

Net/SMTP.php

+3
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,9 @@ public function data($data, $headers = null)
10341034
if (PEAR::isError($result = $this->send($headers . "\r\n\r\n"))) {
10351035
return $result;
10361036
}
1037+
1038+
/* Subtract the headers size now that they've been sent. */
1039+
$size -= strlen($headers) + 4;
10371040
}
10381041

10391042
/* Now we can send the message body data. */

tests/basic.phpt

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ if (PEAR::isError($res = $smtp->rcptTo(TEST_TO))) {
2929
$res->getMessage() . "\n");
3030
}
3131

32-
if (PEAR::isError($smtp->data('Subject: ' . TEST_SUBJECT . "\r\n\r\n" . TEST_BODY))) {
32+
$headers = 'Subject: ' . TEST_SUBJECT;
33+
if (PEAR::isError($smtp->data(TEST_BODY, $headers))) {
3334
die("Unable to send data\n");
3435
}
3536

0 commit comments

Comments
 (0)