address.cc
3.64 KB
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
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include <mailutils/cpp/address.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
using namespace mailutils;
//
// Address
//
Address :: Address (const std::string& str)
{
int status = mu_address_create (&addr, str.c_str ());
if (status)
throw Exception ("Address::Address", status);
}
Address :: Address (const mu_address_t addr)
{
if (addr == 0)
throw Exception ("Address::Address", EINVAL);
this->addr = addr;
}
Address :: ~Address ()
{
mu_address_destroy (&addr);
}
bool
Address :: is_group (size_t n)
{
int isgroup;
int status = mu_address_is_group (addr, n, &isgroup);
if (status == EINVAL)
throw Address::EInval ("Address::is_group", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::is_group", status);
return (bool) isgroup;
}
size_t
Address :: get_count ()
{
size_t count;
mu_address_get_count (addr, &count);
return count;
}
std::string
Address :: get_email (size_t n)
{
int status = mu_address_get_email (addr, n, buf, sizeof (buf), 0);
if (status == EINVAL)
throw Address::EInval ("Address::get_email", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::get_email", status);
return std::string (buf);
}
std::string
Address :: get_local_part (size_t n)
{
int status = mu_address_get_local_part (addr, n, buf, sizeof (buf), 0);
if (status == EINVAL)
throw Address::EInval ("Address::get_local_part", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::get_local_part", status);
return std::string (buf);
}
std::string
Address :: get_domain (size_t n)
{
int status = mu_address_get_domain (addr, n, buf, sizeof (buf), 0);
if (status == EINVAL)
throw Address::EInval ("Address::get_domain", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::get_domain", status);
return std::string (buf);
}
std::string
Address :: get_personal (size_t n)
{
int status = mu_address_get_personal (addr, n, buf, sizeof (buf), 0);
if (status == EINVAL)
throw Address::EInval ("Address::get_personal", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::get_personal", status);
return std::string (buf);
}
std::string
Address :: get_comments (size_t n)
{
int status = mu_address_get_comments (addr, n, buf, sizeof (buf), 0);
if (status == EINVAL)
throw Address::EInval ("Address::get_comments", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::get_comments", status);
return std::string (buf);
}
std::string
Address :: get_route (size_t n)
{
int status = mu_address_get_route (addr, n, buf, sizeof (buf), 0);
if (status == EINVAL)
throw Address::EInval ("Address::get_route", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::get_route", status);
return std::string (buf);
}