|
PTLib Version 2.10.2
|
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: 26045 $ 00027 * $Author: rjongbloed $ 00028 * $Date: 2011-06-19 20:28:39 -0500 (Sun, 19 Jun 2011) $ 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 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 // New functions for class. 00088 PBoolean Read( 00089 PInternetProtocol & socket 00090 ); 00091 00097 PBoolean Write( 00098 PInternetProtocol & socket 00099 ) const; 00100 00109 bool AddMIME( 00110 const PString & line 00111 ); 00112 bool AddMIME( 00113 const PString & fieldName, 00114 const PString & fieldValue 00115 ); 00116 bool AddMIME( 00117 const PMIMEInfo & mime 00118 ); 00119 00149 bool GetComplex( 00150 const char * key, 00151 PStringToString & info 00152 ) const { return ParseComplex(GetString(key), info); } 00153 bool GetComplex( 00154 const PString & key, 00155 PStringToString & info 00156 ) const { return ParseComplex(GetString(key), info); } 00157 bool GetComplex( 00158 const PCaselessString & key, 00159 PStringToString & info 00160 ) const { return ParseComplex(GetString(key), info); } 00161 bool GetComplex( 00162 const PCaselessString & (*key)(), 00163 PStringToString & info 00164 ) const { return ParseComplex(GetString(key), info); } 00165 00167 static bool ParseComplex( 00168 const PString & str, 00169 PStringToString & info 00170 ); 00171 00174 bool DecodeMultiPartList( 00175 PMultiPartList & parts, 00176 const PString & body, 00177 const PCaselessString & key 00178 ) const; 00179 00182 bool DecodeMultiPartList( 00183 PMultiPartList & parts, 00184 const PString & body, 00185 const PCaselessString & (*key)() = ContentTypeTag 00186 ) const { return DecodeMultiPartList(parts, body, key()); } 00187 00188 00189 static const PCaselessString & ContentTypeTag(); 00190 static const PCaselessString & ContentDispositionTag(); 00191 static const PCaselessString & ContentTransferEncodingTag(); 00192 static const PCaselessString & ContentDescriptionTag(); 00193 static const PCaselessString & ContentIdTag(); 00194 00195 static const PCaselessString & TextPlain(); 00196 00197 00235 static void SetAssociation( 00236 const PStringToString & allTypes, 00237 PBoolean merge = true 00238 ); 00239 static void SetAssociation( 00240 const PString & fileType, 00241 const PString & contentType 00242 ) { GetContentTypes().SetAt(fileType, contentType); } 00243 00251 static PString GetContentType( 00252 const PString & fileType 00253 ); 00254 00257 virtual ostream & PrintContents( 00258 ostream & strm 00259 ) const; 00260 00261 private: 00262 static PStringToString & GetContentTypes(); 00263 }; 00264 00265 00267 // PMultiPartInfo 00268 00271 class PMultiPartInfo : public PObject 00272 { 00273 PCLASSINFO(PMultiPartInfo, PObject); 00274 public: 00275 PMIMEInfo m_mime; 00276 PString m_textBody; 00277 PBYTEArray m_binaryBody; 00278 }; 00279 00280 class PMultiPartList : public PList<PMultiPartInfo> 00281 { 00282 PCLASSINFO(PMultiPartList, PList<PMultiPartInfo>); 00283 public: 00284 PMultiPartList() { } 00285 00286 bool Decode( 00287 const PString & body, 00288 const PStringToString & contentInfo 00289 ); 00290 }; 00291 00292 00293 #endif // PTLIB_PMIME_H 00294 00295 00296 // End Of File ///////////////////////////////////////////////////////////////