예제 #1
0
 protected function actionZipAllAttachments($params)
 {
     $account = Account::model()->findByPk($params['account_id']);
     //$imap  = $account->openImapConnection($params['mailbox']);
     $message = \GO\Email\Model\ImapMessage::model()->findByUid($account, $params["mailbox"], $params["uid"]);
     $tmpFolder = \GO\Base\Fs\Folder::tempFolder(uniqid(time()));
     $atts = $message->getAttachments();
     while ($att = array_shift($atts)) {
         if (empty($att->content_id) || $att->disposition == 'attachment') {
             $att->saveToFile($tmpFolder);
         }
     }
     $archiveFile = $tmpFolder->parent()->createChild(GO::t('attachments', 'email') . '.zip');
     \GO\Base\Fs\Zip::create($archiveFile, $tmpFolder, $tmpFolder->ls());
     \GO\Base\Util\Http::outputDownloadHeaders($archiveFile, false);
     readfile($archiveFile->path());
     $tmpFolder->delete();
     $archiveFile->delete();
 }
예제 #2
0
 protected function actionDecompress($params)
 {
     if (!\GO\Base\Util\Common::isWindows()) {
         putenv('LANG=en_US.UTF-8');
     }
     $sources = json_decode($params['decompress_sources'], true);
     $workingFolder = \GO\Files\Model\Folder::model()->findByPk($params['working_folder_id']);
     $workingPath = \GO::config()->file_storage_path . $workingFolder->path;
     chdir($workingPath);
     while ($filePath = array_shift($sources)) {
         $file = new \GO\Base\Fs\File(\GO::config()->file_storage_path . $filePath);
         switch (strtolower($file->extension())) {
             case 'zip':
                 $folder = \GO\Base\Fs\Folder::tempFolder(uniqid());
                 if (class_exists("\\ZipArchive")) {
                     $zip = new \ZipArchive();
                     $zip->open($file->path());
                     $zip->extractTo($folder->path());
                     $this->_convertZipEncoding($folder);
                 } else {
                     chdir($folder->path());
                     $cmd = \GO::config()->cmd_unzip . ' -n ' . escapeshellarg($file->path());
                     exec($cmd, $output, $ret);
                     if ($ret != 0) {
                         throw new \Exception("Could not decompress\n" . implode("\n", $output));
                     }
                 }
                 $items = $folder->ls();
                 foreach ($items as $item) {
                     $item->move(new \GO\Base\Fs\Folder($workingPath));
                 }
                 $folder->delete();
                 break;
             case 'gz':
             case 'tgz':
                 $cmd = \GO::config()->cmd_tar . ' zxf ' . escapeshellarg($file->path());
                 exec($cmd, $output, $ret);
                 if ($ret != 0) {
                     throw new \Exception("Could not decompress\n" . implode("\n", $output));
                 }
                 break;
             case 'tar':
                 $cmd = \GO::config()->cmd_tar . ' xf ' . escapeshellarg($file->path());
                 exec($cmd, $output, $ret);
                 if ($ret != 0) {
                     throw new \Exception("Could not decompress\n" . implode("\n", $output));
                 }
                 break;
         }
     }
     $workingFolder->syncFilesystem(true);
     return array('success' => true);
 }