[imp] dbmail + horde user creation; passwd change
markus
freaked at gmx.at
Tue Feb 24 00:04:30 PST 2004
Hi,
I'm using dbmail with horde.
Dbmail (www.dbmail.org ) is a pop3/imap Mailserver.
It stores everything in a mysql Database is easy to setup and to
administrate through sql statements.
I just wan't to share my experience so here is what I did.
This hook enables automatic mailbox creation for imp if I create
a new user through the horde interface.
dbmail version: dbmail-mysql 1.2.1-2 Fast and scalable sql based
imap and pop mail server
**********************
horde/config/hooks.php
**********************
if (!function_exists('_horde_hook_dbmail')) {
function _horde_hook_dbmail($userID, $passw)
{
global $conf;
$conf['sql_dbmail']['phptype'] = 'mysql';
$conf['sql_dbmail']['persistent'] = false;
$conf['sql_dbamil']['protocol'] = 'tcp';
$conf['sql_dbmail']['hostspec'] = 'localhost';
$conf['sql_dbmail']['username'] = 'mailuser';
$conf['sql_dbmail']['password'] = 'secret';
$conf['sql_dbmail']['database'] = 'dbmail';
$conf['sql_dbmail']['charset'] = 'iso-8859-1';
require_once 'DB.php';
$_db = &DB::connect($conf['sql_dbmail'], true);
$query1 = 'INSERT INTO users (userid, passwd, client_idnr,
maxmail_size)';
$query1 .= 'VALUES (?, ?, 0, 25000000)';
$userpass = array($userID,$passw);
$result1 = $_db->query($query1, $userpass );
if (!(is_a($result1, 'PEAR_Error'))) {
$query2 = 'Select user_idnr from users where userid = ?';
$dbmailID = $_db->getOne($query2, $userID);
$query3 = 'INSERT INTO mailboxes (owner_idnr, name)';
$query3 .= ' VALUES (?, \'INBOX\')';
$result3 = $_db->query($query3, $dbmailID);
if (!(is_a($result3, 'PEAR_Error'))) {
$query4 = 'INSERT INTO mailboxes (owner_idnr,
name)';
$query4 .= ' VALUES (?, \'trash\')';
$result4 = $_db->query($query4, $dbmailID);
if (!(is_a($result4, 'PEAR_Error'))) {
$query5 = 'INSERT INTO mailboxes (owner_idnr,
name)';
$query5 .= ' VALUES (?, \'sent-mail\')';
$result5 = $_db->query($query5, $dbmailID);
if (!(is_a($result5, 'PEAR_Error'))) {
$query6 = 'INSERT INTO aliases (alias,
deliver_to)';
$query6 .= 'VALUES (?, ?)';
$mailalias = $userID . '@example.at';
$useralias = array($mailalias,$dbmailID);
$result = $_db->query($query6, $useralias);
} else { $result = $result5; }
} else { $result = $result4; }
} else { $result = $result3; }
} else { $result = $result1; }
return DB::isError($result) ? $result : true;
}
}
**********************
horde/config/hooks.php END
**********************
to activate the hook you have to add it in user.php
**********************
horde/admin/user.php
**********************
... snip
if (is_a($ret = $auth->addUser($info['user_name'], $credentials),
'PEAR_Error')) {
$notification->push(sprintf(_("There was a problem
adding '%s' to the system: %s"), $info['user_name'], $ret$
} else {
$result = Horde::callHook('_horde_hook_signup_addextra',
array($info['user_name'],
$info['extra']));
$result_dbmail = Horde::callHook('_horde_hook_dbmail',
array($info['user_name'],
$info['password']));
$notification->push(sprintf(_("Added '%s' to the
system, but could not addadditional signup information: %s."),
$info['user_name'], $result->getMessage()), 'horde.warning');
}
elseif (is_a($result_dbmail, 'PEAR_Error')) {
$notification->push(sprintf(_("Added '%s' to the
system, but could not add additional signup information$
}
... snip
**********************
horde/admin/user.php END
**********************
to change the password just configure backends of passwd
**********************
horde/passwd/config
**********************
... snip
'sql2' => array (
'name' => 'Mailserver Auth',
'driver' => 'sql',
'params' => array(
'phptype' => 'mysql',
'hostspec' => 'localhost',
'username' => 'mailuser',
'password' => 'secret',
'encryption' => 'plain',
'database' => 'dbmail',
'table' => 'users',
'user_col' => 'userid',
'pass_col' => 'passwd',
'show_encryption' => false
),
snip ...
**********************
horde/passwd/config END
**********************
configure imp for dbmail
**********************
horde/imp/config/servers.php
**********************
$servers['imap'] = array(
'name' => 'IMAP Server',
'server' => 'localhost',
'hordeauth' => true,
'protocol' => 'imap/notls',
'port' => 143,
'folders' => '',
'namespace' => '',
'maildomain' => 'mail.example.com',
'smtphost' => 'localhost',
'realm' => '',
'preferred' => '',
'dotfiles' => false,
'hierarchies' => array()
);
**********************
horde/imp/config/servers.php END
**********************
feel free to send any question
markus
More information about the imp
mailing list