fix for bug 421645 use of quotes in email_sig preferences

This commit is contained in:
angles 2001-05-30 19:47:13 +00:00
parent 0c0264ccdd
commit 2a381e6dd4

View File

@ -27,11 +27,13 @@
/* $Id$ */ /* $Id$ */
class send { class send
{
var $err = array("code","msg","desc"); var $err = array("code","msg","desc");
var $to_res = array(); var $to_res = array();
function send() { function send()
{
$this->err["code"] = " "; $this->err["code"] = " ";
$this->err["msg"] = " "; $this->err["msg"] = " ";
$this->err["desc"] = " "; $this->err["desc"] = " ";
@ -76,7 +78,9 @@ class send {
if ($phpgw_info['user']['preferences']['email']['email_sig'] && $attach_sig) if ($phpgw_info['user']['preferences']['email']['email_sig'] && $attach_sig)
{ {
$body .= "\n-----\n".$phpgw_info['user']['preferences']['email']['email_sig']; //$body .= "\n-----\n".$phpgw_info['user']['preferences']['email']['email_sig'];
$get_sig = $this->sig_html_to_text($phpgw_info['user']['preferences']['email']['email_sig']);
$body .= "\n-----\n" .$get_sig;
} }
if (ereg('Message-Boundary', $body)) if (ereg('Message-Boundary', $body))
@ -130,33 +134,45 @@ class send {
} }
elseif ($type == 'nntp') elseif ($type == 'nntp')
{ {
// nothing is here?
} }
} }
// ==================================================[ some sub-functions ]=== // ==================================================[ some sub-functions ]===
function socket2msg($socket) { function socket2msg($socket)
$followme = "-"; $this->err["msg"] = ""; {
do { $followme = "-";
$this->err["msg"] = "";
do
{
$rmsg = fgets($socket,255); $rmsg = fgets($socket,255);
// echo "< $rmsg<BR>\n"; // echo "< $rmsg<BR>\n";
$this->err["code"] = substr($rmsg,0,3); $this->err["code"] = substr($rmsg,0,3);
$followme = substr($rmsg,3,1); $followme = substr($rmsg,3,1);
$this->err["msg"] = substr($rmsg,4); $this->err["msg"] = substr($rmsg,4);
if (substr($this->err["code"],0,1) != 2 && substr($this->err["code"],0,1) != 3) { if (substr($this->err["code"],0,1) != 2 && substr($this->err["code"],0,1) != 3)
{
$rc = fclose($socket); $rc = fclose($socket);
return false; return false;
} }
if ($followme = " ") { break; } if ($followme = " ")
} while ($followme = "-"); {
break;
}
}
while ($followme = "-");
return true; return true;
} }
function msg2socket($socket,$message) { // send single line\n function msg2socket($socket,$message)
{
// send single line\n
// echo "raw> $message<BR>\n"; // echo "raw> $message<BR>\n";
// echo "hex> ".bin2hex($message)."<BR>\n"; // echo "hex> ".bin2hex($message)."<BR>\n";
$rc = fputs($socket,"$message"); $rc = fputs($socket,"$message");
if (!$rc) { if (!$rc)
{
$this->err["code"] = "420"; $this->err["code"] = "420";
$this->err["msg"] = "lost connection"; $this->err["msg"] = "lost connection";
$this->err["desc"] = "Lost connection to smtp server."; $this->err["desc"] = "Lost connection to smtp server.";
@ -166,45 +182,67 @@ class send {
return true; return true;
} }
function put2socket($socket,$message) { // check for multiple lines 1st function put2socket($socket,$message)
{
// check for multiple lines 1st
$pos = strpos($message,"\n"); $pos = strpos($message,"\n");
if (!is_int($pos)) { // no new line found if (!is_int($pos))
{
// no new line found
$message .= "\r\n"; $message .= "\r\n";
$this->msg2socket($socket,$message); $this->msg2socket($socket,$message);
} else { // multiple lines, we have to split it }
do { else
{
// multiple lines, we have to split it
do
{
$msglen = $pos + 1; $msglen = $pos + 1;
$msg = substr($message,0,$msglen); $msg = substr($message,0,$msglen);
$message = substr($message,$msglen); $message = substr($message,$msglen);
$pos = strpos($msg,"\r\n"); $pos = strpos($msg,"\r\n");
if (!is_int($pos)) { // line not terminated if (!is_int($pos))
{
// line not terminated
$msg = chop($msg)."\r\n"; $msg = chop($msg)."\r\n";
} }
$pos = strpos($msg,"."); // escape leading periods $pos = strpos($msg,"."); // escape leading periods
if (is_int($pos) && !$pos) { if (is_int($pos) && !$pos)
{
$msg = "." . $msg; $msg = "." . $msg;
} }
if (!$this->msg2socket($socket,$msg)) { return false; } if (!$this->msg2socket($socket,$msg))
{
return false;
}
$pos = strpos($message,"\n"); $pos = strpos($message,"\n");
} while (strlen($message)>0); }
while (strlen($message)>0);
} }
return true; return true;
} }
function check_header($subject,$header) { // check if header contains subject function check_header($subject,$header)
// and is correctly terminated {
// check if header contains subject and is correctly terminated
$header = chop($header); $header = chop($header);
$header .= "\n"; $header .= "\n";
if (is_string($subject) && !$subject) { // no subject specified if (is_string($subject) && !$subject)
{
// no subject specified
return $header; return $header;
} }
$theader = strtolower($header); $theader = strtolower($header);
$pos = strpos($theader,"\nsubject:"); $pos = strpos($theader,"\nsubject:");
if (is_int($pos)) { // found after a new line if (is_int($pos))
{
// found after a new line
return $header; return $header;
} }
$pos = strpos($theader,"subject:"); $pos = strpos($theader,"subject:");
if (is_int($pos) && !$pos) { // found at start if (is_int($pos) && !$pos)
{
// found at start
return $header; return $header;
} }
$pos = substr($subject,"\n"); $pos = substr($subject,"\n");
@ -214,24 +252,46 @@ class send {
return $header; return $header;
} }
function sig_html_to_text($sig)
{
// convert HTML chars in the email sig to normal text
// note: initially include a "magic_quote" like escape slash with the single and double quotes
$sig_clean = $sig;
$sig_clean = ereg_replace('&gt;', '>', $sig_clean);
$sig_clean = ereg_replace('&lt;', '<', $sig_clean);
$sig_clean = ereg_replace('&quot;', '\"', $sig_clean);
$sig_clean = ereg_replace('&#039;', '\'', $sig_clean);
$sig_clean = ereg_replace('&amp;', '&', $sig_clean);
// now strip the "magic_quote" like escape slashs
$sig_clean = stripslashes($sig_clean);
return $sig_clean;
}
// ==============================================[ main function: smail() ]=== // ==============================================[ main function: smail() ]===
function smail($to,$subject,$message,$header) { function smail($to,$subject,$message,$header)
{
global $phpgw_info; global $phpgw_info;
$fromuser = $phpgw_info["user"]["preferences"]["email"]["address"]; $fromuser = $phpgw_info["user"]["preferences"]["email"]["address"];
$mymachine = $phpgw_info["server"]["hostname"]; $mymachine = $phpgw_info["server"]["hostname"];
$errcode = ""; $errmsg = ""; // error code and message of failed connection // error code and message of failed connection
$timeout = 5; // timeout in secs $errcode = "";
$errmsg = "";
// timeout in secs
$timeout = 5;
// now we try to open the socket and check, if any smtp server responds // now we try to open the socket and check, if any smtp server responds
$socket = fsockopen($phpgw_info["server"]["smtp_server"],$phpgw_info["server"]["smtp_port"],$errcode,$errmsg,$timeout); $socket = fsockopen($phpgw_info["server"]["smtp_server"],$phpgw_info["server"]["smtp_port"],$errcode,$errmsg,$timeout);
if (!$socket) { if (!$socket)
{
$this->err["code"] = "420"; $this->err["code"] = "420";
$this->err["msg"] = "$errcode:$errmsg"; $this->err["msg"] = "$errcode:$errmsg";
$this->err["desc"] = "Connection to ".$phpgw_info["server"]["smtp_server"].":".$phpgw_info["server"]["smtp_port"]." failed - could not open socket."; $this->err["desc"] = "Connection to ".$phpgw_info["server"]["smtp_server"].":".$phpgw_info["server"]["smtp_port"]." failed - could not open socket.";
return false; return false;
} else { }
else
{
$rrc = $this->socket2msg($socket); $rrc = $this->socket2msg($socket);
} }
@ -242,18 +302,24 @@ class send {
"\$src = \$this->msg2socket(\$socket,\"MAIL FROM:<\$fromuser>\r\n\");", "\$src = \$this->msg2socket(\$socket,\"MAIL FROM:<\$fromuser>\r\n\");",
"\$rrc = \$this->socket2msg(\$socket);" "\$rrc = \$this->socket2msg(\$socket);"
); );
for ($src=true,$rrc=true,$i=0; $i<count($cmds);$i++) { for ($src=true,$rrc=true,$i=0; $i<count($cmds);$i++)
{
eval ($cmds[$i]); eval ($cmds[$i]);
if (!$src || !$rrc) return false; if (!$src || !$rrc)
{
return false;
}
} }
// now we've got to evaluate the $to's // now we've got to evaluate the $to's
$toaddr = explode(",",$to); $toaddr = explode(",",$to);
$numaddr = count($toaddr); $numaddr = count($toaddr);
for ($i=0; $i<$numaddr; $i++) { for ($i=0; $i<$numaddr; $i++)
{
$src = $this->msg2socket($socket,'RCPT TO:<'.$toaddr[$i].">\r\n"); $src = $this->msg2socket($socket,'RCPT TO:<'.$toaddr[$i].">\r\n");
$rrc = $this->socket2msg($socket); $rrc = $this->socket2msg($socket);
$this->to_res[$i][addr] = $toaddr[$i]; // for lateron validation // for lateron validation
$this->to_res[$i][addr] = $toaddr[$i];
$this->to_res[$i][code] = $this->err["code"]; $this->to_res[$i][code] = $this->err["code"];
$this->to_res[$i][msg] = $this->err["msg"]; $this->to_res[$i][msg] = $this->err["msg"];
$this->to_res[$i][desc] = $this->err["desc"]; $this->to_res[$i][desc] = $this->err["desc"];
@ -261,31 +327,65 @@ class send {
//now we have to make sure that at least one $to-address was accepted //now we have to make sure that at least one $to-address was accepted
$stop = 1; $stop = 1;
for ($i=0;$i<count($this->to_res);$i++) { for ($i=0;$i<count($this->to_res);$i++)
{
$rc = substr($this->to_res[$i][code],0,1); $rc = substr($this->to_res[$i][code],0,1);
if ($rc == 2) { // at least to this address we can deliver if ($rc == 2)
{
// at least to this address we can deliver
$stop = 0; $stop = 0;
} }
} }
if ($stop) return false; // no address found we can deliver to if ($stop)
{
// no address found we can deliver to
return false;
}
// now we can go to deliver the message! // now we can go to deliver the message!
if (!$this->msg2socket($socket,"DATA\r\n")) return false; if (!$this->msg2socket($socket,"DATA\r\n"))
if (!$this->socket2msg($socket)) return false; {
if ($header != "") { return false;
}
if (!$this->socket2msg($socket))
{
return false;
}
if ($header != "")
{
$header = $this->check_header($subject,$header); $header = $this->check_header($subject,$header);
if (!$this->put2socket($socket,$header)) return false; if (!$this->put2socket($socket,$header))
if (!$this->put2socket($socket,"\r\n")) return false; {
return false;
}
if (!$this->put2socket($socket,"\r\n"))
{
return false;
}
} }
$message = chop($message); $message = chop($message);
$message .= "\n"; $message .= "\n";
if (!$this->put2socket($socket,$message)) return false; if (!$this->put2socket($socket,$message))
if (!$this->msg2socket($socket,".\r\n")) return false; {
if (!$this->socket2msg($socket)) return false; return false;
if (!$this->msg2socket($socket,"QUIT\r\n")) return false; }
Do { if (!$this->msg2socket($socket,".\r\n"))
{
return false;
}
if (!$this->socket2msg($socket))
{
return false;
}
if (!$this->msg2socket($socket,"QUIT\r\n"))
{
return false;
}
do
{
$closing = $this->socket2msg($socket); $closing = $this->socket2msg($socket);
} while ($closing); }
while ($closing);
return true; return true;
} }