/** * @see ExpressoLite\Backend\Request\LiteRequest::execute */ public function execute() { // This method will directly output the binary stream to client. // Intended to be called on a "_blank" window. $fileName = $this->param('fileName'); $messageId = $this->param('messageId'); $partId = $this->param('partId'); $mimeType = $this->isParamSet('forceDownload') ? null : $this->getMimeType($fileName); if ($mimeType != null) { //WITHOUT 'attachment' in header, will be opened in browser header("Content-Disposition: filename=\"{$fileName}\""); header('Content-Type: ' . $mimeType); } else { //WITH 'attachment' in header, will be downloaded header("Content-Disposition: attachment; filename=\"{$fileName}\""); header('Content-Type: application/octet-stream'); header('Content-Transfer-Encoding: binary'); } $req = new Request(); $req->setUrl($this->tineSession->getTineUrl() . '?method=Tinebase.uploadTempFile'); $req->setCookieHandler($this->tineSession); //tineSession has the necessary cookies $req->setBinaryOutput(true); // directly output binary stream to client $req->setPostFields('requestType=HTTP&method=Expressomail.downloadAttachment&' . "messageId={$messageId}&partId={$partId}&getAsJson=false"); $req->setHeaders(array('Connection: keep-alive', 'DNT: 1', 'User-Agent: ' . TineJsonRpc::DEFAULT_USERAGENT, 'Pragma: no-cache', 'Cache-Control: no-cache')); $req->send(Request::POST); // We set our Request with binaryOutput = true. Because of this, // it has already outputed all the expected response. So, we return // a null here. return null; }
/** * Uploads raw data to Tine as a temp file that may be used as a message attachment. * * @param TineSession $tineSession The TineSession used to communicate with Tine. * @param string $rawData The file raw content * @param string $fileDisplayName The file name * @param string $mimeType The file's mimetype * * @return string The temp file information. */ public static function uploadTempFile(TineSession $tineSession, $rawData, $fileDisplayName, $mimeType) { $req = new Request(); $req->setUrl($tineSession->getTineUrl() . '?method=Tinebase.uploadTempFile&eid=' . sha1(mt_rand() . microtime())); $req->setCookieHandler($tineSession); //tineSession has the necessary cookies $req->setPostFields($rawData); $req->setHeaders(array('DNT: 1', 'User-Agent: ' . TineJsonRpc::DEFAULT_USERAGENT, 'X-File-Name: ' . $fileDisplayName, 'X-File-Size: 0', 'X-File-Type: ' . $mimeType, 'X-Requested-With: XMLHttpRequest', 'X-Tine20-Request-Type: HTTP')); return $req->send(REQUEST::POST); }