Back to index

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

#include <nsMailboxProtocol.h>

Collaboration diagram for nsMailboxProtocol:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsMailboxProtocol (nsIURI *aURL)
virtual ~nsMailboxProtocol ()
nsresult Initialize (nsIURI *aURL)
virtual nsresult LoadUrl (nsIURI *aURL, nsISupports *aConsumer)
NS_IMETHOD OnStartRequest (nsIRequest *request, nsISupports *ctxt)
NS_IMETHOD OnStopRequest (nsIRequest *request, nsISupports *ctxt, nsresult aStatus)
NS_IMETHOD GetContentLength (PRInt32 *aContentLength)

Private Member Functions

virtual nsresult ProcessProtocolState (nsIURI *url, nsIInputStream *inputStream, PRUint32 sourceOffset, PRUint32 length)
virtual nsresult CloseSocket ()
PRInt32 SetupMessageExtraction ()
nsresult OpenMultipleMsgTransport (PRUint32 offset, PRInt32 size)
nsresult OpenFileSocketForReuse (nsIURI *aURL, PRUint32 aStartPosition, PRInt32 aReadCount)
PRBool RunningMultipleMsgUrl ()
PRInt32 ReadFolderResponse (nsIInputStream *inputStream, PRUint32 sourceOffset, PRUint32 length)
PRInt32 ReadMessageResponse (nsIInputStream *inputStream, PRUint32 sourceOffset, PRUint32 length)
PRInt32 DoneReadingMessage ()

Private Attributes

nsCOMPtr< nsIMailboxUrlm_runningUrl
nsMailboxAction m_mailboxAction
PRInt32 m_originalContentLength
nsCOMPtr< nsIStreamListenerm_mailboxParser
nsMsgLineStreamBuffer * m_lineStreamBuffer
MailboxStatesEnum m_nextState
MailboxStatesEnum m_initialState
PRInt32 mCurrentProgress
PRUint32 m_messageID
nsCOMPtr< nsIFileSpecm_tempMessageFile
nsCOMPtr< nsIInputStreamm_multipleMsgMoveCopyStream

Detailed Description

Definition at line 78 of file nsMailboxProtocol.h.


Constructor & Destructor Documentation

Definition at line 86 of file nsMailboxProtocol.cpp.

    : nsMsgProtocol(aURI)
{
  m_lineStreamBuffer =nsnull;

  // initialize the pr log if it hasn't been initialiezed already
  if (!MAILBOX)
    MAILBOX = PR_NewLogModule("MAILBOX");
}

Definition at line 96 of file nsMailboxProtocol.cpp.

{
  // free our local state 
  delete m_lineStreamBuffer;
}

Member Function Documentation

nsresult nsMailboxProtocol::CloseSocket ( ) [private, virtual]

Definition at line 742 of file nsMailboxProtocol.cpp.

{
  // how do you force a release when closing the connection??
  nsMsgProtocol::CloseSocket(); 
  m_runningUrl = nsnull;
  m_mailboxParser = nsnull;
  return 0;
}

Here is the caller graph for this function:

Definition at line 402 of file nsMailboxProtocol.cpp.

{
  nsresult rv = NS_OK;
  // and close the article file if it was open....
  
  if (m_mailboxAction == nsIMailboxUrl::ActionSaveMessageToDisk && m_tempMessageFile)
    rv = m_tempMessageFile->CloseStream();
  
  return rv;
}

Here is the caller graph for this function:

Definition at line 102 of file nsMailboxProtocol.cpp.

{
  *aContentLength = -1;
  if (m_mailboxAction == nsIMailboxUrl::ActionParseMailbox)
  {
    // our file transport knows the entire length of the berkley mail folder
    // so get it from there.
    if (!m_request)
      return NS_OK;

    nsCOMPtr<nsIChannel> info = do_QueryInterface(m_request);
    if (info) info->GetContentLength(aContentLength);
    return NS_OK;

  }
  else if (m_runningUrl)
  {
    PRUint32 msgSize = 0;
    m_runningUrl->GetMessageSize(&msgSize);
    *aContentLength = (PRInt32) msgSize;
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 170 of file nsMailboxProtocol.cpp.

{
  NS_PRECONDITION(aURL, "invalid URL passed into MAILBOX Protocol");
  nsresult rv = NS_OK;
  if (aURL)
  {
    rv = aURL->QueryInterface(NS_GET_IID(nsIMailboxUrl), (void **) getter_AddRefs(m_runningUrl));
    if (NS_SUCCEEDED(rv) && m_runningUrl)
    {
      nsCOMPtr <nsIMsgWindow> window;
      rv = m_runningUrl->GetMailboxAction(&m_mailboxAction); 
      // clear stopped flag on msg window, because we care.
      nsCOMPtr <nsIMsgMailNewsUrl> mailnewsUrl = do_QueryInterface(m_runningUrl);
      if (mailnewsUrl)
      {
        mailnewsUrl->GetMsgWindow(getter_AddRefs(window));
        if (window)
          window->SetStopped(PR_FALSE);
      }
      if (m_mailboxAction == nsIMailboxUrl::ActionParseMailbox)
        rv = OpenFileSocket(aURL, 0, -1 /* read in all the bytes in the file */);
      else
      {
        // we need to specify a byte range to read in so we read in JUST the message we want.
        rv = SetupMessageExtraction();
        if (NS_FAILED(rv)) return rv;
        nsMsgKey aMsgKey;
        PRUint32 aMsgSize = 0;
        rv = m_runningUrl->GetMessageKey(&aMsgKey);
        NS_ASSERTION(NS_SUCCEEDED(rv), "oops....i messed something up");
        rv = m_runningUrl->GetMessageSize(&aMsgSize);
        NS_ASSERTION(NS_SUCCEEDED(rv), "oops....i messed something up");
        if (RunningMultipleMsgUrl())
        {
          rv = OpenFileSocketForReuse(aURL, (PRUint32) aMsgKey, aMsgSize);
          // if we're running multiple msg url, we clear the event sink because the multiple
          // msg urls will handle setting the progress.
          mProgressEventSink = nsnull;
        }
        else
          rv = OpenFileSocket(aURL, (PRUint32) aMsgKey, aMsgSize);
        NS_ASSERTION(NS_SUCCEEDED(rv), "oops....i messed something up");
      }
    }
  }
  
#if defined(XP_MAC)
  m_lineStreamBuffer = new nsMsgLineStreamBuffer(OUTPUT_BUFFER_SIZE, PR_TRUE, PR_TRUE, '\r');
#else
  m_lineStreamBuffer = new nsMsgLineStreamBuffer(OUTPUT_BUFFER_SIZE, PR_TRUE);
#endif
  
  m_nextState = MAILBOX_READ_FOLDER;
  m_initialState = MAILBOX_READ_FOLDER;
  mCurrentProgress = 0;
  
  NS_NewFileSpecWithSpec(m_tempMsgFileSpec, getter_AddRefs(m_tempMessageFile));
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsMailboxProtocol::LoadUrl ( nsIURI aURL,
nsISupports *  aConsumer 
) [virtual]

Definition at line 446 of file nsMailboxProtocol.cpp.

{
  nsresult rv = NS_OK;
  // if we were already initialized with a consumer, use it...
  nsCOMPtr<nsIStreamListener> consumer = do_QueryInterface(aConsumer);
  if (consumer)
    m_channelListener = consumer;
  
  if (aURL)
  {
    m_runningUrl = do_QueryInterface(aURL);
    if (m_runningUrl)
    {
      // find out from the url what action we are supposed to perform...
      rv = m_runningUrl->GetMailboxAction(&m_mailboxAction);
      
      PRBool convertData = PR_FALSE;

      // need to check if we're fetching an rfc822 part in order to
      // quote a message.
      if (m_mailboxAction == nsIMailboxUrl::ActionFetchMessage)
      {
        nsCOMPtr<nsIMsgMailNewsUrl> msgUrl = do_QueryInterface(m_runningUrl, &rv);
        NS_ENSURE_SUCCESS(rv,rv);

        nsCAutoString queryStr;
        rv = msgUrl->GetQuery(queryStr);
        NS_ENSURE_SUCCESS(rv,rv);

        // check if this is a filter plugin requesting the message.
        // in that case, set up a text converter
        convertData = (queryStr.Find("header=filter") != kNotFound || queryStr.Find("header=attach") != kNotFound);
      }
      else if (m_mailboxAction == nsIMailboxUrl::ActionFetchPart)
      {
        // when fetching a part, we need to insert a converter into the listener chain order to
        // force just the part out of the message. Our channel listener is the consumer we'll
        // pass in to AsyncConvertData.
        convertData = PR_TRUE;
        consumer = m_channelListener;
      }
      if (convertData)
      {
          nsCOMPtr<nsIStreamConverterService> streamConverter = do_GetService("@mozilla.org/streamConverters;1", &rv);
          NS_ENSURE_SUCCESS(rv, rv);
          nsCOMPtr <nsIStreamListener> conversionListener;
          nsCOMPtr<nsIChannel> channel;
          QueryInterface(NS_GET_IID(nsIChannel), getter_AddRefs(channel));

          rv = streamConverter->AsyncConvertData("message/rfc822",
                                                 "*/*",
                                                 consumer, channel, getter_AddRefs(m_channelListener));
      }
      
      if (NS_SUCCEEDED(rv))
      {
        switch (m_mailboxAction)
        {
        case nsIMailboxUrl::ActionParseMailbox:
          // extract the mailbox parser..
          rv = m_runningUrl->GetMailboxParser(getter_AddRefs(m_mailboxParser));
          m_nextState = MAILBOX_READ_FOLDER;
          break;
        case nsIMailboxUrl::ActionSaveMessageToDisk:
          // ohhh, display message already writes a msg to disk (as part of a hack)
          // so we can piggy back off of that!! We just need to change m_tempMessageFile
          // to be the name of our save message to disk file. Since save message to disk
          // urls are run without a docshell to display the msg into, we won't be trying
          // to display the message after we write it to disk...
          {
            nsCOMPtr<nsIMsgMessageUrl> msgUri = do_QueryInterface(m_runningUrl);
            msgUri->GetMessageFile(getter_AddRefs(m_tempMessageFile));
            m_tempMessageFile->OpenStreamForWriting();
          }
        case nsIMailboxUrl::ActionCopyMessage:
        case nsIMailboxUrl::ActionMoveMessage:
        case nsIMailboxUrl::ActionFetchMessage:
          if (m_mailboxAction == nsIMailboxUrl::ActionSaveMessageToDisk) 
          {
            nsCOMPtr<nsIMsgMessageUrl> messageUrl = do_QueryInterface(aURL, &rv);
            if (NS_SUCCEEDED(rv))
            {
              PRBool addDummyEnvelope = PR_FALSE;
              messageUrl->GetAddDummyEnvelope(&addDummyEnvelope);
              if (addDummyEnvelope)
                SetFlag(MAILBOX_MSG_PARSE_FIRST_LINE);
              else
                ClearFlag(MAILBOX_MSG_PARSE_FIRST_LINE);
            }
          }
          else
          {
            ClearFlag(MAILBOX_MSG_PARSE_FIRST_LINE);
          }
          
          m_nextState = MAILBOX_READ_MESSAGE;
          break;
        case nsIMailboxUrl::ActionFetchPart:
            m_nextState = MAILBOX_READ_MESSAGE;
            break;
        default:
          break;
        }
      }
      
      rv = nsMsgProtocol::LoadUrl(aURL, m_channelListener);
      
    } // if we received an MAILBOX url...
  } // if we received a url!
  
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsMailboxProtocol::OnStartRequest ( nsIRequest request,
nsISupports *  ctxt 
)

Definition at line 234 of file nsMailboxProtocol.cpp.

{
  // extract the appropriate event sinks from the url and initialize them in our protocol data
  // the URL should be queried for a nsINewsURL. If it doesn't support a news URL interface then
  // we have an error.
  if (m_nextState == MAILBOX_READ_FOLDER && m_mailboxParser)
  {
    // we need to inform our mailbox parser that it's time to start...
    m_mailboxParser->OnStartRequest(request, ctxt);
  }
  return nsMsgProtocol::OnStartRequest(request, ctxt);
}
NS_IMETHODIMP nsMailboxProtocol::OnStopRequest ( nsIRequest request,
nsISupports *  ctxt,
nsresult  aStatus 
)

Definition at line 260 of file nsMailboxProtocol.cpp.

{
  nsresult rv;
  if (m_nextState == MAILBOX_READ_FOLDER && m_mailboxParser)
  {
    // we need to inform our mailbox parser that there is no more incoming data...
    m_mailboxParser->OnStopRequest(request, ctxt, aStatus);
  }
  else if (m_nextState == MAILBOX_READ_MESSAGE) 
  {
    DoneReadingMessage();
  }
  // I'm not getting cancel status - maybe the load group still has the status.
  PRBool stopped = PR_FALSE;
  if (m_runningUrl)
  {
    nsCOMPtr <nsIMsgMailNewsUrl> mailnewsUrl = do_QueryInterface(m_runningUrl);
    if (mailnewsUrl)
    {
      nsCOMPtr <nsIMsgWindow> window;
      mailnewsUrl->GetMsgWindow(getter_AddRefs(window));
      if (window)
        window->GetStopped(&stopped);
    }
    
    if (!stopped && NS_SUCCEEDED(aStatus) && (m_mailboxAction == nsIMailboxUrl::ActionCopyMessage || m_mailboxAction == nsIMailboxUrl::ActionMoveMessage))
    {
      PRUint32 numMoveCopyMsgs;
      PRUint32 curMoveCopyMsgIndex;
      rv = m_runningUrl->GetNumMoveCopyMsgs(&numMoveCopyMsgs);
      if (NS_SUCCEEDED(rv) && numMoveCopyMsgs > 0)
      {
        m_runningUrl->GetCurMoveCopyMsgIndex(&curMoveCopyMsgIndex);
        if (++curMoveCopyMsgIndex < numMoveCopyMsgs)
        {
          if (!mSuppressListenerNotifications && m_channelListener)
          {
                  nsCOMPtr<nsICopyMessageStreamListener> listener = do_QueryInterface(m_channelListener, &rv);
            if (listener)
            {
              listener->EndCopy(ctxt, aStatus);
              listener->StartMessage(); // start next message.
            }
          }
          m_runningUrl->SetCurMoveCopyMsgIndex(curMoveCopyMsgIndex);
          nsCOMPtr <nsIMsgDBHdr> nextMsg;
          rv = m_runningUrl->GetMoveCopyMsgHdrForIndex(curMoveCopyMsgIndex, getter_AddRefs(nextMsg));
          if (NS_SUCCEEDED(rv) && nextMsg)
          {
            PRUint32 msgSize = 0;
            nsMsgKey msgKey;
            nsCOMPtr <nsIMsgFolder> msgFolder;
            nextMsg->GetFolder(getter_AddRefs(msgFolder));
            if (msgFolder)
            {
              nsXPIDLCString uri;
              msgFolder->GetUriForMsg(nextMsg, getter_Copies(uri));
              nsCOMPtr<nsIMsgMessageUrl> msgUrl = do_QueryInterface(m_runningUrl);
              if (msgUrl)
              {
                msgUrl->SetOriginalSpec(uri);
                msgUrl->SetUri(uri);
                
                nextMsg->GetMessageKey(&msgKey);
                nextMsg->GetMessageSize(&msgSize);
                // now we have to seek to the right position in the file and
                // basically re-initialize the transport with the correct message size.
                // then, we have to make sure the url keeps running somehow.
                nsCOMPtr<nsISupports> urlSupports = do_QueryInterface(m_runningUrl);
                //
                // put us in a state where we are always notified of incoming data
                //
                
                m_transport = 0; // open new stream transport
                m_inputStream = 0;
                m_outputStream = 0;
                
                rv = OpenMultipleMsgTransport(msgKey, msgSize);
                if (NS_SUCCEEDED(rv))
                {
                  if (!m_inputStream)
                    rv = m_transport->OpenInputStream(0, 0, 0, getter_AddRefs(m_inputStream));
                  
                  if (NS_SUCCEEDED(rv))
                  {
                    nsCOMPtr<nsIInputStreamPump> pump;
                    rv = NS_NewInputStreamPump(getter_AddRefs(pump), m_inputStream);
                    if (NS_SUCCEEDED(rv)) {
                      rv = pump->AsyncRead(this, urlSupports);
                      if (NS_SUCCEEDED(rv))
                        m_request = pump;
                    }
                  }
                }
                
                NS_ASSERTION(NS_SUCCEEDED(rv), "AsyncRead failed");
                if (m_loadGroup)
                  m_loadGroup->RemoveRequest(NS_STATIC_CAST(nsIRequest *, this), nsnull, aStatus);
                m_socketIsOpen = PR_TRUE; // mark the channel as open
                return aStatus;
              }
            }
          }
        }
        else
        {
        }
      }
    }
  }
  // and we want to mark ourselves for deletion or some how inform our protocol manager that we are 
  // available for another url if there is one.
  
  // mscott --> maybe we should set our state to done because we don't run multiple urls in a mailbox
  // protocol connection....
  m_nextState = MAILBOX_DONE;
  
  // the following is for smoke test purposes. QA is looking at this "Mailbox Done" string which
  // is printed out to the console and determining if the mail app loaded up correctly...obviously
  // this solution is not very good so we should look at something better, but don't remove this
  // line before talking to me (mscott) and mailnews QA....
  
  PR_LOG(MAILBOX, PR_LOG_ALWAYS, ("Mailbox Done\n"));
  
  // when on stop binding is called, we as the protocol are done...let's close down the connection
  // releasing all of our interfaces. It's important to remember that this on stop binding call
  // is coming from netlib so they are never going to ping us again with on data available. This means
  // we'll never be going through the Process loop...
  
  if (m_multipleMsgMoveCopyStream)
  {
    m_multipleMsgMoveCopyStream->Close();
    m_multipleMsgMoveCopyStream = nsnull;
  }
  nsMsgProtocol::OnStopRequest(request, ctxt, aStatus);
  return CloseSocket(); 
}

Here is the call graph for this function:

nsresult nsMailboxProtocol::OpenFileSocketForReuse ( nsIURI aURL,
PRUint32  aStartPosition,
PRInt32  aReadCount 
) [private]

Definition at line 144 of file nsMailboxProtocol.cpp.

{
  NS_ENSURE_ARG_POINTER(aURL);

  nsresult rv = NS_OK;
  m_readCount = aReadCount;

  nsCOMPtr <nsIFile> file;

  rv = GetFileFromURL(aURL, getter_AddRefs(file));
  NS_ENSURE_SUCCESS(rv, rv);
    
  nsCOMPtr<nsIFileInputStream> fileStream = do_CreateInstance(NS_LOCALFILEINPUTSTREAM_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  m_multipleMsgMoveCopyStream = do_QueryInterface(fileStream, &rv);
  NS_ENSURE_SUCCESS(rv, rv);
  fileStream->Init(file,  PR_RDONLY, 0664, PR_FALSE);  //just have to read the messages

  rv = OpenMultipleMsgTransport(aStartPosition, aReadCount);

  m_socketIsOpen = PR_FALSE;
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 127 of file nsMailboxProtocol.cpp.

{
  nsresult rv;

  NS_DEFINE_CID(kStreamTransportServiceCID, NS_STREAMTRANSPORTSERVICE_CID);
  nsCOMPtr<nsIStreamTransportService> serv =
      do_GetService(kStreamTransportServiceCID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  // XXX 64-bit
  rv = serv->CreateInputTransport(m_multipleMsgMoveCopyStream, nsInt64(offset),
                                  nsInt64(size), PR_FALSE,
                                  getter_AddRefs(m_transport));

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsMailboxProtocol::ProcessProtocolState ( nsIURI url,
nsIInputStream inputStream,
PRUint32  sourceOffset,
PRUint32  length 
) [private, virtual]

Definition at line 685 of file nsMailboxProtocol.cpp.

{
  nsresult rv = NS_OK;
  PRInt32 status = 0;
  ClearFlag(MAILBOX_PAUSE_FOR_READ); /* already paused; reset */
  
  while(!TestFlag(MAILBOX_PAUSE_FOR_READ))
  {
    
    switch(m_nextState) 
    {
    case MAILBOX_READ_MESSAGE:
      if (inputStream == nsnull)
        SetFlag(MAILBOX_PAUSE_FOR_READ);
      else
        status = ReadMessageResponse(inputStream, offset, length);
      break;
    case MAILBOX_READ_FOLDER:
      if (inputStream == nsnull)
        SetFlag(MAILBOX_PAUSE_FOR_READ);   // wait for file socket to read in the next chunk...
      else
        status = ReadFolderResponse(inputStream, offset, length);
      break;
    case MAILBOX_DONE:
    case MAILBOX_ERROR_DONE:
      {
        nsCOMPtr <nsIMsgMailNewsUrl> anotherUrl = do_QueryInterface(m_runningUrl);
        rv = m_nextState == MAILBOX_DONE ? NS_OK : NS_ERROR_FAILURE;
        anotherUrl->SetUrlState(PR_FALSE, rv);
        m_nextState = MAILBOX_FREE;
      }
      break;
      
    case MAILBOX_FREE:
      // MAILBOX is a one time use connection so kill it if we get here...
      CloseSocket(); 
      return rv; /* final end */
      
    default: /* should never happen !!! */
      m_nextState = MAILBOX_ERROR_DONE;
      break;
    }
    
    /* check for errors during load and call error 
    * state if found
    */
    if(status < 0 && m_nextState != MAILBOX_FREE)
    {
      m_nextState = MAILBOX_ERROR_DONE;
      /* don't exit! loop around again and do the free case */
      ClearFlag(MAILBOX_PAUSE_FOR_READ);
    }
  } /* while(!MAILBOX_PAUSE_FOR_READ) */
  
  return rv;
}

Here is the call graph for this function:

PRInt32 nsMailboxProtocol::ReadFolderResponse ( nsIInputStream inputStream,
PRUint32  sourceOffset,
PRUint32  length 
) [private]

Definition at line 559 of file nsMailboxProtocol.cpp.

{
  // okay we are doing a folder read in 8K chunks of a mail folder....
  // this is almost too easy....we can just forward the data in this stream on to our
  // folder parser object!!!
  
  nsresult rv = NS_OK;
  mCurrentProgress += length;
  
  if (m_mailboxParser)
  {
    nsCOMPtr <nsIURI> url = do_QueryInterface(m_runningUrl);
    rv = m_mailboxParser->OnDataAvailable(nsnull, url, inputStream, sourceOffset, length); // let the parser deal with it...
  }
  if (NS_FAILED(rv))
  {
    m_nextState = MAILBOX_ERROR_DONE; // drop out of the loop....
    return -1;
  }
  
  // now wait for the next 8K chunk to come in.....
  SetFlag(MAILBOX_PAUSE_FOR_READ);
  
  // leave our state alone so when the next chunk of the mailbox comes in we jump to this state
  // and repeat....how does this process end? Well when the file is done being read in, core net lib
  // will issue an ::OnStopRequest to us...we'll use that as our sign to drop out of this state and to
  // close the protocol instance...
  
  return 0; 
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt32 nsMailboxProtocol::ReadMessageResponse ( nsIInputStream inputStream,
PRUint32  sourceOffset,
PRUint32  length 
) [private]

Definition at line 590 of file nsMailboxProtocol.cpp.

{
  char *line = nsnull;
  PRUint32 status = 0;
  nsresult rv = NS_OK;
  mCurrentProgress += length;
  
  // if we are doing a move or a copy, forward the data onto the copy handler...
  // if we want to display the message then parse the incoming data...
  
  if (m_channelListener)
  {
    // just forward the data we read in to the listener...
    rv = m_channelListener->OnDataAvailable(this, m_channelContext, inputStream, sourceOffset, length);
  }
  else
  {
    PRBool pauseForMoreData = PR_FALSE;
    PRBool canonicalLineEnding = PR_FALSE;
    nsCOMPtr<nsIMsgMessageUrl> msgurl = do_QueryInterface(m_runningUrl);
    
    if (msgurl)
      msgurl->GetCanonicalLineEnding(&canonicalLineEnding);
    do
    {
      char *saveLine;
      saveLine = line = m_lineStreamBuffer->ReadNextLine(inputStream, status, pauseForMoreData);
      
      if (!line || (line[0] == '.' && line[1] == 0))
      {
        // we reached the end of the message!
        ClearFlag(MAILBOX_PAUSE_FOR_READ);
      } // otherwise process the line
      else
      {
        if (line[0] == '.')
          line++; // skip over the '.'
        
        /* When we're sending this line to a converter (ie,
        it's a message/rfc822) use the local line termination
        convention, not CRLF.  This makes text articles get
        saved with the local line terminators.  Since SMTP
        and NNTP mandate the use of CRLF, it is expected that
        the local system will convert that to the local line
        terminator as it is read.
        */
        // mscott - the firstline hack is aimed at making sure we don't write
        // out the dummy header when we are trying to display the message.
        // The dummy header is the From line with the date tag on it.
        if (m_tempMessageFile && TestFlag(MAILBOX_MSG_PARSE_FIRST_LINE))
        {
          PRInt32 count = 0;
          if (line)
            rv = m_tempMessageFile->Write(line, PL_strlen(line),
            &count);
          if (NS_FAILED(rv)) break;
          
          if (canonicalLineEnding)
            rv = m_tempMessageFile->Write(CRLF, 2, &count);
          else
            rv = m_tempMessageFile->Write(MSG_LINEBREAK,
            MSG_LINEBREAK_LEN, &count);
          
          if (NS_FAILED(rv)) break;
        }
        else
          SetFlag(MAILBOX_MSG_PARSE_FIRST_LINE);
      } 
      PR_Free(saveLine);
    }
    while (line && !pauseForMoreData);
  }
  
  SetFlag(MAILBOX_PAUSE_FOR_READ); // wait for more data to become available...
  if (mProgressEventSink)
  {
    PRInt32 contentLength = 0;
    GetContentLength(&contentLength);
    // XXX 64-bit
    mProgressEventSink->OnProgress(this, m_channelContext,
                                   nsUint64(mCurrentProgress),
                                   nsUint64(contentLength));
  }
  
  if (NS_FAILED(rv)) return -1;
  
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 247 of file nsMailboxProtocol.cpp.

{
  if (m_mailboxAction == nsIMailboxUrl::ActionCopyMessage || m_mailboxAction == nsIMailboxUrl::ActionMoveMessage)
  {
    PRUint32 numMoveCopyMsgs;
    nsresult rv = m_runningUrl->GetNumMoveCopyMsgs(&numMoveCopyMsgs);
    if (NS_SUCCEEDED(rv) && numMoveCopyMsgs > 1)
      return PR_TRUE;
  }
  return PR_FALSE;
}

Here is the caller graph for this function:

Definition at line 413 of file nsMailboxProtocol.cpp.

{
  // Determine the number of bytes we are going to need to read out of the 
  // mailbox url....
  nsCOMPtr<nsIMsgDBHdr> msgHdr;
  nsresult rv = NS_OK;
  
  NS_ASSERTION(m_runningUrl, "Not running a url");
  if (m_runningUrl)
  {
    PRUint32 messageSize = 0;
    m_runningUrl->GetMessageSize(&messageSize);
    if (!messageSize)
    {
      nsCOMPtr<nsIMsgMessageUrl> msgUrl = do_QueryInterface(m_runningUrl, &rv);
      NS_ENSURE_SUCCESS(rv,rv);
      rv = msgUrl->GetMessageHeader(getter_AddRefs(msgHdr));
      if (NS_SUCCEEDED(rv) && msgHdr)
      {
        msgHdr->GetMessageSize(&messageSize);
        m_runningUrl->SetMessageSize(messageSize);
      }
      else
        NS_ASSERTION(PR_FALSE, "couldn't get message header");
    }
  }
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 114 of file nsMailboxProtocol.h.

nsMsgLineStreamBuffer* nsMailboxProtocol::m_lineStreamBuffer [private]

Definition at line 109 of file nsMailboxProtocol.h.

Definition at line 102 of file nsMailboxProtocol.h.

Definition at line 106 of file nsMailboxProtocol.h.

Definition at line 117 of file nsMailboxProtocol.h.

Definition at line 123 of file nsMailboxProtocol.h.

Definition at line 113 of file nsMailboxProtocol.h.

Definition at line 103 of file nsMailboxProtocol.h.

Definition at line 101 of file nsMailboxProtocol.h.

Definition at line 119 of file nsMailboxProtocol.h.

Definition at line 116 of file nsMailboxProtocol.h.


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