我怎样才能知道一条消息有多少个附件?
这种方法可靠吗?
$attachments = 0;
$msg = $mail->getMessage($msgno);
if($msg->isMultipart()){
$parts = $msg->countParts();
for($i=1; $i<=$parts; $i++){
$part = $msg->getPart($i);
try {
if(strpos($part->contentType,'text/html')===false && strpos($part->contentType,'text/plain')===false)
$attachments++;
} catch (Zend_Mail_Exception $e) {}
}
}
或这个?
$matches = array();
$pattern = '`Content-Disposition: (?!inline)(.*)[\s]*filename=`';
$attachments = (string) preg_match_all($pattern, $storage->getRawContent($msgno), $matches);