/**
  * Encrypt a file (and thumbnail if given), upload the blob and send it to the given threemaId
  *
  * @param string $threemaId
  * @param string $filePath
  * @param null|string $thumbnailPath
  * @throws \Threema\Core\Exception
  * @return \Threema\MsgApi\Commands\Results\SendE2EResult
  */
 public final function sendFileMessage($threemaId, $filePath, $thumbnailPath = null)
 {
     //analyse the file
     $fileAnalyzeResult = FileAnalysisTool::analyse($filePath);
     if (null === $fileAnalyzeResult) {
         throw new Exception('could not analyze the file');
     }
     //fetch the public key
     $receiverPublicKey = $this->fetchPublicKeyAndCheckCapability($threemaId, function (CapabilityResult $capabilityResult) {
         return true === $capabilityResult->canFile();
     });
     //encrypt the main file
     $encryptionResult = $this->cryptTool->encryptFile(file_get_contents($filePath));
     $uploadResult = $this->connection->uploadFile($encryptionResult->getData());
     if ($uploadResult === null || !$uploadResult->isSuccess()) {
         throw new Exception('could not upload the file (' . $uploadResult->getErrorCode() . ' ' . $uploadResult->getErrorMessage() . ') ' . $uploadResult->getRawResponse());
     }
     $thumbnailUploadResult = null;
     //encrypt the thumbnail file (if exists)
     if (strlen($thumbnailPath) > 0 && true === file_exists($thumbnailPath)) {
         //encrypt the main file
         $thumbnailEncryptionResult = $this->cryptTool->encryptFileThumbnail(file_get_contents($thumbnailPath), $encryptionResult->getKey());
         $thumbnailUploadResult = $this->connection->uploadFile($thumbnailEncryptionResult->getData());
         if ($thumbnailUploadResult === null || !$thumbnailUploadResult->isSuccess()) {
             throw new Exception('could not upload the thumbnail file (' . $thumbnailUploadResult->getErrorCode() . ' ' . $thumbnailUploadResult->getErrorMessage() . ') ' . $thumbnailUploadResult->getRawResponse());
         }
     }
     $nonce = $this->cryptTool->randomNonce();
     //create a file message box
     $fileMessage = $this->cryptTool->encryptFileMessage($uploadResult, $encryptionResult, $thumbnailUploadResult, $fileAnalyzeResult, $this->privateKey, $receiverPublicKey, $nonce);
     return $this->connection->sendE2E($threemaId, $nonce, $fileMessage);
 }