Back to index

lightning-sunbird  0.9+nobinonly
nsMimeBaseEmitter.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; 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) 1999
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 #ifndef _nsMimeBaseEmitter_h_
00038 #define _nsMimeBaseEmitter_h_
00039 
00040 #include "prtypes.h"
00041 #include "prio.h"
00042 #include "nsIMimeEmitter.h"
00043 #include "nsMimeRebuffer.h"
00044 #include "nsIStreamListener.h"
00045 #include "nsIInputStream.h"
00046 #include "nsIOutputStream.h"
00047 #include "nsIAsyncInputStream.h"
00048 #include "nsIURI.h"
00049 #include "nsIChannel.h"
00050 #include "nsString.h"
00051 #include "nsFileSpec.h"
00052 #include "nsIMimeMiscStatus.h"
00053 #include "nsIMsgHeaderParser.h"
00054 #include "nsIPipe.h"
00055 #include "nsIStringBundle.h"
00056 #include "nsCOMPtr.h"
00057 #include "nsVoidArray.h"
00058 #include "nsIMimeConverter.h"
00059 #include "nsIInterfaceRequestor.h"
00060 #include "nsIInterfaceRequestorUtils.h"
00061 
00062 //
00063 // The base emitter will serve as the place to do all of the caching,
00064 // sorting, etc... of mail headers and bodies for this internally developed
00065 // emitter library. The other emitter classes in this file (nsMimeHTMLEmitter, etc.)
00066 // will only be concerned with doing output processing ONLY.
00067 //
00068 
00069 //
00070 // Used for keeping track of the attachment information...
00071 //
00072 typedef struct {
00073   char      *displayName;
00074   char      *urlSpec;
00075   char      *contentType;
00076   PRBool    isExternalAttachment;
00077 } attachmentInfoType;
00078 
00079 //
00080 // For header info...
00081 //
00082 typedef struct {
00083   char      *name;
00084   char      *value;
00085 } headerInfoType;
00086 
00087 class nsMimeBaseEmitter : public nsIMimeEmitter, 
00088                           public nsIInterfaceRequestor
00089 {
00090 public: 
00091   nsMimeBaseEmitter ();
00092   virtual             ~nsMimeBaseEmitter (void);
00093 
00094   // nsISupports interface
00095   NS_DECL_ISUPPORTS
00096 
00097   NS_DECL_NSIMIMEEMITTER
00098   NS_DECL_NSIINTERFACEREQUESTOR
00099 
00100   // Utility output functions...
00101   NS_IMETHOD          UtilityWriteCRLF(const char *buf);
00102 
00103   // For string bundle usage...
00104   char                *MimeGetStringByName(const char *aHeaderName);
00105   char                *MimeGetStringByID(PRInt32 aID);
00106   char                *LocalizeHeaderName(const char *aHeaderName, const char *aDefaultName);
00107 
00108   // For header processing...
00109   const char          *GetHeaderValue(const char  *aHeaderName);
00110 
00111   // To write out a stored header array as HTML
00112   virtual nsresult            WriteHeaderFieldHTMLPrefix();
00113   virtual nsresult            WriteHeaderFieldHTML(const char *field, const char *value);
00114   virtual nsresult            WriteHeaderFieldHTMLPostfix();
00115 
00116 protected:
00117   // Internal methods...
00118   void                CleanupHeaderArray(nsVoidArray *aArray);
00119 
00120   // For header output...
00121   nsresult            DumpSubjectFromDate();
00122   nsresult            DumpToCC();
00123   nsresult            DumpRestOfHeaders();
00124   nsresult            OutputGenericHeader(const char *aHeaderVal);
00125 
00126   nsresult            WriteHelper(const char *buf, PRUint32 count, PRUint32 *countWritten);
00127 
00128   // For string bundle usage...
00129   nsCOMPtr<nsIStringBundle> m_stringBundle;        // for translated strings
00130   nsCOMPtr<nsIStringBundle> m_headerStringBundle;  // for non-translated header strings
00131 
00132   // For buffer management on output
00133   MimeRebuffer        *mBufferMgr;
00134 
00135        // mscott
00136   // dont ref count the streams....the emitter is owned by the converter
00137        // which owns these streams...
00138   //
00139   nsIOutputStream     *mOutStream;
00140        nsIInputStream           *mInputStream;
00141   nsIStreamListener   *mOutListener;
00142   nsIChannel                    *mChannel;
00143 
00144   // For gathering statistics on processing...
00145   PRUint32            mTotalWritten;
00146   PRUint32            mTotalRead;
00147 
00148   // Output control and info...
00149   PRBool              mDocHeader;         // For header determination...
00150   nsIURI              *mURL;              // the url for the data being processed...
00151   PRInt32             mHeaderDisplayType; // The setting for header output...
00152   nsCString           mHTMLHeaders;       // HTML Header Data...
00153 
00154   // For attachment processing...
00155   PRInt32             mAttachCount;
00156   nsVoidArray         *mAttachArray;
00157   attachmentInfoType  *mCurrentAttachment;
00158 
00159   // For header caching...
00160   nsVoidArray         *mHeaderArray;
00161   nsVoidArray         *mEmbeddedHeaderArray;
00162   nsCOMPtr<nsIMsgHeaderParser>  mHeaderParser;
00163 
00164   // For body caching...
00165   PRBool              mBodyStarted;
00166   nsCString           mBody;
00167   PRBool              mFirstHeaders;
00168 
00169   // For the format being used...
00170   PRInt32             mFormat;
00171 
00172   // For I18N Conversion...
00173   nsCOMPtr<nsIMimeConverter> mUnicodeConverter;
00174   nsString            mCharset;
00175 };
00176 
00177 #endif /* _nsMimeBaseEmitter_h_ */