Esempio n. 1
0
 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) : $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 ($this->ApiFileCache()->MoveUploadedFile($oAccount, $sSavedName, $aFileData['tmp_name'])) {
                     $sSavedFullName = $this->ApiFileCache()->GenerateFullFilePath($oAccount, $sSavedName);
                     $this->oApiMail->MessageAppendFile($oAccount, $sSavedFullName, $sFolder);
                     //$aResponse['File'] = $bIsMessage;
                 } else {
                     $sError = 'unknown';
                 }
             } else {
                 throw new \ProjectSeven\Exceptions\ClientException(\ProjectSeven\Notifications::IncorrectFileExtension);
             }
         }
     } else {
         $sError = 'auth';
     }
     if (0 < strlen($sError)) {
         $aResponse['Error'] = $sError;
     }
     return $this->DefaultResponse($oAccount, __FUNCTION__, $aResponse);
 }