Example #1
0
 protected function createAttachment($mail, $structure, $params, $partNo)
 {
     $attachment = new IncomingMailAttachment();
     $attachmentId = null;
     if ($structure->ifid) {
         $attachmentId = trim($structure->id, " <>");
     } elseif (isset($params['filename'])) {
         $attachmentId = md5($params['filename']) . $partNo;
     } elseif (isset($params['name'])) {
         $attachmentId = md5($params['name']) . $partNo;
     }
     if ($attachmentId) {
         if (empty($params['filename']) && empty($params['name'])) {
             $fileName = $attachmentId . '.' . strtolower($structure->subtype);
         } else {
             $fileName = !empty($params['filename']) ? $params['filename'] : $params['name'];
             $fileName = self::decodeMimeStr($fileName, $this->imap->serverEncoding);
             $fileName = self::decodeRFC2231($fileName, $this->imap->serverEncoding);
         }
         $attachment->setId($attachmentId);
         $attachment->setName($fileName);
         $attachment->setSubtype($structure->subtype);
     }
     return $attachment;
 }