Back to index

lightning-sunbird  0.9+nobinonly
nsMsgCompose.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 _nsMsgCompose_H_
00039 #define _nsMsgCompose_H_
00040 
00041 #include "nsIMsgCompose.h"
00042 #include "nsCOMPtr.h"
00043 #include "nsWeakReference.h"
00044 #include "nsMsgCompFields.h"
00045 #include "nsIOutputStream.h"
00046 #include "nsIDocumentStateListener.h"
00047 #include "nsIMsgQuote.h"
00048 #include "nsIMsgSendListener.h"
00049 #include "nsIMsgCopyServiceListener.h"
00050 #include "nsIMsgSend.h"
00051 #include "nsIMsgQuotingOutputStreamListener.h"
00052 #include "nsIMimeHeaders.h"
00053 #include "nsIBaseWindow.h"
00054 #include "nsIAbDirectory.h"
00055 #include "nsIAbCard.h"
00056 #include "nsIWebProgressListener.h"
00057 #include "nsIAbDirectory.h"
00058 #include "nsIMimeConverter.h"
00059 #include "nsIUnicodeDecoder.h"
00060 #include "nsIEditor.h"
00061 #include "nsIMsgFolder.h"
00062 
00063 // Forward declares
00064 class QuotingOutputStreamListener;
00065 class nsMsgComposeSendListener;
00066 class nsIAddrDatabase;
00067 class nsIEditorMailSupport;
00068 
00069 class nsMsgCompose : public nsIMsgCompose, public nsSupportsWeakReference
00070 {
00071  public: 
00072 
00073        nsMsgCompose();
00074        virtual ~nsMsgCompose();
00075 
00076        /* this macro defines QueryInterface, AddRef and Release for this class */
00077        NS_DECL_ISUPPORTS
00078 
00079        /*** nsIMsgCompose pure virtual functions */
00080        NS_DECL_NSIMSGCOMPOSE
00081 
00082 private:
00083 
00084  // Deal with quoting issues...
00085        nsresult                      QuoteOriginalMessage(const char * originalMsgURI, PRInt32 what); // New template
00086   nsresult                      SetQuotingToFollow(PRBool aVal);
00087   nsresult                      ConvertHTMLToText(nsFileSpec& aSigFile, nsString &aSigData);
00088   nsresult                      ConvertTextToHTML(nsFileSpec& aSigFile, nsString &aSigData);
00089   PRBool                        IsEmbeddedObjectSafe(const char * originalScheme,
00090                                                      const char * originalHost,
00091                                                      const char * originalPath,
00092                                                      nsIDOMNode * object);
00093   nsresult                      ResetUrisForEmbeddedObjects();
00094   nsresult                      TagEmbeddedObjects(nsIEditorMailSupport *aMailEditor);
00095 
00096   nsCString                     mQuoteCharset;
00097   nsCString                     mOriginalMsgURI; // used so we can mark message disposition flags after we send the message
00098 
00099   PRInt32                       mWhatHolder;
00100 
00101   nsresult                      LoadDataFromFile(nsFileSpec& fSpec,
00102                                                  nsString &sigData,
00103                                                  PRBool aAllowUTF8 = PR_TRUE,
00104                                                  PRBool aAllowUTF16 = PR_TRUE);
00105 
00106 /*
00107   nsresult                      GetCompFields(nsMsgCompFields **aCompFields) 
00108                                 {
00109                                   if (aCompFields)
00110                                     *aCompFields = m_compFields;
00111                                   return NS_OK;
00112                                 }
00113  */
00114   nsresult                      GetIdentity(nsIMsgIdentity **aIdentity)
00115                                 {
00116                                   *aIdentity = m_identity;
00117                                   return NS_OK;
00118                                 }
00119   //m_folderName to store the value of the saved drafts folder.
00120   nsCString                     m_folderName;
00121 
00122  private:
00123   nsresult _SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity *identity, const char *accountKey, PRBool entityConversionDone);
00124   nsresult CreateMessage(const char * originalMsgURI, MSG_ComposeType type, nsIMsgCompFields* compFields);
00125   void CleanUpRecipients(nsString& recipients);
00126   nsresult GetABDirectories(const nsACString& dirUri, nsISupportsArray* directoriesArray, PRBool searchSubDirectory);
00127   nsresult BuildMailListArray(nsIAddrDatabase* database, nsIAbDirectory* parentDir, nsISupportsArray* array);
00128   nsresult GetMailListAddresses(nsString& name, nsISupportsArray* mailListArray, nsISupportsArray** addresses);
00129   nsresult TagConvertible(nsIDOMNode *node,  PRInt32 *_retval);
00130   nsresult _BodyConvertible(nsIDOMNode *node, PRInt32 *_retval);
00131 
00132 
00133 #if !defined(XP_MAC)
00134   PRBool IsLastWindow();
00135 #endif /* XP_MAC */
00136  
00137        // Helper function. Parameters are not checked.
00138   PRBool                                    mConvertStructs;    // for TagConvertible
00139   
00140        nsCOMPtr<nsIEditor>                       m_editor;
00141        nsIDOMWindowInternal                      *m_window;
00142   nsCOMPtr<nsIBaseWindow>                   m_baseWindow;
00143        nsMsgCompFields                           *m_compFields;
00144        nsCOMPtr<nsIMsgIdentity>                  m_identity;
00145        PRBool                                                            m_composeHTML;
00146        QuotingOutputStreamListener               *mQuoteStreamListener;
00147        nsCOMPtr<nsIOutputStream>                 mBaseStream;
00148 
00149   nsCOMPtr<nsIMsgComposeRecyclingListener>  mRecyclingListener;
00150   PRBool                                    mRecycledWindow;
00151        nsCOMPtr<nsIMsgSend>                      mMsgSend;           // for composition back end
00152        nsCOMPtr<nsIMsgProgress>                  mProgress;          // use by the back end to report progress to the front end
00153 
00154   // Deal with quoting issues...
00155   nsString                                  mCiteReference;
00156        nsCOMPtr<nsIMsgQuote>                     mQuote;
00157        PRBool                                                            mQuotingToFollow;   // Quoting indicator
00158        MSG_ComposeType                           mType;                  // Message type
00159   nsCOMPtr<nsISupportsArray>                mStateListeners;          // contents are nsISupports
00160   PRBool                                    mCharsetOverride;
00161   PRBool                                    mDeleteDraft;
00162   nsMsgDispositionState                     mDraftDisposition;
00163   nsCOMPtr <nsIMsgDBHdr>                    mOrigMsgHdr;
00164 
00165   nsCOMPtr<nsIMsgSendListener>              mExternalSendListener;
00166   nsCString                                 mSmtpPassword;
00167     
00168   PRBool                                    mInsertingQuotedContent;
00169     
00170   friend class QuotingOutputStreamListener;
00171        friend class nsMsgComposeSendListener;
00172 };
00173 
00175 // THIS IS THE CLASS THAT IS THE STREAM Listener OF THE HTML OUPUT
00176 // FROM LIBMIME. THIS IS FOR QUOTING
00178 class QuotingOutputStreamListener : public nsIMsgQuotingOutputStreamListener
00179 {
00180 public:
00181     QuotingOutputStreamListener(const char *originalMsgURI,
00182                                 nsIMsgDBHdr *origMsgHdr,
00183                                 PRBool quoteHeaders,
00184                                 PRBool headersOnly,
00185                                 nsIMsgIdentity *identity,
00186                                 const char *charset,
00187                                 PRBool charetOverride, 
00188                                 PRBool quoteOriginal);
00189     virtual ~QuotingOutputStreamListener(void);
00190 
00191     NS_DECL_ISUPPORTS
00192     NS_DECL_NSIREQUESTOBSERVER
00193     NS_DECL_NSISTREAMLISTENER
00194     NS_DECL_NSIMSGQUOTINGOUTPUTSTREAMLISTENER
00195 
00196     NS_IMETHOD  SetComposeObj(nsIMsgCompose *obj);
00197          NS_IMETHOD  ConvertToPlainText(PRBool formatflowed = PR_FALSE);
00198     NS_IMETHOD InsertToCompose(nsIEditor *aEditor, PRBool aHTMLEditor);
00199 
00200 private:
00201     nsWeakPtr                 mWeakComposeObj;
00202     nsString                                  mMsgBody;
00203     nsString                                  mCitePrefix;
00204     nsString                                  mSignature;
00205     PRBool                                               mQuoteHeaders;
00206     PRBool                                               mHeadersOnly;
00207     nsCOMPtr<nsIMimeHeaders>       mHeaders;
00208     nsCOMPtr<nsIMsgIdentity>  mIdentity;
00209     nsString                  mCiteReference;
00210     nsCOMPtr<nsIMimeConverter> mMimeConverter;
00211     nsCOMPtr<nsIUnicodeDecoder> mUnicodeDecoder;
00212     PRInt32                   mUnicodeBufferCharacterLength;
00213     PRUnichar*                mUnicodeConversionBuffer;
00214     PRBool                    mQuoteOriginal;
00215 };
00216 
00218 // This is the listener class for the send operation. We have to create this class 
00219 // to listen for message send completion and eventually notify the caller
00221 class nsMsgComposeSendListener : public nsIMsgComposeSendListener, public nsIMsgSendListener, public nsIMsgCopyServiceListener, public nsIWebProgressListener
00222 {
00223 public:
00224   nsMsgComposeSendListener(void);
00225   virtual ~nsMsgComposeSendListener(void);
00226 
00227   // nsISupports interface
00228   NS_DECL_ISUPPORTS
00229 
00230   // nsIMsgComposeSendListener interface
00231   NS_DECL_NSIMSGCOMPOSESENDLISTENER
00232 
00233   // nsIMsgSendListener interface
00234   NS_DECL_NSIMSGSENDLISTENER
00235   
00236   // nsIMsgCopyServiceListener interface
00237   NS_DECL_NSIMSGCOPYSERVICELISTENER
00238   
00239        // nsIWebProgressListener interface
00240        NS_DECL_NSIWEBPROGRESSLISTENER
00241 
00242   nsresult    RemoveCurrentDraftMessage(nsIMsgCompose *compObj, PRBool calledByCopy);
00243   nsresult    GetMsgFolder(nsIMsgCompose *compObj, nsIMsgFolder **msgFolder);
00244 
00245 private:
00246   nsWeakPtr               mWeakComposeObj;
00247        MSG_DeliverMode         mDeliverMode;
00248 };
00249 
00250 /******************************************************************************
00251  * nsMsgRecipient
00252  ******************************************************************************/
00253 class nsMsgRecipient : public nsISupports
00254 {
00255 public:
00256   nsMsgRecipient();
00257   nsMsgRecipient(nsString fullAddress, nsString email, PRUint32 preferFormat = nsIAbPreferMailFormat::unknown,
00258                  PRBool processed = PR_FALSE);
00259        virtual ~nsMsgRecipient();
00260 
00261   NS_DECL_ISUPPORTS
00262   
00263 public:
00264   nsString mAddress;      /* full email address (name + email) */
00265   nsString mEmail;        /* email address only */
00266   PRUint32 mPreferFormat; /* nsIAbPreferMailFormat:: unknown, plaintext or html */
00267   PRBool mProcessed;
00268 };
00269 
00270 /******************************************************************************
00271  * nsMsgMailList
00272  ******************************************************************************/
00273 class nsMsgMailList : public nsISupports
00274 {
00275 public:
00276   nsMsgMailList();
00277   nsMsgMailList(nsString listName, nsString listDescription, nsIAbDirectory* directory);
00278        virtual ~nsMsgMailList();
00279 
00280   NS_DECL_ISUPPORTS
00281   
00282 public:
00283   nsString mFullName;  /* full email address (name + email) */
00284   nsCOMPtr<nsIAbDirectory> mDirectory;
00285 };
00286 
00287 #endif /* _nsMsgCompose_H_ */