[dev] [patch] new sam driver
Ben Chavet
ben at chavet.net
Thu Apr 8 14:29:26 PDT 2004
Attached is a patch to add vfs support to sam.
Modified files:
sam/config/backends.php.dist
New files:
sam/lib/Driver/vfs.php
--Ben
-------------- next part --------------
<?php
class SAM_Driver_vfs extends SAM_Driver {
var $_capabilities = array('tag_level',
'hit_level',
'kill_level',
'rewrite_sub',
'spam_quarantine',
'allow_virus',
'allow_spam',
'allow_banned',
'allow_header',
'skip_virus',
'skip_spam',
'skip_banned',
'skip_header',
'whitelist_from',
'blacklist_from');
function SAM_Driver_vfs($params = array())
{
$default_params = array(
'hostspec' => 'localhost',
'port' => 21,
'user_prefs' => '.spamassassin/user_prefs',
'vfstype' => 'ftp'
);
$this->_params = array_merge($default_params, $params);
}
/**
* Retreives the user options and stores them in the member array.
*
* @access public
*
* @return mixed True on success or a PEAR_Error object on failure.
*/
function retrieve()
{
$options = $this->_retrieve();
if (!is_a($options, 'PEAR_Error')) {
$this->_options = $options;
} else {
return $options;
}
return true;
}
/**
* Stores the user options from the member array.
*
* @access public
*
* @return mixed True on success or a PEAR_Error object on failure.
*/
function store()
{
return $this->_store();
}
function _retrieve()
{
if ($this->_params['vfstype'] != 'ftp') {
return PEAR::raiseError(_(sprintf("VFStype '%s' not yet implemented.", $this->_params['vfstype'])));
}
$this->_params['username'] = Auth::getBareAuth();
$this->_params['password'] = Auth::getCredential('password');
// get user's SA config file
require_once 'VFS.php';
$vfs = &VFS::singleton($this->_params['vfstype'], $this->_params);
$conf = $vfs->read('', $this->_params['user_prefs']);
$vfs->_disconnect();
// Ignore comments and whitespace
$conf = explode("\n", $conf);
foreach ($conf as $index => $line) {
$comment = strpos($line, '#');
if ($comment === 0 || trim($line) == '') {
unset($conf[$index]);
} else if ($comment) {
$conf[$index] = substr($line, 0, $comment);
}
}
foreach ($conf as $index => $line) {
$conf[$index] = preg_split("/\s+/", trim($line));
}
$return = array();
foreach($conf as $line) {
$return[$line[0]] = $line[1];
}
return $return;
}
function _store()
{
if ($this->_params['vfstype'] != 'ftp') {
return PEAR::raiseError(_(sprintf("VFStype '%s' not yet implemented.", $this->_params['vfstype'])));
}
$this->_params['username'] = Auth::getBareAuth();
$this->_params['password'] = Auth::getCredential('password');
// generate config file
$output = _("# SpamAssassin config file generated by SAM") . ' (' . date('F j, Y, g:i a') . ")\n";
$store = $this->_options;
foreach ($store as $attribute => $value) {
$output .= "$attribute $value\n";
}
// write config file
require_once 'VFS.php';
$vfs = &VFS::singleton($this->_params['vfstype'], $this->_params);
$res = $vfs->writeData('', $this->_params['user_prefs'], $output);
$vfs->_disconnect();
if (is_a($res, 'PEAR_Error')) {
return $res;
}
return true;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: backends.php.dist.diff
Type: text/x-patch
Size: 666 bytes
Desc: not available
Url : http://lists.horde.org/archives/dev/attachments/20040408/78303a3b/backends.php.dist.bin
More information about the dev
mailing list