I have a function that connects to an imap email account (currently testing with gmail) to get emails that are UNSEEN. After getting the emails I loop through them and do imap_fetch_overview()
and imap_fetchbody()
on each email.
After running this function all the emails that have been searched get set to READ in the inbox.
Is there anyway to stop this happening? Ideally i'd like the email to remain UNSEEN.
Here is my function
function build_email_data(){
$this->connect();
/* grab emails */
$emails = imap_search($this->inbox,'UNSEEN');
/* if emails are returned, cycle through each... */
if($emails) {
/* put the newest emails on top */
rsort($emails);
$data = array();
/* for every email... */
foreach($emails as $email_number) {
/* get information specific to this email */
$overview = imap_fetch_overview($this->inbox,$email_number,0);
$message = imap_fetchbody($this->inbox,$email_number,1);
$_data['subject'] = $overview[0]->subject;
$_data['from'] = $overview[0]->from;
$_data['body'] = $message;
$_data['owner_id'] = 1;
$_data['email_number'] = $email_number;
$_data['folder_id'] = 1;
$_data['created'] = timestamp_to_mysqldatetime();
$_data['updated'] = timestamp_to_mysqldatetime();
$_data['email_date'] = timestamp_to_mysqldatetime(strtotime($overview[0]->date));
$data[] = $_data;
}
$this->disconnect();
return $data;
}
}