Back to index

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

List of all members.

Public Types

enum  { eUnknown, ePlainText, eHTML }

Public Member Functions

 nsSaveMsgListener (nsIFileSpec *fileSpec, nsMessenger *aMessenger)
virtual ~nsSaveMsgListener ()
nsresult InitializeDownload (nsIRequest *aRequest, PRInt32 aBytesDownloaded)
void OnStartRunningUrl (in nsIURI url)
void OnStopRunningUrl (in nsIURI url, in nsresult aExitCode)
void OnStartCopy ()
 Notify the observer that the message has started to be copied.
void OnProgress (in PRUint32 aProgress, in PRUint32 aProgressMax)
 Notify the observer that progress as occurred for the message copy aProgress - aProgressMax -.
void SetMessageKey (in PRUint32 aKey)
 Setting newly created message key.
void GetMessageId (in nsCString aMessageId)
 Getting the file message message ID.
void OnStopCopy (in nsresult aStatus)
 Notify the observer that the message copied operation has completed.
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.
void cancel (in nsresult aReason)
 Call this method to request that this object abort whatever operation it may be performing.

Public Attributes

NS_DECL_ISUPPORTS
NS_DECL_NSIURLLISTENER
NS_DECL_NSIMSGCOPYSERVICELISTENER
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSICANCELABLE nsCOMPtr
< nsIFileSpec
m_fileSpec
nsCOMPtr< nsIOutputStreamm_outputStream
char * m_dataBuffer
nsCOMPtr< nsIChannelm_channel
nsXPIDLCString m_templateUri
nsMessengerm_messenger
nsSaveAllAttachmentsStatem_saveAllAttachmentsState
PRBool m_doCharsetConversion
nsString m_charset
enum nsSaveMsgListener:: { ... }  m_outputFormat
nsString m_msgBuffer
nsCString m_contentType
nsCOMPtr< nsITransfermTransfer
PRInt32 mProgress
PRInt32 mContentLength
PRBool mCanceled
PRBool mInitialized

Detailed Description

Definition at line 254 of file nsMessenger.cpp.


Member Enumeration Documentation

anonymous enum
Enumerator:
eUnknown 
ePlainText 
eHTML 

Definition at line 282 of file nsMessenger.cpp.


Constructor & Destructor Documentation

nsSaveMsgListener::nsSaveMsgListener ( nsIFileSpec fileSpec,
nsMessenger aMessenger 
)

Definition at line 1817 of file nsMessenger.cpp.

Here is the call graph for this function:

Definition at line 1835 of file nsMessenger.cpp.

{
}

Member Function Documentation

void nsICancelable::cancel ( in nsresult  aReason) [inherited]

Call this method to request that this object abort whatever operation it may be performing.

Parameters:
aReasonPass a failure code to indicate the reason why this operation is being canceled. It is an error to pass a success code.

Getting the file message message ID.

This method is taylored specifically for nsIMsgCopyService::CopyFileMessage() when saving Drafts/Templates. In order to work with imap server which doesn't support uidplus we have to use search comman to retrieve the key of newly created message. Message ID generated by the compose gurantee its uniqueness. aMessageId -

nsresult nsSaveMsgListener::InitializeDownload ( nsIRequest aRequest,
PRInt32  aBytesDownloaded 
)

Definition at line 1946 of file nsMessenger.cpp.

{
  nsresult rv = NS_OK;

  mInitialized = PR_TRUE;
  nsCOMPtr<nsIChannel> channel (do_QueryInterface(aRequest));

  if (!channel)
    return rv;

  // Set content length if we haven't already got it.
  if (mContentLength == -1)
      channel->GetContentLength(&mContentLength);

  if (!m_contentType.IsEmpty())
  {
      nsCOMPtr<nsIMIMEService> mimeService (do_GetService(NS_MIMESERVICE_CONTRACTID));
      nsCOMPtr<nsIMIMEInfo> mimeinfo;

      mimeService->GetFromTypeAndExtension(m_contentType, EmptyCString(), getter_AddRefs(mimeinfo)); 
      nsFileSpec realSpec;
      m_fileSpec->GetFileSpec(&realSpec);

      // Create nsILocalFile from a nsFileSpec.
      nsCOMPtr<nsILocalFile> outputFile;
      NS_FileSpecToIFile(&realSpec, getter_AddRefs(outputFile)); 

      // create a download progress window
      // XXX: we don't want to show the progress dialog if the download is really small.
      // but what is a small download? Well that's kind of arbitrary
      // so make an arbitrary decision based on the content length of the attachment
      if (mContentLength != -1 && mContentLength > aBytesDownloaded * 2)
      {
        nsCOMPtr<nsITransfer> tr = do_CreateInstance(NS_TRANSFER_CONTRACTID, &rv);
        if (tr && outputFile)
        {
          PRTime timeDownloadStarted = PR_Now();

          nsCOMPtr<nsIURI> outputURI;
          NS_NewFileURI(getter_AddRefs(outputURI), outputFile);

          nsCOMPtr<nsIURI> url;
          channel->GetURI(getter_AddRefs(url));
          rv = tr->Init(url, outputURI, EmptyString(), mimeinfo,
                        timeDownloadStarted, nsnull, this);

          // now store the web progresslistener 
          mTransfer = tr;
        }
      }

#if defined(XP_MAC) || defined(XP_MACOSX)
      /* if we are saving an appledouble or applesingle attachment, we need to use an Apple File Decoder */
      if ((nsCRT::strcasecmp(m_contentType.get(), APPLICATION_APPLEFILE) == 0) ||
          (nsCRT::strcasecmp(m_contentType.get(), MULTIPART_APPLEDOUBLE) == 0))
      {        

        nsCOMPtr<nsIAppleFileDecoder> appleFileDecoder = do_CreateInstance(NS_IAPPLEFILEDECODER_CONTRACTID, &rv);
        if (NS_SUCCEEDED(rv) && appleFileDecoder)
        {
          rv = appleFileDecoder->Initialize(m_outputStream, outputFile);
          if (NS_SUCCEEDED(rv))
            m_outputStream = do_QueryInterface(appleFileDecoder, &rv);
        }
      }
      else
      {
          if (mimeinfo)
          {
            PRUint32 aMacType;
            PRUint32 aMacCreator;
            if (NS_SUCCEEDED(mimeinfo->GetMacType(&aMacType)) && NS_SUCCEEDED(mimeinfo->GetMacCreator(&aMacCreator)))
            {
              nsCOMPtr<nsILocalFileMac> macFile =  do_QueryInterface(outputFile, &rv);
              if (NS_SUCCEEDED(rv) && macFile)
              {
                macFile->SetFileCreator((OSType)aMacCreator);
                macFile->SetFileType((OSType)aMacType);
              }
            }
          }
      }
#endif // XP_MACOSX
  }

  return rv;
}

Here is the call graph for this function:

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 nsIMsgCopyServiceListener::OnProgress ( in PRUint32  aProgress,
in PRUint32  aProgressMax 
) [inherited]

Notify the observer that progress as occurred for the message copy aProgress - aProgressMax -.

Notify the observer that the message has started to be copied.

This method is called only once, at the beginning of a message copyoperation.

Implemented in CopyListener.

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:

Here is the caller graph for this function:

Notify the observer that the message copied operation has completed.

This method is called regardless of whether the the operation was successful. aStatus - indicate whether the operation was succeeded

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:

void nsIUrlListener::OnStopRunningUrl ( in nsIURI  url,
in nsresult  aExitCode 
) [inherited]

Here is the caller graph for this function:

Setting newly created message key.

This method is taylored specifically for nsIMsgCopyService::CopyFileMessage() when saveing Drafts/Templates. We need to have a way to inform the client what's the key of the newly created message. aKey -


Member Data Documentation

Definition at line 274 of file nsMessenger.cpp.

Definition at line 281 of file nsMessenger.cpp.

Definition at line 289 of file nsMessenger.cpp.

Definition at line 273 of file nsMessenger.cpp.

Definition at line 280 of file nsMessenger.cpp.

NS_DECL_ISUPPORTS NS_DECL_NSIURLLISTENER NS_DECL_NSIMSGCOPYSERVICELISTENER NS_DECL_NSISTREAMLISTENER NS_DECL_NSIREQUESTOBSERVER NS_DECL_NSICANCELABLE nsCOMPtr<nsIFileSpec> nsSaveMsgListener::m_fileSpec

Definition at line 271 of file nsMessenger.cpp.

Definition at line 276 of file nsMessenger.cpp.

Definition at line 287 of file nsMessenger.cpp.

Definition at line 272 of file nsMessenger.cpp.

Definition at line 277 of file nsMessenger.cpp.

Definition at line 275 of file nsMessenger.cpp.

Definition at line 294 of file nsMessenger.cpp.

Definition at line 293 of file nsMessenger.cpp.

Definition at line 295 of file nsMessenger.cpp.

Definition at line 292 of file nsMessenger.cpp.

Definition at line 291 of file nsMessenger.cpp.


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