/** * @return string */ public function ContentType() { return \MailSo\Base\Utils::MimeContentType($this->sFileName); }
/** * @param bool $bDownload * @param bool $bThumbnail = false * * @return bool */ private function rawSmart($bDownload, $bThumbnail = false) { $sRawKey = (string) $this->GetActionParam('RawKey', ''); $aValues = $this->getDecodedRawKeyValue($sRawKey); $sFolder = isset($aValues['Folder']) ? $aValues['Folder'] : ''; $iUid = isset($aValues['Uid']) ? (int) $aValues['Uid'] : 0; $sMimeIndex = isset($aValues['MimeIndex']) ? (string) $aValues['MimeIndex'] : ''; $sContentTypeIn = isset($aValues['MimeType']) ? (string) $aValues['MimeType'] : ''; $sFileNameIn = isset($aValues['FileName']) ? (string) $aValues['FileName'] : ''; $sFileHashIn = isset($aValues['FileHash']) ? (string) $aValues['FileHash'] : ''; $bDetectImageOrientation = !!$this->Config()->Get('labs', 'detect_image_exif_orientation', true); if (!empty($sFileHashIn)) { $this->verifyCacheByKey($sRawKey); $oAccount = $this->getAccountFromToken(); $sContentTypeOut = empty($sContentTypeIn) ? \MailSo\Base\Utils::MimeContentType($sFileNameIn) : $sContentTypeIn; $sFileNameOut = $this->MainClearFileName($sFileNameIn, $sContentTypeIn, $sMimeIndex); $rResource = $this->FilesProvider()->GetFile($oAccount, $sFileHashIn); if (\is_resource($rResource)) { $sFileNameOut = \MailSo\Base\Utils::ConvertEncoding($sFileNameOut, \MailSo\Base\Enumerations\Charset::UTF_8, \MailSo\Base\Enumerations\Charset::CP858); \header('Content-Type: ' . $sContentTypeOut); \header('Content-Disposition: attachment; ' . \trim(\MailSo\Base\Utils::EncodeHeaderUtf8AttributeValue('filename', $sFileNameOut)), true); \header('Accept-Ranges: none', true); \header('Content-Transfer-Encoding: binary'); \MailSo\Base\Utils::FpassthruWithTimeLimitReset($rResource); return true; } return false; } else { if (!empty($sFolder) && 0 < $iUid) { $this->verifyCacheByKey($sRawKey); } } $oAccount = $this->initMailClientConnection(); $self = $this; return $this->MailClient()->MessageMimeStream(function ($rResource, $sContentType, $sFileName, $sMimeIndex = '') use($self, $oAccount, $sRawKey, $sContentTypeIn, $sFileNameIn, $bDownload, $bThumbnail, $bDetectImageOrientation) { if ($oAccount && \is_resource($rResource)) { $sContentTypeOut = $sContentTypeIn; if (empty($sContentTypeOut)) { $sContentTypeOut = $sContentType; if (empty($sContentTypeOut)) { $sContentTypeOut = empty($sFileName) ? 'text/plain' : \MailSo\Base\Utils::MimeContentType($sFileName); } } $sFileNameOut = $sFileNameIn; if (empty($sFileNameOut)) { $sFileNameOut = $sFileName; } $sFileNameOut = $self->MainClearFileName($sFileNameOut, $sContentTypeOut, $sMimeIndex); $self->cacheByKey($sRawKey); $bDone = false; if ($bThumbnail && !$bDownload) { try { $oImagine = new \Imagine\Gd\Imagine(); $bDone = true; $oImage = $oImagine->load(\stream_get_contents($rResource)); $oImage = $this->correctImageOrientation($oImage, $bDetectImageOrientation, 60); \header('Content-Disposition: inline; ' . \trim(\MailSo\Base\Utils::EncodeHeaderUtf8AttributeValue('filename', $sFileNameOut . '_thumb60x60.png')), true); $oImage->show('png'); } catch (\Exception $oException) { $self->Logger()->WriteExceptionShort($oException); } } if (!$bDone && !$bDownload && $bDetectImageOrientation && \in_array($sContentTypeOut, array('image/png', 'image/jpeg', 'image/jpg')) && \MailSo\Base\Utils::FunctionExistsAndEnabled('gd_info')) { try { $oImagine = new \Imagine\Gd\Imagine(); $bDone = true; $oImage = $oImagine->load(\stream_get_contents($rResource)); $oImage = $this->correctImageOrientation($oImage, $bDetectImageOrientation); \header('Content-Disposition: inline; ' . \trim(\MailSo\Base\Utils::EncodeHeaderUtf8AttributeValue('filename', $sFileNameOut)), true); $oImage->show($sContentTypeOut === 'image/png' ? 'png' : 'jpg'); } catch (\Exception $oException) { $self->Logger()->WriteExceptionShort($oException); } } if (!$bDone) { \header('Content-Type: ' . $sContentTypeOut); \header('Content-Disposition: ' . ($bDownload ? 'attachment' : 'inline') . '; ' . \trim(\MailSo\Base\Utils::EncodeHeaderUtf8AttributeValue('filename', $sFileNameOut)), true); \header('Accept-Ranges: none', true); \header('Content-Transfer-Encoding: binary'); \MailSo\Base\Utils::FpassthruWithTimeLimitReset($rResource); } } }, $sFolder, $iUid, true, $sMimeIndex); }
/** * @return array */ public function UploadHelpdeskFile() { $oAccount = null; $oUser = $this->getHelpdeskAccountFromParam($oAccount); if (!$this->oApiCapability->isHelpdeskSupported() || !$this->oApiCapability->isFilesSupported()) { throw new \ProjectCore\Exceptions\ClientException(\ProjectCore\Notifications::AccessDenied); } $aFileData = $this->getParamValue('FileData', null); $iSizeLimit = 0; $sError = ''; $aResponse = array(); if ($oUser) { if (is_array($aFileData)) { if (0 < $iSizeLimit && $iSizeLimit < (int) $aFileData['size']) { $sError = 'size'; } else { $sSavedName = 'upload-post-' . md5($aFileData['name'] . $aFileData['tmp_name']); if ($this->ApiFileCache()->moveUploadedFile($oUser, $sSavedName, $aFileData['tmp_name'])) { $sUploadName = $aFileData['name']; $iSize = $aFileData['size']; $sMimeType = \MailSo\Base\Utils::MimeContentType($sUploadName); $aResponse['HelpdeskFile'] = array('Name' => $sUploadName, 'TempName' => $sSavedName, 'MimeType' => $sMimeType, 'Size' => (int) $iSize, 'Hash' => \CApi::EncodeKeyValues(array('TempFile' => true, 'HelpdeskTenantID' => $oUser->IdTenant, 'HelpdeskUserID' => $oUser->IdHelpdeskUser, 'Name' => $sUploadName, 'TempName' => $sSavedName))); } else { $sError = 'unknown'; } } } else { $sError = 'unknown'; } } else { $sError = 'auth'; } if (0 < strlen($sError)) { $aResponse['Error'] = $sError; } return $this->DefaultResponse($oAccount, __FUNCTION__, $aResponse); }
public function CreateFile($oAccount, $sType, $sPath, $sFileName, $mData, &$bResult, &$bBreak) { $oClient = $this->GetClient($oAccount, $sType); if ($oClient) { $bResult = false; $bBreak = true; $sMimeType = \MailSo\Base\Utils::MimeContentType($sFileName); $file = new Google_Service_Drive_DriveFile(); $file->setTitle($sFileName); $file->setMimeType($sMimeType); $sPath = trim($sPath, '/'); // Set the parent folder. if ($sPath != null) { $parent = new Google_Service_Drive_ParentReference(); $parent->setId($sPath); $file->setParents(array($parent)); } $oDrive = new Google_Service_Drive($oClient); try { $sData = ''; if (is_resource($mData)) { rewind($mData); $sData = stream_get_contents($mData); } else { $sData = $mData; } $oDrive->files->insert($file, array('data' => $sData, 'mimeType' => $sMimeType, 'uploadType' => 'media')); $bResult = true; } catch (Exception $ex) { $bResult = false; } } }
/** * @param \CAccount $oAccount * @param mixed $mResponse * @param string $sParent * @param array $aParameters = array() * * @return mixed */ protected function responseObject($oAccount, $mResponse, $sParent, $aParameters = array()) { $mResult = $mResponse; if (is_object($mResponse)) { $sClassName = get_class($mResponse); if ('CApiMailMessage' === $sClassName) { $iTrimmedLimit = \CApi::GetConf('labs.message-body-size-limit', 0); $oAttachments = $mResponse->getAttachments(); $iInternalTimeStampInUTC = $mResponse->getInternalTimeStamp(); $iReceivedOrDateTimeStampInUTC = $mResponse->getReceivedOrDateTimeStamp(); $aFlags = $mResponse->getFlagsLowerCase(); $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('Folder' => $mResponse->getFolder(), 'Uid' => $mResponse->getUid(), 'Subject' => $mResponse->getSubject(), 'MessageId' => $mResponse->getMessageId(), 'Size' => $mResponse->getSize(), 'TextSize' => $mResponse->getTextSize(), 'InternalTimeStampInUTC' => $iInternalTimeStampInUTC, 'ReceivedOrDateTimeStampInUTC' => $iReceivedOrDateTimeStampInUTC, 'TimeStampInUTC' => \CApi::GetConf('labs.use-date-from-headers', false) && 0 < $iReceivedOrDateTimeStampInUTC ? $iReceivedOrDateTimeStampInUTC : $iInternalTimeStampInUTC, 'From' => $this->responseObject($oAccount, $mResponse->getFrom(), $sParent, $aParameters), 'To' => $this->responseObject($oAccount, $mResponse->getTo(), $sParent, $aParameters), 'Cc' => $this->responseObject($oAccount, $mResponse->getCc(), $sParent, $aParameters), 'Bcc' => $this->responseObject($oAccount, $mResponse->getBcc(), $sParent, $aParameters), 'Sender' => $this->responseObject($oAccount, $mResponse->getSender(), $sParent, $aParameters), 'ReplyTo' => $this->responseObject($oAccount, $mResponse->getReplyTo(), $sParent, $aParameters), 'IsSeen' => in_array('\\seen', $aFlags), 'IsFlagged' => in_array('\\flagged', $aFlags), 'IsAnswered' => in_array('\\answered', $aFlags), 'IsForwarded' => false, 'HasAttachments' => $oAttachments && $oAttachments->hasNotInlineAttachments(), 'HasVcardAttachment' => $oAttachments && $oAttachments->hasVcardAttachment(), 'HasIcalAttachment' => $oAttachments && $oAttachments->hasIcalAttachment(), 'Priority' => $mResponse->getPriority(), 'DraftInfo' => $mResponse->getDraftInfo(), 'Sensitivity' => $mResponse->getSensitivity())); $mResult['TrimmedTextSize'] = $mResult['TextSize']; if (0 < $iTrimmedLimit && $mResult['TrimmedTextSize'] > $iTrimmedLimit) { $mResult['TrimmedTextSize'] = $iTrimmedLimit; } $sLowerForwarded = strtolower(\CApi::GetConf('webmail.forwarded-flag-name', '')); if (!empty($sLowerForwarded)) { $mResult['IsForwarded'] = in_array($sLowerForwarded, $aFlags); } $mResult['Hash'] = \CApi::EncodeKeyValues(array('AccountID' => $oAccount ? $oAccount->IdAccount : 0, 'Folder' => $mResult['Folder'], 'Uid' => $mResult['Uid'], 'MimeType' => 'message/rfc822', 'FileName' => $mResult['Subject'] . '.eml')); if ('MessageGet' === $sParent || 'MessagesGetBodies' === $sParent) { $mResult['Headers'] = \MailSo\Base\Utils::Utf8Clear($mResponse->getHeaders()); $mResult['InReplyTo'] = $mResponse->getInReplyTo(); $mResult['References'] = $mResponse->getReferences(); $mResult['ReadingConfirmation'] = $mResponse->getReadingConfirmation(); if (!empty($mResult['ReadingConfirmation']) && in_array('$readconfirm', $aFlags)) { $mResult['ReadingConfirmation'] = ''; } $bHasExternals = false; $aFoundedCIDs = array(); $sPlain = ''; $sHtml = trim($mResponse->getHtml()); if (0 === strlen($sHtml)) { $sPlain = $mResponse->getPlain(); } $aContentLocationUrls = array(); $aFoundedContentLocationUrls = array(); if ($oAttachments && 0 < $oAttachments->Count()) { $aList =& $oAttachments->GetAsArray(); foreach ($aList as $oAttachment) { if ($oAttachment) { $sContentLocation = $oAttachment->getContentLocation(); if ($sContentLocation && 0 < \strlen($sContentLocation)) { $aContentLocationUrls[] = $oAttachment->getContentLocation(); } } } } $iTextSizeLimit = 500000; if ($iTextSizeLimit < \strlen($sHtml)) { $iSpacePost = \strpos($sHtml, ' ', $iTextSizeLimit); $sHtml = \substr($sHtml, 0, false !== $iSpacePost && $iSpacePost > $iTextSizeLimit ? $iSpacePost : $iTextSizeLimit); } if ($iTextSizeLimit < \strlen($sPlain)) { $iSpacePost = \strpos($sPlain, ' ', $iTextSizeLimit); $sPlain = \substr($sPlain, 0, false !== $iSpacePost && $iSpacePost > $iTextSizeLimit ? $iSpacePost : $iTextSizeLimit); } if (0 < \strlen($sHtml) && \CApi::GetConf('labs.webmail.display-inline-css', false)) { include_once PSEVEN_APP_ROOT_PATH . 'libraries/other/CssToInlineStyles.php'; $oCssToInlineStyles = new \TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($sHtml); $oCssToInlineStyles->setEncoding('utf-8'); $oCssToInlineStyles->setUseInlineStylesBlock(true); $mResult['Html'] = \MailSo\Base\HtmlUtils::ClearHtml($oCssToInlineStyles->convert(), $bHasExternals, $aFoundedCIDs, $aContentLocationUrls, $aFoundedContentLocationUrls, false, true); } else { $mResult['Html'] = 0 === strlen($sHtml) ? '' : \MailSo\Base\HtmlUtils::ClearHtml($sHtml, $bHasExternals, $aFoundedCIDs, $aContentLocationUrls, $aFoundedContentLocationUrls, false, true); } $mResult['Trimmed'] = false; $mResult['Plain'] = 0 === strlen($sPlain) ? '' : \MailSo\Base\HtmlUtils::ConvertPlainToHtml($sPlain); $mResult['PlainRaw'] = \trim($sPlain); $mResult['Rtl'] = 0 < \strlen($mResult['Plain']) ? \MailSo\Base\Utils::IsRTL($mResult['Plain']) : false; if (0 < $iTrimmedLimit && 'Messages' === $sParent) { if ($iTrimmedLimit < strlen($mResult['Plain'])) { $iPos = strpos($mResult['Plain'], ' ', $iTrimmedLimit); if (false !== $iPos && $iTrimmedLimit <= $iPos) { $mResult['Plain'] = substr($mResult['Plain'], 0, $iPos); $mResult['Trimmed'] = true; } } if ($iTrimmedLimit < strlen($mResult['Html'])) { $iPos = strpos($mResult['Html'], ' <', $iTrimmedLimit); if (false !== $iPos && $iTrimmedLimit <= $iPos) { $mResult['Html'] = substr($mResult['Html'], 0, $iPos) . '<!-- cutted -->'; $mResult['Trimmed'] = true; } } } $mResult['ICAL'] = $this->responseObject($oAccount, $mResponse->getExtend('ICAL'), $sParent, $aParameters); $mResult['VCARD'] = $this->responseObject($oAccount, $mResponse->getExtend('VCARD'), $sParent, $aParameters); $mResult['Safety'] = $mResponse->getSafety(); $mResult['HasExternals'] = $bHasExternals; $mResult['FoundedCIDs'] = $aFoundedCIDs; $mResult['FoundedContentLocationUrls'] = $aFoundedContentLocationUrls; $mResult['Attachments'] = $this->responseObject($oAccount, $oAttachments, $sParent, array_merge($aParameters, array('FoundedCIDs' => $aFoundedCIDs, 'FoundedContentLocationUrls' => $aFoundedContentLocationUrls))); // $mResult['Html'] = \MailSo\Base\Utils::Utf8Clear($mResult['Html']); // $mResult['Plain'] = \MailSo\Base\Utils::Utf8Clear($mResult['Plain']); } else { $mResult['@Object'] = 'Object/MessageListItem'; $mResult['Threads'] = $mResponse->getThreads(); } $mResult['Custom'] = $this->responseObject($oAccount, $mResponse->getCustomList(), $sParent, $aParameters); $mResult['Subject'] = \MailSo\Base\Utils::Utf8Clear($mResult['Subject']); } else { if ('CApiMailIcs' === $sClassName) { $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('Uid' => $mResponse->Uid, 'Sequence' => $mResponse->Sequence, 'Attendee' => $mResponse->Attendee, 'File' => $mResponse->File, 'Type' => $mResponse->Type, 'Location' => $mResponse->Location, 'Description' => \MailSo\Base\LinkFinder::NewInstance()->Text($mResponse->Description)->UseDefaultWrappers(true)->CompileText(), 'When' => $mResponse->When, 'CalendarId' => $mResponse->CalendarId)); } else { if ('CApiMailVcard' === $sClassName) { $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('Uid' => $mResponse->Uid, 'File' => $mResponse->File, 'Name' => $mResponse->Name, 'Email' => $mResponse->Email, 'Exists' => $mResponse->Exists)); } else { if ('CFilter' === $sClassName) { $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('Enable' => $mResponse->Enable, 'Field' => $mResponse->Field, 'Filter' => $mResponse->Filter, 'Condition' => $mResponse->Condition, 'Action' => $mResponse->Action, 'FolderFullName' => $mResponse->FolderFullName)); } else { if ('CHelpdeskThread' === $sClassName) { $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('IdHelpdeskThread' => $mResponse->IdHelpdeskThread, 'ThreadHash' => $mResponse->StrHelpdeskThreadHash, 'IdOwner' => $mResponse->IdOwner, 'Owner' => $mResponse->Owner, 'Type' => $mResponse->Type, 'Subject' => $mResponse->Subject, 'IsRead' => $mResponse->IsRead, 'IsArchived' => $mResponse->IsArchived, 'ItsMe' => $mResponse->ItsMe, 'HasAttachments' => $mResponse->HasAttachments, 'PostCount' => $mResponse->PostCount, 'Created' => $mResponse->Created, 'Updated' => $mResponse->Updated)); } else { if ('CHelpdeskPost' === $sClassName) { $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('IdHelpdeskPost' => $mResponse->IdHelpdeskPost, 'IdHelpdeskThread' => $mResponse->IdHelpdeskThread, 'IdOwner' => $mResponse->IdOwner, 'Owner' => $mResponse->Owner, 'Attachments' => $this->responseObject($oAccount, $mResponse->Attachments, $sParent), 'IsThreadOwner' => $mResponse->IsThreadOwner, 'ItsMe' => $mResponse->ItsMe, 'Type' => $mResponse->Type, 'SystemType' => $mResponse->SystemType, 'Text' => \MailSo\Base\HtmlUtils::ConvertPlainToHtml($mResponse->Text), 'Created' => $mResponse->Created)); } else { if ('CHelpdeskAttachment' === $sClassName) { $iThumbnailLimit = 1024 * 1024 * 2; // 2MB /* @var $mResponse CHelpdeskAttachment */ $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('IdHelpdeskAttachment' => $mResponse->IdHelpdeskAttachment, 'IdHelpdeskPost' => $mResponse->IdHelpdeskPost, 'IdHelpdeskThread' => $mResponse->IdHelpdeskThread, 'SizeInBytes' => $mResponse->SizeInBytes, 'FileName' => $mResponse->FileName, 'MimeType' => \MailSo\Base\Utils::MimeContentType($mResponse->FileName), 'Thumb' => \CApi::GetConf('labs.allow-thumbnail', true) && $mResponse->SizeInBytes < $iThumbnailLimit && \api_Utils::IsGDImageMimeTypeSuppoted(\MailSo\Base\Utils::MimeContentType($mResponse->FileName), $mResponse->FileName), 'Hash' => $mResponse->Hash, 'Content' => $mResponse->Content, 'Created' => $mResponse->Created)); } else { if ('CFetcher' === $sClassName) { /* @var $mResponse \CFetcher */ $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('IdFetcher' => $mResponse->IdFetcher, 'IdAccount' => $mResponse->IdAccount, 'IsEnabled' => $mResponse->IsEnabled, 'IsLocked' => $mResponse->IsLocked, 'Folder' => $mResponse->Folder, 'Name' => $mResponse->Name, 'Email' => $mResponse->Email, 'Signature' => $mResponse->Signature, 'SignatureOptions' => $mResponse->SignatureOptions, 'LeaveMessagesOnServer' => $mResponse->LeaveMessagesOnServer, 'IncomingMailServer' => $mResponse->IncomingMailServer, 'IncomingMailPort' => $mResponse->IncomingMailPort, 'IncomingMailLogin' => $mResponse->IncomingMailLogin, 'IsOutgoingEnabled' => $mResponse->IsOutgoingEnabled, 'OutgoingMailServer' => $mResponse->OutgoingMailServer, 'OutgoingMailPort' => $mResponse->OutgoingMailPort, 'OutgoingMailAuth' => $mResponse->OutgoingMailAuth, 'IncomingMailSsl' => $mResponse->IncomingMailSecurity === \MailSo\Net\Enumerations\ConnectionSecurityType::SSL, 'OutgoingMailSsl' => $mResponse->OutgoingMailSecurity === \MailSo\Net\Enumerations\ConnectionSecurityType::SSL)); } else { if ('CApiMailFolder' === $sClassName) { $aExtended = null; $mStatus = $mResponse->getStatus(); if (is_array($mStatus) && isset($mStatus['MESSAGES'], $mStatus['UNSEEN'], $mStatus['UIDNEXT'])) { $aExtended = array('MessageCount' => (int) $mStatus['MESSAGES'], 'MessageUnseenCount' => (int) $mStatus['UNSEEN'], 'UidNext' => (string) $mStatus['UIDNEXT'], 'Hash' => \api_Utils::GenerateFolderHash($mResponse->getRawFullName(), $mStatus['MESSAGES'], $mStatus['UNSEEN'], $mStatus['UIDNEXT'])); } $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('Type' => $mResponse->getType(), 'Name' => $mResponse->getName(), 'FullName' => $mResponse->getFullName(), 'FullNameRaw' => $mResponse->getRawFullName(), 'FullNameHash' => md5($mResponse->getRawFullName()), 'Delimiter' => $mResponse->getDelimiter(), 'IsSubscribed' => $oAccount->isExtensionEnabled(\CAccount::IgnoreSubscribeStatus) ? true : $mResponse->isSubscribed(), 'IsSelectable' => $mResponse->isSelectable(), 'Exists' => $mResponse->exists(), 'Extended' => $aExtended, 'SubFolders' => $this->responseObject($oAccount, $mResponse->getSubFolders(), $sParent, $aParameters))); } else { if ('CApiMailAttachment' === $sClassName) { $mFoundedCIDs = isset($aParameters['FoundedCIDs']) && is_array($aParameters['FoundedCIDs']) ? $aParameters['FoundedCIDs'] : null; $mFoundedContentLocationUrls = isset($aParameters['FoundedContentLocationUrls']) && \is_array($aParameters['FoundedContentLocationUrls']) && 0 < \count($aParameters['FoundedContentLocationUrls']) ? $aParameters['FoundedContentLocationUrls'] : null; if ($mFoundedCIDs || $mFoundedContentLocationUrls) { $aFoundedCIDs = \array_merge($mFoundedCIDs ? $mFoundedCIDs : array(), $mFoundedContentLocationUrls ? $mFoundedContentLocationUrls : array()); $aFoundedCIDs = 0 < \count($mFoundedCIDs) ? $mFoundedCIDs : null; } $sMimeType = strtolower(trim($mResponse->getMimeType())); $sMimeIndex = strtolower(trim($mResponse->getMimeIndex())); $sContentTransferEncoding = strtolower(trim($mResponse->getEncoding())); $sFileName = $mResponse->getFileName(true); $iEstimatedSize = $mResponse->getEstimatedSize(); $iThumbnailLimit = 1024 * 1024 * 2; // 2MB //TODO if (in_array($sMimeType, array('application/octet-stream'))) { $sMimeType = \MailSo\Base\Utils::MimeContentType($sFileName); } $sCid = \trim(\trim($mResponse->getCid()), '<>'); $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('FileName' => $sFileName, 'MimeType' => $sMimeType, 'MimePartIndex' => 'message/rfc822' === $sMimeType && ('base64' === $sContentTransferEncoding || 'quoted-printable' === $sContentTransferEncoding) ? '' : $sMimeIndex, 'EstimatedSize' => $iEstimatedSize, 'CID' => $sCid, 'ContentLocation' => $mResponse->getContentLocation(), 'Thumb' => \CApi::GetConf('labs.allow-thumbnail', true) && $iEstimatedSize < $iThumbnailLimit && \api_Utils::IsGDImageMimeTypeSuppoted($sMimeType, $sFileName), 'Expand' => \CApi::isExpandMimeTypeSupported($sMimeType, $sFileName), 'Iframed' => \CApi::isIframedMimeTypeSupported($sMimeType, $sFileName), 'Content' => $mResponse->getContent(), 'IsInline' => $mResponse->isInline(), 'IsLinked' => !empty($sCid) && $mFoundedCIDs && \in_array($sCid, $mFoundedCIDs) || $mFoundedContentLocationUrls && \in_array(\trim($mResponse->getContentLocation()), $mFoundedContentLocationUrls))); $mResult['Hash'] = \CApi::EncodeKeyValues(array('Iframed' => $mResult['Iframed'], 'AccountID' => $oAccount ? $oAccount->IdAccount : 0, 'Folder' => $mResponse->getFolder(), 'Uid' => $mResponse->getUid(), 'MimeIndex' => $sMimeIndex, 'MimeType' => $sMimeType, 'FileName' => $mResponse->getFileName(true))); } else { if ('MailSo\\Mime\\Email' === $sClassName) { $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('DisplayName' => \MailSo\Base\Utils::Utf8Clear($mResponse->GetDisplayName()), 'Email' => \MailSo\Base\Utils::Utf8Clear($mResponse->GetEmail()))); } else { if ('CApiMailMessageCollection' === $sClassName) { $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('Uids' => $mResponse->Uids, 'UidNext' => $mResponse->UidNext, 'FolderHash' => $mResponse->FolderHash, 'MessageCount' => $mResponse->MessageCount, 'MessageUnseenCount' => $mResponse->MessageUnseenCount, 'MessageResultCount' => $mResponse->MessageResultCount, 'FolderName' => $mResponse->FolderName, 'Offset' => $mResponse->Offset, 'Limit' => $mResponse->Limit, 'Search' => $mResponse->Search, 'Filters' => $mResponse->Filters, 'New' => $mResponse->New)); } else { if ('CIdentity' === $sClassName) { $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('IdIdentity' => $mResponse->IdIdentity, 'IdAccount' => $mResponse->IdAccount, 'Default' => $mResponse->Default, 'Enabled' => $mResponse->Enabled, 'Email' => $mResponse->Email, 'FriendlyName' => $mResponse->FriendlyName, 'UseSignature' => $mResponse->UseSignature, 'Signature' => $mResponse->Signature)); } else { if ('CApiMailFolderCollection' === $sClassName) { $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('Namespace' => $mResponse->GetNamespace())); } else { if ('CContactListItem' === $sClassName) { $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('IdUser' => $oAccount->IdUser, 'Id' => $mResponse->Id, 'Name' => $mResponse->Name, 'Email' => $mResponse->Email, 'Emails' => $mResponse->Emails, 'Phones' => $mResponse->Phones, 'UseFriendlyName' => $mResponse->UseFriendlyName, 'IsGroup' => $mResponse->IsGroup, 'IsOrganization' => $mResponse->IsOrganization, 'ReadOnly' => $mResponse->ReadOnly, 'ItsMe' => $mResponse->ItsMe, 'Global' => $mResponse->Global, 'ForSharedToAll' => $mResponse->ForSharedToAll, 'SharedToAll' => $mResponse->SharedToAll, 'Frequency' => $mResponse->Frequency, 'AgeScore' => $mResponse->AgeScore)); } else { if ('CContact' === $sClassName) { $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('IdUser' => $mResponse->IdUser, 'IdContact' => $mResponse->IdContact, 'IdContactStr' => $mResponse->IdContactStr, 'Global' => $mResponse->Global, 'ItsMe' => $mResponse->ItsMe, 'PrimaryEmail' => $mResponse->PrimaryEmail, 'UseFriendlyName' => $mResponse->UseFriendlyName, 'GroupsIds' => $mResponse->GroupsIds, 'FullName' => $mResponse->FullName, 'Title' => $mResponse->Title, 'FirstName' => $mResponse->FirstName, 'LastName' => $mResponse->LastName, 'NickName' => $mResponse->NickName, 'Skype' => $mResponse->Skype, 'Facebook' => $mResponse->Facebook, 'HomeEmail' => $mResponse->HomeEmail, 'HomeStreet' => $mResponse->HomeStreet, 'HomeCity' => $mResponse->HomeCity, 'HomeState' => $mResponse->HomeState, 'HomeZip' => $mResponse->HomeZip, 'HomeCountry' => $mResponse->HomeCountry, 'HomePhone' => $mResponse->HomePhone, 'HomeFax' => $mResponse->HomeFax, 'HomeMobile' => $mResponse->HomeMobile, 'HomeWeb' => $mResponse->HomeWeb, 'BusinessEmail' => $mResponse->BusinessEmail, 'BusinessCompany' => $mResponse->BusinessCompany, 'BusinessStreet' => $mResponse->BusinessStreet, 'BusinessCity' => $mResponse->BusinessCity, 'BusinessState' => $mResponse->BusinessState, 'BusinessZip' => $mResponse->BusinessZip, 'BusinessCountry' => $mResponse->BusinessCountry, 'BusinessJobTitle' => $mResponse->BusinessJobTitle, 'BusinessDepartment' => $mResponse->BusinessDepartment, 'BusinessOffice' => $mResponse->BusinessOffice, 'BusinessPhone' => $mResponse->BusinessPhone, 'BusinessMobile' => $mResponse->BusinessMobile, 'BusinessFax' => $mResponse->BusinessFax, 'BusinessWeb' => $mResponse->BusinessWeb, 'OtherEmail' => $mResponse->OtherEmail, 'Notes' => $mResponse->Notes, 'BirthdayDay' => $mResponse->BirthdayDay, 'BirthdayMonth' => $mResponse->BirthdayMonth, 'BirthdayYear' => $mResponse->BirthdayYear, 'ReadOnly' => $mResponse->ReadOnly, 'ETag' => $mResponse->ETag, 'SharedToAll' => $mResponse->SharedToAll)); } else { if ('CGroup' === $sClassName) { $aContacts = $this->ApiContacts()->getContactItems($mResponse->IdUser, \EContactSortField::Name, \ESortOrder::ASC, 0, 299, '', '', $mResponse->IdGroup); $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('IdUser' => $mResponse->IdUser, 'IdGroup' => $mResponse->IdGroup, 'IdGroupStr' => $mResponse->IdGroupStr, 'Name' => $mResponse->Name, 'IsOrganization' => $mResponse->IsOrganization, 'Email' => $mResponse->Email, 'Company' => $mResponse->Company, 'Street' => $mResponse->Street, 'City' => $mResponse->City, 'State' => $mResponse->City, 'Zip' => $mResponse->Zip, 'Country' => $mResponse->Country, 'Phone' => $mResponse->Phone, 'Fax' => $mResponse->Fax, 'Web' => $mResponse->Web, 'Contacts' => $this->responseObject($oAccount, $aContacts, $sParent, $aParameters))); } else { if ($mResponse instanceof \MailSo\Base\Collection) { $aCollection = $mResponse->GetAsArray(); if (150 < \count($aCollection) && $mResponse instanceof \MailSo\Mime\EmailCollection) { $aCollection = \array_slice($aCollection, 0, 150); } $mResult = $this->responseObject($oAccount, $aCollection, $sParent, $aParameters); unset($aCollection); } else { if ('CSocial' === $sClassName) { $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), $mResponse->toArray()); } else { if ('CFileStorageItem' === $sClassName) { $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('Id' => $mResponse->Id, 'Type' => $mResponse->TypeStr, 'Path' => $mResponse->Path, 'FullPath' => $mResponse->FullPath, 'Name' => $mResponse->Name, 'Size' => $mResponse->Size, 'IsFolder' => $mResponse->IsFolder, 'IsLink' => $mResponse->IsLink, 'LinkType' => $mResponse->LinkType, 'LinkUrl' => $mResponse->LinkUrl, 'LastModified' => $mResponse->LastModified, 'ContentType' => $mResponse->ContentType, 'Iframed' => $mResponse->Iframed, 'Thumb' => $mResponse->Thumb, 'ThumbnailLink' => $mResponse->ThumbnailLink, 'OembedHtml' => $mResponse->OembedHtml, 'Hash' => $mResponse->Hash, 'Shared' => $mResponse->Shared, 'Owner' => $mResponse->Owner, 'Content' => $mResponse->Content, 'IsExternal' => $mResponse->IsExternal)); } else { $mResult = '[' . $sClassName . ']'; } } } } } } } } } } } } } } } } } } } } } else { if (is_array($mResponse)) { foreach ($mResponse as $iKey => $oItem) { $mResponse[$iKey] = $this->responseObject($oAccount, $oItem, $sParent, $aParameters); } $mResult = $mResponse; } } unset($mResponse); return $mResult; }
/** * @param bool $bDownload * @param bool $bThumbnail = false * * @return bool */ private function rawSmart($bDownload, $bThumbnail = false) { $sRawKey = (string) $this->GetActionParam('RawKey', ''); $aValues = $this->getDecodedRawKeyValue($sRawKey); $sFolder = isset($aValues['Folder']) ? $aValues['Folder'] : ''; $iUid = isset($aValues['Uid']) ? (int) $aValues['Uid'] : 0; $sMimeIndex = isset($aValues['MimeIndex']) ? (string) $aValues['MimeIndex'] : ''; $sContentTypeIn = isset($aValues['MimeType']) ? (string) $aValues['MimeType'] : ''; $sFileNameIn = isset($aValues['FileName']) ? (string) $aValues['FileName'] : ''; $sFileHashIn = isset($aValues['FileHash']) ? (string) $aValues['FileHash'] : ''; if (!empty($sFileHashIn)) { $this->verifyCacheByKey($sRawKey); $oAccount = $this->getAccountFromToken(); $sContentTypeOut = empty($sContentTypeIn) ? \MailSo\Base\Utils::MimeContentType($sFileNameIn) : $sContentTypeIn; $sFileNameOut = $this->MainClearFileName($sFileNameIn, $sContentTypeIn, $sMimeIndex); $rResource = $this->FilesProvider()->GetFile($oAccount, $sFileHashIn); if (\is_resource($rResource)) { $sFileNameOut = \MailSo\Base\Utils::ConvertEncoding($sFileNameOut, \MailSo\Base\Enumerations\Charset::UTF_8, \MailSo\Base\Enumerations\Charset::CP858); \header('Content-Type: ' . $sContentTypeOut); \header('Content-Disposition: attachment; ' . \trim(\MailSo\Base\Utils::EncodeHeaderUtf8AttributeValue('filename', $sFileNameOut)), true); \header('Accept-Ranges: none', true); \header('Content-Transfer-Encoding: binary'); \MailSo\Base\Utils::FpassthruWithTimeLimitReset($rResource); return true; } return false; } else { if (!empty($sFolder) && 0 < $iUid) { $this->verifyCacheByKey($sRawKey); } } $oAccount = $this->initMailClientConnection(); $self = $this; return $this->MailClient()->MessageMimeStream(function ($rResource, $sContentType, $sFileName, $sMimeIndex = '') use($self, $oAccount, $sRawKey, $sContentTypeIn, $sFileNameIn, $bDownload, $bThumbnail) { if ($oAccount && \is_resource($rResource)) { $sContentTypeOut = $sContentTypeIn; if (empty($sContentTypeOut)) { $sContentTypeOut = $sContentType; if (empty($sContentTypeOut)) { $sContentTypeOut = empty($sFileName) ? 'text/plain' : \MailSo\Base\Utils::MimeContentType($sFileName); } } $sFileNameOut = $sFileNameIn; if (empty($sFileNameOut)) { $sFileNameOut = $sFileName; } $sFileNameOut = $self->MainClearFileName($sFileNameOut, $sContentTypeOut, $sMimeIndex); $self->cacheByKey($sRawKey); $bDone = false; if ($bThumbnail && !$bDownload) { $sFileName = ''; $rTempResource = \MailSo\Base\StreamWrappers\TempFile::CreateStream(\MailSo\Base\Utils::Md5Rand($sFileNameOut), $sFileName); if (@\is_resource($rTempResource)) { $bDone = true; \MailSo\Base\Utils::MultipleStreamWriter($rResource, array($rTempResource)); @\fclose($rTempResource); try { $oThumb = new \PHPThumb\GD($sFileName); if ($oThumb) { $oThumb->adaptiveResize(60, 60)->show(); } } catch (\Exception $oException) { $self->Logger()->WriteExceptionShort($oException); } } } if (!$bDone) { \header('Content-Type: ' . $sContentTypeOut); \header('Content-Disposition: ' . ($bDownload ? 'attachment' : 'inline') . '; ' . \trim(\MailSo\Base\Utils::EncodeHeaderUtf8AttributeValue('filename', $sFileNameOut)), true); \header('Accept-Ranges: none', true); \header('Content-Transfer-Encoding: binary'); \MailSo\Base\Utils::FpassthruWithTimeLimitReset($rResource); } } }, $sFolder, $iUid, true, $sMimeIndex); }
/** * @param string $sFontName * @return string */ public function GetFont($sFontName) { $sFontFileName = $this->oPluginManager->GetFont($this->sName, $sFontName); if ($sFontFileName) { $sContentType = \MailSo\Base\Utils::MimeContentType($sFontFileName); $sType = \MailSo\Base\Utils::ContentTypeType($sContentType, $sFontFileName); if ('font' === $sType) { @header('Content-Type: ' . $sContentType); // @header('Content-Disposition: attachment; filename="' . $sFontName . '"'); $sFilePath = $sFontFileName; if (file_exists($sFilePath)) { return file_get_contents($sFilePath); } else { if (function_exists('http_response_code')) { \http_response_code(404); } else { \header("HTTP/1.1 404 Not Found", true, 404); } } } } }
/** * @param bool $bDownload * @param bool $bThumbnail = false * * @return bool */ private function rawSmart($bDownload, $bThumbnail = false) { $sRawKey = (string) $this->GetActionParam('RawKey', ''); $aValues = $this->getDecodedRawKeyValue($sRawKey); $sFolder = isset($aValues['Folder']) ? $aValues['Folder'] : ''; $iUid = (int) isset($aValues['Uid']) ? $aValues['Uid'] : 0; $sMimeIndex = (string) isset($aValues['MimeIndex']) ? $aValues['MimeIndex'] : ''; $sContentTypeIn = (string) isset($aValues['MimeType']) ? $aValues['MimeType'] : ''; $sFileNameIn = (string) isset($aValues['FileName']) ? $aValues['FileName'] : ''; if (!empty($sFolder) && 0 < $iUid) { $this->verifyCacheByKey($sRawKey); } $oAccount = $this->initMailClientConnection(); $self = $this; return $this->MailClient()->MessageMimeStream(function ($rResource, $sContentType, $sFileName, $sMimeIndex = '') use($self, $oAccount, $sRawKey, $sContentTypeIn, $sFileNameIn, $bDownload, $bThumbnail) { if ($oAccount && \is_resource($rResource)) { $sContentTypeOut = $sContentTypeIn; if (empty($sContentTypeOut)) { $sContentTypeOut = $sContentType; if (empty($sContentTypeOut)) { $sContentTypeOut = empty($sFileName) ? 'text/plain' : \MailSo\Base\Utils::MimeContentType($sFileName); } } $sFileNameOut = $sFileNameIn; if (empty($sFileNameOut)) { $sFileNameOut = $sFileName; } $sFileNameOut = $self->MainClearFileName($sFileNameOut, $sContentTypeOut, $sMimeIndex); $self->cacheByKey($sRawKey); $bDone = false; if ($bThumbnail && !$bDownload) { \MailSo\Base\StreamWrappers\TempFile::Reg(); $sFileName = 'mailsotempfile://' . \MailSo\Base\Utils::Md5Rand($sFileNameOut); $rTempResource = @\fopen($sFileName, 'r+b'); if (@\is_resource($rTempResource)) { \MailSo\Base\Utils::MultipleStreamWriter($rResource, array($rTempResource)); @\fclose($rTempResource); $oThumb = @new \PHPThumb\GD($sFileName); if ($oThumb) { $oThumb->adaptiveResize(60, 60)->show(); $bDone = true; } } } if (!$bDone) { \header('Content-Type: ' . $sContentTypeOut); \header('Content-Disposition: ' . ($bDownload ? 'attachment' : 'inline') . '; ' . \trim(\MailSo\Base\Utils::EncodeHeaderUtf8AttributeValue('filename', $sFileNameOut)), true); \header('Accept-Ranges: none', true); \header('Content-Transfer-Encoding: binary'); \MailSo\Base\Utils::FpassthruWithTimeLimitReset($rResource); } } }, $sFolder, $iUid, true, $sMimeIndex); }
/** * @param bool $bDownload * * @return bool */ private function rawSmart($bDownload) { $sRawKey = (string) $this->GetActionParam('RawKey', ''); $aValues = $this->getDecodedRawKeyValue($sRawKey); $sFolder = isset($aValues['Folder']) ? $aValues['Folder'] : ''; $iUid = (int) isset($aValues['Uid']) ? $aValues['Uid'] : 0; $sMimeIndex = (string) isset($aValues['MimeIndex']) ? $aValues['MimeIndex'] : ''; $sContentTypeIn = (string) isset($aValues['MimeType']) ? $aValues['MimeType'] : ''; $sFileNameIn = (string) isset($aValues['FileName']) ? $aValues['FileName'] : ''; if (!empty($sFolder) && 0 < $iUid) { $this->verifyCacheByKey($sRawKey); } $this->initMailClientConnection(); $self = $this; return $this->MailClient()->MessageMimeStream(function ($rResource, $sContentType, $sFileName, $sMimeIndex = '') use($self, $sRawKey, $sContentTypeIn, $sFileNameIn, $bDownload) { if (\is_resource($rResource)) { $sContentTypeOut = $sContentTypeIn; if (empty($sContentTypeOut)) { $sContentTypeOut = $sContentType; if (empty($sContentTypeOut)) { $sContentTypeOut = empty($sFileName) ? 'text/plain' : \MailSo\Base\Utils::MimeContentType($sFileName); } } $sFileNameOut = $sFileNameIn; if (empty($sFileNameOut)) { $sFileNameOut = $sFileName; } $sFileNameOut = $self->MainClearFileName($sFileNameOut, $sContentTypeOut, $sMimeIndex); \header('Content-Type: ' . $sContentTypeOut); \header('Content-Disposition: ' . ($bDownload ? 'attachment' : 'inline') . '; ' . \trim(\MailSo\Base\Utils::EncodeHeaderUtf8AttributeValue('filename', $sFileNameOut)), true); \header('Accept-Ranges: none', true); \header('Content-Transfer-Encoding: binary'); $self->cacheByKey($sRawKey); \MailSo\Base\Utils::FpassthruWithTimeLimitReset($rResource); } }, $sFolder, $iUid, true, $sMimeIndex); }
/** * @param string $sFileName * @return string */ public function GetImage($sFileName) { $sContentType = \MailSo\Base\Utils::MimeContentType($sFileName); if ('image' === \MailSo\Base\Utils::ContentTypeType($sContentType, $sFileName)) { @header('Content-Type: ' . $sContentType); $sFilePath = $this->GetPath() . '/images/' . $sFileName; if (file_exists($sFilePath)) { return file_get_contents($sFilePath); } else { if (function_exists('http_response_code')) { \http_response_code(404); } else { \header("HTTP/1.1 404 Not Found", true, 404); } } } }