/** * * @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; }
public function actionImportIcs($params) { \GO::setMaxExecutionTime(0); \GO::session()->closeWriting(); \GO::$disableModelCache = true; $response = array('success' => true); $count = 0; $failed = array(); if (!isset($_FILES['ical_file']) || !file_exists($_FILES['ical_file']['tmp_name'][0])) { throw new \Exception(\GO::t('noFileUploaded')); } else { $file = new File($_FILES['ical_file']['tmp_name'][0]); $ext = strtolower(File::getExtension($_FILES['ical_file']['name'][0])); if ($ext == 'ics') { $i = new \GO\Base\Vobject\Iterator($file, "VEVENT"); foreach ($i as $vevent) { $event = new Event(); try { $event->importVObject($vevent, array('calendar_id' => $params['calendar_id'])); $count++; } catch (\Exception $e) { $failed[] = $e->getMessage(); } } } elseif ($ext == 'xml') { return $this->_importSmarterMailXml($params, $file); } else { throw new \Exception("Extension {$ext} is not supported"); } } $response['feedback'] = sprintf(\GO::t('import_success', 'calendar'), $count); if (count($failed)) { $response['feedback'] .= "\n\n" . count($failed) . " events failed: " . implode("\n", $failed); } return $response; }