bytesCopied += curLine.Length();
bytesCopied += curLine.Length(); }
char *MsgMapiListContext::ConvertBodyToMapiFormat (nsIMsgDBHdr *hdr){  const int kBufLen = 64000; // I guess we only return the first 64K of a message.  int bytesUsed = 0;#define EMPTY_MESSAGE_LINE(buf) (buf[0] == nsCRT::CR || buf[0] == nsCRT::LF || buf[0] == '\0')  nsCOMPtr <nsIMsgFolder> folder;  hdr->GetFolder(getter_AddRefs(folder));  if (!folder)    return nsnull;  nsCOMPtr <nsIInputStream> inputStream;  nsCOMPtr <nsIFileSpec> fileSpec;  folder->GetPath(getter_AddRefs(fileSpec));  nsFileSpec realSpec;  fileSpec->GetFileSpec(&realSpec);  nsCOMPtr <nsILocalFile> localFile;  NS_FileSpecToIFile(&realSpec, getter_AddRefs(localFile));  nsresult rv;  nsCOMPtr<nsIFileInputStream> fileStream = do_CreateInstance(NS_LOCALFILEINPUTSTREAM_CONTRACTID, &rv);  NS_ENSURE_SUCCESS(rv, nsnull);  rv = fileStream->Init(localFile,  PR_RDONLY, 0664, PR_FALSE);  //just have to read the messages  inputStream = do_QueryInterface(fileStream);  if (inputStream)  {    nsCOMPtr <nsILineInputStream> fileLineStream = do_QueryInterface(inputStream);    if (!fileLineStream)      return nsnull;    // ### really want to skip past headers...    PRUint32 messageOffset;    PRUint32 lineCount;    hdr->GetMessageOffset(&messageOffset);    hdr->GetLineCount(&lineCount);    nsCOMPtr <nsISeekableStream> seekableStream = do_QueryInterface(inputStream);    seekableStream->Seek(PR_SEEK_SET, messageOffset);    PRBool hasMore = PR_TRUE;    nsCAutoString curLine;    PRBool inMessageBody = PR_FALSE;    nsresult rv = NS_OK;    while (hasMore) // advance past message headers    {      nsresult rv = fileLineStream->ReadLine(curLine, &hasMore);      if (NS_FAILED(rv) || EMPTY_MESSAGE_LINE(curLine))        break;    }    PRUint32 msgSize;    hdr->GetMessageSize(&msgSize);    if (msgSize > kBufLen)      msgSize = kBufLen - 1;    // this is too big, since it includes the msg hdr size...oh well    char *body = (char*) CoTaskMemAlloc (msgSize + 1);    if (!body)      return nsnull;    PRInt32 bytesCopied = 0;    for (hasMore = TRUE; lineCount > 0 && hasMore && NS_SUCCEEDED(rv); lineCount--)    {      rv = fileLineStream->ReadLine(curLine, &hasMore);      if (NS_FAILED(rv))        break;      curLine.Append(CRLF);      // make sure we have room left      if (bytesCopied + curLine.Length() < msgSize)        strcpy(body + bytesCopied, curLine.get());      bytesCopied += curLine.Length();    }    PR_LOG(MAPI, PR_LOG_DEBUG, ("ConvertBodyToMapiFormat size=%x allocated size %x body = %100.100s\n",         bytesCopied, msgSize + 1, (char *) body) );    body[bytesCopied] = '\0';   // rhp - fix last line garbage...    return body;  }  return nsnull;}