From 4ec908ebe425103403a56d6a7624746a9efb83b5 Mon Sep 17 00:00:00 2001 From: Lars Kneschke Date: Fri, 23 Jun 2006 19:13:22 +0000 Subject: [PATCH] added support for fetching body and header for composed email --- phpgwapi/inc/class.phpmailer.inc.php | 27 +++++++++++++++++++++++ phpgwapi/inc/class.smtp.php | 33 ++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/phpgwapi/inc/class.phpmailer.inc.php b/phpgwapi/inc/class.phpmailer.inc.php index 97f67f119c..dd92e4880a 100644 --- a/phpgwapi/inc/class.phpmailer.inc.php +++ b/phpgwapi/inc/class.phpmailer.inc.php @@ -330,6 +330,33 @@ class PHPMailer $this->ReplyTo[$cur][1] = $name; } + function getMessageBody() { + if(!isset($this->sentBody)) { + // Set whether the message is multipart/alternative + if(!empty($this->AltBody)) + $this->ContentType = "multipart/alternative"; + + $this->SetMessageType(); + $body = $this->CreateBody(); + $this->sentBody = $body; + } + + return $this->sentBody; + } + + function getMessageHeader() { + if(!isset($this->sentHeader)) { + // Set whether the message is multipart/alternative + if(!empty($this->AltBody)) + $this->ContentType = "multipart/alternative"; + + $this->SetMessageType(); + $header = $this->CreateHeader(); + $this->sentHeader = $header; + } + + return $this->sentHeader; + } ///////////////////////////////////////////////// // MAIL SENDING METHODS diff --git a/phpgwapi/inc/class.smtp.php b/phpgwapi/inc/class.smtp.php index 6b45c3ae25..5eda180619 100644 --- a/phpgwapi/inc/class.smtp.php +++ b/phpgwapi/inc/class.smtp.php @@ -332,6 +332,12 @@ class SMTP # smaller lines while(strlen($line) > $max_line_length) { $pos = strrpos(substr($line,0,$max_line_length)," "); + + # Patch to fix DOS attack + if(!$pos) { + $pos = $max_line_length - 1; + } + $lines_out[] = substr($line,0,$pos); $line = substr($line,$pos + 1); # if we are processing headers we need to @@ -359,7 +365,31 @@ class SMTP # over with aleady fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF); + # get server response $rply = $this->get_lines(); + + # if the server is slow try to get an answer within 30 seconds + $timeout_counter = 0; + while(($rply=="") && ($timeout_counter<30)) + { + $timeout_counter+=1; + sleep(1); + $rply = $this->get_lines(); + } + # still no response to our data -> fail! + if($rply=="") + { + $this->error = array("error" => "timeout from server after data sent.", + "smtp_code" => 0, + "smtp_msg" => "(nothing)"); + + if($this->do_debug >= 1) { + echo "SMTP -> ERROR: " . $this->error["error"] . + ": " . $rply . $this->CRLF; + } + return false; + } + $code = substr($rply,0,3); if($this->do_debug >= 2) { @@ -1035,5 +1065,4 @@ class SMTP } - - ?> +?>