PTLib  Version 2.10.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mime.h
Go to the documentation of this file.
1 /*
2  * mime.h
3  *
4  * Multipurpose Internet Mail Extensions support classes.
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1993-2002 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Contributor(s): ______________________________________.
25  *
26  * $Revision: 26837 $
27  * $Author: rjongbloed $
28  * $Date: 2012-01-08 01:01:11 -0600 (Sun, 08 Jan 2012) $
29  */
30 
31 #ifndef PTLIB_PMIME_H
32 #define PTLIB_PMIME_H
33 
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37 
38 #include <ptclib/inetprot.h>
39 #include <ptclib/cypher.h>
40 
41 
42 class PMultiPartList;
43 
44 
46 // PMIMEInfo
47 
52 class PMIMEInfo : public PStringOptions
53 {
54  public:
55  PMIMEInfo() { }
56 
58  PMIMEInfo(
59  istream &strm
60  );
61  PMIMEInfo(
62  PInternetProtocol & socket
63  );
64  PMIMEInfo(
65  const PStringToString & dict
66  );
67  PMIMEInfo(
68  const PString & str
69  );
70 
71 
72  // Overrides from class PObject
76  virtual void PrintOn(
77  ostream &strm
78  ) const;
79 
83  virtual void ReadFrom(
84  istream &strm
85  );
86 
87 
88  // New functions for class.
94  PBoolean Read(
95  PInternetProtocol & socket
96  );
97 
103  PBoolean Write(
104  PInternetProtocol & socket
105  ) const;
106 
109  PString AsString() const;
110 
119  bool AddMIME(
120  const PString & line
121  );
122  bool AddMIME(
123  const PString & fieldName,
124  const PString & fieldValue
125  ) { return InternalAddMIME(fieldName, fieldValue); }
126  bool AddMIME(
127  const PMIMEInfo & mime
128  );
129 
130  virtual bool InternalAddMIME(
131  const PString & fieldName,
132  const PString & fieldValue
133  );
134 
165  const char * key,
166  PStringToString & info
167  ) const { return ParseComplex(GetString(key), info); }
169  const PString & key,
170  PStringToString & info
171  ) const { return ParseComplex(GetString(key), info); }
173  const PCaselessString & key,
174  PStringToString & info
175  ) const { return ParseComplex(GetString(key), info); }
177  const PCaselessString & (*key)(),
178  PStringToString & info
179  ) const { return ParseComplex(GetString(key), info); }
180 
182  static bool ParseComplex(
183  const PString & str,
184  PStringToString & info
185  );
186 
189  bool DecodeMultiPartList(
190  PMultiPartList & parts,
191  const PString & body,
192  const PCaselessString & key
193  ) const;
194 
198  PMultiPartList & parts,
199  const PString & body,
200  const PCaselessString & (*key)() = ContentTypeTag
201  ) const { return DecodeMultiPartList(parts, body, key()); }
202 
203 
204  static const PCaselessString & ContentTypeTag();
205  static const PCaselessString & ContentDispositionTag();
207  static const PCaselessString & ContentDescriptionTag();
208  static const PCaselessString & ContentIdTag();
209 
210  static const PCaselessString & TextPlain();
211 
212 
250  static void SetAssociation(
251  const PStringToString & allTypes,
252  PBoolean merge = true
253  );
254  static void SetAssociation(
255  const PString & fileType,
256  const PString & contentType
257  ) { GetContentTypes().SetAt(fileType, contentType); }
258 
266  static PString GetContentType(
267  const PString & fileType
268  );
269 
272  virtual ostream & PrintContents(
273  ostream & strm
274  ) const;
275 
276  private:
277  static PStringToString & GetContentTypes();
278 };
279 
280 
282 // PMultiPartInfo
283 
286 class PMultiPartInfo : public PObject
287 {
288  PCLASSINFO(PMultiPartInfo, PObject);
289  public:
293 };
294 
295 class PMultiPartList : public PList<PMultiPartInfo>
296 {
298  public:
300 
301  bool Decode(
302  const PString & body,
303  const PStringToString & contentInfo
304  );
305 };
306 
307 
308 #endif // PTLIB_PMIME_H
309 
310 
311 // End Of File ///////////////////////////////////////////////////////////////
virtual void PrintOn(ostream &strm) const
Output the contents of the MIME dictionary to the stream.
static const PCaselessString & ContentTypeTag()
bool DecodeMultiPartList(PMultiPartList &parts, const PString &body, const PCaselessString &key) const
Decode parts from a multipart body using the field value.
This class contains the Multipurpose Internet Mail Extensions parameters and variables.
Definition: mime.h:52
Definition: mime.h:295
virtual bool InternalAddMIME(const PString &fieldName, const PString &fieldValue)
PString m_textBody
Definition: mime.h:291
bool GetComplex(const PString &key, PStringToString &info) const
Definition: mime.h:168
bool GetComplex(const char *key, PStringToString &info) const
Get a complex MIME field.
Definition: mime.h:164
static bool ParseComplex(const PString &str, PStringToString &info)
Parse the string as a complex field, see GetComplex()
This is a dictionary collection class of PString objects, keyed by another string.
Definition: pstring.h:2784
PBoolean Write(PInternetProtocol &socket) const
Write MIME information to the socket.
bool Decode(const PString &body, const PStringToString &contentInfo)
This class is a variation of a string that ignores case.
Definition: pstring.h:1708
bool AddMIME(const PString &line)
Add a MIME field given a &quot;name: value&quot; format string.
static PString GetContentType(const PString &fileType)
Look up the file type to MIME content type association dictionary and return the MIME content type st...
This template class maps the PAbstractList to a specific object type.
Definition: lists.h:321
PBYTEArray m_binaryBody
Definition: mime.h:292
A TCP/IP socket for process/application layer high level protocols.
Definition: inetprot.h:62
BOOL PBoolean
Definition: object.h:102
Array of unsigned characters.
Definition: array.h:670
Specialised version of PStringToString to contain a dictionary of options/attributes.
Definition: pstring.h:2845
static const PCaselessString & ContentDispositionTag()
PMIMEInfo m_mime
Definition: mime.h:290
static const PCaselessString & ContentTransferEncodingTag()
virtual ostream & PrintContents(ostream &strm) const
Output the contents without the trailing CRLF.
The character string class.
Definition: pstring.h:108
bool GetComplex(const PCaselessString &key, PStringToString &info) const
Definition: mime.h:172
PBoolean Read(PInternetProtocol &socket)
Read MIME information from the socket.
virtual PBoolean SetAt(const K &key, const PString &str)
Add a new object to the collection.
Definition: pstring.h:2590
bool AddMIME(const PString &fieldName, const PString &fieldValue)
Definition: mime.h:122
PMultiPartList()
Definition: mime.h:299
bool GetComplex(const PCaselessString &(*key)(), PStringToString &info) const
Definition: mime.h:176
static void SetAssociation(const PStringToString &allTypes, PBoolean merge=true)
Set an association between a file type and a MIME content type.
PString GetString(const char *key, const char *dflt=NULL) const
Get an option value.
Definition: pstring.h:2877
static const PCaselessString & ContentIdTag()
static void SetAssociation(const PString &fileType, const PString &contentType)
Definition: mime.h:254
bool DecodeMultiPartList(PMultiPartList &parts, const PString &body, const PCaselessString &(*key)()=ContentTypeTag) const
Decode parts from a multipart body using the field value.
Definition: mime.h:197
PMIMEInfo()
Definition: mime.h:55
static const PCaselessString & TextPlain()
This object describes the information associated with a multi-part bodies.
Definition: mime.h:286
virtual void ReadFrom(istream &strm)
Input the contents of the MIME dictionary from the stream.
PString AsString() const
Return a string presentation of the MIME.
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
static const PCaselessString & ContentDescriptionTag()