<?php
require_once('inc/debug.php');
require_once('inc/db_connect.php');
function mailaccounts($uid)
{
$uid = (int) $uid;
$query = "SELECT m.id,concat_ws('@',`m`.`local`,if(isnull(`m`.`domain`),_utf8'schokokeks.org',`d`.`domainname`)) AS `account`, `m`.`password` AS `cryptpass`,`m`.`maildir` AS `maildir`,aktiv from (`mail`.`mailaccounts` `m` left join `mail`.`v_domains` `d` on((`d`.`id` = `m`.`domain`))) WHERE m.uid=$uid";
DEBUG("SQL-Query: {$query}");
$result = @mysql_query($query);
if (mysql_error())
system_failure(mysql_error());
DEBUG("Found ".@mysql_num_rows($result)." rows!");
$accounts = array();
if (@mysql_num_rows($result) > 0)
while ($acc = @mysql_fetch_object($result))
array_push($accounts, array('id'=> $acc->id, 'account' => $acc->account, 'mailbox' => $acc->maildir, 'cryptpass' => $acc->cryptpass, 'enabled' => ($acc->aktiv == 1)));
return $accounts;
}
function get_mailaccount($id)
{
$uid = (int) $uid;
$query = "SELECT concat_ws('@',`m`.`local`,if(isnull(`m`.`domain`),_utf8'schokokeks.org',`d`.`domainname`)) AS `account`, `m`.`password` AS `cryptpass`,`m`.`maildir` AS `maildir`,aktiv from (`mail`.`mailaccounts` `m` left join `mail`.`v_domains` `d` on((`d`.`id` = `m`.`domain`))) WHERE m.id=$id";
$result = mysql_query($query);
DEBUG("Found ".mysql_num_rows($result)." rows!");
$acc = mysql_fetch_object($result);
$ret = array('account' => $acc->account, 'mailbox' => $acc->maildir, 'enabled' => ($acc->aktiv == 1));
DEBUG(print_r($ret, true));
return $ret;
}
/*
FIXME: Hier auch die crypt-Funktion nehmen wie beim systemuser-Passwort
*/
function encrypt_mail_password($pw)
{
DEBUG("unencrypted PW: ".$pw);
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w")
);
$process = proc_open("/usr/local/bin/exec/userdbpw -md5", $descriptorspec, $pipes);
fwrite($pipes[0], $pw);
fclose($pipes[0]);
$encpw = fgets($pipes[1]);
DEBUG("encrypted PW: ".$encpw);
fclose($pipes[1]);
proc_close($process);
return chop($encpw);