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
|
/* $Id: rfcaddr.H,v 1.5 2004/05/30 02:43:00 mrsam Exp $
**
** Copyright 2002, Double Precision Inc.
**
** See COPYING for distribution information.
*/
#ifndef libmail_rfcaddr_h
#define libmail_rfcaddr_h
#include "libmail_config.h"
#include "namespace.H"
#include <stdlib.h>
#include <vector>
#include <string>
//
// An RFC 2822 address, a name and user@domain.
//
LIBMAIL_START
class address {
protected:
std::string name;
std::string addr;
public:
std::string getName() const { return name; }
std::string getAddr() const { return addr; }
virtual void setName(std::string s);
void setAddr(std::string a) { addr=a; }
// If addr.size() == 0 this is the obsolete rfc 822
// group list notation, and name is either ";" or "name:"
address(std::string n, std::string a);
virtual ~address();
// Convert myself to "name" <addr> format.
std::string toString() const;
//
// Create an RFC 2822 address header, from a vector of addresss.
//
template<class T>
static std::string toString(std::string hdr, // Name:
const std::vector<T> &h,
size_t w=76); // Max length of lines.
//
// Create a vector of addresses from a string
//
template<class T> static bool fromString(std::string addresses,
std::vector<T> &h,
size_t &errIndex);
// Addresses are appended to h
// Returns false if memory allocation failed or addresses is
// syntactically invalid. errIndex points where in addresses the
// syntax error is (or is string::npos if memory allocation failed)
std::string getCanonAddress() const;
// Return addr with domain portion converted to lowercase
bool operator==(const address &) const;
// Compare the addr portions only, ignoring domain case
bool operator!=(const address &a) const
{
return !operator==(a);
}
};
// INPROGRESS: slowly migrate to automatic MIME encoding of names.
//
// Subclass address, override getName() and setName() to use a MIME-encoded
// name, using mail::appcharset.
//
// emailAddress transparently casts to mail::address, importing/exporting
// the name in its encoded form.
class emailAddress : public address {
std::string encodedName;
void decode();
public:
emailAddress(std::string n, std::string a);
emailAddress(const address &);
virtual ~emailAddress();
std::string getAddrName() const { return encodedName; }
void setAddrName(std::string s);
virtual void setName(std::string s);
bool operator==(const address &a) const
{
return mail::address::operator==(a);
}
bool operator!=(const address &a) const
{
return !operator==(a);
}
};
LIBMAIL_END
#endif
|