Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
nsEudoraCompose Class Reference

#include <nsEudoraCompose.h>

Collaboration diagram for nsEudoraCompose:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsEudoraCompose ()
 ~nsEudoraCompose ()
nsresult SendTheMessage (nsIFileSpec *pMsg)
void SetBody (const char *pBody, PRInt32 len, nsCString &bodyType)
void SetHeaders (const char *pHeaders, PRInt32 len)
void SetAttachments (nsVoidArray *pAttachments)
void SetDefaultDate (nsCString date)
nsresult CopyComposedMessage (nsCString &fromLine, nsIFileSpec *pSrc, nsIFileSpec *pDst, SimpleBufferTonyRCopiedOnce &copy)

Static Public Member Functions

static nsresult FillMailBuffer (ReadFileState *pState, SimpleBufferTonyRCopiedOnce &read)

Private Member Functions

nsresult CreateComponents (void)
nsresult CreateIdentity (void)
void GetNthHeader (const char *pData, PRInt32 dataLen, PRInt32 n, nsCString &header, nsCString &val, PRBool unwrap)
void GetHeaderValue (const char *pData, PRInt32 dataLen, const char *pHeader, nsCString &val, PRBool unwrap=PR_TRUE)
void GetHeaderValue (const char *pData, PRInt32 dataLen, const char *pHeader, nsString &val)
void ExtractCharset (nsString &str)
void ExtractType (nsString &str)
nsMsgAttachedFileGetLocalAttachments (void)
void CleanUpAttach (nsMsgAttachedFile *a, PRInt32 count)
nsresult ReadHeaders (ReadFileState *pState, SimpleBufferTonyRCopiedOnce &copy, SimpleBufferTonyRCopiedOnce &header)
PRInt32 FindNextEndLine (SimpleBufferTonyRCopiedOnce &data)
PRInt32 IsEndHeaders (SimpleBufferTonyRCopiedOnce &data)
PRInt32 IsSpecialHeader (const char *pHeader)
nsresult WriteHeaders (nsIFileSpec *pDst, SimpleBufferTonyRCopiedOnce &newHeaders)
PRBool IsReplaceHeader (const char *pHeader)

Private Attributes

nsVoidArraym_pAttachments
nsIMsgSendListenerm_pListener
nsIMsgSendm_pMsgSend
nsIMsgSendm_pSendProxy
nsIMsgCompFieldsm_pMsgFields
nsIMsgIdentitym_pIdentity
nsIIOServicem_pIOService
PRInt32 m_headerLen
const char * m_pHeaders
PRInt32 m_bodyLen
const char * m_pBody
nsCString m_bodyType
nsString m_defCharset
SimpleBufferTonyRCopiedOnce m_readHeaders
nsCOMPtr< nsIImportServicem_pImportService
nsCString m_defaultDate

Detailed Description

Definition at line 127 of file nsEudoraCompose.h.


Constructor & Destructor Documentation

Definition at line 208 of file nsEudoraCompose.cpp.

{
       NS_IF_RELEASE( m_pSendProxy);
       NS_IF_RELEASE( m_pIOService);
       NS_IF_RELEASE( m_pMsgSend);
       NS_IF_RELEASE( m_pListener);
       NS_IF_RELEASE( m_pMsgFields);

       if (m_pIdentity) {   
              nsresult rv = m_pIdentity->ClearAllValues();
        NS_ASSERTION(NS_SUCCEEDED(rv),"failed to clear values");
              if (NS_FAILED(rv)) return;

              NS_WITH_PROXIED_SERVICE(nsIMsgAccountManager, accMgr, NS_MSGACCOUNTMANAGER_CONTRACTID, NS_UI_THREAD_EVENTQ, &rv);
        NS_ASSERTION(NS_SUCCEEDED(rv) && accMgr,"failed to get account manager");
              if (NS_FAILED(rv) || !accMgr) return;

              rv = accMgr->RemoveIdentity(m_pIdentity);
        NS_ASSERTION(NS_SUCCEEDED(rv),"failed to remove identity");
              if (NS_FAILED(rv)) return;

           NS_RELEASE(m_pIdentity);
       }

}

Member Function Documentation

Definition at line 528 of file nsEudoraCompose.cpp.

{
  for (PRInt32 i = 0; i < count; i++) {
    a[i].orig_url=nsnull;
    if (a[i].type)
      nsCRT::free( a[i].type);
    if (a[i].description)
      nsCRT::free( a[i].description);
    if (a[i].encoding)
      nsCRT::free( a[i].encoding);
  }
  delete [] a;
}

Here is the caller graph for this function:

Definition at line 931 of file nsEudoraCompose.cpp.

{
       copy.m_bytesInBuf = 0;
       copy.m_writeOffset = 0;
       ReadFileState state;
       state.pFile = pSrc;
       state.offset = 0;
       state.size = 0;
       pSrc->GetFileSize( &state.size);
       if (!state.size) {
              IMPORT_LOG0( "*** Error, unexpected zero file size for composed message\n");
              return( NS_ERROR_FAILURE);
       }

       nsresult rv = pSrc->OpenStreamForReading();
       if (NS_FAILED( rv)) {
              IMPORT_LOG0( "*** Error, unable to open composed message file\n");
              return( NS_ERROR_FAILURE);
       }
       
       PRInt32 written;
       rv = pDst->Write( fromLine.get(), fromLine.Length(), &written);

       // well, isn't this a hoot!
       // Read the headers from the new message, get the ones we like
       // and write out only the headers we want from the new message,
       // along with all of the other headers from the "old" message!
       if (NS_SUCCEEDED( rv))
              rv = FillMailBuffer( &state, copy);
       if (NS_SUCCEEDED( rv))
              rv = ReadHeaders( &state, copy, m_readHeaders);
       
       if (NS_SUCCEEDED( rv)) {
              rv = WriteHeaders( pDst, m_readHeaders);
       }

       // We need to go ahead and write out the rest of the copy buffer
       // so that the following will properly copy the rest of the body
       char   lastChar = 0;

       if (NS_SUCCEEDED( rv)) {
    rv = EscapeFromSpaceLine(pDst, copy.m_pBuffer + copy.m_writeOffset, copy.m_pBuffer+copy.m_bytesInBuf);
              if (copy.m_bytesInBuf)
                     lastChar = copy.m_pBuffer[copy.m_bytesInBuf - 1];
    if (NS_SUCCEEDED(rv))
                copy.m_writeOffset = copy.m_bytesInBuf;
       }

       while ((state.offset < state.size) && NS_SUCCEEDED( rv)) {
              rv = FillMailBuffer( &state, copy);
              if (NS_SUCCEEDED( rv)) {
      rv = EscapeFromSpaceLine(pDst, copy.m_pBuffer + copy.m_writeOffset, copy.m_pBuffer+copy.m_bytesInBuf);
                     lastChar = copy.m_pBuffer[copy.m_bytesInBuf - 1];
                     if (NS_SUCCEEDED( rv))
                  copy.m_writeOffset = copy.m_bytesInBuf;
           else
        IMPORT_LOG0( "*** Error writing to destination mailbox\n");
              }
       }

       pSrc->CloseStream();
       
       if ((lastChar != 0x0A) && NS_SUCCEEDED( rv)) {
              rv = pDst->Write( "\x0D\x0A", 2, &written);
              if (written != 2)
                     rv = NS_ERROR_FAILURE;
       }

       return( rv);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 253 of file nsEudoraCompose.cpp.

{
       nsresult      rv = NS_OK;
       
       if (!m_pIOService) {
              IMPORT_LOG0( "Creating nsIOService\n");

              NS_WITH_PROXIED_SERVICE(nsIIOService, service, kIOServiceCID, NS_UI_THREAD_EVENTQ, &rv);
              if (NS_FAILED(rv)) 
                     return( rv);
              m_pIOService = service;
              NS_IF_ADDREF( m_pIOService);
       }
       
       NS_IF_RELEASE( m_pMsgFields);
       if (!m_pMsgSend) {
              rv = CallCreateInstance( kMsgSendCID, &m_pMsgSend); 
              if (NS_SUCCEEDED( rv) && m_pMsgSend) {
                     nsCOMPtr<nsIProxyObjectManager> proxyMgr = 
                              do_GetService(kProxyObjectManagerCID, &rv);
                     if (NS_SUCCEEDED(rv)) {
                            rv = proxyMgr->GetProxyForObject( NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIMsgSend),
                                                                      m_pMsgSend, PROXY_SYNC, (void**)&m_pSendProxy);
                            if (NS_FAILED( rv)) {
                                   m_pSendProxy = nsnull;
                            }
                     }
                     if (NS_FAILED( rv)) {
                            NS_RELEASE( m_pMsgSend);
                            m_pMsgSend = nsnull;
                     }
              }
       }
       if (!m_pListener && NS_SUCCEEDED( rv)) {
              rv = EudoraSendListener::CreateSendListener( &m_pListener);
       }

       if (NS_SUCCEEDED(rv) && m_pMsgSend) { 
           rv = CallCreateInstance( kMsgCompFieldsCID, &m_pMsgFields); 
              if (NS_SUCCEEDED(rv) && m_pMsgFields) {
                     // IMPORT_LOG0( "nsOutlookCompose - CreateComponents succeeded\n");
                     m_pMsgFields->SetForcePlainText( PR_FALSE);
                     return( NS_OK);
              }
       }

       return( NS_ERROR_FAILURE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 234 of file nsEudoraCompose.cpp.

{
       if (m_pIdentity)
              return( NS_OK);

       nsresult      rv;
    NS_WITH_PROXIED_SERVICE(nsIMsgAccountManager, accMgr, NS_MSGACCOUNTMANAGER_CONTRACTID, NS_UI_THREAD_EVENTQ, &rv);
    if (NS_FAILED(rv)) return( rv);
       rv = accMgr->CreateIdentity( &m_pIdentity);
       nsString      name(NS_LITERAL_STRING("Import Identity"));
       if (m_pIdentity) {
              m_pIdentity->SetFullName( name.get());
              m_pIdentity->SetIdentityName( name.get());
              m_pIdentity->SetEmail( "import@import.service");
       }
       
       return( rv);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 480 of file nsEudoraCompose.cpp.

{
       nsString      tStr;
       PRInt32 idx = str.Find( "charset=", PR_TRUE);
       if (idx != -1) {
              idx += 8;
              str.Right( tStr, str.Length() - idx);
              idx = tStr.FindChar( ';');
              if (idx != -1)
                     tStr.Left( str, idx);
              else
                     str = tStr;
              str.Trim( kWhitespace);
              if ((str.CharAt( 0) == '"') && (str.Length() > 2)) {
                     str.Mid( tStr, 1, str.Length() - 2);
                     str = tStr;
                     str.Trim( kWhitespace);
              }
       }
       else
              str.Truncate();
}

Here is the caller graph for this function:

Definition at line 503 of file nsEudoraCompose.cpp.

{
       nsString      tStr;
       PRInt32       idx = str.FindChar( ';');
       if (idx != -1) {
              str.Left( tStr, idx);
              str = tStr;
       }
       str.Trim( kWhitespace);

       if ((str.CharAt( 0) == '"') && (str.Length() > 2)) {
              str.Mid( tStr, 1, str.Length() - 2);
              str = tStr;
              str.Trim( kWhitespace);
       }

       // if multipart then ignore it since no outlook message body is ever
       // valid multipart!
       if (str.Length() > 10) {
              str.Left( tStr, 10);
              if (tStr.LowerCaseEqualsLiteral("multipart/"))
                     str.Truncate();
       }
}

Here is the caller graph for this function:

Definition at line 1002 of file nsEudoraCompose.cpp.

{
       if (read.m_writeOffset >= read.m_bytesInBuf) {
              read.m_writeOffset = 0;
              read.m_bytesInBuf = 0;
       }
       else if (read.m_writeOffset) {
              memcpy( read.m_pBuffer, read.m_pBuffer + read.m_writeOffset, read.m_bytesInBuf - read.m_writeOffset);
              read.m_bytesInBuf -= read.m_writeOffset;
              read.m_writeOffset = 0;
       }

       PRInt32       count = read.m_size - read.m_bytesInBuf;
       if (((PRUint32)count + pState->offset) > pState->size)
              count = pState->size - pState->offset;
       if (count) {
              PRInt32              bytesRead = 0;
              char *        pBuffer = read.m_pBuffer + read.m_bytesInBuf;
              nsresult      rv = pState->pFile->Read( &pBuffer, count, &bytesRead);
              if (NS_FAILED( rv)) return( rv);
              if (bytesRead != count) return( NS_ERROR_FAILURE);
              read.m_bytesInBuf += bytesRead;
              pState->offset += bytesRead;
       }

       return( NS_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 890 of file nsEudoraCompose.cpp.

{
       PRInt32 len = data.m_bytesInBuf - data.m_writeOffset;
       if (!len)
              return( -1);
       PRInt32       count = 0;
       const char *pData = data.m_pBuffer + data.m_writeOffset;
       while (((*pData == 0x0D) || (*pData == 0x0A)) && (count < len)) {
              pData++;
              count++;
       }
       while ((*pData != 0x0D) && (*pData != 0x0A) && (count < len)) {
              pData++;
              count++;
       }
       
       if (count < len)
              return( count);

       return( -1);
}

Here is the caller graph for this function:

void nsEudoraCompose::GetHeaderValue ( const char *  pData,
PRInt32  dataLen,
const char *  pHeader,
nsCString val,
PRBool  unwrap = PR_TRUE 
) [private]

Definition at line 403 of file nsEudoraCompose.cpp.

{
       val.Truncate();
       if (!pData)
              return;

       PRInt32       start = 0;
       PRInt32 len = strlen( pHeader);
       const char *pChar = pData;
       if (!nsCRT::strncasecmp( pHeader, pData, len)) {
              start = len;
       }
       else {
              while (start < dataLen) {
                     while ((start < dataLen) && (*pChar != 0x0D) && (*pChar != 0x0A)) {
                            start++;
                            pChar++;
                     }
                     while ((start < dataLen) && ((*pChar == 0x0D) || (*pChar == 0x0A))) {
                            start++;
                            pChar++;
                     }
                     if ((start < dataLen) && !nsCRT::strncasecmp( pChar, pHeader, len))
                            break;
              }
              if (start < dataLen)
                     start += len;
       }

       if (start >= dataLen)
              return;

       PRInt32                     end = start;
       PRInt32                     lineEnd;
       const char *  pStart;

       pChar =              pData + start;

       while (end < dataLen) {
              while ((end < dataLen) && (*pChar != 0x0D) && (*pChar != 0x0A)) {
                     end++;
                     pChar++;
              }
              if (end > start) {
                     val.Append( pData + start, end - start);
              }
              
              lineEnd = end;
              pStart = pChar;
              while ((end < dataLen) && ((*pChar == 0x0D) || (*pChar == 0x0A))) {
                     end++;
                     pChar++;
              }
              
              start = end;

              while ((end < dataLen) && ((*pChar == ' ') || (*pChar == '\t'))) {
                     end++;
                     pChar++;
              }

              if (start == end)
                     break;
              
              if (unwrap)
                     val.Append( ' ');
              else {
                     val.Append( pStart, end - lineEnd);
              }

              start = end;
       }
              
       val.Trim( kWhitespace);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsEudoraCompose::GetHeaderValue ( const char *  pData,
PRInt32  dataLen,
const char *  pHeader,
nsString val 
) [inline, private]

Definition at line 149 of file nsEudoraCompose.h.

                                                                                                             {
              val.Truncate();
              nsCString     hVal;
              GetHeaderValue( pData, dataLen, pHeader, hVal, PR_TRUE);
              NS_CopyNativeToUnicode( hVal, val);
       }

Here is the call graph for this function:

Definition at line 542 of file nsEudoraCompose.cpp.

{  
       /*
       nsIURI      *url = nsnull;
       */

       PRInt32              count = 0;
       if (m_pAttachments)
              count = m_pAttachments->Count();
       if (!count)
              return( nsnull);

       nsMsgAttachedFile *a = (nsMsgAttachedFile *) new nsMsgAttachedFile[count + 1];
       if (!a)
              return( nsnull);
       memset(a, 0, sizeof(nsMsgAttachedFile) * (count + 1));
       
       nsresult                    rv;
       nsXPIDLCString       urlStr;
       ImportAttachment *   pAttach;

       for (PRInt32 i = 0; i < count; i++) {
              // nsMsgNewURL(&url, "file://C:/boxster.jpg");
              // a[i].orig_url = url;

              // NS_PRECONDITION( PR_FALSE, "Forced Break");

              pAttach = (ImportAttachment *) m_pAttachments->ElementAt( i);
              a[i].file_spec = new nsFileSpec;
              pAttach->pAttachment->GetFileSpec( a[i].file_spec);
              urlStr.Adopt(0);
              pAttach->pAttachment->GetURLString(getter_Copies(urlStr));
              if (!urlStr) {
                     CleanUpAttach( a, count);
                     return( nsnull);
              }
              rv = m_pIOService->NewURI( urlStr, nsnull, nsnull, getter_AddRefs(a[i].orig_url));
              if (NS_FAILED( rv)) {
                     CleanUpAttach( a, count);
                     return( nsnull);
              }

              a[i].type = nsCRT::strdup( pAttach->mimeType);
              a[i].real_name = nsCRT::strdup( pAttach->description);
              a[i].encoding = nsCRT::strdup( ENCODING_BINARY);
       }

       return( a);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsEudoraCompose::GetNthHeader ( const char *  pData,
PRInt32  dataLen,
PRInt32  n,
nsCString header,
nsCString val,
PRBool  unwrap 
) [private]

Definition at line 302 of file nsEudoraCompose.cpp.

{
       header.Truncate();
       val.Truncate();
       if (!pData)
              return;

       PRInt32       index = 0;
       PRInt32       len;
       PRInt32       start = 0;
       const char *pChar = pData;
       const char *pStart;
       if (n == 0) {
              pStart = pChar;
              len = 0;
              while ((start < dataLen) && (*pChar != ':')) {
                     start++;
                     len++;
                     pChar++;
              }
              header.Append( pStart, len);
              header.Trim( kWhitespace);
              start++;
              pChar++;
       }
       else {
              while (start < dataLen) {
                     if ((*pChar != ' ') && (*pChar != 9)) {
                            if (n == index) {
                                   pStart = pChar;
                                   len = 0;
                                   while ((start < dataLen) && (*pChar != ':')) {
                                          start++;
                                          len++;
                                          pChar++;
                                   }
                                   header.Append( pStart, len);
                                   header.Trim( kWhitespace);
                                   start++;
                                   pChar++;
                                   break;
                            }
                            else
                                   index++;
                     }

                     while ((start < dataLen) && (*pChar != 0x0D) && (*pChar != 0x0A)) {
                            start++;
                            pChar++;
                     }
                     while ((start < dataLen) && ((*pChar == 0x0D) || (*pChar == 0x0A))) {
                            start++;
                            pChar++;
                     }
              }
       }

       if (start >= dataLen)
              return;

       PRInt32              lineEnd;
       PRInt32              end = start;
       while (end < dataLen) {
              while ((end < dataLen) && (*pChar != 0x0D) && (*pChar != 0x0A)) {
                     end++;
                     pChar++;
              }
              if (end > start) {
                     val.Append( pData + start, end - start);
              }
              
              lineEnd = end;
              pStart = pChar;
              while ((end < dataLen) && ((*pChar == 0x0D) || (*pChar == 0x0A))) {
                     end++;
                     pChar++;
              }
              
              start = end;

              while ((end < dataLen) && ((*pChar == ' ') || (*pChar == '\t'))) {
                     end++;
                     pChar++;
              }

              if (start == end)
                     break;
              
              if (unwrap)
                     val.Append( ' ');
              else {
                     val.Append( pStart, end - lineEnd);
              }

              start = end;
       }
       
       val.Trim( kWhitespace);
}

Here is the caller graph for this function:

Definition at line 912 of file nsEudoraCompose.cpp.

{
       PRInt32 len = data.m_bytesInBuf - data.m_writeOffset;
       if (len < 2)
              return( -1);
       const char *pChar = data.m_pBuffer + data.m_writeOffset;
       if ((*pChar == 0x0D) && (*(pChar + 1) == 0x0D))
              return( 2);

       if (len < 4)
              return( -1);
       if ((*pChar == 0x0D) && (*(pChar + 1) == 0x0A) &&
              (*(pChar + 2) == 0x0D) && (*(pChar + 3) == 0x0A))
              return( 4);

       return( -1);
}

Here is the caller graph for this function:

PRBool nsEudoraCompose::IsReplaceHeader ( const char *  pHeader) [private]

Definition at line 1048 of file nsEudoraCompose.cpp.

{
       for (int i = 0; i < kMaxReplaceHeaders; i++) {
              if (!nsCRT::strcasecmp( pHeader, gReplaceHeaders[i]))
                     return( PR_TRUE);
       }

       return( PR_FALSE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt32 nsEudoraCompose::IsSpecialHeader ( const char *  pHeader) [private]

Definition at line 1058 of file nsEudoraCompose.cpp.

{
       for (int i = 0; i < kMaxSpecialHeaders; i++) {
              if (!nsCRT::strcasecmp( pHeader, gSpecialHeaders[i]))
                     return( (PRInt32) i);
       }

       return( -1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 837 of file nsEudoraCompose.cpp.

{
       // This should be the headers...
       header.m_writeOffset = 0;

       nsresult      rv;
       PRInt32              lineLen;
       PRInt32              endLen = -1;
       PRInt8        endBuffer = 0;

       while ((endLen = IsEndHeaders( copy)) == -1) {
              while ((lineLen = FindNextEndLine( copy)) == -1) {
                     copy.m_writeOffset = copy.m_bytesInBuf;
                     if (!header.Write( copy.m_pBuffer, copy.m_writeOffset)) {
                            IMPORT_LOG0( "*** ERROR, writing headers\n");
                            return( NS_ERROR_FAILURE);
                     }
                     if (NS_FAILED( rv = FillMailBuffer( pState, copy))) {
                            IMPORT_LOG0( "*** Error reading message headers\n");
                            return( rv);
                     }
                     if (!copy.m_bytesInBuf) {
                            IMPORT_LOG0( "*** Error, end of file while reading headers\n");
                            return( NS_ERROR_FAILURE);
                     }
              }
              copy.m_writeOffset += lineLen;
              if ((copy.m_writeOffset + 4) >= copy.m_bytesInBuf) {
                     if (!header.Write( copy.m_pBuffer, copy.m_writeOffset)) {
                            IMPORT_LOG0( "*** ERROR, writing headers 2\n");
                            return( NS_ERROR_FAILURE);
                     }
                     if (NS_FAILED( rv = FillMailBuffer( pState, copy))) {
                            IMPORT_LOG0( "*** Error reading message headers 2\n");
                            return( rv);
                     }
              }
       }

       if (!header.Write( copy.m_pBuffer, copy.m_writeOffset)) {
              IMPORT_LOG0( "*** Error writing final headers\n");
              return( NS_ERROR_FAILURE);
       }
       if (!header.Write( (const char *)&endBuffer, 1)) {
              IMPORT_LOG0( "*** Error writing header trailing null\n");
              return( NS_ERROR_FAILURE);
       }

       copy.m_writeOffset += endLen;
       
       return( NS_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 593 of file nsEudoraCompose.cpp.

{
       nsresult      rv = CreateComponents();
       if (NS_SUCCEEDED( rv))
              rv = CreateIdentity();
       if (NS_FAILED( rv))
              return( rv);
       
       // IMPORT_LOG0( "Outlook Compose created necessary components\n");

       nsString      bodyType;
       nsString      charSet;
       nsString      headerVal;
       GetHeaderValue( m_pHeaders, m_headerLen, "From:", headerVal);
       if (!headerVal.IsEmpty())
              m_pMsgFields->SetFrom( headerVal);
       GetHeaderValue( m_pHeaders, m_headerLen, "To:", headerVal);
       if (!headerVal.IsEmpty())
              m_pMsgFields->SetTo( headerVal);
       GetHeaderValue( m_pHeaders, m_headerLen, "Subject:", headerVal);
       if (!headerVal.IsEmpty())
              m_pMsgFields->SetSubject( headerVal);
       GetHeaderValue( m_pHeaders, m_headerLen, "Content-type:", headerVal);
       bodyType = headerVal;
       ExtractType( bodyType);
       ExtractCharset( headerVal);
  // Use platform charset as default if the msg doesn't specify one
  // (ie, no 'charset' param in the Content-Type: header). As the last
  // resort we'll use the mail default charset.
  if (headerVal.IsEmpty())
  {
    headerVal.AssignWithConversion(nsMsgI18NFileSystemCharset());
    if (headerVal.IsEmpty())
    { // last resort
      if (m_defCharset.IsEmpty())
      {
        nsXPIDLString defaultCharset;
        NS_GetLocalizedUnicharPreferenceWithDefault(nsnull, "mailnews.view_default_charset",
                                                    NS_LITERAL_STRING("ISO-8859-1"), defaultCharset);
        m_defCharset = defaultCharset;
      }
      headerVal = m_defCharset;
    }
  }
  m_pMsgFields->SetCharacterSet( NS_LossyConvertUCS2toASCII(headerVal).get() );
  charSet = headerVal;
       GetHeaderValue( m_pHeaders, m_headerLen, "CC:", headerVal);
       if (!headerVal.IsEmpty())
              m_pMsgFields->SetCc( headerVal);
       GetHeaderValue( m_pHeaders, m_headerLen, "Message-ID:", headerVal);
       if (!headerVal.IsEmpty())
              m_pMsgFields->SetMessageId( NS_LossyConvertUCS2toASCII(headerVal).get() );
       GetHeaderValue( m_pHeaders, m_headerLen, "Reply-To:", headerVal);
       if (!headerVal.IsEmpty())
              m_pMsgFields->SetReplyTo( headerVal);

       // what about all of the other headers?!?!?!?!?!?!
  char *pMimeType; 
       if (!bodyType.IsEmpty())
              pMimeType = ToNewCString(bodyType);
  else
    pMimeType = ToNewCString(m_bodyType);
       
       // IMPORT_LOG0( "Outlook compose calling CreateAndSendMessage\n");
       nsMsgAttachedFile *pAttach = GetLocalAttachments();


       /*
              l10n - I have the body of the message in the system charset,
              I need to "encode" it to be the charset for the message
              *UNLESS* of course, I don't know what the charset of the message
              should be?  How do I determine what the charset should
              be if it doesn't exist?

       */
       
       nsString      uniBody;
       NS_CopyNativeToUnicode( nsDependentCString(m_pBody), uniBody);

       nsCString     body;

       rv = nsMsgI18NConvertFromUnicode( NS_LossyConvertUTF16toASCII(charSet).get(),
                                    uniBody, body);
       if (NS_FAILED( rv)) {
              // in this case, if we did not use the default compose
              // charset, then try that.
              if (!charSet.Equals( m_defCharset)) {
                     body.Truncate();
                     rv = nsMsgI18NConvertFromUnicode( NS_LossyConvertUTF16toASCII(charSet).get(),
                                        uniBody, body);
              }
       }
       uniBody.Truncate();


  // See if it's a draft msg (ie, no From: or no To: AND no Cc: AND no Bcc:).
  // Eudora saves sent and draft msgs in Out folder (ie, mixed) and it does
  // store Bcc: header in the msg itself.
  nsMsgDeliverMode mode = nsIMsgSend::nsMsgDeliverNow;
  nsAutoString from, to, cc, bcc;
  rv = m_pMsgFields->GetFrom(from);
  rv = m_pMsgFields->GetTo(to);
  rv = m_pMsgFields->GetCc(cc);
  rv = m_pMsgFields->GetBcc(bcc);
  if ( from.IsEmpty() || to.IsEmpty() && cc.IsEmpty() && bcc.IsEmpty() )
    mode = nsIMsgSend::nsMsgSaveAsDraft;

       if (NS_FAILED( rv)) {

              rv = m_pSendProxy->CreateAndSendMessage(
                    nsnull,                                 // no editor shell
                                                                      m_pIdentity,                  // dummy identity
                                                                                nsnull,                         // account key
                                                                      m_pMsgFields,                 // message fields
                                                                      PR_FALSE,                              // digest = NO
                                                                      PR_TRUE,                               // dont_deliver = YES, make a file
                                                                      mode,                         // mode
                                                                      nsnull,                                       // no message to replace
                                                                      pMimeType,                           // body type
                                                                      m_pBody,                               // body pointer
                                                                      m_bodyLen,                           // body length
                                                                      nsnull,                                       // remote attachment data
                                                                      pAttach,                               // local attachments
                                                                      nsnull,                                       // related part
                                                                      nsnull,                       // parent window
                                                                      nsnull,                       // progress listener
                                                                      m_pListener,                       // listener
                                                                      nsnull,                       // password
                                                                      EmptyCString(),               // originalMsgURI
                    nsnull);                      // message compose type

       }
       else {
              rv = m_pSendProxy->CreateAndSendMessage(
                    nsnull,                                 // no editor shell
                                                                      m_pIdentity,                  // dummy identity
                                                                                nsnull,                         // account key
                                                                      m_pMsgFields,                 // message fields
                                                                      PR_FALSE,                              // digest = NO
                                                                      PR_TRUE,                               // dont_deliver = YES, make a file
                                                                      mode,                         // mode
                                                                      nsnull,                                       // no message to replace
                                                                      pMimeType,                           // body type
                                                                      body.get(),                                // body pointer
                                                                      body.Length(),                          // body length
                                                                      nsnull,                                       // remote attachment data
                                                                      pAttach,                               // local attachments
                                                                      nsnull,                                       // related part
                                                                      nsnull,                       // parent window
                                                                      nsnull,                       // progress listener
                                                                      m_pListener,                       // listener
                                                                      nsnull,                       // password
                                                                      EmptyCString(),               // originalMsgURI
                    nsnull);                      // message compose type

       }

       // IMPORT_LOG0( "Returned from CreateAndSendMessage\n");

       if (pAttach)
              delete [] pAttach;

       EudoraSendListener *pListen = (EudoraSendListener *)m_pListener;
       if (NS_FAILED( rv)) {
              IMPORT_LOG1( "*** Error, CreateAndSendMessage FAILED: 0x%lx\n", rv);
              // IMPORT_LOG1( "Headers: %80s\n", m_pHeaders);
       }
       else {
              // wait for the listener to get done!
              PRInt32       abortCnt = 0;
              PRInt32       cnt = 0;
              PRInt32       sleepCnt = 1;        
              while (!pListen->m_done && (abortCnt < kHungAbortCount)) {
                     PR_Sleep( sleepCnt);
                     cnt++;
                     if (cnt > kHungCount) {
                            abortCnt++;
                            sleepCnt *= 2;
                            cnt = 0;
                     }
              }

              if (abortCnt >= kHungAbortCount) {
                     IMPORT_LOG0( "**** Create and send message hung\n");
                     IMPORT_LOG1( "Headers: %s\n", m_pHeaders);
                     IMPORT_LOG1( "Body: %s\n", m_pBody);
                     rv = NS_ERROR_FAILURE;
              }

       }

       if (pMimeType)
              nsCRT::free( pMimeType);

       if (pListen->m_location) {
              pMsg->FromFileSpec( pListen->m_location);
              rv = NS_OK;
       }
       else {
              rv = NS_ERROR_FAILURE;
              IMPORT_LOG0( "*** Error, Outlook compose unsuccessful\n");
       }
       
       pListen->Reset();

       return( rv);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsEudoraCompose::SetAttachments ( nsVoidArray pAttachments) [inline]

Definition at line 136 of file nsEudoraCompose.h.

{ m_pAttachments = pAttachments;}

Here is the caller graph for this function:

void nsEudoraCompose::SetBody ( const char *  pBody,
PRInt32  len,
nsCString bodyType 
) [inline]

Definition at line 134 of file nsEudoraCompose.h.

{ m_pBody = pBody; m_bodyLen = len; m_bodyType = bodyType;}

Here is the caller graph for this function:

Definition at line 137 of file nsEudoraCompose.h.

Here is the caller graph for this function:

void nsEudoraCompose::SetHeaders ( const char *  pHeaders,
PRInt32  len 
) [inline]

Definition at line 135 of file nsEudoraCompose.h.

{ m_pHeaders = pHeaders; m_headerLen = len;}

Here is the caller graph for this function:

Definition at line 1069 of file nsEudoraCompose.cpp.

{
       // Well, ain't this a peach?
       // This is rather disgusting but there really isn't much to be done about it....

       // 1. For each "old" header, replace it with the new one if we want,
       // then right it out.
       // 2. Then if we haven't written the "important" new headers, write them out
       // 3. Terminate the headers with an extra eol.
       
       PRInt32              n = 0;
       nsCString     header;
       nsCString     val;
       nsCString     replaceVal;
       PRInt32              written;
       nsresult      rv = NS_OK; // it's ok if we don't have the first header on the predefined lists.
       PRInt32              specialHeader;
       PRBool        specials[kMaxSpecialHeaders];
  PRBool    hasDateHeader = PR_FALSE;
       int                  i;

       for (i = 0; i < kMaxSpecialHeaders; i++)
              specials[i] = PR_FALSE;

  // m_pHeaders - contains headers from a Eudora msg.
  // newHeaders - contains headers from a mozilla msg (more headers here).
       do {
              GetNthHeader( m_pHeaders, m_headerLen, n, header, val, PR_FALSE);
              // GetNthHeader( newHeaders.m_pBuffer, newHeaders.m_writeOffset, n, header, val, PR_FALSE);
              if (!header.IsEmpty()) {
                     if ((specialHeader = IsSpecialHeader( header.get())) != -1) {
                            header.Append( ':');
                            GetHeaderValue( newHeaders.m_pBuffer, newHeaders.m_writeOffset - 1, header.get(), val, PR_FALSE);
                            header.Truncate( header.Length() - 1);
                            specials[specialHeader] = PR_TRUE;
                     }
                     else if (IsReplaceHeader( header.get())) {
                            replaceVal.Truncate( 0);
                            header.Append( ':');
                            GetHeaderValue( newHeaders.m_pBuffer, newHeaders.m_writeOffset - 1, header.get(), replaceVal, PR_FALSE);
                            header.Truncate( header.Length() - 1);
                            if (!replaceVal.IsEmpty())
                                   val = replaceVal;
                     }
                     if (!val.IsEmpty()) {
        // See if we're writing out a Date: header.
        if (!nsCRT::strcasecmp(header.get(), "Date"))
          hasDateHeader = PR_TRUE;
                            rv = pDst->Write( header.get(), header.Length(), &written);
                            if (NS_SUCCEEDED( rv))
                                   rv = pDst->Write( ": ", 2, &written);
                            if (NS_SUCCEEDED( rv))
                                   rv = pDst->Write( val.get(), val.Length(), &written);
                            if (NS_SUCCEEDED( rv))
                                   rv = pDst->Write( "\x0D\x0A", 2, &written);

                     }
              }
              n++;
       } while (NS_SUCCEEDED( rv) && !header.IsEmpty());

  // If we don't have Date: header so far then use the default one (taken from Eudora "From " line).
  if (!hasDateHeader)
  {
    rv = pDst->Write(m_defaultDate.get(), m_defaultDate.Length(), &written);
    if (NS_SUCCEEDED( rv))
      rv = pDst->Write( "\x0D\x0A", 2, &written);
  }

       for (i = 0; (i < kMaxSpecialHeaders) && NS_SUCCEEDED( rv); i++) {
              if (!specials[i]) {
                     header = gSpecialHeaders[i];
                     header.Append( ':');
                     GetHeaderValue( newHeaders.m_pBuffer, newHeaders.m_writeOffset - 1, header.get(), val, PR_FALSE);
                     header.Truncate( header.Length() - 1);
                     if (!val.IsEmpty()) {
                            rv = pDst->Write( header.get(), header.Length(), &written);
                            if (NS_SUCCEEDED( rv))
                                   rv = pDst->Write( ": ", 2, &written);
                            if (NS_SUCCEEDED( rv))
                                   rv = pDst->Write( val.get(), val.Length(), &written);
                            if (NS_SUCCEEDED( rv))
                                   rv = pDst->Write( "\x0D\x0A", 2, &written);
                     }
              }
       }
       

       if (NS_SUCCEEDED( rv))
              rv = pDst->Write( "\x0D\x0A", 2, &written);
       return( rv);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 178 of file nsEudoraCompose.h.

Definition at line 180 of file nsEudoraCompose.h.

Definition at line 184 of file nsEudoraCompose.h.

Definition at line 181 of file nsEudoraCompose.h.

Definition at line 176 of file nsEudoraCompose.h.

Definition at line 169 of file nsEudoraCompose.h.

Definition at line 179 of file nsEudoraCompose.h.

Definition at line 177 of file nsEudoraCompose.h.

Definition at line 174 of file nsEudoraCompose.h.

Definition at line 183 of file nsEudoraCompose.h.

Definition at line 175 of file nsEudoraCompose.h.

Definition at line 170 of file nsEudoraCompose.h.

Definition at line 173 of file nsEudoraCompose.h.

Definition at line 171 of file nsEudoraCompose.h.

Definition at line 172 of file nsEudoraCompose.h.

Definition at line 182 of file nsEudoraCompose.h.


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