Due to the lack of speed that Imap provides i have to write some filters to avoid bringing in countless un-needed emails. I have had a little mess with the sort functions and other functions Imap has to offer but i can?t seem to drag out email in a specific order using imap_sort().
// Connection method
function _connection() {
$this->dir = imap_open($this->host,$this->user,$this->password);
if($this->dir!=FALSE) {
return 'Connection successful.';
return $this->dir;
} else {
return 'Connection error: ';
return imap_last_error();
}
}
// List emails method
function _readMail() {
if($this->collect) {
$i = 0;
$mail = array();
for($i=1; $i<20; $i++) {
$details = imap_fetch_overview($this->dir,$i,0);
$body = imap_fetchbody($this->dir,$i,2);
$status = $details[0]->seen ? 'read' : 'unread';
$from = $details[0]->from;
$date = $details[0]->date;
if(isset($details[0]->subject)) $subject = $details[0]->subject ; else $subject = 'no subject';
if(isset($details[0]->parts)) $attach = 'yes'; else $attach = 'no';
if($status='unread') {
$mail[$i] = (array(
'subject' => $subject,
'status' => $status,
'from' => $from,
'date' => $date,
'attach' => $attach
)
);
}
}// endforeach
} // endif
if(count($mail) < 0) {
return 'Alert: No mail in your inbox ('.$user.')';
} else {
return $mail;
}
}