/**
  * @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;
 }
 /**
  * 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)
 }
 /**
  * Gets the binary content of a contact picture
  *
  * @param TineSession $tineSession The TineSession used to communicate with Tine.
  * @param $contactId The id of the contact whose picture we want
  * @param $creationTime The contact creation time (needed by Tine)
  * @param int $cx The desired picture width
  * @param int $cy The desired picture height
  *
  * @return The binary content of a contact picture
  */
 public static function getContactPicture(TineSession $tineSession, $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($tineSession);
     //tineSession has the necessary cookies
     $req->setUrl($tineSession->getTineUrl() . '?method=Tinebase.getImage&application=Addressbook' . "&location=&id={$contactId}&width={$cx}&height={$cy}&ratiomode=0&mtime={$creationTime}000");
     $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 ? $mugshot : '';
 }