/** * @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; }
/** * Sends the RPC and returns it results * * @return The RPC result * */ public function send($method = self::POST) { if ($this->rpcMethod == null) { throw new RpcException('rpcMethod is not defined'); } $this->setPostFields(json_encode(array('id' => 1, 'jsonrpc' => self::JSON_RPC_VERSION, 'method' => $this->rpcMethod, 'params' => $this->rpcParams))); $rawResponse = parent::send($method); return json_decode($rawResponse); }
/** * Returns the binary content of a contact picture * * @param $contactId The id of the contact * @param $creationTime The creation time of the contact * @param $cx The desired picture width * @param $cy The desired picture height * * @return The binary contact of the contact picture. */ public function getContactPicture($contactId, $creationTime, $cx, $cy) { //we need to make a 'custom' request to get the contact picture, so //we build a Request object manually instead of relying on tineSession //to do it for us $req = new Request(); $req->setBinaryOutput(false); // do not directly output the binary stream to client $req->setCookieHandler($this->tineSession); //tineSession has the necessary cookies $req->setUrl($this->assemblyMugshotUrl($contactId, $creationTime, $cx, $cy)); $req->setHeaders(array('Connection: keep-alive', 'DNT: 1', 'User-Agent: ' . TineJsonRpc::DEFAULT_USERAGENT, 'Pragma: no-cache', 'Cache-Control: no-cache')); $mugshot = $req->send(); return $mugshot === null || substr($mugshot, 0, 14) === '<!DOCTYPE html' ? '' : $mugshot; // dummy if binaryOutput(true) }
/** * 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); }