return(0);
}
- /* If $_SERVER['HTTP_HOST'] is set, use that in our HELO to the SMTP
- server. This should fix the DNS issues some people have had */
+ /*
+ * If $_SERVER['HTTP_HOST'] is set, use that in our HELO to the SMTP
+ * server. This should fix the DNS issues some people have had
+ */
if (sqgetGlobalVar('HTTP_HOST', $HTTP_HOST, SQ_SERVER)) { // HTTP_HOST is set
+ // optionally trim off port number
+ if($p = strrpos($HTTP_HOST, ':')) {
+ $HTTP_HOST = substr($HTTP_HOST, 0, $p);
+ }
$helohost = $HTTP_HOST;
} else { // For some reason, HTTP_HOST is not set - revert to old behavior
$helohost = $domain;
}
/* Lets introduce ourselves */
+ fputs($stream, "EHLO $helohost\r\n");
+ $tmp = fgets($stream,1024);
+ if ($this->errorCheck($tmp,$stream)) {
+ return(0);
+ }
+
if (( $smtp_auth_mech == 'cram-md5') or ( $smtp_auth_mech == 'digest-md5' )) {
// Doing some form of non-plain auth
- fputs($stream, "EHLO $helohost\r\n");
- $tmp = fgets($stream,1024);
- if ($this->errorCheck($tmp,$stream)) {
- return(0);
- }
if ($smtp_auth_mech == 'cram-md5') {
fputs($stream, "AUTH CRAM-MD5\r\n");
} elseif ($smtp_auth_mech == 'digest-md5') {
fputs($stream, "AUTH DIGEST-MD5\r\n");
}
+
$tmp = fgets($stream,1024);
if ($this->errorCheck($tmp,$stream)) {
}
} elseif ($smtp_auth_mech == 'login') {
// The LOGIN method
- fputs($stream, "EHLO $helohost\r\n");
- $tmp = fgets($stream, 1024);
- if ($this->errorCheck($tmp, $stream)) {
- return(0);
- }
fputs($stream, "AUTH LOGIN\r\n");
$tmp = fgets($stream, 1024);
if ($this->errorCheck($tmp, $stream)) {
return(0);
}
- } else {
+ } elseif ($smtp_auth_mech == "plain") {
+ /* SASL Plain */
+ $auth = base64_encode("$username\0$username\0$pass");
+
+ $query = "AUTH PLAIN\r\n";
+ fputs($stream, $query);
+ $read=fgets($stream, 1024);
+
+ if (substr($read,0,3) == '334') { // OK so far..
+ fputs($stream, "$auth\r\n");
+ $read = fgets($stream, 1024);
+ }
+
+ $results=explode(" ",$read,3);
+ $response=$results[1];
+ $message=$results[2];
+
+
+ } else {
/* Right here, they've reached an unsupported auth mechanism.
This is the ugliest hack I've ever done, but it'll do till I can fix
things up better tomorrow. So tired... */
}
/* Ok, who is sending the message? */
- fputs($stream, 'MAIL FROM: <'.$from->mailbox.'@'.$from->host.">\r\n");
+ fputs($stream, 'MAIL FROM:<'.$from->mailbox.'@'.$from->host.">\r\n");
$tmp = fgets($stream, 1024);
if ($this->errorCheck($tmp, $stream)) {
return(0);
for ($i = 0, $cnt = count($to); $i < $cnt; $i++) {
if (!$to[$i]->host) $to[$i]->host = $domain;
if ($to[$i]->mailbox) {
- fputs($stream, 'RCPT TO: <'.$to[$i]->mailbox.'@'.$to[$i]->host.">\r\n");
+ fputs($stream, 'RCPT TO:<'.$to[$i]->mailbox.'@'.$to[$i]->host.">\r\n");
$tmp = fgets($stream, 1024);
if ($this->errorCheck($tmp, $stream)) {
return(0);
for ($i = 0, $cnt = count($cc); $i < $cnt; $i++) {
if (!$cc[$i]->host) $cc[$i]->host = $domain;
if ($cc[$i]->mailbox) {
- fputs($stream, 'RCPT TO: <'.$cc[$i]->mailbox.'@'.$cc[$i]->host.">\r\n");
+ fputs($stream, 'RCPT TO:<'.$cc[$i]->mailbox.'@'.$cc[$i]->host.">\r\n");
$tmp = fgets($stream, 1024);
if ($this->errorCheck($tmp, $stream)) {
return(0);
}
}
}
+
for ($i = 0, $cnt = count($bcc); $i < $cnt; $i++) {
if (!$bcc[$i]->host) $bcc[$i]->host = $domain;
if ($bcc[$i]->mailbox) {
- fputs($stream, 'RCPT TO: <'.$bcc[$i]->mailbox.'@'.$bcc[$i]->host.">\r\n");
+ fputs($stream, 'RCPT TO:<'.$bcc[$i]->mailbox.'@'.$bcc[$i]->host.">\r\n");
$tmp = fgets($stream, 1024);
if ($this->errorCheck($tmp, $stream)) {
return(0);
. " $err_no : $err_str");
} else {
$tmp = fgets($popConnection, 1024); /* banner */
- if (!eregi("^\+OK", $tmp, $regs)) {
+ if (substr($tmp, 0, 3) != '+OK') {
return(0);
}
fputs($popConnection, "USER $user\r\n");
$tmp = fgets($popConnection, 1024);
- if (!eregi("^\+OK", $tmp, $regs)) {
+ if (substr($tmp, 0, 3) != '+OK') {
return(0);
}
fputs($popConnection, 'PASS ' . $pass . "\r\n");
$tmp = fgets($popConnection, 1024);
- if (!eregi("^\+OK", $tmp, $regs)) {
+ if (substr($tmp, 0, 3) != '+OK') {
return(0);
}
fputs($popConnection, "QUIT\r\n"); /* log off */