<?
########## Confixx(R) 3.0 Professional ############
####### Copyright SWsoft, Inc. 2004-2005 ##########
#### http://www.sw-soft.com - info@sw-soft.com ####

include_once( "../include/class.SQLString.php" );
include_once("auth.php");

db_connect($db_host, $db_user, $db_pass);

$id = safe_query( "select account from pop3 where account = ?  and kunde = ? ", TRUE, new SQLString( $pop3 ), new SQLString( $PHP_AUTH_USER ) );
$werte = db_fetch_array($id);
$pop = $werte["account"];

if ($pop != $pop3)
	{
	 $fehlertext = ltext("empolo2_error1");
	 db_close();
	 include("email_pop3.php");
	 exit();
	}

safe_query( "delete from pop3 where account = ?  and kunde = ? ", TRUE, new SQLString($pop3), new SQLString($PHP_AUTH_USER) );
safe_query( "delete from webmail_ab WHERE pop3 = ? ", TRUE, new SQLString($pop3) );
safe_query( "delete from webmail_session where pop3 = ? ", TRUE, new SQLString($pop3) );
safe_query( "delete from webmail_sign where pop3 = ? ", TRUE, new SQLString($pop3) );
safe_query( "delete from webmail_def_from where pop3 = ? ", TRUE, new SQLString($pop3) );
safe_query( "delete from spampref where username = ? ", TRUE, new SQLString($pop3) );

$eID = safe_query( "select prefix, domain, ident from email where pop3 = ?  and kunde = ?  and neu = 0", TRUE, new SQLString( $pop3 ), new SQLString( $PHP_AUTH_USER ) );
safe_query( "delete from email where pop3 = ?  and kunde = ? ", TRUE, new SQLString($pop3), new SQLString($PHP_AUTH_USER) );
	while ($eWERTE = db_fetch_array($eID))
		{
		 $eaccount = $eWERTE["prefix"];
		 $epfad = $eWERTE["domain"];
		 safe_query( "insert into delaccs (account, type, kunde, pfad) VALUES (  ? ,  'alias',  ? ,  ?  )", TRUE, new SQLString( $eaccount ), new SQLString( $PHP_AUTH_USER ), new SQLString( $epfad ) );
		}

# delete additional recipients
$id = safe_query2( "SELECT pop3x, prefix, domain FROM email ".
									 "WHERE pop3x = ? OR pop3x LIKE ? OR pop3x LIKE ? OR pop3x LIKE ?",
									 new SQLString($pop3), new SQLString($pop3.':%'), new SQLString('%:'.$pop3), new SQLString('%:'.$pop3.':%'));
while ($werte = db_fetch_array($id)) {
	$pop3x = $werte["pop3x"];
	$prefix = $werte["prefix"];
	$domain = $werte["domain"];

	$ar_pop3x = explode(":",$pop3x);
	for ($i=0; $i < count($ar_pop3x); $i++) {
	    if ($pop3 != $ar_pop3x[$i]) {
	        $new_ar_pop3x[$i] = $ar_pop3x[$i];
	    }
	}

	$new_pop3x = "";
	if (count($new_ar_pop3x) > 0)
		{
		 $new_pop3x = implode(":", $new_ar_pop3x);
		}

	safe_query( "update email set pop3x = ?  where prefix = ?  and domain = ? ", TRUE, new SQLString( $new_pop3x ), new SQLString( $prefix ), new SQLString( $domain ) );
}
# / delete additional recipients

$id = safe_query( "select account from delaccs where account = ? ", TRUE, new SQLString( $pop3 ) );
if (db_num_rows($id) == 0)	{
safe_query( "insert into delaccs (account, type, kunde) VALUES (  ? ,  'pop3',  ?  )", TRUE, new SQLString( $pop3 ), new SQLString( $PHP_AUTH_USER ) );
							}
safe_query( "update allgemein set delpop='1', aliases='1'", TRUE );
$fehlertitel = ltext("empolo2_error2");
$fehlertext = ltext("empolo2_error3",array($pop3));
db_close();
include("email_pop3.php");
exit();
?>
