From ce579f09143160e84aba768bc38054d09a11063f Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Thu, 4 Jan 2007 17:54:22 +0000 Subject: Fix email_check for servers using greylisting --- mail.class | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'mail.class') diff --git a/mail.class b/mail.class index 08006cc..b033770 100644 --- a/mail.class +++ b/mail.class @@ -327,23 +327,26 @@ function fullname_escape($string) * @param $fp Connection to SMTP server opened using fsockopen * @param $command Command to send, e.g. HELO gna.ch * @param $anwer String containing full answer from SMTP server - * @return True if SMTP result code is 2XX + * @param timeoutok Whether a timeout is considered ok + * @param $failcode Lowest SMTP result code which is considered a failure (default 300) + * @return True if SMTP result code is lower than $failcode * */ -function send_smtp_cmd($fp, $cmd, &$answer, $timeoutok = false) +function send_smtp_cmd($fp, $cmd, &$answer, $timeoutok = false, $failcode = 300) { $result = false; $answer = ''; if (!$cmd || (!feof($fp) && fwrite($fp, "$cmd\r\n"))) { - while (!feof($fp) && ereg('^(.)..(.?)(.*)$', fgets($fp, 1024), $regs)) + while (!feof($fp) && ereg('^(...)(.?)(.*)$', fgets($fp, 1024), $regs)) { $answer .= $regs[0]; + $resultcode = intval($regs[1]); if ($regs[2] != '-') /* Multi line response? */ { - if ($regs[1] == 2) + if (($resultcode >= 100) && ($resultcode < $failcode)) $result = true; break; @@ -442,7 +445,7 @@ function check_email($email, $checkmailbox = true) $timeout($fp, 2); $timeoutok = ($domain != 'bluewin.ch'); - if (it_mail::send_smtp_cmd($fp, "RCPT TO: <$email>", $answer, $timeoutok)) + if (it_mail::send_smtp_cmd($fp, "RCPT TO: <$email>", $answer, $timeoutok, 500)) # 450 is often used for Greylisting $result = IT_MAIL_CHECKEMAIL_OK; else if (eregi('quota|full|exceeded storage', $answer)) $result = IT_MAIL_CHECKEMAIL_MAILBOXFULL; -- cgit v1.2.3