Back to index

lightning-sunbird  0.9+nobinonly
mimemoz2.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) 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 _MIMEMOZ_H_
00039 #define _MIMEMOZ_H_
00040 
00041 #include "prtypes.h"
00042 #include "nsStreamConverter.h"
00043 #include "nsIMimeEmitter.h"
00044 #include "nsIURI.h"
00045 #include "mozITXTToHTMLConv.h"
00046 #include "nsIMsgSend.h"
00047 #include "nsIMimeConverter.h"
00048 
00049 class nsOutputFileStream;
00050 
00051 // SHERRY - Need to get these out of here eventually
00052 
00053 #ifdef XP_UNIX
00054 #undef Bool
00055 #endif
00056 
00057 
00058   
00059 #include "mimei.h"
00060 
00061 #ifdef __cplusplus
00062 extern "C" {
00063 #endif /* __cplusplus */
00064 
00065 #include "nsIPrefBranch.h"
00066 
00067 typedef struct _nsMIMESession nsMIMESession;
00068 
00069 /* stream functions */
00070 typedef unsigned int
00071 (*MKSessionWriteReadyFunc) (nsMIMESession *stream);
00072 
00073 #define MAX_WRITE_READY (((unsigned) (~0) << 1) >> 1)   /* must be <= than MAXINT!!!!! */
00074 
00075 typedef int 
00076 (*MKSessionWriteFunc) (nsMIMESession *stream, const char *str, PRInt32 len);
00077 
00078 typedef void 
00079 (*MKSessionCompleteFunc) (nsMIMESession *stream);
00080 
00081 typedef void 
00082 (*MKSessionAbortFunc) (nsMIMESession *stream, int status);
00083 
00084 /* streamclass function */
00085 struct _nsMIMESession {
00086 
00087     char      * name;          /* Just for diagnostics */
00088 
00089     void      * window_id;     /* used for progress messages, etc. */
00090 
00091     void      * data_object;   /* a pointer to whatever
00092                                 * structure you wish to have
00093                                 * passed to the routines below
00094                                 * during writes, etc...
00095                                 * 
00096                                 * this data object should hold
00097                                 * the document, document
00098                                 * structure or a pointer to the
00099                                 * document.
00100                                 */
00101 
00102     MKSessionWriteReadyFunc  is_write_ready;   /* checks to see if the stream is ready
00103                                                * for writing.  Returns 0 if not ready
00104                                                * or the number of bytes that it can
00105                                                * accept for write
00106                                                */
00107     MKSessionWriteFunc       put_block;        /* writes a block of data to the stream */
00108     MKSessionCompleteFunc    complete;         /* normal end */
00109     MKSessionAbortFunc       abort;            /* abnormal end */
00110 
00111     PRBool                  is_multipart;    /* is the stream part of a multipart sequence */
00112 };
00113 
00114 /*
00115  * This is for the reworked mime parser.
00116  */
00117 struct mime_stream_data {           /* This struct is the state we pass around
00118                                        amongst the various stream functions
00119                                        used by MIME_MessageConverter(). */
00120   char                *url_name;
00121   char                *orig_url_name; /* original url name */
00122   nsIChannel          *channel;
00123   nsMimeOutputType    format_out;
00124   void                *pluginObj2;  /* The new XP-COM stream converter object */
00125   nsMIMESession       *istream;     /* Holdover - new stream we're writing out image data-if any. */
00126   MimeObject          *obj;         /* The root parser object */
00127   MimeDisplayOptions  *options;     /* Data for communicating with libmime.a */
00128   MimeHeaders         *headers;     /* Copy of outer most mime header */
00129 
00130   nsIMimeEmitter      *output_emitter;  /* Output emitter engine for libmime */
00131   PRBool              firstCheck;   /* Is this the first look at the stream data */
00132 };
00133 
00134 // 
00135 // This struct is the state we use for loading drafts and templates...
00136 //
00137 struct mime_draft_data 
00138 {
00139   /* WARNING: You cannot use a c++ object, in that structure, which is dependent on its constructor or 
00140            destructor as mime_draft_data is not created using the new operator. nsCOMPtr however are ok
00141            to use as long you set it to null before the structure get freed.
00142   */
00143 
00144   char                *url_name;           // original url name */
00145   nsMimeOutputType    format_out;          // intended output format; should be FO_OPEN_DRAFT */
00146   nsMIMESession       *stream;             // not used for now 
00147   MimeObject          *obj;                // The root 
00148   MimeDisplayOptions  *options;            // data for communicating with libmime
00149   MimeHeaders         *headers;            // Copy of outer most mime header 
00150   PRInt32             attachments_count;   // how many attachments we have 
00151   nsMsgAttachedFile   *attachments;        // attachments 
00152   nsMsgAttachedFile   *messageBody;        // message body 
00153   nsMsgAttachedFile   *curAttachment;               // temp 
00154 
00155   nsIFileSpec         *tmpFileSpec;
00156   nsOutputFileStream  *tmpFileStream;      // output file handle 
00157 
00158   MimeDecoderData     *decoder_data;
00159   char                *mailcharset;        // get it from CHARSET of Content-Type 
00160   PRBool              forwardInline;
00161   nsCOMPtr<nsIMsgIdentity>      identity;
00162   char                *originalMsgURI;     // the original URI of the message we are currently processing
00163 };
00164 
00166 // Bridge routines for legacy mime code
00168 
00169 // Create bridge stream for libmime
00170 extern "C"
00171 void         *mime_bridge_create_display_stream(nsIMimeEmitter      *newEmitter,
00172                                                 nsStreamConverter   *newPluginObj2,
00173                                                 nsIURI              *uri,
00174                                                 nsMimeOutputType    format_out,
00175                                                                               PRUint32               whattodo,
00176                                                 nsIChannel          *aChannel);
00177 
00178 // To get the mime emitter...
00179 extern "C" nsIMimeEmitter   *GetMimeEmitter(MimeDisplayOptions *opt);
00180 
00181 // To support 2 types of emitters...we need these routines :-(
00182 extern "C" nsresult     mimeSetNewURL(nsMIMESession *stream, char *url);
00183 extern "C" nsresult     mimeEmitterAddAttachmentField(MimeDisplayOptions *opt, const char *field, const char *value); 
00184 extern "C" nsresult     mimeEmitterAddHeaderField(MimeDisplayOptions *opt, const char *field, const char *value);
00185 extern "C" nsresult     mimeEmitterAddAllHeaders(MimeDisplayOptions *opt, const char *allheaders, const PRInt32 allheadersize);
00186 extern "C" nsresult     mimeEmitterStartAttachment(MimeDisplayOptions *opt, const char *name, const char *contentType, const char *url,
00187                                                    PRBool aIsExternalAttachment);
00188 extern "C" nsresult     mimeEmitterEndAttachment(MimeDisplayOptions *opt);
00189 extern "C" nsresult           mimeEmitterEndAllAttachments(MimeDisplayOptions *opt);
00190 extern "C" nsresult     mimeEmitterStartBody(MimeDisplayOptions *opt, PRBool bodyOnly, const char *msgID, const char *outCharset);
00191 extern "C" nsresult     mimeEmitterEndBody(MimeDisplayOptions *opt);
00192 extern "C" nsresult     mimeEmitterEndHeader(MimeDisplayOptions *opt);
00193 extern "C" nsresult     mimeEmitterStartHeader(MimeDisplayOptions *opt, PRBool rootMailHeader, PRBool headerOnly, const char *msgID,
00194                                                const char *outCharset);
00195 extern "C" nsresult     mimeEmitterUpdateCharacterSet(MimeDisplayOptions *opt, const char *aCharset);
00196 
00197 /* To Get the connnection to prefs service manager */
00198 extern "C" nsIPrefBranch      *GetPrefBranch(MimeDisplayOptions *opt);
00199 
00200 // Get the text converter...
00201 mozITXTToHTMLConv           *GetTextConverter(MimeDisplayOptions *opt);
00202 
00203 nsresult
00204 HTML2Plaintext(const nsString& inString, nsString& outString,
00205                PRUint32 flags, PRUint32 wrapCol);
00206 nsresult
00207 HTMLSanitize(const nsString& inString, nsString& outString,
00208              PRUint32 flags, const nsAString& allowedTags);
00209 
00210 extern "C" char             *MimeGetStringByID(PRInt32 stringID);
00211 
00212 // Utility to create a nsIURI object...
00213 extern "C" nsresult         nsMimeNewURI(nsIURI** aInstancePtrResult, const char *aSpec, nsIURI *aBase);
00214 
00215 extern "C" nsresult SetMailCharacterSetToMsgWindow(MimeObject *obj, const char *aCharacterSet); 
00216 
00217 extern "C"  nsresult GetMailNewsFont(MimeObject *obj, PRBool styleFixed, PRInt32 *fontPixelSize, PRInt32 *fontSizePercentage, nsCString& fontLang);
00218 
00219 
00220 #ifdef __cplusplus
00221 }
00222 #endif /* __cplusplus */
00223 
00224 #endif /* _MIMEMOZ_H_ */
00225