Jump to content

Recommended Posts

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;
	}

}

 

 

Link to comment
https://forums.phpfreaks.com/topic/267378-imap-sort-function/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.