Bincimap 2.0.16
Easy Imapping
Loading...
Searching...
No Matches
address.cc
Go to the documentation of this file.
1
7#include "address.h"
8#include "convert.h"
9#include <string>
10
11using namespace ::std;
12using namespace Binc;
13
14//------------------------------------------------------------------------
15Address::Address(const string &name, const string &addr)
16{
17 string::size_type pos = addr.find('@');
18 this->name = name;
19 if (pos != string::npos) {
20 this->local = addr.substr(0, pos);
21 this->host = addr.substr(pos + 1);
22 } else this->local = addr;
23}
24
25//------------------------------------------------------------------------
26Address::Address(const string &wholeaddress)
27{
28 string::size_type start = wholeaddress.find('<');
29 string addr;
30 if (start != string::npos)
31 addr = wholeaddress.substr(start + 1);
32 else
33 addr = wholeaddress;
34
35 trim(addr, "<>");
36
37 if (start != string::npos)
38 name = wholeaddress.substr(0, start);
39 else
40 name = "";
41 trim(name);
42 trim(name, "\"");
43
44 start = addr.find('@');
45 local = addr.substr(0, start);
46 host = addr.substr(start + 1);
47
48 trim(local);
49 trim(host);
50 trim(name);
51}
52
53//------------------------------------------------------------------------
54string Address::toParenList(void) const
55{
56 string tmp = "(";
57 tmp += name == "" ? "NIL" : toImapString(name);
58 tmp += " NIL ";
59 tmp += local == "" ? "\"\"" : toImapString(local);
60 tmp += " ";
61 tmp += host == "" ? "\"\"" : toImapString(host);
62 tmp += ")";
63
64 return tmp;
65}
Declaration of the Address class.
std::string toParenList(void) const
Definition: address.cc:54
std::string host
Definition: address.h:18
std::string local
Definition: address.h:17
Address(const std::string &name, const std::string &addr)
std::string name
Definition: address.h:16
Declaration of miscellaneous convertion functions.
Definition: bincimapd.cc:9
std::string toImapString(const std::string &s_in)
Definition: convert.h:103
void trim(std::string &s_in, const std::string &chars=" \t\r\n")
Definition: convert.h:137