Back to index

lightning-sunbird  0.9+nobinonly
nsMsgAttachmentHandler.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 _nsMsgAttachmentHandler_H_
00039 #define _nsMsgAttachmentHandler_H_
00040 
00041 #include "nsIURL.h"
00042 #include "nsIMimeConverter.h"
00043 #include "nsMsgCompFields.h"
00044 #include "nsIMsgStatusFeedback.h"
00045 #include "nsIChannel.h"
00046 #include "nsIMsgSend.h"
00047 #include "nsIFileStreams.h"
00048 #include "nsIStreamConverter.h"
00049 
00050 #if defined(XP_MAC) || defined(XP_MACOSX)
00051 
00052 #include "nsMsgAppleDouble.h"
00053 
00054 typedef struct _AppledoubleEncodeObject
00055 {
00056   appledouble_encode_object   ap_encode_obj;
00057   char                        *buff;          // the working buff
00058   PRInt32                     s_buff;         // the working buff size
00059   nsIOFileStream              *fileStream;    // file to hold the encoding
00060 } AppleDoubleEncodeObject;
00061 
00062 #endif  // XP_MAC
00063 
00064 //
00065 // This is a class that deals with processing remote attachments. It implements
00066 // an nsIStreamListener interface to deal with incoming data
00067 //
00068 class nsMsgAttachmentHandler
00069 {
00070 public:
00071   nsMsgAttachmentHandler();
00072   ~nsMsgAttachmentHandler();
00073   
00074 
00076   // Object methods...
00078   //
00079 public:
00080   nsresult              SnarfAttachment(nsMsgCompFields *compFields);
00081   int                   PickEncoding (const char *charset, nsIMsgSend* mime_delivery_state);
00082   void                  AnalyzeSnarfedFile ();      // Analyze a previously-snarfed file.
00083                                                     // (Currently only used for plaintext
00084                                                     // converted from HTML.) 
00085   nsresult              Abort();
00086   nsresult              UrlExit(nsresult status, const PRUnichar* aMsg);
00087 
00088 private:
00089   nsresult              SnarfMsgAttachment(nsMsgCompFields *compFields);
00090   PRBool                UseUUEncode_p(void);
00091   void                  AnalyzeDataChunk (const char *chunk, PRInt32 chunkSize);
00092   nsresult              LoadDataFromFile(nsFileSpec& fSpec, nsString &sigData, PRBool charsetConversion); //A similar function already exist in nsMsgCompose!
00093 #if defined(XP_MAC) || defined(XP_MACOSX)
00094   PRBool HasResourceFork(FSSpec *fsSpec);
00095 #endif
00096 
00098   // Member vars...
00100   //
00101 public:
00102   nsCOMPtr <nsIURI> mURL;
00103   nsFileSpec            *mFileSpec;         // The temp file to which we save it 
00104   nsCOMPtr<nsIFileOutputStream>  mOutFile;          
00105   nsIRequest            *mRequest;          // The live request used while fetching an attachment
00106   nsMsgCompFields       *mCompFields;       // Message composition fields for the sender
00107   PRBool                m_bogus_attachment; // This is to catch problem children...
00108 
00109 #if defined(XP_MAC) || defined(XP_MACOSX)
00110   nsFileSpec            *mAppleFileSpec;    // The temp file holds the appledouble
00111                                             // encoding of the file we want to send.
00112 #endif
00113   char                  *m_x_mac_type;      // Mac file type
00114   char                  *m_x_mac_creator;   // Mac file creator
00115   
00116   PRBool                m_done;
00117   char                  *m_charset;         // charset name 
00118   char                  *m_content_id;      // This is for mutipart/related Content-ID's
00119   char                  *m_type;            // The real type, once we know it.
00120   char                  *m_type_param;      // Any addition parameters to add to the content-type (other than charset, macType and maccreator)
00121   char                  *m_override_type;   // The type we should assume it to be
00122                                             // or 0, if we should get it from the
00123                                             // server)
00124   char                  *m_override_encoding; // Goes along with override_type 
00125 
00126   char                  *m_desired_type;    // The type it should be converted to. 
00127   char                  *m_description;     // For Content-Description header
00128   char                  *m_real_name;       // The name for the headers, if different
00129                                             // from the URL. 
00130   char                  *m_encoding;        // The encoding, once we've decided. */
00131   PRBool                m_already_encoded_p; // If we attach a document that is already
00132                                              // encoded, we just pass it through.
00133 
00134   PRBool                m_decrypted_p;  /* S/MIME -- when attaching a message that was
00135                                            encrypted, it's necessary to decrypt it first
00136                                            (since nobody but the original recipient can
00137                                            read it -- if you forward it to someone in the
00138                                            raw, it will be useless to them.)  This flag
00139                                            indicates whether decryption occurred, so that
00140                                            libmsg can issue appropriate warnings about
00141                                            doing a cleartext forward of a message that was
00142                                            originally encrypted. */
00143 
00144   PRBool                mDeleteFile;      // If this is true, Delete the file...its 
00145                                           // NOT the original file!
00146 
00147   PRBool                mMHTMLPart;           // This is true if its an MHTML part, otherwise, PR_FALSE
00148   PRBool                mPartUserOmissionOverride;  // This is true if the user send send the email without this part
00149   PRBool                mMainBody;            // True if this is a main body.
00150 
00151   //
00152   // Vars for analyzing file data...
00153   //
00154   PRUint32              m_size;         /* Some state used while filtering it */
00155   PRUint32              m_unprintable_count;
00156   PRUint32              m_highbit_count;
00157   PRUint32              m_ctl_count;
00158   PRUint32              m_null_count;
00159   PRUint8               m_have_cr, m_have_lf, m_have_crlf; 
00160   PRBool                m_prev_char_was_cr;
00161   PRUint32              m_current_column;
00162   PRUint32              m_max_column;
00163   PRUint32              m_lines;
00164   PRBool                m_file_analyzed;
00165 
00166   MimeEncoderData       *m_encoder_data;  /* Opaque state for base64/qp encoder. */
00167   char *                m_uri; // original uri string
00168   
00169   nsresult              GetMimeDeliveryState(nsIMsgSend** _retval);
00170   nsresult              SetMimeDeliveryState(nsIMsgSend* mime_delivery_state);
00171 private:
00172   nsCOMPtr<nsIMsgSend>  m_mime_delivery_state;
00173   nsCOMPtr<nsIStreamConverter> m_mime_parser;
00174   nsCOMPtr<nsIChannel>  m_converter_channel;
00175 };
00176 
00177 
00178 #endif /* _nsMsgAttachmentHandler_H_ */