Back to index

lightning-sunbird  0.9+nobinonly
nsMsgSendLater.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef _nsMsgSendLater_H_
00039 #define _nsMsgSendLater_H_
00040 
00041 #include "nsIMsgSendLater.h"
00042 
00043 #include "nsIMsgIdentity.h"
00044 #include "nsIEnumerator.h"
00045 #include "nsISupportsArray.h"
00046 #include "nsIMsgFolder.h"
00047 #include "nsIFileSpec.h"
00048 #include "nsFileStream.h"
00049 #include "nsIMsgSendListener.h"
00050 #include "nsIMsgSendLaterListener.h"
00051 #include "nsMsgDeliveryListener.h"
00052 #include "nsIMsgSendLater.h"
00053 #include "nsIMsgWindow.h"
00054 
00056 // This is the listener class for the send operation. We have to create this class 
00057 // to listen for message send completion and eventually notify the caller
00059 class nsMsgSendLater;
00060 class nsMsgDeliveryListener;
00061 
00062 class SendOperationListener : public nsIMsgSendListener,
00063                               public nsIMsgCopyServiceListener
00064 {
00065 public:
00066   SendOperationListener(void);
00067   virtual ~SendOperationListener(void);
00068 
00069   // nsISupports interface
00070   NS_DECL_ISUPPORTS
00071 
00072   // nsIMsgSendListener interface
00073   NS_DECL_NSIMSGSENDLISTENER
00074 
00075   // nsIMsgCopyServiceListener interface
00076   NS_DECL_NSIMSGCOPYSERVICELISTENER
00077   
00078   NS_IMETHOD SetSendLaterObject(nsMsgSendLater *obj);
00079 private:
00080   nsMsgSendLater    *mSendLater;
00081 };
00082 
00083 class nsMsgSendLater: public nsIMsgSendLater
00084 {
00085 public:
00086        nsMsgSendLater();
00087        virtual     ~nsMsgSendLater();
00088 
00089        NS_DECL_ISUPPORTS
00090 
00091   NS_DECL_NSIMSGSENDLATER
00092   // For nsIStreamListener interface...
00093   NS_DECL_NSISTREAMLISTENER
00094 
00095   // For nsIRequestObserver interface...
00096   NS_DECL_NSIREQUESTOBSERVER
00097 
00098   // Methods needed for implementing interface...
00099   nsresult                  StartNextMailFileSend();
00100   nsresult                  CompleteMailFileSend();
00101 
00102   nsresult                  DeleteCurrentMessage();
00103   nsresult                  SetOrigMsgDisposition();
00104   // Necessary for creating a valid list of recipients
00105   nsresult                  BuildHeaders();
00106   nsresult                  DeliverQueuedLine(char *line, PRInt32 length);
00107   nsresult                  RebufferLeftovers(char *startBuf,  PRUint32 aLen);
00108   nsresult                  BuildNewBuffer(const char* aBuf, PRUint32 aCount, PRUint32 *totalBufSize);
00109 
00110   // methods for listener array processing...
00111   nsresult  NotifyListenersOnStartSending(PRUint32 aTotalMessageCount);
00112   nsresult  NotifyListenersOnProgress(PRUint32 aCurrentMessage, PRUint32 aTotalMessage);
00113   nsresult  NotifyListenersOnStatus(const PRUnichar *aMsg);
00114   nsresult  NotifyListenersOnStopSending(nsresult aStatus, const PRUnichar *aMsg, 
00115                                            PRUint32 aTotalTried, PRUint32 aSuccessful);
00116 
00117   // counters and things for enumeration 
00118   PRUint32                  mTotalSentSuccessfully;
00119   PRUint32                  mTotalSendCount;
00120   nsCOMPtr<nsISupportsArray> mMessagesToSend;
00121   nsCOMPtr<nsIEnumerator> mEnumerator;
00122   nsCOMPtr<nsIMsgFolder>    mMessageFolder;
00123   nsCOMPtr<nsIMsgWindow>    m_window;
00124  
00125   // Private Information
00126 private:
00127   nsresult GetIdentityFromKey(const char *aKey, nsIMsgIdentity **aIdentity);
00128 
00129   nsIMsgSendLaterListener   **mListenerArray;
00130   PRInt32                   mListenerArrayCount;
00131 
00132   nsMsgSendUnsentMessagesCallback  mCompleteCallback;
00133 
00134   nsCOMPtr<nsIMsgDBHdr>      mMessage;
00135 
00136   //
00137   // File output stuff...
00138   //
00139   nsFileSpec                *mTempFileSpec;
00140   nsIFileSpec               *mTempIFileSpec;
00141   nsOutputFileStream        *mOutFile;
00142 
00143   void                      *mTagData;
00144 
00145   // For building headers and stream parsing...
00146   char                      *m_to;
00147   char                      *m_bcc;
00148   char                      *m_fcc;
00149   char                      *m_newsgroups;
00150   char                      *m_newshost;
00151   char                      *m_headers;
00152   PRInt32                   m_flags;
00153   PRInt32                   m_headersFP;
00154   PRBool                    m_inhead;
00155   PRInt32                   m_headersPosition;
00156   PRInt32                   m_bytesRead;
00157   PRInt32                   m_position;
00158   PRInt32                   m_flagsPosition;
00159   PRInt32                   m_headersSize;
00160   char                      *mLeftoverBuffer;
00161   PRBool                    mRequestReturnReceipt;
00162   char                      *mIdentityKey;
00163   char                      *mAccountKey;
00164 };
00165 
00166 
00167 #endif /* _nsMsgSendLater_H_ */