2010-04-07 174 views
3

如何使用Zend_Mail_Storage_Imap檢查電子郵件文件夾是否存在,createFOlder,renameFOlder和removeFolder以及getFOlders,但不是確切的任何固定方法來查詢某個郵件文件夾是否存在? GetFOlders返回一個以文件夾開頭的混雜樹。使用Zend郵件檢查郵件文件夾是否存在

回答

1

我不Zend_Mail_Storage_Imap合作過,但是從我可以從源蒐集,這應該做的伎倆:如果你想通過檢查,以保持當前文件夾

/** 
* Checks if a folder exists by name. 
* @param Zend_Mail_Storage_Imap $imapObj Our IMAP object. 
* @param string $folder The name of the folder to check for. 
* @return boolean True if the folder exists, false otherwise. 
*/ 
function folderExists(Zend_Mail_Storage_Imap $imapObj, $folder) { 
    try { 
     $imapObj->selectFolder($folder); 
    } catch (Zend_Mail_Storage_Exception $e) { 
     return false; 
    } 
    return true; 
} 

,它得到有點麻煩,當然,:

/** 
* Checks if a folder exists by name. 
* @param Zend_Mail_Storage_Imap $imapObj Our IMAP object. 
* @param string $folder The name of the folder to check for. 
* @return boolean True if the folder exists, false otherwise. 
* @throws Zend_Mail_Storage_Exception if the current folder cannot be restored. 
*/ 
function folderExists(Zend_Mail_Storage_Imap $imapObj, $folder) { 
    $result = true; 
    $oldFolder = $imapObj->getCurrentFolder(); 
    try { 
     $imapObj->selectFolder($folder); 
    } catch (Zend_Mail_Storage_Exception $e) { 
     $result = false; 
    } 
    $imapObj->selectFolder($oldFolder); 
    return $result; 
} 

(你如何處理這種情況的偏好可能,當然,各不相同,一個是相當草率。)

相關問題