Back to index

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

List of all members.

Public Types

enum  {
  eStarting, eCopyingNewMsg, eUpdatingFolder, eDeletingOldMessage,
  eSelectingNewMessage
}

Public Member Functions

 nsDelAttachListener ()
virtual ~nsDelAttachListener ()
nsresult StartProcessing (nsMessenger *aMessenger, nsIMsgWindow *aMsgWindow, nsAttachmentState *aAttach, PRBool aSaveFirst)
nsresult DeleteOriginalMessage ()
void SelectNewMessage ()
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 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.

Public Attributes

nsAttachmentStatemAttach
PRBool mSaveFirst
nsCOMPtr< nsIFileSpecmMsgFileSpec
nsCOMPtr< nsIOutputStreammMsgFileStream
nsCOMPtr< nsIMsgMessageServicemMessageService
nsCOMPtr< nsIMsgDBHdrmOriginalMessage
nsCOMPtr< nsIMsgFoldermMessageFolder
nsCOMPtr< nsIMessengermMessenger
nsCOMPtr< nsIMsgWindowmMsgWindow
PRUint32 mNewMessageKey
PRUint32 mOrigMsgFlags
enum nsDelAttachListener:: { ... }  m_state
PRBool mWrittenExtra
PRBool mDetaching
nsCStringArray mDetachedFileUris

Detailed Description

Definition at line 2733 of file nsMessenger.cpp.


Member Enumeration Documentation

anonymous enum
Enumerator:
eStarting 
eCopyingNewMsg 
eUpdatingFolder 
eDeletingOldMessage 
eSelectingNewMessage 

Definition at line 2766 of file nsMessenger.cpp.


Constructor & Destructor Documentation

Definition at line 2987 of file nsMessenger.cpp.

{
  if (mAttach) 
  {
    delete mAttach;
  }
  if (mMsgFileStream)
  {
    mMsgFileStream->Close();
    mMsgFileStream = 0;
  }
  if (mMsgFileSpec) 
  {
    mMsgFileSpec->Flush();
    mMsgFileSpec->CloseStream();
    mMsgFileSpec->Delete(PR_FALSE);
  }
}

Member Function Documentation

Definition at line 2855 of file nsMessenger.cpp.

{
  nsCOMPtr<nsISupportsArray> messageArray;
  nsresult rv = NS_NewISupportsArray(getter_AddRefs(messageArray));
  NS_ENSURE_SUCCESS(rv,rv);
  rv = messageArray->AppendElement(mOriginalMessage);
  NS_ENSURE_SUCCESS(rv,rv);
  nsCOMPtr<nsIMsgCopyServiceListener> listenerCopyService;

  QueryInterface( NS_GET_IID(nsIMsgCopyServiceListener), getter_AddRefs(listenerCopyService) );

  mOriginalMessage = nsnull;
  m_state = eDeletingOldMessage;
  return mMessageFolder->DeleteMessages( 
    messageArray,         // messages
    mMsgWindow,           // msgWindow
    PR_TRUE,              // deleteStorage
    PR_TRUE,              // isMove
    listenerCopyService,  // listener
    PR_FALSE);            // allowUndo
}

Here is the call graph for this function:

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 -

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:

Definition at line 2877 of file nsMessenger.cpp.

{
  nsXPIDLCString displayUri;
  // all attachments refer to the same message
  const char * messageUri = mAttach->mAttachmentArray[0].mMessageUri;
  mMessenger->GetLastDisplayedMessageUri(getter_Copies(displayUri));
  if (displayUri.Equals(messageUri))
  {
    mMessageFolder->GenerateMessageURI(mNewMessageKey, getter_Copies(displayUri));
    if (displayUri)
    {
      mMsgWindow->SelectMessage(displayUri);
    }
  }
  mNewMessageKey = PR_UINT32_MAX;
}

Here is the call 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 -

nsresult nsDelAttachListener::StartProcessing ( nsMessenger aMessenger,
nsIMsgWindow aMsgWindow,
nsAttachmentState aAttach,
PRBool  aSaveFirst 
)

Definition at line 3007 of file nsMessenger.cpp.

{
  aMessenger->QueryInterface(NS_GET_IID(nsIMessenger), getter_AddRefs(mMessenger));
  mMsgWindow = aMsgWindow;
  mAttach    = aAttach;
  mDetaching = detaching;

  nsresult rv;

  // all attachments refer to the same message
  const char * messageUri = mAttach->mAttachmentArray[0].mMessageUri;

  // get the message service, original message and folder for this message
  rv = GetMessageServiceFromURI(messageUri, getter_AddRefs(mMessageService));
  NS_ENSURE_SUCCESS(rv,rv);
  rv = mMessageService->MessageURIToMsgHdr(messageUri, getter_AddRefs(mOriginalMessage));
  NS_ENSURE_SUCCESS(rv,rv);
  rv = mOriginalMessage->GetFolder(getter_AddRefs(mMessageFolder));
  NS_ENSURE_SUCCESS(rv,rv);
  mOriginalMessage->GetFlags(&mOrigMsgFlags);

  // ensure that we can store and delete messages in this folder, if we 
  // can't then we can't do attachment deleting
  PRBool canDelete = PR_FALSE;
  mMessageFolder->GetCanDeleteMessages(&canDelete);
  PRBool canFile = PR_FALSE;
  mMessageFolder->GetCanFileMessages(&canFile);
  if (!canDelete || !canFile)
    return NS_ERROR_FAILURE;

  // create an output stream on a temporary file. This stream will save the modified 
  // message data to a file which we will later use to replace the existing message.
  // The file is removed in the destructor.
  nsFileSpec * msgFileSpec = new nsFileSpec(
    nsSpecialSystemDirectory(nsSpecialSystemDirectory::OS_TemporaryDirectory) );
  if (!msgFileSpec) return NS_ERROR_OUT_OF_MEMORY;
  *msgFileSpec += "nsmail.tmp";
  msgFileSpec->MakeUnique();
  rv = NS_NewFileSpecWithSpec(*msgFileSpec, getter_AddRefs(mMsgFileSpec));
  nsCOMPtr<nsILocalFile> msgFile;
  if (NS_SUCCEEDED(rv))
    rv = NS_FileSpecToIFile(msgFileSpec, getter_AddRefs(msgFile));
  delete msgFileSpec;
  NS_ENSURE_SUCCESS(rv,rv);
  nsCOMPtr<nsIOutputStream> fileOutputStream;
  rv = NS_NewLocalFileOutputStream(getter_AddRefs(fileOutputStream), msgFile, -1, 00600);
  NS_ENSURE_SUCCESS(rv,rv);
  rv = NS_NewBufferedOutputStream(getter_AddRefs(mMsgFileStream), fileOutputStream, FOUR_K);
  NS_ENSURE_SUCCESS(rv,rv);

  // create the additional header for data conversion. This will tell the stream converter
  // which MIME emitter we want to use, and it will tell the MIME emitter which attachments
  // should be deleted.
  const char * partId;
  const char * nextField;
  nsCAutoString sHeader("attach&del=");
  nsCAutoString detachToHeader("&detachTo=");
  for (PRUint32 u = 0; u < mAttach->mCount; ++u)
  {
    if (u > 0)
    {
      sHeader.Append(",");
      if (detaching)
        detachToHeader.Append(",");
    }
    partId = GetAttachmentPartId(mAttach->mAttachmentArray[u].mUrl);
    nextField = PL_strchr(partId, '&');
    sHeader.Append(partId, nextField ? nextField - partId : -1);
    if (detaching)
      detachToHeader.Append(mDetachedFileUris.CStringAt(u)->get());
  }

  if (detaching)
    sHeader.Append(detachToHeader);
  // stream this message to our listener converting it via the attachment mime
  // converter. The listener will just write the converted message straight to disk.
  nsCOMPtr<nsISupports> listenerSupports;
  rv = this->QueryInterface(NS_GET_IID(nsISupports), getter_AddRefs(listenerSupports));
  NS_ENSURE_SUCCESS(rv,rv);
  nsCOMPtr<nsIUrlListener> listenerUrlListener = do_QueryInterface(listenerSupports, &rv);
  NS_ENSURE_SUCCESS(rv,rv);
  rv = mMessageService->StreamMessage(
    messageUri,           // aMessageURI 
    listenerSupports,     // aConsumer 
    mMsgWindow,           // aMsgWindow 
    listenerUrlListener,  // aUrlListener
    PR_TRUE,              // aConvertData
    sHeader.get(),        // aAdditionalHeader
    nsnull );             // requestUri
  NS_ENSURE_SUCCESS(rv,rv);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 2753 of file nsMessenger.cpp.

Definition at line 2776 of file nsMessenger.cpp.

Definition at line 2775 of file nsMessenger.cpp.

Definition at line 2759 of file nsMessenger.cpp.

Definition at line 2757 of file nsMessenger.cpp.

Definition at line 2760 of file nsMessenger.cpp.

Definition at line 2755 of file nsMessenger.cpp.

Definition at line 2756 of file nsMessenger.cpp.

Definition at line 2761 of file nsMessenger.cpp.

Definition at line 2762 of file nsMessenger.cpp.

Definition at line 2758 of file nsMessenger.cpp.

Definition at line 2763 of file nsMessenger.cpp.

Definition at line 2754 of file nsMessenger.cpp.

Definition at line 2774 of file nsMessenger.cpp.


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