我有一个处理电子邮件并将其移动到另一个文件夹的脚本。它目前工作正常,但我希望能够在执行imap_mail_move()
之前测试我想要将电子邮件移动到的文件夹是否存在。有这么快的方法吗?
$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);
答案 0 :(得分:0)
$folder = 'INBOX/Processed';
$cstr = '{server.foo.com:993/ssl}';
$imap = imap_open($cstr, ...);
$list = imap_list($imap, $cstr, "*");
if( array_search($cstr.$folder, $list) === false ) {
die("no folder!");
}
答案 1 :(得分:0)
array_search()返回数组中元素的键。
if(array_search($ cstr。$ folder,$ list)===" -1"){
die("no folder!");
}
答案 2 :(得分:0)
我认为没有理由使用array_search
代替in_array
。
$folder = 'INBOX/Processed';
$cstr = '{server.foo.com:993/ssl}';
$imap = imap_open($cstr, ...);
$list = imap_list($imap, $cstr, "*");
if (in_array($cstr . $folder, $list))
exit("No such folder!");