December 22, 2010

 Purging users via CSV

Should you need to purge a large set of users from your Atmail system, you can use a new script to batch delete via a CSV file.

This will be included in Atmail 6.2.1 due Jan 2011 - In the meantime you can use the script below, store under:

webmail/utilities/tools/purge-users-csv.php
The usage is simple:

cd webmail/utilities/tools/

php purge-users.csv.php /path/to/userlist.txt

Where /path/to/userlist.txt contains a list of users, seperated by a newline.

This script will remove all the users database entries, clear the users maildir and purge the account from the system.
-

/**
* Purge users from the system who have not logged in
* in the last X days (where X is passed as an argument)
* to this script
*
* @author Ben Duncan
* @usage php purge-users-csv.php /path/to/csv
*/

require_once("/usr/local/atmail/webmail/utilities/nfc-bootloader.php");

// require that the argument is numeric
if (empty($_SERVER['argv'][1])) {
echo "\nUsage: php purge-users-csv.php /path/to/csvfile.txt\n\n".
"Where csvfile.txt contains a list of users seperated by a newline\n";
exit;
}

// setup api access
require_once('application/models/api.php');
$_SERVER['PHP_AUTH_USER'] = 'admin';
$api = new api( array('directApi' => 1) );

echo "Opening " . $_SERVER['argv'][1] . "\n";

$fp = fopen($_SERVER['argv'][1], "r");

while ( ($line = fgets($fp)) !== false) {

$line = trim($line);

// fetch our list of inactive accounts
$userExists = $dbAdapter->fetchOne("select Account from UserSession where Account=?", array($line));

if( !empty($userExists) )    {
echo "Deleting $line - ";

$arr = $api->userDelete($line);

if($arr['status'] == 'failed')
echo 'FAIL ' . $arr['response'] . "\n";
else
echo "OK\n";

} else {
echo "Deleting $line - FAIL ( no such user )\n";
}

}


Filed under: API, Atmail 6 — info @ 1:08 am

 

March 15, 2006

 Manually deleting accounts via SQL

Question:I want to integrate @Mail into my billing system, and need a way to manually delete a user-account via an SQL query

Answer:To manually delete a user-account in @Mail via SQL you can use the following.

Note there are various tables within @Mail that start with a prefix, depending on the first character of the username ( if non A-Z, use the prefix _other )

(more...)


Filed under: API — info @ 9:56 am