Back to index

enigmail  1.4.3
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
nsEnigMimeDecrypt Class Reference

#include <nsEnigMimeDecrypt.h>

Inheritance diagram for nsEnigMimeDecrypt:
Inheritance graph
[legend]
Collaboration diagram for nsEnigMimeDecrypt:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIENIGMIMEDECRYPT
NS_DECL_NSIPIPEREADER 
nsEnigMimeDecrypt ()
virtual ~nsEnigMimeDecrypt ()
void init (in boolean verifyOnly, in boolean rfc2015, in EnigDecryptCallbackFun outputFun, in voidPtr outputClosure)
void write (in string buf, in unsigned long count)
void finish (in nsIMsgWindow msgWindow, in nsIURI uri)
void readData (in string data, in unsigned long count)
void stopRequest (in unsigned long status)

Static Public Member Functions

static NS_METHOD Create (nsISupports *aOuter, REFNSIID aIID, void **aResult)

Protected Member Functions

nsresult Finalize ()
nsresult FinishAux (nsIMsgWindow *msgWindow, nsIURI *uri)
nsresult ProcessPlainData (char *buf, PRUint32 readCount)
nsresult ProcessEnd (nsIInputStream *plainStream)

Protected Attributes

EMBool mInitialized
EMBool mVerifyOnly
EMBool mRfc2015
EMBool mDone
EnigDecryptCallbackFun mOutputFun
void * mOutputClosure
PRUint32 mInputLen
PRUint32 mOutputLen
PRUint32 mIterations
PRInt32 mCtFound
nsCOMPtr< nsIIPCBuffermBuffer
nsCOMPtr< nsIPipeFilterListenermListener
nsCOMPtr< nsIPipeTransportmPipeTrans
nsCOMPtr< nsISupports > mSecurityInfo
nsIURI * mUri

Detailed Description

Definition at line 51 of file nsEnigMimeDecrypt.h.


Constructor & Destructor Documentation

NS_DECL_ISUPPORTS NS_DECL_NSIENIGMIMEDECRYPT NS_DECL_NSIPIPEREADER nsEnigMimeDecrypt::nsEnigMimeDecrypt ( )

Definition at line 115 of file nsEnigMimeDecrypt.cpp.

{
  nsresult rv;
#ifdef FORCE_PR_LOG
  nsCOMPtr<nsIThread> myThread;
  rv = ENIG_GET_THREAD(myThread);
  DEBUG_LOG(("nsEnigMimeDecrypt:: >>>>>>>>> DTOR(%p): myThread=%p\n",
         this, myThread.get()));
#endif

  Finalize();
}

Here is the call graph for this function:


Member Function Documentation

static NS_METHOD nsEnigMimeDecrypt::Create ( nsISupports *  aOuter,
REFNSIID  aIID,
void **  aResult 
) [static]
nsresult nsEnigMimeDecrypt::Finalize ( ) [protected]

Definition at line 174 of file nsEnigMimeDecrypt.cpp.

{
  DEBUG_LOG(("nsEnigMimeDecrypt::Finalize:\n"));

  mOutputFun = NULL;
  mOutputClosure = NULL;

  if (mPipeTrans) {
    mPipeTrans->Terminate();
    mPipeTrans = nsnull;
  }

  if (mListener) {
    mListener = nsnull;
  }

  if (mBuffer) {
    mBuffer->Shutdown();
    mBuffer = nsnull;
  }

  return NS_OK;
}

Here is the caller graph for this function:

void nsIEnigMimeDecrypt::finish ( in nsIMsgWindow  msgWindow,
in nsIURI  uri 
) [inherited]
nsresult nsEnigMimeDecrypt::FinishAux ( nsIMsgWindow *  msgWindow,
nsIURI *  uri 
) [protected]

Definition at line 238 of file nsEnigMimeDecrypt.cpp.

{
  // Enigmail stuff
  nsresult rv;
  nsCOMPtr<nsIThread> myThread;
  rv = ENIG_GET_THREAD(myThread);

  mUri = uri;
  nsCAutoString uriSpec("");

  if (mListener) {
    rv = mListener->OnStopRequest(nsnull, nsnull, 0);
    if (NS_FAILED(rv))
      return rv;

    nsCAutoString endLine;
    rv = mListener->GetEndLine(endLine);
    if (NS_FAILED(rv)) return rv;

    if (endLine.IsEmpty()) {
      ERROR_LOG(("nsEnigMimeDecrypt::FinishAux: ERROR MIME part not terminated\n"));
      return NS_ERROR_FAILURE;
    }

    mListener = nsnull;
  }

  rv = mBuffer->OnStopRequest(nsnull, nsnull, 0);
  if (NS_FAILED(rv))
    return rv;

  if (msgWindow) {
    nsCOMPtr<nsIMsgHeaderSink> headerSink;
    msgWindow->GetMsgHeaderSink(getter_AddRefs(headerSink));
    if (headerSink)
        headerSink->GetSecurityInfo(getter_AddRefs(mSecurityInfo));
  }
  DEBUG_LOG(("nsEnigMimeDecrypt::FinishAux: securityInfo=%p\n", mSecurityInfo.get()));

  nsCOMPtr<nsIPrompt> prompter;
  if (msgWindow) {
    msgWindow->GetPromptDialog(getter_AddRefs(prompter));
  }

  if (!prompter) {
    nsCOMPtr <nsIMsgMailSession> mailSession (do_GetService(NS_MSGMAILSESSION_CONTRACTID));
    if (mailSession) {
      nsCOMPtr<nsIMsgWindow> msgwin;
      mailSession->GetTopmostMsgWindow(getter_AddRefs(msgwin));
      if (msgwin)
        msgwin->GetPromptDialog(getter_AddRefs(prompter));
    }
  }

  DEBUG_LOG(("nsEnigMimeDecrypt::FinishAux: prompter=%p\n", prompter.get()));

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

  nsString errorMsg;
  EMBool noOutput = PR_FALSE;
  PRUint32 statusFlags;

  rv = enigmailSvc->DecryptMessageStart(nsnull,
                                        prompter,
                                        mVerifyOnly,
                                        noOutput,
                                        nsnull,
                                        &statusFlags,
                                        getter_Copies(errorMsg),
                                        getter_AddRefs(mPipeTrans) );
  if (NS_FAILED(rv)) return rv;

  if (!mPipeTrans) {
    if (mSecurityInfo) {
      nsCOMPtr<nsIEnigMimeHeaderSink> enigHeaderSink = do_QueryInterface(mSecurityInfo);
      if (enigHeaderSink) {
        NS_NAMED_LITERAL_STRING(nullString, "");
        rv = enigHeaderSink->UpdateSecurityStatus(uriSpec, -1, statusFlags, nullString.get(), nullString.get(), nullString.get(), errorMsg.get(), nullString.get(), mUri);
      }
    }

    return NS_ERROR_FAILURE;
  }

  mIterations = 0;
  mCtFound = -1;
  nsCOMPtr<nsIInputStream> plainStream = nsnull;

  // read via pipeTransport.jsm
  nsCOMPtr<nsIRequest> request;
  rv = mPipeTrans->ReadInputStream(this, getter_AddRefs(request));
  NS_ENSURE_SUCCESS(rv, rv);

  // Write buffered data asyncronously to process
  nsCOMPtr<nsIInputStream> bufStream;
  rv = mBuffer->OpenInputStream(getter_AddRefs(bufStream));
  if (NS_FAILED(rv)) return rv;

  PRUint32 available;
  rv = bufStream->Available(&available);
  if (NS_FAILED(rv)) return rv;

  DEBUG_LOG(("nsEnigMimeDecrypt::FinishAux: available=%d\n", available));

  rv = mPipeTrans->WriteAsync(bufStream, available, PR_TRUE);
  if (NS_FAILED(rv)) return rv;

  // read via pipeTransport.jsm

  nsCOMPtr<nsIThread> currentThread;
  rv = ENIG_GET_THREAD(currentThread);
  NS_ENSURE_SUCCESS(rv, rv);

  mDone = PR_FALSE;

  // wait with returning until message is completely processed
  // (simulate synchronous function)
  while (! mDone) {
    EMBool pendingEvents;
    rv = currentThread->ProcessNextEvent(PR_TRUE, &pendingEvents);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  return NS_OK;
}
void nsIEnigMimeDecrypt::init ( in boolean  verifyOnly,
in boolean  rfc2015,
in EnigDecryptCallbackFun  outputFun,
in voidPtr  outputClosure 
) [inherited]
nsresult nsEnigMimeDecrypt::ProcessEnd ( nsIInputStream *  plainStream) [protected]

Definition at line 428 of file nsEnigMimeDecrypt.cpp.

{
  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;
}
nsresult nsEnigMimeDecrypt::ProcessPlainData ( char *  buf,
PRUint32  readCount 
) [protected]

Definition at line 367 of file nsEnigMimeDecrypt.cpp.

{
  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
void nsIPipeReader::readData ( in string  data,
in unsigned long  count 
) [inherited]
void nsIPipeReader::stopRequest ( in unsigned long  status) [inherited]
void nsIEnigMimeDecrypt::write ( in string  buf,
in unsigned long  count 
) [inherited]

Member Data Documentation

Definition at line 85 of file nsEnigMimeDecrypt.h.

PRInt32 nsEnigMimeDecrypt::mCtFound [protected]

Definition at line 83 of file nsEnigMimeDecrypt.h.

Definition at line 75 of file nsEnigMimeDecrypt.h.

Definition at line 72 of file nsEnigMimeDecrypt.h.

PRUint32 nsEnigMimeDecrypt::mInputLen [protected]

Definition at line 80 of file nsEnigMimeDecrypt.h.

PRUint32 nsEnigMimeDecrypt::mIterations [protected]

Definition at line 82 of file nsEnigMimeDecrypt.h.

Definition at line 86 of file nsEnigMimeDecrypt.h.

Definition at line 78 of file nsEnigMimeDecrypt.h.

Definition at line 77 of file nsEnigMimeDecrypt.h.

PRUint32 nsEnigMimeDecrypt::mOutputLen [protected]

Definition at line 81 of file nsEnigMimeDecrypt.h.

Definition at line 87 of file nsEnigMimeDecrypt.h.

Definition at line 74 of file nsEnigMimeDecrypt.h.

nsCOMPtr<nsISupports> nsEnigMimeDecrypt::mSecurityInfo [protected]

Definition at line 88 of file nsEnigMimeDecrypt.h.

nsIURI* nsEnigMimeDecrypt::mUri [protected]

Definition at line 90 of file nsEnigMimeDecrypt.h.

Definition at line 73 of file nsEnigMimeDecrypt.h.


The documentation for this class was generated from the following files: