Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Attributes
nsMsgSaveAsListener Class Reference
Inheritance diagram for nsMsgSaveAsListener:
Inheritance graph
[legend]
Collaboration diagram for nsMsgSaveAsListener:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER 
nsMsgSaveAsListener (nsIFileSpec *aFileSpec, PRBool addDummyEnvelope)
virtual ~nsMsgSaveAsListener ()
nsresult SetupMsgWriteStream (nsIFileSpec *aFileSpec, PRBool addDummyEnvelope)
void onDataAvailable (in nsIRequest aRequest, in nsISupports aContext, in nsIInputStream aInputStream, in unsigned long aOffset, in unsigned long aCount)
 Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.
void onStartRequest (in nsIRequest aRequest, in nsISupports aContext)
 Called to signify the beginning of an asynchronous request.
void onStopRequest (in nsIRequest aRequest, in nsISupports aContext, in nsresult aStatusCode)
 Called to signify the end of an asynchronous request.

Protected Attributes

nsCOMPtr< nsIOutputStreamm_outputStream
nsCOMPtr< nsIFileSpecm_outputFile
PRBool m_addDummyEnvelope
PRBool m_writtenData
PRUint32 m_leftOver
char m_dataBuffer [SAVE_BUF_SIZE+1]

Detailed Description

Definition at line 805 of file nsMsgMailNewsUrl.cpp.


Constructor & Destructor Documentation

nsMsgSaveAsListener::nsMsgSaveAsListener ( nsIFileSpec aFileSpec,
PRBool  addDummyEnvelope 
)

Definition at line 827 of file nsMsgMailNewsUrl.cpp.

{
  m_outputFile = aFileSpec;
  m_writtenData = PR_FALSE;
  m_addDummyEnvelope = addDummyEnvelope;
  m_leftOver = 0;
}

Definition at line 835 of file nsMsgMailNewsUrl.cpp.

{
}

Member Function Documentation

void nsIStreamListener::onDataAvailable ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsIInputStream  aInputStream,
in unsigned long  aOffset,
in unsigned long  aCount 
) [inherited]

Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.

The onDataAvailable impl must read exactly |aCount| bytes of data before returning.

Parameters:
aRequestrequest corresponding to the source of the data
aContextuser defined context
aInputStreaminput stream containing the data chunk
aOffsetNumber of bytes that were sent in previous onDataAvailable calls for this request. In other words, the sum of all previous count parameters. If that number is greater than or equal to 2^32, this parameter will be PR_UINT32_MAX (2^32 - 1).
aCountnumber of bytes available in the stream

NOTE: The aInputStream parameter must implement readSegments.

An exception thrown from onDataAvailable has the side-effect of causing the request to be canceled.

void nsIRequestObserver::onStartRequest ( in nsIRequest  aRequest,
in nsISupports  aContext 
) [inherited]

Called to signify the beginning of an asynchronous request.

Parameters:
aRequestrequest being observed
aContextuser defined context

An exception thrown from onStartRequest has the side-effect of causing the request to be canceled.

Here is the caller graph for this function:

void nsIRequestObserver::onStopRequest ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsresult  aStatusCode 
) [inherited]

Called to signify the end of an asynchronous request.

This call is always preceded by a call to onStartRequest.

Parameters:
aRequestrequest being observed
aContextuser defined context
aStatusCodereason for stopping (NS_OK if completed successfully)

An exception thrown from onStopRequest is generally ignored.

Here is the caller graph for this function:

nsresult nsMsgSaveAsListener::SetupMsgWriteStream ( nsIFileSpec aFileSpec,
PRBool  addDummyEnvelope 
)

Definition at line 949 of file nsMsgMailNewsUrl.cpp.

{
  nsresult rv = NS_ERROR_FAILURE;

  // If the file already exists, delete it, but do this before
  // getting the outputstream.
  // Due to bug 328027, the nsSaveMsgListener created in 
  // nsMessenger::SaveAs now opens the stream on the nsIFileSpec
  // object, thus creating an empty file. Actual save operations for
  // IMAP and NNTP use this nsMsgSaveAsListener here, though, so we
  // have to close the stream before deleting the file, else data
  // would still be written happily into a now non-existing file.
  // (Windows doesn't care, btw, just unixoids do...)
  nsFileSpec fileSpec;
  aFileSpec->CloseStream();
  aFileSpec->GetFileSpec(&fileSpec);
  fileSpec.Delete(PR_FALSE);

  rv = aFileSpec->GetOutputStream(getter_AddRefs(m_outputStream));
  NS_ENSURE_SUCCESS(rv,rv);

  if (m_outputStream && addDummyEnvelope)
  {
    nsCAutoString result;
    char *ct;
    PRUint32 writeCount;
    time_t now = time ((time_t*) 0);
    ct = ctime(&now);
    ct[24] = 0;
    result = "From - ";
    result += ct;
    result += MSG_LINEBREAK;
    
    m_outputStream->Write(result.get(), result.Length(),
                               &writeCount);
    result = "X-Mozilla-Status: 0001";
    result += MSG_LINEBREAK;
    m_outputStream->Write(result.get(), result.Length(),
                               &writeCount);
    result =  "X-Mozilla-Status2: 00000000";
    result += MSG_LINEBREAK;
    m_outputStream->Write(result.get(), result.Length(),
                               &writeCount);
  }
  return rv;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 818 of file nsMsgMailNewsUrl.cpp.

Definition at line 821 of file nsMsgMailNewsUrl.cpp.

Definition at line 820 of file nsMsgMailNewsUrl.cpp.

Definition at line 817 of file nsMsgMailNewsUrl.cpp.

Definition at line 816 of file nsMsgMailNewsUrl.cpp.

Definition at line 819 of file nsMsgMailNewsUrl.cpp.


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