how to search through only unread emails and mark them read after
<p>I have emails coming in with vehicle locations and I would like to record location in my database. I figured out how to fetch emails and find part of the content. Now I need to figure out how to search the content ONLY of not yet read emails and mark them read after I'm done.</p>

<pre><code>$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'myusername';
$password = 'mypassword';

$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' .     imap_last_error());
$emails = imap_search($inbox,'FROM "onlyoneemail@email.com"');

if($emails) {
  $output = '';
  rsort($emails);
  foreach($emails as $email_number) {
    $overview = imap_fetch_overview($inbox,$email_number,0);
    $message = imap_fetchbody($inbox,$email_number,1);

    if (preg_match('/\bAddress\s*:\s*(.+?)\s*$/mi', $message, $match)){
        echo $match[1] . "&lt;br&gt;";
    }
  }
  echo $output;
} 

imap_close($inbox);
</code></pre>
