Specifications
After execution returns to index.php, the body stage will run the following code:
case ‘store-settings’ :
case ‘account-setup’ :
case ‘delete-account’ :
{
display_account_setup($auth_user);
break;
}
You will recognize this as the same code we ran before—it just displays the list of the user’s
accounts.
Reading Mail
After the user has set up some accounts, we can move on to the main game: connecting to
these accounts and reading mail.
Selecting an Account
We need to select one of the user’s accounts to read mail from. The currently selected account
is stored in the $selected_account session variable.
If the user has a single account registered in the system, it will be automatically selected when
he logs in, as follows:
if(number_of_accounts($auth_user)==1)
{
$accounts = get_account_list($auth_user);
$selected_account = $accounts[0];
session_register(“selected_account”);
}
The number_of_accounts() function, from mail_fns.php, is used to work out whether the
user has more than one account. The
get_account_list() function retrieves an array of the
names of the user’s accounts. In this case there is exactly one, so we can access it as the
array’s
0 value.
The number_of_accounts() function is shown in Listing 27.7.
LISTING 27.7 number_of_accounts() Function from mail_fns.php—Function to Work Out
How Many Accounts a User Has Registered
function number_of_accounts($auth_user)
{
// get the number of accounts that belong to this user
Building a Web-Based Email Service
C
HAPTER 27
27
BUILDING A
WEB-BASED
EMAIL
SERVICE
637
33 7842 CH27 3/6/01 3:41 PM Page 637










