37 |
|
|
38 |
#include <mailer0.h> |
#include <mailer0.h> |
39 |
|
|
40 |
static |
static char *mailer_url_default; |
|
char* |
|
|
mailer_url_default; |
|
41 |
|
|
42 |
/* FIXME: I'd like to check that the URL is valid, but that requires that the |
/* FIXME: I'd like to check that the URL is valid, but that requires that the |
43 |
mailers already be registered! */ |
mailers already be registered! */ |
44 |
int |
int |
45 |
mailer_set_url_default(const char* url) |
mailer_set_url_default (const char *url) |
46 |
{ |
{ |
47 |
char* n = NULL; |
char *n = NULL; |
48 |
|
|
49 |
if(!url) |
if (!url) |
50 |
return EINVAL; |
return EINVAL; |
51 |
|
|
52 |
if((n = strdup(url)) == NULL) |
if ((n = strdup (url)) == NULL) |
53 |
return ENOMEM; |
return ENOMEM; |
54 |
|
|
55 |
if(mailer_url_default) |
if (mailer_url_default) |
56 |
free(mailer_url_default); |
free (mailer_url_default); |
57 |
|
|
58 |
mailer_url_default = n; |
mailer_url_default = n; |
59 |
|
|
61 |
} |
} |
62 |
|
|
63 |
int |
int |
64 |
mailer_get_url_default(const char** url) |
mailer_get_url_default (const char **url) |
65 |
{ |
{ |
66 |
if(!url) |
if (!url) |
67 |
return EINVAL; |
return EINVAL; |
68 |
|
|
69 |
if(mailer_url_default) |
if (mailer_url_default) |
70 |
*url = mailer_url_default; |
*url = mailer_url_default; |
71 |
else |
else |
72 |
*url = MAILER_URL_DEFAULT; |
*url = MAILER_URL_DEFAULT; |
151 |
} |
} |
152 |
|
|
153 |
void |
void |
154 |
mailer_destroy (mailer_t *pmailer) |
mailer_destroy (mailer_t * pmailer) |
155 |
{ |
{ |
156 |
if (pmailer && *pmailer) |
if (pmailer && *pmailer) |
157 |
{ |
{ |
164 |
observable_destroy (&(mailer->observable), mailer); |
observable_destroy (&(mailer->observable), mailer); |
165 |
} |
} |
166 |
|
|
167 |
/* Call the object destructor. */ |
/* Call the object destructor. */ |
168 |
if (mailer->_destroy) |
if (mailer->_destroy) |
169 |
mailer->_destroy (mailer); |
mailer->_destroy (mailer); |
170 |
|
|
178 |
} |
} |
179 |
|
|
180 |
if (mailer->url) |
if (mailer->url) |
181 |
url_destroy (&(mailer->url)); |
url_destroy (&(mailer->url)); |
182 |
|
|
183 |
if (mailer->debug) |
if (mailer->debug) |
184 |
mu_debug_destroy (&(mailer->debug), mailer); |
mu_debug_destroy (&(mailer->debug), mailer); |
185 |
|
|
186 |
if (mailer->property) |
if (mailer->property) |
187 |
property_destroy (&(mailer->property), mailer); |
property_destroy (&(mailer->property), mailer); |
188 |
|
|
189 |
free (mailer); |
free (mailer); |
190 |
*pmailer = NULL; |
*pmailer = NULL; |
214 |
|
|
215 |
|
|
216 |
int |
int |
217 |
mailer_check_from(address_t from) |
mailer_check_from (address_t from) |
218 |
{ |
{ |
219 |
size_t n = 0; |
size_t n = 0; |
220 |
|
|
221 |
if(!from) |
if (!from) |
222 |
return EINVAL; |
return EINVAL; |
223 |
|
|
224 |
if(address_get_count(from, &n) || n != 1) |
if (address_get_count (from, &n) || n != 1) |
225 |
return MU_ERR_MAILER_BAD_FROM; |
return MU_ERR_MAILER_BAD_FROM; |
226 |
|
|
227 |
if(address_get_email_count(from, &n) || n == 0) |
if (address_get_email_count (from, &n) || n == 0) |
228 |
return MU_ERR_MAILER_BAD_FROM; |
return MU_ERR_MAILER_BAD_FROM; |
229 |
|
|
230 |
return 0; |
return 0; |
231 |
} |
} |
232 |
|
|
233 |
int |
int |
234 |
mailer_check_to(address_t to) |
mailer_check_to (address_t to) |
235 |
{ |
{ |
236 |
size_t count = 0; |
size_t count = 0; |
237 |
size_t emails = 0; |
size_t emails = 0; |
238 |
size_t groups = 0; |
size_t groups = 0; |
239 |
|
|
240 |
if(!to) |
if (!to) |
241 |
return EINVAL; |
return EINVAL; |
242 |
|
|
243 |
if(address_get_count(to, &count)) |
if (address_get_count (to, &count)) |
244 |
return MU_ERR_MAILER_BAD_TO; |
return MU_ERR_MAILER_BAD_TO; |
245 |
|
|
246 |
if(address_get_email_count(to, &emails)) |
if (address_get_email_count (to, &emails)) |
247 |
return MU_ERR_MAILER_BAD_TO; |
return MU_ERR_MAILER_BAD_TO; |
248 |
|
|
249 |
if(emails == 0) |
if (emails == 0) |
250 |
return MU_ERR_MAILER_NO_RCPT_TO; |
return MU_ERR_MAILER_NO_RCPT_TO; |
251 |
|
|
252 |
if(address_get_group_count(to, &groups)) |
if (address_get_group_count (to, &groups)) |
253 |
return MU_ERR_MAILER_BAD_TO; |
return MU_ERR_MAILER_BAD_TO; |
254 |
|
|
255 |
if(count - emails - groups != 0) |
if (count - emails - groups != 0) |
256 |
/* then not everything is a group or an email address */ |
/* then not everything is a group or an email address */ |
257 |
return MU_ERR_MAILER_BAD_TO; |
return MU_ERR_MAILER_BAD_TO; |
258 |
|
|
270 |
/* Common API checking. */ |
/* Common API checking. */ |
271 |
|
|
272 |
/* FIXME: this should be done in the concrete APIs, sendmail doesn't |
/* FIXME: this should be done in the concrete APIs, sendmail doesn't |
273 |
yet, though, so do it here. */ |
yet, though, so do it here. */ |
274 |
if (from) |
if (from) |
275 |
{ |
{ |
276 |
if ((status = mailer_check_from (from)) != 0) |
if ((status = mailer_check_from (from)) != 0) |
296 |
} |
} |
297 |
|
|
298 |
int |
int |
299 |
mailer_get_stream (mailer_t mailer, stream_t *pstream) |
mailer_get_stream (mailer_t mailer, stream_t * pstream) |
300 |
{ |
{ |
301 |
if (mailer == NULL || pstream == NULL) |
if (mailer == NULL || pstream == NULL) |
302 |
return EINVAL; |
return EINVAL; |
306 |
} |
} |
307 |
|
|
308 |
int |
int |
309 |
mailer_get_observable (mailer_t mailer, observable_t *pobservable) |
mailer_get_observable (mailer_t mailer, observable_t * pobservable) |
310 |
{ |
{ |
311 |
/* FIXME: I should check for invalid types */ |
/* FIXME: I should check for invalid types */ |
312 |
if (mailer == NULL || pobservable == NULL) |
if (mailer == NULL || pobservable == NULL) |
323 |
} |
} |
324 |
|
|
325 |
int |
int |
326 |
mailer_get_property (mailer_t mailer, property_t *pproperty) |
mailer_get_property (mailer_t mailer, property_t * pproperty) |
327 |
{ |
{ |
328 |
if (mailer == NULL || pproperty == NULL) |
if (mailer == NULL || pproperty == NULL) |
329 |
return EINVAL; |
return EINVAL; |
331 |
{ |
{ |
332 |
int status = property_create (&(mailer->property), mailer); |
int status = property_create (&(mailer->property), mailer); |
333 |
if (status != 0) |
if (status != 0) |
334 |
return status; |
return status; |
335 |
} |
} |
336 |
*pproperty = mailer->property; |
*pproperty = mailer->property; |
337 |
return 0; |
return 0; |
348 |
} |
} |
349 |
|
|
350 |
int |
int |
351 |
mailer_get_debug (mailer_t mailer, mu_debug_t *pdebug) |
mailer_get_debug (mailer_t mailer, mu_debug_t * pdebug) |
352 |
{ |
{ |
353 |
if (mailer == NULL || pdebug == NULL) |
if (mailer == NULL || pdebug == NULL) |
354 |
return EINVAL; |
return EINVAL; |
363 |
} |
} |
364 |
|
|
365 |
int |
int |
366 |
mailer_get_url (mailer_t mailer, url_t *purl) |
mailer_get_url (mailer_t mailer, url_t * purl) |
367 |
{ |
{ |
368 |
if (!mailer || !purl) |
if (!mailer || !purl) |
369 |
return EINVAL; |
return EINVAL; |