Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Added POP-before-SMTP Support
Browse files Browse the repository at this point in the history
Ignore-this: 6df5ad3a74b32e27ae808bb19a2435f5

The Swift-Class for POP-before-SMTP had a bug and was missing logging. This
was fixed.

darcs-hash:20090808191324-7ad00-20923c1f429d6dd325e7a8104166ad770a20d284.gz
  • Loading branch information
splitbrain committed Aug 8, 2009
1 parent 4cfe9b9 commit ddfbbb6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions Swift/Authenticator/@PopB4Smtp.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function isAuthenticated($user, $pass, Swift $swift)
} catch (Swift_ConnectionException $e) { } catch (Swift_ConnectionException $e) {
if ($log->hasLevel(Swift_Log::LOG_ERRORS)) if ($log->hasLevel(Swift_Log::LOG_ERRORS))
{ {
$log->add($e->getMessage(),Swift_Log::ERROR);
$log->add("POP3 authentication failed."); $log->add("POP3 authentication failed.");
} }
return false; return false;
Expand Down
29 changes: 24 additions & 5 deletions Swift/Authenticator/PopB4Smtp/Pop3Connection.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Swift_Authenticator_PopB4Smtp_Pop3Connection
* @var resource * @var resource
*/ */
protected $handle = null; protected $handle = null;

/** /**
* Constructor * Constructor
* @param string The name of the POP3 server * @param string The name of the POP3 server
Expand Down Expand Up @@ -123,8 +123,14 @@ public function start()
{ {
$url = $this->getServer(); $url = $this->getServer();
if ($this->getEncryption() == self::ENC_SSL) $url = "ssl://" . $url; if ($this->getEncryption() == self::ENC_SSL) $url = "ssl://" . $url;


if ((false === $this->handle = fsockopen($url, $this->getPort(), $errno, $errstr, $timeout))) $log = Swift_LogContainer::getLog();
if ($log->hasLevel(Swift_Log::LOG_NETWORK))
{
$log->add("Trying to connect to POP3 server ".$url." on port ".$this->getPort());
}

if ((false === $this->handle = @fsockopen($url, $this->getPort(), $errno, $errstr, 5)))
{ {
Swift_ClassLoader::load("Swift_ConnectionException"); Swift_ClassLoader::load("Swift_ConnectionException");
throw new Swift_ConnectionException("The POP3 connection failed to start. The error string returned from fsockopen() is [" . $errstr . "] #" . $errno); throw new Swift_ConnectionException("The POP3 connection failed to start. The error string returned from fsockopen() is [" . $errstr . "] #" . $errno);
Expand Down Expand Up @@ -158,7 +164,14 @@ public function read()
Swift_ClassLoader::load("Swift_ConnectionException"); Swift_ClassLoader::load("Swift_ConnectionException");
throw new Swift_ConnectionException("Data could not be read from the POP3 connection."); throw new Swift_ConnectionException("Data could not be read from the POP3 connection.");
} }
return trim($response); $response = trim($response);

$log = Swift_LogContainer::getLog();
if ($log->hasLevel(Swift_Log::LOG_NETWORK))
{
$log->add($response,Swift_Log::RESPONSE);
}
return $response;
} }
/** /**
* Write a command to the remote socket * Write a command to the remote socket
Expand All @@ -167,10 +180,16 @@ public function read()
*/ */
public function write($command) public function write($command)
{ {
if (false !== fwrite($this->handle, $command . "\r\n")) if (false === fwrite($this->handle, $command . "\r\n"))
{ {
Swift_ClassLoader::load("Swift_ConnectionException"); Swift_ClassLoader::load("Swift_ConnectionException");
throw new Swift_ConnectionException("Data could not be written to the POP3 connection."); throw new Swift_ConnectionException("Data could not be written to the POP3 connection.");
} }

$log = Swift_LogContainer::getLog();
if ($log->hasLevel(Swift_Log::LOG_NETWORK))
{
$log->add($command,Swift_Log::COMMAND);
}
} }
} }
6 changes: 6 additions & 0 deletions action.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ function handle_message_send(&$event, $param){
$this->getConf('smtp_ssl') $this->getConf('smtp_ssl')
); );


// use Pop-before-SMTP
if($this->getConf('pop3_host')) {
require_once dirname(__FILE__).'/Swift/Authenticator/@PopB4Smtp.php';
$smtp->attachAuthenticator(new Swift_Authenticator_PopB4Smtp($this->getConf('pop3_host')));
}

// use SMTP auth? // use SMTP auth?
if($this->getConf('auth_user')) $smtp->setUsername($this->getConf('auth_user')); if($this->getConf('auth_user')) $smtp->setUsername($this->getConf('auth_user'));
if($this->getConf('auth_pass')) $smtp->setPassword($this->getConf('auth_pass')); if($this->getConf('auth_pass')) $smtp->setPassword($this->getConf('auth_pass'));
Expand Down
1 change: 1 addition & 0 deletions conf/default.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@


$conf['auth_user'] = ''; $conf['auth_user'] = '';
$conf['auth_pass'] = ''; $conf['auth_pass'] = '';
$conf['pop3_host'] = '';


$conf['debug'] = 0; $conf['debug'] = 0;
1 change: 1 addition & 0 deletions conf/metadata.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


$meta['auth_user'] = array('string'); $meta['auth_user'] = array('string');
$meta['auth_pass'] = array('password'); $meta['auth_pass'] = array('password');
$meta['pop3_host'] = array('string');


$meta['localdomain'] = array('string'); $meta['localdomain'] = array('string');


Expand Down
1 change: 1 addition & 0 deletions lang/en/settings.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


$lang['auth_user'] = 'If authentication is required, put your user name here.'; $lang['auth_user'] = 'If authentication is required, put your user name here.';
$lang['auth_pass'] = 'Password for the above user.'; $lang['auth_pass'] = 'Password for the above user.';
$lang['pop3_host'] = 'If your server uses POP-before-SMTP for authentication, give your POP3 credentials above and put your POP3 server here. For usual SMTP auth leave this field empty.';


$lang['localdomain'] = 'The name to be used during HELO phase of SMTP. Should be the FQDN of the webserver DokuWiki is running on. Leave empty for autodetection.'; $lang['localdomain'] = 'The name to be used during HELO phase of SMTP. Should be the FQDN of the webserver DokuWiki is running on. Leave empty for autodetection.';


Expand Down

0 comments on commit ddfbbb6

Please sign in to comment.