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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
/* $Id: headers.H,v 1.3 2004/06/23 00:55:01 mrsam Exp $
**
** Copyright 2004, Double Precision Inc.
**
** See COPYING for distribution information.
*/
#ifndef libmail_header_H
#define libmail_header_H
///////////////////////////////////////////////////////////////////////////
//
// Helper classes for parsing headers.
#include <list>
#include <string>
#include <vector>
#include "structure.H"
#include "rfcaddr.H"
#include "namespace.H"
LIBMAIL_START
class emailAddress;
//
// Superclass of all headers
//
class Header {
protected:
std::string wrap(std::string) const;
class listitem;
public:
class plain;
class encoded;
class addresslist;
class mime;
class list;
std::string name; // Header name, without the colon
Header(std::string nameArg) : name(nameArg) {}
virtual ~Header();
Header(const Header &); // UNDEFINED
Header &operator=(const Header &); // UNDEFINED
virtual std::string toString() const=0; // Convert to string format.
virtual Header *clone() const=0; // Clone myself
};
//
// An unstructured header, 7-bit only.
//
class Header::plain : public Header {
std::string text;
public:
plain(std::string name, std::string textArg)
: Header(name), text(textArg) {}
~plain();
std::string toString() const;
mail::Header *clone() const;
};
//
// An unstructured header, MIME-encoded.
//
class Header::encoded : public Header::plain {
static std::string encode(std::string, std::string, std::string);
public:
encoded(std::string name,
std::string text, std::string charset,
std::string lang="");
~encoded();
};
//
// A header containing a list of addresses.
//
class Header::addresslist : public Header {
public:
std::vector<mail::emailAddress> addresses;
addresslist(std::string name);
addresslist(std::string name,
const std::vector<mail::emailAddress> &addressesArg);
~addresslist();
addresslist &operator()(std::string name, std::string addr)
{
addresses.push_back(mail::emailAddress(name, addr));
return *this;
}
addresslist &operator()(const mail::emailAddress &a)
{
addresses.push_back(a);
return *this;
}
std::string toString() const;
mail::Header *clone() const;
};
//
// A MIME header, such as Content-Type: or Content-Description:
//
class Header::mime : public Header {
public:
std::string value;
mimestruct::parameterList parameters;
typedef mimestruct::parameterList::iterator parameter_iterator;
typedef mimestruct::parameterList::const_iterator const_parameter_iterator;
mime(std::string name);
mime(std::string name, std::string value);
static mime fromString(std::string);
private:
static void cb_type(const char *, void *);
static void cb_param(const char *, const char *, void *);
public:
~mime();
std::string toString() const;
mime &operator()(std::string name,
std::string value)
{
parameters.set_simple(name, value);
return *this;
}
mime &operator()(std::string name,
std::string value,
std::string charset,
std::string language="")
{
parameters.set(name, value, charset, language);
return *this;
}
parameter_iterator begin() { return parameters.begin(); }
parameter_iterator end() { return parameters.end(); }
const_parameter_iterator begin() const
{
return parameters.begin();
}
const_parameter_iterator end() const
{
return parameters.end();
}
mail::Header *clone() const;
};
//
// Helper class for a list of headers. Header::listitem wraps around a
// Header superclass, and pretends to be one.
//
class Header::listitem {
Header *h;
public:
listitem(const Header &);
~listitem();
listitem &operator=(const Header &);
operator Header &() { return *h; }
operator const Header &() const { return *h; }
};
//
// A list of headers is just a subclass of a list<Header::listitem> which
// defines a convenient string operator that returns the string representation
// of this list of headers
//
class Header::list : public std::list<Header::listitem> {
public:
list();
~list();
operator std::string() const;
Header::list &operator<<(const Header &h)
{
push_back(h);
return *this;
}
};
LIBMAIL_END
#endif
|