コード例 #1
0
ファイル: Actions.php プロジェクト: pkdevboxy/webmail-lite
 public function UploadMessage()
 {
     $aFileData = $this->getParamValue('FileData', null);
     $sAccountId = (int) $this->getParamValue('AccountID', '0');
     $sAdditionalData = $this->getParamValue('AdditionalData', '{}');
     $aAdditionalData = @json_decode($sAdditionalData, true);
     $oAccount = $sAccountId ? $this->getAccount($sAccountId, true, $this->getParamValue('AuthToken', null)) : $this->getDefaultAccountFromParam();
     $sError = '';
     $aResponse = array();
     if ($oAccount) {
         if (is_array($aFileData)) {
             $sUploadName = $aFileData['name'];
             $bIsEmlExtension = strtolower(pathinfo($sUploadName, PATHINFO_EXTENSION)) === 'eml';
             if ($bIsEmlExtension) {
                 $sFolder = isset($aAdditionalData['Folder']) ? $aAdditionalData['Folder'] : '';
                 $sMimeType = \MailSo\Base\Utils::MimeContentType($sUploadName);
                 $sSavedName = 'upload-post-' . md5($aFileData['name'] . $aFileData['tmp_name']);
                 if (is_resource($aFileData['tmp_name'])) {
                     $this->ApiFileCache()->putFile($oAccount, $sSavedName, $aFileData['tmp_name']);
                 } else {
                     $this->ApiFileCache()->moveUploadedFile($oAccount, $sSavedName, $aFileData['tmp_name']);
                 }
                 if ($this->ApiFileCache()->isFileExists($oAccount, $sSavedName)) {
                     $sSavedFullName = $this->ApiFileCache()->generateFullFilePath($oAccount, $sSavedName);
                     $this->oApiMail->appendMessageFromFile($oAccount, $sSavedFullName, $sFolder);
                 } else {
                     $sError = 'unknown';
                 }
             } else {
                 throw new \ProjectCore\Exceptions\ClientException(\ProjectCore\Notifications::IncorrectFileExtension);
             }
         }
     } else {
         $sError = 'auth';
     }
     if (0 < strlen($sError)) {
         $aResponse['Error'] = $sError;
     }
     return $this->DefaultResponse($oAccount, __FUNCTION__, $aResponse);
 }