mime.h
Go to the documentation of this file.
/*
* mime.h
*
* Multipurpose Internet Mail Extensions support classes.
*
* Portable Windows Library
*
* Copyright (c) 1993-2002 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Contributor(s): ______________________________________.
*
* $Revision: 26837 $
* $Author: rjongbloed $
* $Date: 2012-01-08 01:01:11 -0600 (Sun, 08 Jan 2012) $
*/
#ifndef PTLIB_PMIME_H
#define PTLIB_PMIME_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#include <ptclib/inetprot.h>
#include <ptclib/cypher.h>
class PMultiPartList;
// PMIMEInfo
class PMIMEInfo : public PStringOptions
{
public:
PMIMEInfo() { }
PMIMEInfo(
istream &strm
);
PMIMEInfo(
PInternetProtocol & socket
);
PMIMEInfo(
const PStringToString & dict
);
PMIMEInfo(
const PString & str
);
// Overrides from class PObject
virtual void PrintOn(
ostream &strm
) const;
virtual void ReadFrom(
istream &strm
);
// New functions for class.
PBoolean Read(
PInternetProtocol & socket
);
PBoolean Write(
PInternetProtocol & socket
) const;
PString AsString() const;
bool AddMIME(
const PString & line
);
bool AddMIME(
const PString & fieldName,
const PString & fieldValue
) { return InternalAddMIME(fieldName, fieldValue); }
bool AddMIME(
const PMIMEInfo & mime
);
virtual bool InternalAddMIME(
const PString & fieldName,
const PString & fieldValue
);
bool GetComplex(
const char * key,
PStringToString & info
) const { return ParseComplex(GetString(key), info); }
bool GetComplex(
const PString & key,
PStringToString & info
) const { return ParseComplex(GetString(key), info); }
bool GetComplex(
const PCaselessString & key,
PStringToString & info
) const { return ParseComplex(GetString(key), info); }
bool GetComplex(
const PCaselessString & (*key)(),
PStringToString & info
) const { return ParseComplex(GetString(key), info); }
static bool ParseComplex(
const PString & str,
PStringToString & info
);
bool DecodeMultiPartList(
PMultiPartList & parts,
const PString & body,
const PCaselessString & key
) const;
bool DecodeMultiPartList(
PMultiPartList & parts,
const PString & body,
const PCaselessString & (*key)() = ContentTypeTag
) const { return DecodeMultiPartList(parts, body, key()); }
static const PCaselessString & ContentTypeTag();
static const PCaselessString & ContentDispositionTag();
static const PCaselessString & ContentTransferEncodingTag();
static const PCaselessString & ContentDescriptionTag();
static const PCaselessString & ContentIdTag();
static const PCaselessString & TextPlain();
static void SetAssociation(
const PStringToString & allTypes,
PBoolean merge = true
);
static void SetAssociation(
const PString & fileType,
const PString & contentType
) { GetContentTypes().SetAt(fileType, contentType); }
static PString GetContentType(
const PString & fileType
);
virtual ostream & PrintContents(
ostream & strm
) const;
private:
static PStringToString & GetContentTypes();
};
// PMultiPartInfo
class PMultiPartInfo : public PObject
{
PCLASSINFO(PMultiPartInfo, PObject);
public:
PMIMEInfo m_mime;
PString m_textBody;
PBYTEArray m_binaryBody;
};
class PMultiPartList : public PList<PMultiPartInfo>
{
PCLASSINFO(PMultiPartList, PList<PMultiPartInfo>);
public:
PMultiPartList() { }
bool Decode(
const PString & body,
const PStringToString & contentInfo
);
};
#endif // PTLIB_PMIME_H
// End Of File ///////////////////////////////////////////////////////////////
inetprot.h
PMIMEInfo::PrintOn
virtual void PrintOn(ostream &strm) const
Output the contents of the MIME dictionary to the stream.
PMIMEInfo::ContentTypeTag
static const PCaselessString & ContentTypeTag()
PMIMEInfo::DecodeMultiPartList
bool DecodeMultiPartList(PMultiPartList &parts, const PString &body, const PCaselessString &key) const
Decode parts from a multipart body using the field value.
PMIMEInfo
This class contains the Multipurpose Internet Mail Extensions parameters and variables.
Definition: mime.h:52
PMultiPartList
Definition: mime.h:295
PMIMEInfo::InternalAddMIME
virtual bool InternalAddMIME(const PString &fieldName, const PString &fieldValue)
PMultiPartInfo::m_textBody
PString m_textBody
Definition: mime.h:291
PMIMEInfo::GetComplex
bool GetComplex(const PString &key, PStringToString &info) const
Definition: mime.h:168
PMIMEInfo::GetComplex
bool GetComplex(const char *key, PStringToString &info) const
Get a complex MIME field.
Definition: mime.h:164
PMIMEInfo::ParseComplex
static bool ParseComplex(const PString &str, PStringToString &info)
Parse the string as a complex field, see GetComplex()
PStringToString
This is a dictionary collection class of PString objects, keyed by another string.
Definition: pstring.h:2784
PMIMEInfo::Write
PBoolean Write(PInternetProtocol &socket) const
Write MIME information to the socket.
PMultiPartList::Decode
bool Decode(const PString &body, const PStringToString &contentInfo)
PCaselessString
This class is a variation of a string that ignores case.
Definition: pstring.h:1708
PMIMEInfo::AddMIME
bool AddMIME(const PString &line)
Add a MIME field given a "name: value" format string.
PMIMEInfo::GetContentType
static PString GetContentType(const PString &fileType)
Look up the file type to MIME content type association dictionary and return the MIME content type st...
PList
This template class maps the PAbstractList to a specific object type.
Definition: lists.h:321
PMultiPartInfo::m_binaryBody
PBYTEArray m_binaryBody
Definition: mime.h:292
PInternetProtocol
A TCP/IP socket for process/application layer high level protocols.
Definition: inetprot.h:62
PBoolean
BOOL PBoolean
Definition: object.h:102
PBYTEArray
Array of unsigned characters.
Definition: array.h:670
PStringOptions
Specialised version of PStringToString to contain a dictionary of options/attributes.
Definition: pstring.h:2845
PMIMEInfo::ContentDispositionTag
static const PCaselessString & ContentDispositionTag()
PMultiPartInfo::m_mime
PMIMEInfo m_mime
Definition: mime.h:290
PMIMEInfo::ContentTransferEncodingTag
static const PCaselessString & ContentTransferEncodingTag()
PMIMEInfo::PrintContents
virtual ostream & PrintContents(ostream &strm) const
Output the contents without the trailing CRLF.
cypher.h
PString
The character string class.
Definition: pstring.h:108
PMIMEInfo::GetComplex
bool GetComplex(const PCaselessString &key, PStringToString &info) const
Definition: mime.h:172
PMIMEInfo::Read
PBoolean Read(PInternetProtocol &socket)
Read MIME information from the socket.
PStringDictionary::SetAt
virtual PBoolean SetAt(const K &key, const PString &str)
Add a new object to the collection.
Definition: pstring.h:2590
PMIMEInfo::AddMIME
bool AddMIME(const PString &fieldName, const PString &fieldValue)
Definition: mime.h:122
PMultiPartList::PMultiPartList
PMultiPartList()
Definition: mime.h:299
PMIMEInfo::GetComplex
bool GetComplex(const PCaselessString &(*key)(), PStringToString &info) const
Definition: mime.h:176
PMIMEInfo::SetAssociation
static void SetAssociation(const PStringToString &allTypes, PBoolean merge=true)
Set an association between a file type and a MIME content type.
PStringOptions::GetString
PString GetString(const char *key, const char *dflt=NULL) const
Get an option value.
Definition: pstring.h:2877
PMIMEInfo::ContentIdTag
static const PCaselessString & ContentIdTag()
PMIMEInfo::SetAssociation
static void SetAssociation(const PString &fileType, const PString &contentType)
Definition: mime.h:254
PMIMEInfo::DecodeMultiPartList
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::PMIMEInfo
PMIMEInfo()
Definition: mime.h:55
PMIMEInfo::TextPlain
static const PCaselessString & TextPlain()
PMultiPartInfo
This object describes the information associated with a multi-part bodies.
Definition: mime.h:286
PMIMEInfo::ReadFrom
virtual void ReadFrom(istream &strm)
Input the contents of the MIME dictionary from the stream.
PMIMEInfo::AsString
PString AsString() const
Return a string presentation of the MIME.
PObject
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PMIMEInfo::ContentDescriptionTag
static const PCaselessString & ContentDescriptionTag()