mime.h

Go to the documentation of this file.
00001 /*
00002  * mime.h
00003  *
00004  * Multipurpose Internet Mail Extensions support classes.
00005  *
00006  * Portable Windows Library
00007  *
00008  * Copyright (c) 1993-2002 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Portable Windows Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Contributor(s): ______________________________________.
00025  *
00026  * $Revision: 24177 $
00027  * $Author: rjongbloed $
00028  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
00029  */
00030 
00031 #ifndef PTLIB_PMIME_H
00032 #define PTLIB_PMIME_H
00033 
00034 #ifdef P_USE_PRAGMA
00035 #pragma interface
00036 #endif
00037 
00038 #include <ptclib/inetprot.h>
00039 #include <ptclib/cypher.h>
00040 
00041 
00042 class PMultiPartList;
00043 
00044 
00046 // PMIMEInfo
00047 
00052 #ifdef DOC_PLUS_PLUS
00053 class PMIMEInfo : public PStringToString {
00054 #endif
00055 PDECLARE_STRING_DICTIONARY(PMIMEInfo, PCaselessString);
00056   public:
00057     PMIMEInfo(
00058       istream &strm   
00059     );
00060     PMIMEInfo(
00061       PInternetProtocol & socket   
00062     );
00063     // Construct a MIME information dictionary from the specified source.
00064 
00065 
00066   // Overrides from class PObject
00070     virtual void PrintOn(
00071       ostream &strm   
00072     ) const;
00073 
00077     virtual void ReadFrom(
00078       istream &strm   
00079     );
00080 
00081 
00082   // Overrides from class PStringToString
00089     PBoolean SetAt(
00090       const char * key,
00091       const PString value
00092     ) { return AbstractSetAt(PCaselessString(key), PNEW PString(value)); }
00093 
00100     PBoolean SetAt(
00101       const PString & key,
00102       const PString value
00103     ) { return AbstractSetAt(PCaselessString(key), PNEW PString(value)); }
00104 
00111     PBoolean SetAt(
00112       const PCaselessString & key,
00113       const PString value
00114     ) { return AbstractSetAt(key, PNEW PString(value)); }
00115 
00122     PBoolean SetAt(
00123       const PString & (*key)(),
00124       const PString value
00125     ) { return AbstractSetAt(PCaselessString(key()), PNEW PString(value)); }
00126 
00133     PBoolean Contains(
00134       const char * key       
00135     ) const { return GetAt(PCaselessString(key)) != NULL; }
00136 
00143     PBoolean Contains(
00144       const PString & key       
00145     ) const { return GetAt(PCaselessString(key)) != NULL; }
00146 
00153     PBoolean Contains(
00154       const PCaselessString & key       
00155     ) const { return GetAt(key) != NULL; }
00156 
00163     PBoolean Contains(
00164       const PString & (*key)()       
00165     ) const { return GetAt(PCaselessString(key())) != NULL; }
00166 
00167   // New functions for class.
00173     PBoolean Read(
00174       PInternetProtocol & socket   
00175     );
00176 
00182     PBoolean Write(
00183       PInternetProtocol & socket   
00184     ) const;
00185 
00194     bool AddMIME(
00195       const PString & line
00196     );
00197     bool AddMIME(
00198       const PString & fieldName, 
00199       const PString & fieldValue 
00200     );
00201     bool AddMIME(
00202       const PMIMEInfo & mime
00203     );
00204 
00212     PString GetString(
00213       const PString & key,       
00214       const PString & dflt = PString::Empty() 
00215     ) const;
00216     PString GetString(
00217       const PString & (*key)(),               
00218       const PString & dflt = PString::Empty() 
00219     ) const { return GetString(key(), dflt); }
00220 
00228     long GetInteger(
00229       const PString & key,    
00230       long dflt = 0           
00231     ) const;
00232     long GetInteger(
00233       const PString & (*key)(), 
00234       long dflt = 0             
00235     ) const { return GetInteger(key(), dflt); }
00236 
00239     void SetInteger(
00240       const PCaselessString & key,  
00241       long value                    
00242     );
00243     void SetInteger(
00244       const PString & (*key)(), 
00245       long value                    
00246     ) { SetInteger(PCaselessString(key()), value); }
00247 
00277     bool GetComplex(
00278       const PString & key,    
00279       PStringToString & info  
00280     ) const { return ParseComplex(GetString(key), info); }
00281     bool GetComplex(
00282       const PString & (*key)(), 
00283       PStringToString & info    
00284     ) const { return ParseComplex(GetString(key), info); }
00285 
00287     static bool ParseComplex(
00288       const PString & str,      
00289       PStringToString & info    
00290     );
00291 
00294     bool DecodeMultiPartList(
00295       PMultiPartList & parts,   
00296       const PString & body,     
00297       const PString & key       
00298     ) const;
00299 
00300     static const PString & ContentTypeTag();
00301     static const PString & ContentDispositionTag();
00302     static const PString & ContentTransferEncodingTag();
00303     static const PString & ContentDescriptionTag();
00304     static const PString & ContentIdTag();
00305 
00308     bool DecodeMultiPartList(
00309       PMultiPartList & parts,   
00310       const PString & body,     
00311       const PString & (*key)() = ContentTypeTag 
00312     ) const { return DecodeMultiPartList(parts, body, key()); }
00313 
00351     static void SetAssociation(
00352       const PStringToString & allTypes,  
00353       PBoolean merge = true                  
00354     );
00355     static void SetAssociation(
00356       const PString & fileType,         
00357       const PString & contentType       
00358     ) { GetContentTypes().SetAt(fileType, contentType); }
00359 
00367     static PString GetContentType(
00368       const PString & fileType   
00369     );
00370 
00373     virtual ostream & PrintContents(
00374       ostream & strm
00375     ) const;
00376 
00377   private:
00378     static PStringToString & GetContentTypes();
00379 };
00380 
00381 
00383 // PMultiPartInfo
00384 
00387 class PMultiPartInfo : public PObject
00388 {
00389     PCLASSINFO(PMultiPartInfo, PObject);
00390   public:
00391     PMIMEInfo  m_mime;
00392     PString    m_textBody;
00393     PBYTEArray m_binaryBody;
00394 };
00395 
00396 class PMultiPartList : public PList<PMultiPartInfo>
00397 {
00398     PCLASSINFO(PMultiPartList, PList<PMultiPartInfo>);
00399   public:
00400     PMultiPartList() { }
00401 
00402     bool Decode(
00403       const PString & body,               
00404       const PStringToString & contentInfo 
00405     );
00406 };
00407 
00408 
00409 #endif // PTLIB_PMIME_H
00410 
00411 
00412 // End Of File ///////////////////////////////////////////////////////////////

Generated on Fri Oct 14 01:44:09 2011 for PTLib by  doxygen 1.4.7