PTLib
Version 2.10.4
|
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: 26837 $ 00027 * $Author: rjongbloed $ 00028 * $Date: 2012-01-08 01:01:11 -0600 (Sun, 08 Jan 2012) $ 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 class PMIMEInfo : public PStringOptions 00053 { 00054 public: 00055 PMIMEInfo() { } 00056 00058 PMIMEInfo( 00059 istream &strm 00060 ); 00061 PMIMEInfo( 00062 PInternetProtocol & socket 00063 ); 00064 PMIMEInfo( 00065 const PStringToString & dict 00066 ); 00067 PMIMEInfo( 00068 const PString & str 00069 ); 00070 00071 00072 // Overrides from class PObject 00076 virtual void PrintOn( 00077 ostream &strm 00078 ) const; 00079 00083 virtual void ReadFrom( 00084 istream &strm 00085 ); 00086 00087 00088 // New functions for class. 00094 PBoolean Read( 00095 PInternetProtocol & socket 00096 ); 00097 00103 PBoolean Write( 00104 PInternetProtocol & socket 00105 ) const; 00106 00109 PString AsString() const; 00110 00119 bool AddMIME( 00120 const PString & line 00121 ); 00122 bool AddMIME( 00123 const PString & fieldName, 00124 const PString & fieldValue 00125 ) { return InternalAddMIME(fieldName, fieldValue); } 00126 bool AddMIME( 00127 const PMIMEInfo & mime 00128 ); 00129 00130 virtual bool InternalAddMIME( 00131 const PString & fieldName, 00132 const PString & fieldValue 00133 ); 00134 00164 bool GetComplex( 00165 const char * key, 00166 PStringToString & info 00167 ) const { return ParseComplex(GetString(key), info); } 00168 bool GetComplex( 00169 const PString & key, 00170 PStringToString & info 00171 ) const { return ParseComplex(GetString(key), info); } 00172 bool GetComplex( 00173 const PCaselessString & key, 00174 PStringToString & info 00175 ) const { return ParseComplex(GetString(key), info); } 00176 bool GetComplex( 00177 const PCaselessString & (*key)(), 00178 PStringToString & info 00179 ) const { return ParseComplex(GetString(key), info); } 00180 00182 static bool ParseComplex( 00183 const PString & str, 00184 PStringToString & info 00185 ); 00186 00189 bool DecodeMultiPartList( 00190 PMultiPartList & parts, 00191 const PString & body, 00192 const PCaselessString & key 00193 ) const; 00194 00197 bool DecodeMultiPartList( 00198 PMultiPartList & parts, 00199 const PString & body, 00200 const PCaselessString & (*key)() = ContentTypeTag 00201 ) const { return DecodeMultiPartList(parts, body, key()); } 00202 00203 00204 static const PCaselessString & ContentTypeTag(); 00205 static const PCaselessString & ContentDispositionTag(); 00206 static const PCaselessString & ContentTransferEncodingTag(); 00207 static const PCaselessString & ContentDescriptionTag(); 00208 static const PCaselessString & ContentIdTag(); 00209 00210 static const PCaselessString & TextPlain(); 00211 00212 00250 static void SetAssociation( 00251 const PStringToString & allTypes, 00252 PBoolean merge = true 00253 ); 00254 static void SetAssociation( 00255 const PString & fileType, 00256 const PString & contentType 00257 ) { GetContentTypes().SetAt(fileType, contentType); } 00258 00266 static PString GetContentType( 00267 const PString & fileType 00268 ); 00269 00272 virtual ostream & PrintContents( 00273 ostream & strm 00274 ) const; 00275 00276 private: 00277 static PStringToString & GetContentTypes(); 00278 }; 00279 00280 00282 // PMultiPartInfo 00283 00286 class PMultiPartInfo : public PObject 00287 { 00288 PCLASSINFO(PMultiPartInfo, PObject); 00289 public: 00290 PMIMEInfo m_mime; 00291 PString m_textBody; 00292 PBYTEArray m_binaryBody; 00293 }; 00294 00295 class PMultiPartList : public PList<PMultiPartInfo> 00296 { 00297 PCLASSINFO(PMultiPartList, PList<PMultiPartInfo>); 00298 public: 00299 PMultiPartList() { } 00300 00301 bool Decode( 00302 const PString & body, 00303 const PStringToString & contentInfo 00304 ); 00305 }; 00306 00307 00308 #endif // PTLIB_PMIME_H 00309 00310 00311 // End Of File ///////////////////////////////////////////////////////////////