From c40d2ce48c8723eaffe96b0967a60b329a4bba05 Mon Sep 17 00:00:00 2001 From: Lewis Cowles Date: Sun, 24 May 2015 10:38:53 +0100 Subject: [PATCH] more accurate check with support for zero --- src/Fetch/Server.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Fetch/Server.php b/src/Fetch/Server.php index 883ca0c..2ba2fa1 100644 --- a/src/Fetch/Server.php +++ b/src/Fetch/Server.php @@ -323,13 +323,16 @@ class Server */ public function numMessages( $mailbox='' ) { - $oldMailbox = $this->getMailBox(); - if( $mailbox !== '' ) { + $mboxExists = $this->hasMailbox( $mailbox ); + if( $mboxExists ) { + $oldMailbox = $this->getMailBox(); $this->setMailbox( $mailbox ); } - $cnt = imap_num_msg($this->getImapStream()); - $this->setMailbox( $oldMailbox ); - return $cnt; + $cnt = imap_num_msg( $this->getImapStream() ); + if( $mboxExists ) { + $this->setMailbox( $oldMailbox ); + } + return ( !$mboxExists && $mailbox !== '' ) ? 0 : $cnt; } /**