コード例 #1
0
ファイル: nsEnigMimeDecrypt.cpp プロジェクト: imudak/enigmail
nsresult
nsEnigMimeDecrypt::ProcessPlainData(char* buf, PRUint32 readCount)
{
  DEBUG_LOG(("nsEnigMimeDecrypt::ProcessPlainData: readCount=%d\n", readCount));

  int status;
  ++mIterations;
  // Read synchronously


  if (mIterations == 1 && readCount > 25) {
    // add mime boundaries around text/plain message (bug 6627)
    if (PL_strncasecmp("content-type:", buf, 13)==0) {
      PRUint32 whitespace=13;
      while((whitespace<readCount) && buf[whitespace] &&
            ((buf[whitespace]==' ') || (buf[whitespace]=='\t'))) { whitespace++; }
      if (buf[whitespace] && (whitespace<readCount)) {
        mCtFound = PL_strncasecmp(buf + whitespace, "text/plain", 10);
        if (mCtFound != 0) {
          mCtFound=PL_strncasecmp(buf + whitespace, "text/html", 9);
        }
      }
      if (mCtFound == 0) {
        char* header = PR_smprintf(
        "Content-Type: multipart/mixed; boundary=\"enigDummy\""
        "\n\n--enigDummy\n");
        PR_SetError(0,0);
        status = mOutputFun(header, strlen(header), mOutputClosure);
        if (status < 0) {
          PR_SetError(status, 0);
          mOutputFun = NULL;
          mOutputClosure = NULL;

          return NS_ERROR_FAILURE;
        }
        mOutputLen += strlen(header);
      }
    }
  }

  if (readCount < kCharMax) {
    // make sure we can continue to write later
    if (buf[readCount-1]==0) --readCount;
  }

  PR_SetError(0,0);
  status = mOutputFun(buf, readCount, mOutputClosure);
  if (status < 0) {
    PR_SetError(status, 0);
    mOutputFun = NULL;
    mOutputClosure = NULL;

    return NS_ERROR_FAILURE;
  }

  mOutputLen += readCount;

  return NS_OK;
} // loop end
コード例 #2
0
ファイル: nsPgpMimeProxy.cpp プロジェクト: cmotc/spacehamster
NS_IMETHODIMP
nsPgpMimeProxy::OnDataAvailable(nsIRequest* aRequest, nsISupports* aContext,
                              nsIInputStream *aInputStream,
                              uint64_t aSourceOffset,
                              uint32_t aLength)
{
  NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);

  NS_ENSURE_ARG(aInputStream);

  char buf[kCharMax];
  uint32_t readCount, readMax;

  while (aLength > 0) {
    readMax = (aLength < kCharMax) ? aLength : kCharMax;

    nsresult rv;
    rv = aInputStream->Read((char *) buf, readMax, &readCount);
    NS_ENSURE_SUCCESS(rv, rv);

    int status = mOutputFun(buf, readCount, mOutputClosure);
    if (status < 0) {
      PR_SetError(status, 0);
      mOutputFun = nullptr;
      return NS_ERROR_FAILURE;
    }

    aLength -= readCount;
  }

  return NS_OK;
}
コード例 #3
0
ファイル: nsPgpMimeProxy.cpp プロジェクト: cmotc/spacehamster
NS_IMETHODIMP
nsPgpMimeProxy::Finish() {
  NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);

  if (mDecryptor) {
    return mDecryptor->OnStopRequest((nsIRequest*) this, nullptr, NS_OK);
  }
  else {
    nsCString temp;
    temp.Append("Content-Type: text/html\r\nCharset: UTF-8\r\n\r\n<html><body>");
    temp.Append("<BR><text=\"#000000\" bgcolor=\"#FFFFFF\" link=\"#FF0000\" vlink=\"#800080\" alink=\"#0000FF\">");
    temp.Append("<center><table BORDER=1 ><tr><td><CENTER>");

    nsCString tString;
    PgpMimeGetNeedsAddonString(tString);
    temp.Append(tString);
    temp.Append("</CENTER></td></tr></table></center><BR></body></html>\r\n");

    PR_SetError(0,0);
    int status = mOutputFun(temp.get(), temp.Length(), mOutputClosure);
    if (status < 0) {
      PR_SetError(status, 0);
      mOutputFun = nullptr;
      return NS_ERROR_FAILURE;
    }
  }

  return NS_OK;
}
コード例 #4
0
ファイル: nsEnigMimeDecrypt.cpp プロジェクト: imudak/enigmail
nsresult
nsEnigMimeDecrypt::ProcessEnd(nsIInputStream* plainStream)
{
  DEBUG_LOG(("nsEnigMimeDecrypt::ProcessEnd:\n"));

  char buf[kCharMax];
  nsresult rv;
  nsString errorMsg;
  nsCAutoString uriSpec("");


  nsCOMPtr<nsIEnigmail> enigmailSvc = do_GetService(NS_ENIGMAIL_CONTRACTID, &rv);
  if (NS_FAILED(rv))
    return rv;

DEBUG_LOG(("nsEnigMimeDecrypt::ProcessEnd: got Enigmail Svc\n"));

  if (mCtFound==0) {
    // add mime boundaries around text/plain message (bug 6627)
    PR_SetError(0,0);
    strcpy(buf, "\n\n--enigDummy--\n");

    int status = mOutputFun(buf, strlen(buf), mOutputClosure);
    if (status < 0) {
      PR_SetError(status, 0);
      mOutputFun = NULL;
      mOutputClosure = NULL;
DEBUG_LOG(("nsEnigMimeDecrypt::ProcessEnd: error 1\n"));

      return NS_ERROR_FAILURE;
    }
    mOutputLen+=strlen(buf);
  }
  else {
    // add final \n to make sure last line is always displayed (bug 5952)
    buf[0]='\n';
    PR_SetError(0,0);
    int status = mOutputFun(buf, 1, mOutputClosure);
    if (status >= 0) {
      // ignore any errors here
      mOutputLen++;
    }
  }

  PR_SetError(0,0);

  // Close input stream
  if (plainStream) plainStream->Close();

  // Close buffer
  mBuffer->Shutdown();

  PRInt32 exitCode;
  nsString keyId;
  nsString userId;
  nsString sigDate;
  nsString blockSeparation;
  PRUint32 statusFlags;

  PRUint32 uiFlags = nsIEnigmail::UI_PGP_MIME;
  EMBool noOutput = PR_FALSE;

  rv = enigmailSvc->DecryptMessageEnd(uiFlags,
                                      mOutputLen,
                                      mPipeTrans,
                                      mVerifyOnly,
                                      noOutput,
                                      &statusFlags,
                                      getter_Copies(keyId),
                                      getter_Copies(userId),
                                      getter_Copies(sigDate),
                                      getter_Copies(errorMsg),
                                      getter_Copies(blockSeparation),
                                      &exitCode);
DEBUG_LOG(("nsEnigMimeDecrypt::ProcessEnd: location 2\n"));

  if (NS_FAILED(rv)) return rv;
DEBUG_LOG(("nsEnigMimeDecrypt::ProcessEnd: location 3\n"));

  if (mSecurityInfo) {
    nsCOMPtr<nsIEnigMimeHeaderSink> enigHeaderSink = do_QueryInterface(mSecurityInfo);
    if (enigHeaderSink) {
      rv = enigHeaderSink->UpdateSecurityStatus(uriSpec, exitCode, statusFlags, keyId.get(), userId.get(), sigDate.get(), errorMsg.get(), blockSeparation.get(), mUri);
    }
  }

  if (exitCode != 0) {
    DEBUG_LOG(("nsEnigMimeDecrypt::ProcessEnd: ERROR EXIT %d\n", exitCode));
    return NS_ERROR_FAILURE;
  }

  return NS_OK;
}