Back to index

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

#include <nsEnigMsgCompose.h>

Collaboration diagram for nsEnigMsgCompose:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIMSGCOMPOSESECURE
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER 
nsEnigMsgCompose ()
virtual ~nsEnigMsgCompose ()

Static Public Member Functions

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

Protected Member Functions

nsresult Init ()
nsresult Finalize ()
nsresult GetRandomTime (PRUint32 *_retval)
nsresult MakeBoundary (const char *prefix)
nsresult WriteEncryptedHeaders ()
nsresult WriteSignedHeaders1 (EMBool isEightBit)
nsresult WriteSignedHeaders2 ()
nsresult WriteFinalSeparator ()
nsresult WriteOut (const char *aBuf, PRInt32 aLen)
nsresult WriteCopy (const char *aBuf, PRInt32 aLen)
nsresult WriteToPipe (const char *aBuf, PRInt32 aLen)
nsresult FinishAux (EMBool aAbort, nsIMsgSendReport *sendReport)

Protected Attributes

EMBool mInitialized
EMBool mUseSMIME
EMBool mIsDraft
EMBool mRequestStopped
EMBool mLinebreak
PRUint32 mSpace
PRUint32 mMatchFrom
PRUint32 mInputLen
PRUint32 mOutputLen
PRUint32 mSendFlags
PRUint32 mUIFlags
EMBool mMultipartSigned
EMBool mStripWhitespace
nsCString mSenderEmailAddr
nsCString mRecipients
nsCString mBccAddr
nsCString mHashAlgorithm
nsCString mBoundary
nsIOutputStream * mStream
MimeEncoderDatamEncoderData
nsCOMPtr< nsIMsgComposeSecure > mMsgComposeSecure
nsCOMPtr< nsIEnigMimeListenermMimeListener
nsCOMPtr< nsIEnigMimeWritermWriter
nsCOMPtr< nsIPipeTransportmPipeTrans

Static Protected Attributes

static EMBool mRandomSeeded = PR_FALSE
static const char * FromStr = "From "

Detailed Description

Definition at line 64 of file nsEnigMsgCompose.h.


Constructor & Destructor Documentation

NS_DECL_ISUPPORTS NS_DECL_NSIMSGCOMPOSESECURE NS_DECL_NSIREQUESTOBSERVER NS_DECL_NSISTREAMLISTENER nsEnigMsgCompose::nsEnigMsgCompose ( )

Definition at line 187 of file nsEnigMsgCompose.cpp.

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

  Finalize();

}

Here is the call graph for this function:


Member Function Documentation

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

Definition at line 202 of file nsEnigMsgCompose.cpp.

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

  mMsgComposeSecure = nsnull;
  mMimeListener = nsnull;

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

  if (mWriter) {
    mWriter->Close();
    mWriter = nsnull;
  }

  if (mEncoderData) {
    // Clear encoder buffer
    MimeEncoderDestroy(mEncoderData, PR_FALSE);
    mEncoderData = nsnull;
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEnigMsgCompose::FinishAux ( EMBool  aAbort,
nsIMsgSendReport *  sendReport 
) [protected]

Definition at line 675 of file nsEnigMsgCompose.cpp.

{
  nsresult rv;

  if (mMatchFrom > 0) {
    // Flush "buffer" for detecting lines beginning with "From "
    rv = WriteCopy(FromStr, mMatchFrom);
    if (NS_FAILED(rv)) return rv;
  }

  DEBUG_LOG(("nsEnigMsgCompose::FinishAux: \n"));

  if (mMultipartSigned) {
    rv = WriteSignedHeaders2();
    if (NS_FAILED(rv)) return rv;
  }

  // Wait for STDOUT to close
  rv = mPipeTrans->Join();
  if (NS_FAILED(rv)) return rv;

  if (aAbort) {
    // Terminate process
    mPipeTrans->Terminate();
    mPipeTrans = nsnull;

    return NS_ERROR_FAILURE;
  }

  rv = WriteFinalSeparator();
  if (NS_FAILED(rv)) return rv;

  // Count total bytes sent to writer
  PRUint32 cmdOutputLen;
  rv = mWriter->GetBytesWritten(&cmdOutputLen);
  if (NS_FAILED(rv)) return rv;

  // Exclude passthru bytes to determine STDOUT bytes
  cmdOutputLen -= mOutputLen;

  // Close STDOUT writer
  mWriter->Close();
  mWriter = nsnull;

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

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

  PRInt32 exitCode;
  PRUint32 statusFlags;
  nsString errorMsg;
  rv = enigmailSvc->EncryptMessageEnd(nsnull,
                                      prompter,
                                      mUIFlags,
                                      mSendFlags,
                                      cmdOutputLen,
                                      mPipeTrans,
                                      &statusFlags,
                                      getter_Copies(errorMsg),
                                      &exitCode);
  if (NS_FAILED(rv)) return rv;

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

  return NS_OK;
}

Here is the call graph for this function:

nsresult nsEnigMsgCompose::GetRandomTime ( PRUint32 *  _retval) [protected]

Definition at line 230 of file nsEnigMsgCompose.cpp.

{
  if (!*_retval)
    return NS_ERROR_NULL_POINTER;

  // Current local time (microsecond resolution)
  PRExplodedTime localTime;
  PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &localTime);

  PRUint32       randomNumberA = localTime.tm_sec*1000000+localTime.tm_usec;

  // Elapsed time (1 millisecond to 10 microsecond resolution)
  PRIntervalTime randomNumberB = PR_IntervalNow();

  DEBUG_LOG(("nsEnigMsgCompose::GetRandomTime: ranA=0x%p, ranB=0x%p\n",
                                           randomNumberA, randomNumberB));

  *_retval = ((randomNumberA & 0xFFFFF) << 12) | (randomNumberB & 0xFFF);

  return NS_OK;
}

Here is the caller graph for this function:

nsresult nsEnigMsgCompose::Init ( ) [protected]

Definition at line 418 of file nsEnigMsgCompose.cpp.

{
  nsresult rv;

  DEBUG_LOG(("nsEnigMsgCompose::Init: sendFlags=%p\n", mSendFlags));

  EMBool signMsg    = mSendFlags & nsIEnigmail::SEND_SIGNED;
  EMBool encryptMsg = mSendFlags & nsIEnigmail::SEND_ENCRYPTED;
  EMBool usePgpMime = mSendFlags & nsIEnigmail::SEND_PGP_MIME;

  mMultipartSigned = usePgpMime && signMsg && !encryptMsg;

  mWriter = do_CreateInstance(NS_ENIGMIMEWRITER_CONTRACTID, &rv);
  if (NS_FAILED(rv)) return rv;

  rv = mWriter->Init(mStream, PR_TRUE);
  if (NS_FAILED(rv)) return rv;

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

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

  if (usePgpMime && signMsg && (! encryptMsg)) {
    // determine hash algorithm to use for PGP/MIME signed msg
    PRInt32 exitCode;
    PRUnichar* ha;

    rv = enigmailSvc->DetermineHashAlgorithm(prompter,
                                             mUIFlags,
                                             mSenderEmailAddr.get(),
                                             &ha,
                                             &exitCode);

    DEBUG_LOG(("nsEnigMsgCompose::Init: DetermineHash: rv=%d, exitCode=%d\n", rv, exitCode));

    if (NS_FAILED(rv))
      return rv;

    if (exitCode != 0)
      return NS_ERROR_SMTP_PASSWORD_UNDEFINED;

    mHashAlgorithm = NS_ConvertUTF16toUTF8(ha).get();
    DEBUG_LOG(("nsEnigMsgCompose::Init: hashAlgorithm=%s\n", mHashAlgorithm.get()));
  }

  nsString errorMsg;
  PRUint32 statusFlags;
  rv = enigmailSvc->EncryptMessageStart(nsnull, prompter,
                                        mUIFlags,
                                        mSenderEmailAddr.get(),
                                        mRecipients.get(),
                                        mBccAddr.get(),
                                        mHashAlgorithm.get(),
                                        mSendFlags,
                                        (nsIStreamListener*)(mWriter),
                                        &statusFlags,
                                        getter_Copies(errorMsg),
                                        getter_AddRefs(mPipeTrans) );
  if (NS_FAILED(rv))
    return rv;

  if (statusFlags & nsIEnigmail::MISSING_PASSPHRASE)
    return NS_ERROR_SMTP_PASSWORD_UNDEFINED;

  if (!mPipeTrans)
    return NS_OK;

  rv = enigmailSvc->StripWhitespace(mSendFlags,
                                    &mStripWhitespace);
  if (NS_FAILED(rv))
    return rv;

  mInitialized = PR_TRUE;

  return NS_OK;
}
nsresult nsEnigMsgCompose::MakeBoundary ( const char *  prefix) [protected]

Definition at line 254 of file nsEnigMsgCompose.cpp.

{
  DEBUG_LOG(("nsEnigMsgCompose::MakeBoundary:\n"));

  nsresult rv;

  if (!mRandomSeeded) {
    PRUint32 ranTime = 1;

    rv = GetRandomTime(&ranTime);
    if (NS_FAILED(rv))
      return rv;

    srand( ranTime );
    mRandomSeeded = PR_TRUE;
  }


  unsigned char ch[13];
  for( PRUint32 j = 0; j < 12; j++)
    ch[j] = rand() % 256;

  char* boundary = PR_smprintf("------------%s"
           "%02X%02X%02X%02X"
           "%02X%02X%02X%02X"
           "%02X%02X%02X%02X",
           prefix,
           ch[0], ch[1], ch[2], ch[3],
           ch[4], ch[5], ch[6], ch[7],
           ch[8], ch[9], ch[10], ch[11]);

  if (!boundary)
    return NS_ERROR_OUT_OF_MEMORY;

  DEBUG_LOG(("nsEnigMsgCompose::MakeBoundary: boundary='%s'\n",
         boundary));


  mBoundary = boundary;

  PR_Free(boundary);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEnigMsgCompose::WriteCopy ( const char *  aBuf,
PRInt32  aLen 
) [protected]

Definition at line 897 of file nsEnigMsgCompose.cpp.

{
  nsresult rv;

  DEBUG_LOG(("nsEnigMsgCompose::WriteCopy: %d\n", aLen));

  if (aLen <= 0)
    return NS_OK;

  mInputLen += aLen;

  if (mMimeListener) {
    // Write to listener
    rv = mMimeListener->Write(aBuf, aLen, nsnull, nsnull);
    if (NS_FAILED(rv)) return rv;

  } else if (mPipeTrans) {
    // Write to process and copy if multipart/signed
    rv = WriteToPipe(aBuf, aLen);
    if (NS_FAILED(rv)) return rv;

    if (mMultipartSigned) {
      rv = WriteOut(aBuf, aLen);
      if (NS_FAILED(rv)) return rv;
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEnigMsgCompose::WriteEncryptedHeaders ( ) [protected]

Definition at line 300 of file nsEnigMsgCompose.cpp.

{
  nsresult rv;
  DEBUG_LOG(("nsEnigMsgCompose::WriteEncryptedHeaders:\n"));

  rv = MakeBoundary("enig");
  if (NS_FAILED(rv))
    return rv;

  char* headers = PR_smprintf(
 "Content-Type: multipart/encrypted;\r\n"
 " protocol=\"application/pgp-encrypted\";\r\n"
 " boundary=\"%s\"\r\n"
 "\r\n"
 "This is an OpenPGP/MIME encrypted message (RFC 2440 and 3156)\r\n"
 "--%s\r\n"
 "Content-Type: application/pgp-encrypted\r\n"
 "Content-Description: PGP/MIME version identification\r\n"
 "\r\n"
 "Version: 1\r\n"
 "\r\n"
 "--%s\r\n"
 "Content-Type: application/octet-stream; name=\"encrypted.asc\"\r\n"
 "Content-Description: OpenPGP encrypted message\r\n"
 "Content-Disposition: inline; filename=\"encrypted.asc\"\r\n"
 "\r\n",
 mBoundary.get(), mBoundary.get(), mBoundary.get());

  if (!headers)
    return NS_ERROR_OUT_OF_MEMORY;

  rv = WriteOut(headers, strlen(headers));

  PR_Free(headers);

  return rv;
}

Here is the call graph for this function:

nsresult nsEnigMsgCompose::WriteFinalSeparator ( ) [protected]

Definition at line 394 of file nsEnigMsgCompose.cpp.

{
  nsresult rv;
  DEBUG_LOG(("nsEnigMsgCompose::WriteSeparator:\n"));

  if (mBoundary.IsEmpty())
    return NS_OK;

  // Write out final MIME multipart separator
  char* separator = PR_smprintf(
 "\r\n--%s--\r\n",
 mBoundary.get());

  if (!separator)
    return NS_ERROR_OUT_OF_MEMORY;

  rv = WriteOut(separator, strlen(separator));

  PR_Free(separator);

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEnigMsgCompose::WriteOut ( const char *  aBuf,
PRInt32  aLen 
) [protected]

Definition at line 861 of file nsEnigMsgCompose.cpp.

{
  DEBUG_LOG(("nsEnigMsgCompose::WriteOut: %d\n", aLen));

  if (!mWriter)
    return NS_ERROR_FAILURE;

  if (aLen <= 0)
    return NS_OK;

  mOutputLen += aLen;

  if (mEncoderData) {
    // Encode data before transmitting to writer
    int status = MimeEncoderWrite(mEncoderData, aBuf, aLen);
    return (status == 0) ? NS_OK : NS_ERROR_FAILURE;
  }

  return mWriter->Write(aBuf, aLen);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEnigMsgCompose::WriteSignedHeaders1 ( EMBool  isEightBit) [protected]

Definition at line 339 of file nsEnigMsgCompose.cpp.

{
  nsresult rv;
  DEBUG_LOG(("nsEnigMsgCompose::WriteSignedHeaders1: %d\n", (int) isEightBit));

  rv = MakeBoundary("enig");
  if (NS_FAILED(rv))
    return rv;

  char* headers = PR_smprintf(
       "Content-Type: multipart/signed; micalg=pgp-%s;\r\n"
       " protocol=\"application/pgp-signature\";\r\n"
       " boundary=\"%s\"\r\n"
       "%s"
       "This is an OpenPGP/MIME signed message (RFC 2440 and 3156)\r\n"
       "--%s\r\n",
       mHashAlgorithm.get(), mBoundary.get(),
       isEightBit ? "Content-Transfer-Encoding: 8bit\r\n\r\n" : "\r\n",
       mBoundary.get());

  if (!headers)
    return NS_ERROR_OUT_OF_MEMORY;

  rv = WriteOut(headers, strlen(headers));

  PR_Free(headers);

  return rv;
}

Here is the call graph for this function:

nsresult nsEnigMsgCompose::WriteSignedHeaders2 ( ) [protected]

Definition at line 370 of file nsEnigMsgCompose.cpp.

{
  nsresult rv;
  DEBUG_LOG(("nsEnigMsgCompose::WriteSignedHeaders2:\n"));

  char* headers = PR_smprintf(
 "\r\n--%s\r\n"
 "Content-Type: application/pgp-signature; name=\"signature.asc\"\r\n"
 "Content-Description: OpenPGP digital signature\r\n"
 "Content-Disposition: attachment; filename=\"signature.asc\"\r\n"
 "\r\n",
 mBoundary.get());

  if (!headers)
    return NS_ERROR_OUT_OF_MEMORY;

  rv = WriteOut(headers, strlen(headers));

  PR_Free(headers);

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEnigMsgCompose::WriteToPipe ( const char *  aBuf,
PRInt32  aLen 
) [protected]

Definition at line 883 of file nsEnigMsgCompose.cpp.

{
  nsresult rv;
  DEBUG_LOG(("nsEnigMsgCompose::WriteToPipe: %d\n", aLen));

  nsCString tmpStr;
  tmpStr.Assign(aBuf, aLen);
  DEBUG_LOG(("nsEnigMimeWriter::WriteToPipe: data: '%s'\n", tmpStr.get()));

  rv = mPipeTrans->Write(aBuf, aLen);
  return rv;
}

Here is the caller graph for this function:


Member Data Documentation

const char * nsEnigMsgCompose::FromStr = "From " [static, protected]

Definition at line 104 of file nsEnigMsgCompose.h.

nsCString nsEnigMsgCompose::mBccAddr [protected]

Definition at line 126 of file nsEnigMsgCompose.h.

nsCString nsEnigMsgCompose::mBoundary [protected]

Definition at line 129 of file nsEnigMsgCompose.h.

Definition at line 133 of file nsEnigMsgCompose.h.

nsCString nsEnigMsgCompose::mHashAlgorithm [protected]

Definition at line 127 of file nsEnigMsgCompose.h.

Definition at line 106 of file nsEnigMsgCompose.h.

PRUint32 nsEnigMsgCompose::mInputLen [protected]

Definition at line 115 of file nsEnigMsgCompose.h.

Definition at line 108 of file nsEnigMsgCompose.h.

Definition at line 111 of file nsEnigMsgCompose.h.

PRUint32 nsEnigMsgCompose::mMatchFrom [protected]

Definition at line 113 of file nsEnigMsgCompose.h.

Definition at line 136 of file nsEnigMsgCompose.h.

nsCOMPtr<nsIMsgComposeSecure> nsEnigMsgCompose::mMsgComposeSecure [protected]

Definition at line 135 of file nsEnigMsgCompose.h.

Definition at line 121 of file nsEnigMsgCompose.h.

PRUint32 nsEnigMsgCompose::mOutputLen [protected]

Definition at line 116 of file nsEnigMsgCompose.h.

Definition at line 139 of file nsEnigMsgCompose.h.

EMBool nsEnigMsgCompose::mRandomSeeded = PR_FALSE [static, protected]

Definition at line 81 of file nsEnigMsgCompose.h.

nsCString nsEnigMsgCompose::mRecipients [protected]

Definition at line 125 of file nsEnigMsgCompose.h.

Definition at line 109 of file nsEnigMsgCompose.h.

nsCString nsEnigMsgCompose::mSenderEmailAddr [protected]

Definition at line 124 of file nsEnigMsgCompose.h.

PRUint32 nsEnigMsgCompose::mSendFlags [protected]

Definition at line 118 of file nsEnigMsgCompose.h.

PRUint32 nsEnigMsgCompose::mSpace [protected]

Definition at line 112 of file nsEnigMsgCompose.h.

nsIOutputStream* nsEnigMsgCompose::mStream [protected]

Definition at line 131 of file nsEnigMsgCompose.h.

Definition at line 122 of file nsEnigMsgCompose.h.

PRUint32 nsEnigMsgCompose::mUIFlags [protected]

Definition at line 119 of file nsEnigMsgCompose.h.

Definition at line 107 of file nsEnigMsgCompose.h.

Definition at line 138 of file nsEnigMsgCompose.h.


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