Back to index

lightning-sunbird  0.9+nobinonly
MapiMessage.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 #ifndef MapiMessage_h___
00038 #define MapiMessage_h___
00039 
00040 #include "nsUInt32Array.h"
00041 #include "nsString.h"
00042 #include "nsIFileSpec.h"
00043 #include "MapiApi.h"
00044 
00045 
00046 class nsSimpleUInt32Array {
00047 public:
00048        nsSimpleUInt32Array( int growBy = 20) 
00049               { m_growBy = growBy; m_pData = nsnull; m_used = 0; m_allocated = 0;}
00050        ~nsSimpleUInt32Array() { if (m_pData) delete [] m_pData;}
00051 
00052        void Add( PRUint32 data) { Allocate(); if (m_used < m_allocated) { m_pData[m_used] = data; m_used++;}}
00053        PRUint32 GetAt( PRInt32 index) { if ((index >= 0) && (index < m_used)) return( m_pData[index]); else return( 0);}
00054        PRInt32       GetSize( void) { return( m_used);}
00055        void RemoveAll( void) { m_used = 0;}
00056 
00057 private:
00058        void Allocate( void);
00059        
00060        PRInt32              m_allocated;
00061        PRInt32              m_used;
00062        PRUint32 *    m_pData;
00063        int                  m_growBy;
00064 };
00065 
00066 
00067 
00068 class CMapiMessage {
00069 public:
00070        CMapiMessage( LPMESSAGE     lpMsg);
00071        ~CMapiMessage();
00072 
00073        // Headers - fetch will get PR_TRANSPORT_MESSAGE_HEADERS
00074        // or if they do not exist will build a header from
00075        //     PR_DISPLAY_TO, _CC, _BCC
00076        //     PR_SUBJECT
00077        //  PR_MESSAGE_RECIPIENTS
00078        // and PR_CREATION_TIME if needed?
00079        BOOL          FetchHeaders( void);
00080        
00081        // Do the headers need a From separator line.
00082        // TRUE if a From line needs to precede the headers, FALSE
00083        // if the headers already include a from line    
00084        BOOL          NeedsFromLine( void);
00085        
00086        // Fetch the 
00087        BOOL          FetchBody( void);
00088 
00089        // Attachments
00090        int                  CountAttachments( void);
00091        BOOL          GetAttachmentInfo( int idx);
00092 
00093        // Retrieve info for message
00094        BOOL          BodyIsHtml( void) { return( m_bodyIsHtml);}
00095        const char *GetFromLine( int& len) { if (m_fromLine.IsEmpty()) return( NULL); else { len = m_fromLine.Length(); return( m_fromLine.get());}}
00096        const char *GetHeaders( int& len) { if (m_headers.IsEmpty()) return( NULL); else { len = m_headers.Length(); return( m_headers.get());}}
00097        const char *GetBody( int& len) { if (m_body.IsEmpty()) return( NULL); else { len = m_body.Length(); return( m_body.get());}}
00098        const char *GetBody( void) { return( m_body.get());}
00099        const char *GetHeaders( void) { return( m_headers.get());}
00100        PRInt32              GetBodyLen( void) { return( m_body.Length());}
00101        PRInt32              GetHeaderLen( void) { return( m_headers.Length());}
00102 
00103 
00104        BOOL          IsMultipart( void);
00105        BOOL          HasContentHeader( void) { return( !m_mimeContentType.IsEmpty());}
00106        BOOL          HasMimeVersion( void) { return( m_bMimeVersion);}
00107        const char *GetMimeContent( void) { return( m_mimeContentType.get());}
00108   PRInt32     GetMimeContentLen( void) { return( m_mimeContentType.Length());}
00109        const char *GetMimeBoundary( void) { return( m_mimeBoundary.get());}
00110        void          GenerateBoundary( void);
00111 
00112        BOOL          GetAttachFileLoc( nsIFileSpec *pLoc);
00113 
00114        const char *GetMimeType( void) { return( m_attachMimeType.get());}
00115        const char *GetFileName( void) { return( m_attachFileName.get());}
00116 
00117 protected:
00118        BOOL          IterateAttachTable( void);
00119        void          ClearTempAttachFile( void);
00120        BOOL          CopyBinAttachToFile( LPATTACH lpAttach);
00121 
00122        void          ProcessHeaderLine( nsCString& line);
00123        void          ProcessHeaders( void);
00124        void          FormatDateTime( SYSTEMTIME & tm, nsCString& s, BOOL includeTZ = TRUE);
00125        void          BuildHeaders( void);
00126        void          BuildFromLine( void);
00127        void          AddSubject( nsCString& str);
00128        void          AddFrom( nsCString& str);
00129        BOOL          AddHeader( nsCString& str, ULONG tag, const char *pPrefix);
00130        void          AddDate( nsCString& str);
00131        
00132        BOOL          IsSpace( char c) { return( m_whitespace.FindChar( c) != -1);}
00133 
00134 private:
00135        LPMESSAGE            m_lpMsg;
00136        LPMAPITABLE          m_pAttachTable;
00137        nsCString            m_headers;
00138        nsCString            m_fromLine;
00139        nsCString            m_body;
00140        nsCString            m_mimeContentType;
00141        nsCString            m_mimeBoundary;
00142        nsCString            m_mimeCharset;
00143        BOOL                 m_bMimeVersion;
00144        BOOL                 m_bMimeEncoding;
00145        nsSimpleUInt32Array  m_attachNums;
00146        nsCString            m_attachMimeType;
00147        nsCString            m_attachPath;
00148        nsCString            m_attachFileName;
00149        BOOL                 m_ownsAttachFile;
00150        BOOL                 m_bodyIsHtml;
00151        BOOL                 m_bHasSubject;
00152        BOOL                 m_bHasFrom;
00153        BOOL                 m_bHasDate;
00154        nsCString            m_whitespace;
00155 };
00156 
00157 
00158 
00159 
00160 #endif /* MapiMessage_h__ */