<?php

	echo '<div id="my-inbox">';

		echo '<div id="my-inbox-header">';

			echo '<div class="my-inbox-from">From</div>';

			echo '<div class="my-inbox-message">Subject</div>';

			echo '<div class="my-inbox-sent">Received</div>';

		echo '</div>';

		$inbox = $wps_mail->get_inbox(); // defaults to 10 messages from first available

		if ($inbox) {

			foreach($inbox as $mail) {

				echo '<div class="my-inbox-row">';

					echo '<div class="my-inbox-from">';

						echo '<div class="my-inbox-avatar">';

							echo $mail['avatar'];

						echo '</div>';
				// List recent mail (and other info)
				if ($wps->get_current_user_page() == $current_user->ID) {
					$wps_mail = new wps_mail();
					echo '<div id="my-mail-info">';
						echo '<div style="font-weight:bold; margin-bottom:6px;">Mail</div>';
						$unread = $wps_mail->get_inbox_count(true);
						echo 'You have '.($cnt = $wps_mail->get_inbox_count()).' message'.($cnt != 1 ? 's' : '').' of which '.$unread.' '.($unread != 1 ? 'are' : 'is').' unread.';
						
						if ($unread) {
							// Show most recent unread, up to 3, if there are any
							$recent = $unread > 3 ? 3 : $unread;
							if ($recent > 1) {
								echo ' Your most recent '.$recent.' unread messages are:';
							}
							echo '<div style="clear:both; margin-top:6px;">';
							$recent_mail = $wps_mail->get_inbox($recent, 0, 18, "", true, 0, true);
							foreach($recent_mail as $mail) {								
								echo '<div class="my-mail-row">';
									echo '<div class="my-mail-row-avatar">';
										echo $mail['avatar'];
									echo '</div>';
									echo '<div class="my-mail-row-from-and-subject">';
										echo $mail['display_name_link'].'<br />';
										echo '<a href="'.$wps->get_mail_url().'?mail_id='.$mail['mail_id'].'">'.$mail['mail_subject'].'</a>';
									echo '</div>';
								echo '</div>';
							}
							echo '</div>';
						}
					echo '</div>';
				}
				echo '<div class="my-inbox-sent">'.$sent_or_received.'</div>';

			echo '</div>';

			

			$start = isset($_GET['start']) ? $_GET['start'] : 0;

			$page_length = 10;

			// Get mailbox items

			$show_sent_mail = ($action == "sent");

			$inbox = $wps_mail->get_inbox($page_length, $start, 40, $term, true, 75, false, $show_sent_mail);

			if ($inbox) {

				foreach($inbox as $mail) {

					$mail_unread = $mail['mail_read'] == 'on' ? '' : 'my-inbox-unread';

					echo '<div class="my-inbox-row '.$mail_unread.'">';

						echo '<div class="my-inbox-from">';

							echo '<div class="my-inbox-avatar">';

								echo $mail['avatar'];
			echo '<div id="my-inbox-header">';

				echo '<div class="my-inbox-from">From</div>';

				echo '<div class="my-inbox-message">Subject</div>';

				echo '<div class="my-inbox-sent">Received</div>';

			echo '</div>';

			$start = isset($_GET['start']) ? $_GET['start'] : 0;

			$page_length = 5;

			$inbox = $wps_mail->get_inbox($page_length, $start, 40, "", true, 75); // defaults to 10 messages from first available

			if ($inbox) {

				foreach($inbox as $mail) {

					$mail_unread = $mail['mail_read'] == 'on' ? '' : 'my-inbox-unread';

					echo '<div class="my-inbox-row '.$mail_unread.'">';

						echo '<div class="my-inbox-from">';

							echo '<div class="my-inbox-avatar">';

								echo $mail['avatar'];