Specifications
Deleting Mail
If a user clicks the Delete button on a particular email, he will activate the “delete” action.
This will execute the following code from index.php:
case ‘delete’ :
{
delete_message($auth_user, $selected_account, $messageid);
//note deliberately no ‘break’ - we will continue to the next case
}
case ‘select-account’ :
case ‘view-mailbox’ :
{
// if mailbox just chosen, or view mailbox chosen, show mailbox
display_list($auth_user, $selected_account);
break;
}
As you can see, the message is deleted using the delete_message() function, and then the
resulting mailbox is displayed as discussed previously.
The code for the delete_message() function is shown in Listing 27.11.
LISTING 27.11 delete_message() Function from mail_fns.php—This Function Deletes One
Specific Message from a Mailbox
function delete_message($auth_user, $accountid, $message_id)
{
// delete a single message from the server
$imap = open_mailbox($auth_user, $accountid);
if($imap)
{
imap_delete($imap, $message_id);
imap_expunge($imap);
imap_close($imap);
return true;
}
return false;
}
As you can see, this function uses a number of the IMAP functions. The new ones are
imap_delete() and imap_expunge(). Note that imap_delete() only marks messages for dele-
tion. You can mark as many messages as you like. The call to imap_expunge() actually deletes
the messages.
Building Practical PHP and MySQL Projects
P
ART V
648
33 7842 CH27 3/6/01 3:41 PM Page 648