コード例 #1
0
 function cacheAttachments(&$msg_no, &$parts, $breadcrumb = '0', $file_attachment)
 {
     foreach ($parts as $k => $part) {
         $this_breadcrumb = $k + 1;
         if ($breadcrumb != '0') {
             $this_breadcrumb = $breadcrumb . '.' . $this_breadcrumb;
         }
         if (isset($part->parts) && !empty($part->parts)) {
             $this->cacheAttachments($msg_no, $part->parts, $this_breadcrumb, $file_attachment);
         } else {
             if ($part->ifdisposition) {
                 if (strtolower($part->disposition) == 'attachment' || strtolower($part->disposition) == 'inline' && $part->type != 0) {
                     $filename = Imap::handleEncodedFilename($part->dparameters[0]->value);
                     $attachment_name = $file_attachment . '-' . $this_breadcrumb . '.php';
                     $msg_part_raw = imap_fetchbody($this->_inbox->conn, $msg_no, $this_breadcrumb);
                     $msg_part = Imap::handleTranserEncoding($msg_part_raw, '3');
                     if ($h = fopen($attachment_name, 'wb')) {
                         fwrite($h, $msg_part);
                         fclose($h);
                     }
                 }
             }
         }
     }
 }