Back to index

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

#include <nsOutlookCompose.h>

Collaboration diagram for nsOutlookCompose:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsOutlookCompose ()
 ~nsOutlookCompose ()
nsresult SendTheMessage (nsIFileSpec *pMsg, nsMsgDeliverMode mode, nsCString &useThisCType)
void SetBody (const char *pBody)
void SetHeaders (const char *pHeaders)
void SetAttachments (nsVoidArray *pAttachments)
nsresult CopyComposedMessage (nsCString &fromLine, nsIFileSpec *pSrc, nsIFileSpec *pDst, SimpleBufferTonyRCopiedTwice &copy)

Static Public Member Functions

static nsresult FillMailBuffer (ReadFileState *pState, SimpleBufferTonyRCopiedTwice &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, SimpleBufferTonyRCopiedTwice &copy, SimpleBufferTonyRCopiedTwice &header)
PRInt32 FindNextEndLine (SimpleBufferTonyRCopiedTwice &data)
PRInt32 IsEndHeaders (SimpleBufferTonyRCopiedTwice &data)
PRInt32 IsSpecialHeader (const char *pHeader)
nsresult WriteHeaders (nsIFileSpec *pDst, SimpleBufferTonyRCopiedTwice &newHeaders)
PRBool IsReplaceHeader (const char *pHeader)
void ConvertSystemStringToUnicode (const char *pSysStr, nsString &uniStr)

Private Attributes

nsVoidArraym_pAttachments
nsIMsgSendListenerm_pListener
nsIMsgSendm_pMsgSend
nsIMsgSendm_pSendProxy
nsIMsgCompFieldsm_pMsgFields
nsIMsgIdentitym_pIdentity
nsIIOServicem_pIOService
nsCString m_Headers
nsCString m_Body
SimpleBufferTonyRCopiedTwice m_readHeaders
nsCOMPtr< nsIImportServicem_pImportService

Detailed Description

Definition at line 124 of file nsOutlookCompose.h.


Constructor & Destructor Documentation

Definition at line 203 of file nsOutlookCompose.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 522 of file nsOutlookCompose.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:

void nsOutlookCompose::ConvertSystemStringToUnicode ( const char *  pSysStr,
nsString uniStr 
) [private]

Definition at line 873 of file nsOutlookCompose.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 247 of file nsOutlookCompose.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 = OutlookSendListener::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 227 of file nsOutlookCompose.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;
       name.AssignLiteral("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 474 of file nsOutlookCompose.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 497 of file nsOutlookCompose.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 944 of file nsOutlookCompose.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 832 of file nsOutlookCompose.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 nsOutlookCompose::GetHeaderValue ( const char *  pData,
PRInt32  dataLen,
const char *  pHeader,
nsCString val,
PRBool  unwrap = PR_TRUE 
) [private]

Definition at line 397 of file nsOutlookCompose.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 nsOutlookCompose::GetHeaderValue ( const char *  pData,
PRInt32  dataLen,
const char *  pHeader,
nsString val 
) [inline, private]

Definition at line 145 of file nsOutlookCompose.h.

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

Here is the call graph for this function:

Definition at line 537 of file nsOutlookCompose.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;
       OutlookAttachment *  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 = (OutlookAttachment *) 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 nsOutlookCompose::GetNthHeader ( const char *  pData,
PRInt32  dataLen,
PRInt32  n,
nsCString header,
nsCString val,
PRBool  unwrap 
) [private]

Definition at line 296 of file nsOutlookCompose.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 854 of file nsOutlookCompose.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 nsOutlookCompose::IsReplaceHeader ( const char *  pHeader) [private]

Definition at line 990 of file nsOutlookCompose.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 nsOutlookCompose::IsSpecialHeader ( const char *  pHeader) [private]

Definition at line 1000 of file nsOutlookCompose.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 779 of file nsOutlookCompose.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 588 of file nsOutlookCompose.cpp.

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

       nsAutoString  bodyType;
       nsAutoString  charSet;
       nsAutoString  headerVal;
    nsCAutoString asciiHeaderVal;

       GetHeaderValue( m_Headers.get(), m_Headers.Length(), "From:", headerVal);
       if (!headerVal.IsEmpty())
              m_pMsgFields->SetFrom( headerVal);
       GetHeaderValue( m_Headers.get(), m_Headers.Length(), "To:", headerVal);
       if (!headerVal.IsEmpty())
              m_pMsgFields->SetTo( headerVal);
       GetHeaderValue( m_Headers.get(), m_Headers.Length(), "Subject:", headerVal);
       if (!headerVal.IsEmpty())
              m_pMsgFields->SetSubject( headerVal);
       GetHeaderValue( m_Headers.get(), m_Headers.Length(), "Content-type:", headerVal);

  // If callers pass in a content type then use it, else get it from the header.
  if (!useThisCType.IsEmpty())
    CopyASCIItoUTF16(useThisCType, bodyType);
  else
  {
       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
      nsXPIDLString defaultCharset;
      NS_GetLocalizedUnicharPreferenceWithDefault(nsnull, "mailnews.view_default_charset",
                                                  NS_LITERAL_STRING("ISO-8859-1"), defaultCharset);
      headerVal = defaultCharset;
    }
  }
  m_pMsgFields->SetCharacterSet( NS_LossyConvertUTF16toASCII(headerVal).get() );
  charSet = headerVal;
       GetHeaderValue( m_Headers.get(), m_Headers.Length(), "CC:", headerVal);
       if (!headerVal.IsEmpty())
              m_pMsgFields->SetCc( headerVal);
       GetHeaderValue( m_Headers.get(), m_Headers.Length(), "Message-ID:", headerVal);
       if (!headerVal.IsEmpty()) {
        LossyCopyUTF16toASCII(headerVal, asciiHeaderVal);
              m_pMsgFields->SetMessageId(asciiHeaderVal.get());
    }
       GetHeaderValue( m_Headers.get(), m_Headers.Length(), "Reply-To:", headerVal);
       if (!headerVal.IsEmpty())
              m_pMsgFields->SetReplyTo( headerVal);

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

  // Do body conversion here
  nsString    uniBody;
  NS_CopyNativeToUnicode( m_Body, uniBody);

  nsCString body;
  rv = nsMsgI18NConvertFromUnicode( NS_LossyConvertUTF16toASCII(charSet).get(),
                                    uniBody, body);
  uniBody.Truncate();

       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
                    NS_FAILED(rv) ? m_Body.get() : body.get(), // body pointer
                    NS_FAILED(rv) ? m_Body.Length() : 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;

       OutlookSendListener *pListen = (OutlookSendListener *)m_pListener;
       if (NS_FAILED( rv)) {
              IMPORT_LOG1( "*** Error, CreateAndSendMessage FAILED: 0x%lx\n", rv);
       }
       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_Headers.get());
                     IMPORT_LOG1( "Body: %s\n", m_Body.get());
                     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 nsOutlookCompose::SetAttachments ( nsVoidArray pAttachments) [inline]

Definition at line 133 of file nsOutlookCompose.h.

{ m_pAttachments = pAttachments;}

Here is the caller graph for this function:

void nsOutlookCompose::SetBody ( const char *  pBody) [inline]

Definition at line 131 of file nsOutlookCompose.h.

{ m_Body = pBody;}

Here is the caller graph for this function:

void nsOutlookCompose::SetHeaders ( const char *  pHeaders) [inline]

Definition at line 132 of file nsOutlookCompose.h.

{ m_Headers = pHeaders;}

Here is the caller graph for this function:

Definition at line 1011 of file nsOutlookCompose.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];
       int                  i;

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

       do {
              GetNthHeader( m_Headers.get(), m_Headers.Length(), n, header, val, PR_FALSE);
              // GetNthHeader( newHeaders.m_pBuffer, newHeaders.m_writeOffset, n, header.get(), 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);
        // Bug 145150 - Turn "Content-Type: application/ms-tnef" into "Content-Type: text/plain"
        //              so the body text can be displayed normally (instead of in an attachment).
        if (!PL_strcasecmp(header.get(), "Content-Type:") && !PL_strcasecmp(val.get(), "application/ms-tnef"))
          val.Assign("text/plain");
                            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()) {
                            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());

       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 175 of file nsOutlookCompose.h.

Definition at line 174 of file nsOutlookCompose.h.

Definition at line 167 of file nsOutlookCompose.h.

Definition at line 172 of file nsOutlookCompose.h.

Definition at line 177 of file nsOutlookCompose.h.

Definition at line 173 of file nsOutlookCompose.h.

Definition at line 168 of file nsOutlookCompose.h.

Definition at line 171 of file nsOutlookCompose.h.

Definition at line 169 of file nsOutlookCompose.h.

Definition at line 170 of file nsOutlookCompose.h.

Definition at line 176 of file nsOutlookCompose.h.


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