(for those of us with a home installation that want to go out
using the ISP's SMTP server because people arbitrarily block
our dynamic IP addresses).
new function in auth.php assigns the correct user/pass values
based on the auth mechanism.
For some reason the initStream method in Deliver_SMTP was not using
the passed in user name, it was using the global $username, and had
the key and onetimepad declared, though it always used the passed in
parameter pass instead - cleaned that up so it used the user/pass values
passed in instead.
read_body and compose were updated to use the new function in auth.php
to get the correct username and password for SMTP auth, and pass these
values to initStream.
Works for me.
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@6369
7612ce4b-ef26-0410-bec9-
ea0150e637f0
}
function initStream($message, $domain, $length=0, $host='', $port='', $user='', $pass='', $authpop=false) {
- global $use_smtp_tls,$smtp_auth_mech,$username,$key,$onetimepad;
-
+ global $use_smtp_tls,$smtp_auth_mech;
+
if ($authpop) {
- $this->authPop($host, '', $username, $pass);
+ $this->authPop($host, '', $user, $pass);
}
-
+
$rfc822_header = $message->rfc822_header;
$from = $rfc822_header->from[0];
$to = $rfc822_header->to;
$chall = substr($tmp,4);
// Depending on mechanism, generate response string
if ($smtp_auth_mech == 'cram-md5') {
- $response = cram_md5_response($username,$pass,$chall);
+ $response = cram_md5_response($user,$pass,$chall);
} elseif ($smtp_auth_mech == 'digest-md5') {
- $response = digest_md5_response($username,$pass,$chall,'smtp',$host);
+ $response = digest_md5_response($user,$pass,$chall,'smtp',$host);
}
fputs($stream, $response);
if ($this->errorCheck($tmp, $stream)) {
return(0);
}
- fputs($stream, base64_encode ($username) . "\r\n");
+ fputs($stream, base64_encode ($user) . "\r\n");
$tmp = fgets($stream, 1024);
if ($this->errorCheck($tmp, $stream)) {
return(0);
}
} elseif ($smtp_auth_mech == "plain") {
/* SASL Plain */
- $auth = base64_encode("$username\0$username\0$pass");
+ $auth = base64_encode("$user\0$user\0$pass");
$query = "AUTH PLAIN\r\n";
fputs($stream, $query);
return $hmac;
}
+/**
+ * Fillin user and password based on SMTP auth settings.
+ *
+ * @global
+ * @param string $user Reference to SMTP username
+ * @param string $pass Reference to SMTP password (unencrypted)
+ */
+function get_smtp_user(&$user, &$pass) {
+ global $username, $smtp_auth_mech,
+ $smtp_sitewide_user, $smtp_sitewide_pass;
+
+ if ($smtp_auth_mech == 'none') {
+ $user = '';
+ $pass = '';
+ } elseif ( isset($smtp_sitewide_user) && isset($smtp_sitewide_pass) ) {
+ $user = $smtp_sitewide_user;
+ $pass = $smtp_sitewide_pass;
+ } else {
+ global $key, $onetimepad;
+ $user = $username;
+ $pass = OneTimePadDecrypt($key, $onetimepad);
+ }
+}
+
?>
$deliver = new Deliver_SMTP();
global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech;
- if ($smtp_auth_mech == 'none') {
- $user = '';
- $pass = '';
- } else {
- global $key, $onetimepad;
- $user = $username;
- $pass = OneTimePadDecrypt($key, $onetimepad);
- }
-
$authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false;
+ get_smtp_user($user, $pass);
$stream = $deliver->initStream($composeMessage,$domain,0,
$smtpServerAddress, $smtpPort, $user, $pass, $authPop);
} elseif (!$draft) {
require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php');
$deliver = new Deliver_SMTP();
global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp;
- if ($smtp_auth_mech == 'none') {
- $user = '';
- $pass = '';
- } else {
- global $key, $onetimepad;
- $user = $username;
- $pass = OneTimePadDecrypt($key, $onetimepad);
- }
$authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false;
+ get_smtp_user($user, $pass);
$stream = $deliver->initStream($composeMessage,$domain,0,
$smtpServerAddress, $smtpPort, $user, $pass, $authPop);
}