13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

678 Chapter 29 Building a <strong>Web</strong>-Based Email Service<br />

display_message($_SESSION['auth_user'],<br />

$_SESSION['selected_account'],<br />

$messageid, $fullheaders);<br />

break;<br />

Here, you check the value of the $action being equal to ‘show-headers’. In this case,<br />

it is false, <strong>and</strong> $fullheaders is set equal to false.We look at the ‘show-headers’<br />

action in a moment.<br />

The line<br />

$fullheaders = ($action == 'show-headers');<br />

could have been more verbosely—but perhaps more clearly—written as<br />

if ($action == 'show-headers') {<br />

$fullheaders = true;<br />

} else {<br />

$fullheaders = false;<br />

}<br />

Next, you call the display_message() function. Most of this function outputs plain<br />

HTML, so we do not go through it here. It calls the retrieve_message() function to<br />

get the appropriate message from the mailbox:<br />

$message = retrieve_message($auth_user, $accountid, $messageid, $fullheaders);<br />

The retrieve_message() function is in the mail_fns.php library.You can see the code<br />

for it in Listing 29.10.<br />

Listing 29.10 retrieve_message() Function from mail_fns.php—This Function<br />

Retrieves One Specific Message from a Mailbox<br />

function retrieve_message($auth_user, $accountid, $messageid,<br />

$fullheaders) {<br />

$message = array();<br />

if(!($auth_user && $messageid && $accountid)) {<br />

return false;<br />

}<br />

$imap = open_mailbox($auth_user, $accountid);<br />

if(!$imap) {<br />

return false;<br />

}<br />

$header = imap_header($imap, $messageid);<br />

if(!$header) {<br />

return false;<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!