mu_address.c
4.39 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
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
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "mu_scm.h"
typedef int (*address_get_fp) __P((address_t, size_t, char *, size_t, size_t *));
static SCM
_get_address_part (const char *func_name, address_get_fp fun,
SCM ADDRESS, SCM NUM)
{
address_t addr;
int length;
char *str;
SCM ret;
int num;
SCM_ASSERT (SCM_NIMP (ADDRESS) && SCM_STRINGP (ADDRESS),
ADDRESS, SCM_ARG1, func_name);
if (!SCM_UNBNDP (NUM))
{
SCM_ASSERT (SCM_IMP (NUM) && SCM_INUMP (NUM),
NUM, SCM_ARG1, func_name);
num = SCM_INUM (NUM);
}
else
num = 1;
str = SCM_STRING_CHARS (ADDRESS);
length = strlen (str);
if (length == 0)
return scm_makfrom0str("");
if (address_create (&addr, SCM_STRING_CHARS (ADDRESS)))
return SCM_BOOL_F;
str = malloc (length + 1);
if (!str)
{
address_destroy (&addr);
return SCM_BOOL_F;
}
if ((*fun) (addr, num, str, length + 1, NULL) == 0)
ret = scm_makfrom0str (str);
else
ret = SCM_BOOL_F;
address_destroy (&addr);
free (str);
return ret;
}
SCM_DEFINE (mu_address_get_personal, "mu-address-get-personal", 1, 1, 0,
(SCM ADDRESS, SCM NUM),
"Return personal part of an email address.\n")
#define FUNC_NAME s_mu_address_get_personal
{
return _get_address_part (FUNC_NAME,
address_get_personal, ADDRESS, NUM);
}
#undef FUNC_NAME
SCM_DEFINE (mu_address_get_comments, "mu-address-get-comments", 1, 1, 0,
(SCM ADDRESS, SCM NUM),
"Return comment part of an email address.\n")
#define FUNC_NAME s_mu_address_get_comments
{
return _get_address_part (FUNC_NAME,
address_get_comments, ADDRESS, NUM);
}
#undef FUNC_NAME
SCM_DEFINE (mu_address_get_email, "mu-address-get-email", 1, 1, 0,
(SCM ADDRESS, SCM NUM),
"Return email part of an email address.\n")
#define FUNC_NAME s_mu_address_get_email
{
return _get_address_part (FUNC_NAME,
address_get_email, ADDRESS, NUM);
}
#undef FUNC_NAME
SCM_DEFINE (mu_address_get_domain, "mu-address-get-domain", 1, 1, 0,
(SCM ADDRESS, SCM NUM),
"Return domain part of an email address.\n")
#define FUNC_NAME s_mu_address_get_domain
{
return _get_address_part (FUNC_NAME,
address_get_domain, ADDRESS, NUM);
}
#undef FUNC_NAME
SCM_DEFINE (mu_address_get_local, "mu-address-get-local", 1, 1, 0,
(SCM ADDRESS, SCM NUM),
"Return local part of an email address.\n")
#define FUNC_NAME s_mu_address_get_local
{
return _get_address_part (FUNC_NAME,
address_get_local_part, ADDRESS, NUM);
}
#undef FUNC_NAME
SCM_DEFINE (mu_address_get_count, "mu-address-get-count", 1, 0, 0,
(SCM ADDRESS),
"Return number of parts in email address.\n")
#define FUNC_NAME s_mu_address_get_count
{
address_t addr;
size_t count = 0;
SCM_ASSERT (SCM_NIMP (ADDRESS) && SCM_STRINGP (ADDRESS),
ADDRESS, SCM_ARG1, FUNC_NAME);
if (address_create (&addr, SCM_STRING_CHARS (ADDRESS)))
return SCM_MAKINUM(0);
address_get_count (addr, &count);
address_destroy (&addr);
return scm_makenum (count);
}
#undef FUNC_NAME
SCM_DEFINE (mu_username_to_email, "mu-username->email", 0, 1, 0,
(SCM NAME),
"Deduce the email from the username. If NAME is omitted, current username\n"
"is assumed\n")
#define FUNC_NAME s_mu_username_to_email
{
char *name;
char *email;
SCM ret;
if (SCM_UNBNDP (NAME))
name = NULL;
else {
SCM_ASSERT (SCM_NIMP (NAME) && SCM_STRINGP (NAME),
NAME, SCM_ARG1, FUNC_NAME);
name = SCM_STRING_CHARS (NAME);
}
email = mu_get_user_email (name);
if (!email)
return SCM_BOOL_F;
ret = scm_makfrom0str (email);
free (email);
return ret;
}
#undef FUNC_NAME
void
mu_scm_address_init ()
{
#include <mu_address.x>
}