1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
/* $Id: structure.H,v 1.7 2005/06/17 02:05:58 mrsam Exp $
**
** Copyright 2002-2005, Double Precision Inc.
**
** See COPYING for distribution information.
*/
#ifndef libmail_structure_H
#define libmail_structure_H
#include "libmail_config.h"
#include <string>
#include <vector>
#include <map>
#include "namespace.H"
#include "misc.H"
struct unicode_info;
LIBMAIL_START
class envelope;
class xenvelope;
///////////////////////////////////////////////////////////////////////////
//
// The structure of a message is described by a tree of mail::mimestruct
// objects. Each mail::mimestruct objects represents a MIME section in the
// message, and may contain pointers to mail::mimestruct objects for content
// sections if the MIME section is a multipart section.
class mimestruct {
public:
// The Content-Type: and Content-Disposition: headers have an
// optional parameter=value; list, which is parsed into a hash.
//
// The get() method fetches the parameter. It's a pretty smart get()
// method. If a character set is provided, the parameter value is
// mapped to the specified character set. Additionally, the get()
// method automatically handles RFC 2231-encoded attributes.
// Ain't that cool?
class parameterList {
std::map<std::string, std::string> param_map;
public:
typedef std::map<std::string, std::string>::iterator iterator;
typedef std::map<std::string, std::string>::const_iterator
const_iterator;
iterator begin() { return param_map.begin(); }
iterator end() { return param_map.end(); }
const_iterator begin() const { return param_map.begin(); }
const_iterator end() const { return param_map.end(); }
parameterList();
~parameterList();
void set_simple(std::string name, std::string value)
{
mail::upper(name);
param_map.insert(std::make_pair(name, value));
}
void erase(std::string name)
{
mail::upper(name);
iterator p=param_map.find(name);
if (p != end())
param_map.erase(p);
}
void set(std::string name, std::string value,
std::string charset,
std::string language="");
bool exists(std::string name) const;
std::string get(std::string name,
const struct unicode_info *info=NULL) const;
std::string toString(std::string type) const;
// Create a header from "type", plus these parameters
};
std::string mime_id; // An opaque identifier of this MIME section.
std::string type, subtype; // text, plain
bool messagerfc822() const
{
return type == "MESSAGE" && subtype == "RFC822";
}
bool multipartsigned() const
{
return type == "MULTIPART" && subtype == "SIGNED";
}
bool multipartencrypted() const
{
return type == "MULTIPART" && subtype == "ENCRYPTED";
}
parameterList type_parameters;
// <charset, iso-8859-1>
std::string content_id;
std::string content_description;
std::string content_transfer_encoding;
size_t content_size;
size_t content_lines;
std::string content_md5;
std::string content_language;
std::string content_disposition;
parameterList content_disposition_parameters;
mimestruct();
~mimestruct();
// Copy constructors, and assignment operators, are fully functional.
mimestruct(const mimestruct &cpy);
mimestruct &operator=(const mimestruct &cpy);
private:
mail::envelope *message_rfc822_envelope;
std::vector<mimestruct *> children;
mimestruct *parent;
void destroy();
public:
// MESSAGE/RFC822 content also has an associated mail::envelope
// object. getEnvelope() automatically creates this object,
// which is automatically destroyed by the destructor
class mail::envelope &getEnvelope();
const class mail::envelope &getEnvelope() const
{
return *message_rfc822_envelope;
}
mimestruct *addChild();
size_t getNumChildren() const { return children.size(); }
const mimestruct *getChild(size_t n)
const { return children[n]; }
const mimestruct *getParent() const { return parent; }
mimestruct *getChild(size_t n) { return children[n]; }
mimestruct *getParent() { return parent; }
mimestruct *find(std::string mime_idArg)
{
if (mime_idArg == mime_id)
return this;
std::vector<mimestruct *>::iterator b=children.begin(),
e=children.end();
while (b != e)
{
mimestruct *p= (*b)->find(mime_idArg);
++b;
if (p)
return p;
}
return NULL;
}
};
LIBMAIL_END
#endif
|