2016-04-20 200 views
1

我有一个处理电子邮件并将它们移动到另一个文件夹的脚本。它现在正常工作,但我希望能够测试我执行imap_mail_move()之前是否要将邮件移动到的文件夹先存在。有没有一个快速的方法来做到这一点?检查IMAP是否存在文件夹

$hostname="{".$imap_details['imap_server']."}INBOX".$imap_details['imap_path']; 
$imap = imap_open($hostname, $imap_details['email'], $imap_details['imap_password']); 
$processed_folder="INBOX/Processed"; 
//*** I would like to check if the above folder exists here **** 
//And then do some processing here 
//And then move the email to the processed folder 
imap_mail_move($imap,$i,$processed_folder); 
+2

你有访问状态命令?这可以告诉你是否存在文件夹。然而,它可能会在您检查和检查时间之间消失。你仍然需要处理可能的错误。 – Max

+0

@Max,谢谢,状态命令是什么,我如何知道我是否可以访问它? – dlofrodloh

+0

是否有imap_status函数? – Max

回答

0

array_search()返回元件的阵列的关键。

如果(array_search($ CSTR。$文件夹,$名单)=== “-1”){

die("no folder!"); 

}