Ejemplo n.º 1
0
 protected function beforeSubmit(&$response, &$model, &$params)
 {
     if (isset($_FILES['attachments']['tmp_name'][0]) && is_uploaded_file($_FILES['attachments']['tmp_name'][0])) {
         $file = new \GO\Base\Fs\File($_FILES['attachments']['tmp_name'][0]);
         $fileWithName = new \GO\Base\Fs\File($_FILES['attachments']['name'][0]);
         $model->content = $file->contents();
         $model->extension = $fileWithName->extension();
     }
     return parent::beforeSubmit($response, $model, $params);
 }
Ejemplo n.º 2
0
 /**
  * Get the file extension
  * 
  * @return string
  */
 public function getExtension()
 {
     $file = new \GO\Base\Fs\File($this->name);
     return strtolower($file->extension());
 }
Ejemplo n.º 3
0
 /**
  *
  * @return ImapMessageAttachment [] 
  */
 public function &getAttachments()
 {
     if (!$this->_imapAttachmentsLoaded) {
         $this->_imapAttachmentsLoaded = true;
         $imap = $this->getImapConnection();
         $this->_loadBodyParts();
         $parts = $imap->find_message_attachments($this->_getStruct(), $this->_bodyPartNumbers);
         $uniqueNames = array();
         foreach ($parts as $part) {
             //ignore applefile's
             //	Don't ignore it as it seems to be a valid attachment in some mails.
             //				if($part['subtype']=='applefile')
             //					continue;
             $a = new ImapMessageAttachment();
             $a->setImapParams($this->account, $this->mailbox, $this->uid);
             if (empty($part['name']) || $part['name'] == 'false') {
                 if (!empty($part['subject'])) {
                     $a->name = \GO\Base\Fs\File::stripInvalidChars(\GO\Base\Mail\Utils::mimeHeaderDecode($part['subject'])) . '.eml';
                 } elseif ($part['type'] == 'message') {
                     $a->name = isset($part['description']) ? \GO\Base\Fs\File::stripInvalidChars($part['description']) . '.eml' : 'message.eml';
                 } elseif ($part['subtype'] == 'calendar') {
                     $a->name = \GO::t('event', 'email') . '.ics';
                 } else {
                     if ($part['type'] == 'text') {
                         $a->name = $part['subtype'] . '.txt';
                     } else {
                         $a->name = $part['type'] . '-' . $part['subtype'];
                     }
                 }
             } else {
                 $a->name = \GO\Base\Mail\Utils::mimeHeaderDecode($part['name']);
                 $extension = \GO\Base\Fs\File::getExtension($a->name);
                 if (!empty($part['filename']) && empty($extension)) {
                     $a->name = \GO\Base\Mail\Utils::mimeHeaderDecode($part['filename']);
                 }
             }
             $i = 1;
             $a->name = !empty($a->name) ? $a->name : \GO::t('noname', 'email');
             $file = new \GO\Base\Fs\File($a->name);
             while (in_array($a->name, $uniqueNames)) {
                 $a->name = $file->nameWithoutExtension() . ' (' . $i . ').' . $file->extension();
                 $i++;
             }
             $uniqueNames[] = $a->name;
             $a->disposition = isset($part['disposition']) ? strtolower($part['disposition']) : '';
             $a->number = $part['number'];
             $a->content_id = '';
             if (!empty($part["id"])) {
                 //when an image has an id it belongs somewhere in the text we gathered above so replace the
                 //source id with the correct link to display the image.
                 $tmp_id = $part["id"];
                 if (strpos($tmp_id, '>')) {
                     $tmp_id = substr($part["id"], 1, -1);
                 }
                 $id = $tmp_id;
                 $a->content_id = $id;
             }
             $a->mime = $part['type'] . '/' . $part['subtype'];
             $a->index = count($this->attachments);
             $a->size = intval($part['size']);
             $a->encoding = $part['encoding'];
             $a->charset = !empty($part['charset']) ? $part['charset'] : $this->charset;
             $this->addAttachment($a);
         }
     }
     return $this->attachments;
 }