Commit d0e8c315 d0e8c315c1b5e66abfad618848da4e3fe2dc5536 by Sergey Poznyakoff

(mu_address_set_personal)

(mu_address_set_comments): New functions
1 parent 4bacbfc2
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2005 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000, 2005, 2006 Free Software Foundation, Inc.
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 5 modify it under the terms of the GNU Lesser General Public
...@@ -71,6 +71,13 @@ extern int mu_address_contains_email (mu_address_t addr, const char *email); ...@@ -71,6 +71,13 @@ extern int mu_address_contains_email (mu_address_t addr, const char *email);
71 extern int mu_address_union (mu_address_t *a, mu_address_t b); 71 extern int mu_address_union (mu_address_t *a, mu_address_t b);
72 72
73 extern size_t mu_address_format_string (mu_address_t addr, char *buf, size_t buflen); 73 extern size_t mu_address_format_string (mu_address_t addr, char *buf, size_t buflen);
74
75 /* The following setters are not entirely orthogonal to their _get_
76 counterparts. Only personal and comments parts can be set */
77 extern int mu_address_set_personal (mu_address_t addr, size_t no,
78 const char *buf);
79 extern int mu_address_set_comments (mu_address_t addr, size_t no,
80 const char *buf);
74 81
75 #ifdef __cplusplus 82 #ifdef __cplusplus
76 } 83 }
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2005 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000, 2001, 2005, 2006 Free Software Foundation, Inc.
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 5 modify it under the terms of the GNU Lesser General Public
...@@ -214,7 +214,7 @@ mu_address_get_nth (mu_address_t addr, size_t no, mu_address_t *pret) ...@@ -214,7 +214,7 @@ mu_address_get_nth (mu_address_t addr, size_t no, mu_address_t *pret)
214 214
215 int 215 int
216 mu_address_get_personal (mu_address_t addr, size_t no, char *buf, size_t len, 216 mu_address_get_personal (mu_address_t addr, size_t no, char *buf, size_t len,
217 size_t * n) 217 size_t * n)
218 { 218 {
219 size_t i; 219 size_t i;
220 mu_address_t subaddr; 220 mu_address_t subaddr;
...@@ -233,8 +233,31 @@ mu_address_get_personal (mu_address_t addr, size_t no, char *buf, size_t len, ...@@ -233,8 +233,31 @@ mu_address_get_personal (mu_address_t addr, size_t no, char *buf, size_t len,
233 } 233 }
234 234
235 int 235 int
236 mu_address_set_personal (mu_address_t addr, size_t no, const char *buf)
237 {
238 char *s;
239 mu_address_t subaddr;
240
241 if (addr == NULL)
242 return EINVAL;
243
244 subaddr = _address_get_nth (addr, no);
245 if (!subaddr)
246 return MU_ERR_NOENT;
247
248 s = strdup (buf);
249 if (!s)
250 return errno;
251
252 free (subaddr->personal);
253 subaddr->personal = s;
254
255 return 0;
256 }
257
258 int
236 mu_address_get_comments (mu_address_t addr, size_t no, char *buf, size_t len, 259 mu_address_get_comments (mu_address_t addr, size_t no, char *buf, size_t len,
237 size_t * n) 260 size_t * n)
238 { 261 {
239 size_t i; 262 size_t i;
240 mu_address_t subaddr; 263 mu_address_t subaddr;
...@@ -253,8 +276,31 @@ mu_address_get_comments (mu_address_t addr, size_t no, char *buf, size_t len, ...@@ -253,8 +276,31 @@ mu_address_get_comments (mu_address_t addr, size_t no, char *buf, size_t len,
253 } 276 }
254 277
255 int 278 int
279 mu_address_set_comments (mu_address_t addr, size_t no, const char *buf)
280 {
281 char *s;
282 mu_address_t subaddr;
283
284 if (addr == NULL)
285 return EINVAL;
286
287 subaddr = _address_get_nth (addr, no);
288 if (!subaddr)
289 return MU_ERR_NOENT;
290
291 s = strdup (buf);
292 if (!s)
293 return errno;
294
295 free (subaddr->comments);
296 subaddr->comments = s;
297
298 return 0;
299 }
300
301 int
256 mu_address_get_email (mu_address_t addr, size_t no, char *buf, size_t len, 302 mu_address_get_email (mu_address_t addr, size_t no, char *buf, size_t len,
257 size_t * n) 303 size_t * n)
258 { 304 {
259 size_t i; 305 size_t i;
260 mu_address_t subaddr; 306 mu_address_t subaddr;
...@@ -463,7 +509,7 @@ mu_address_aget_domain (mu_address_t addr, size_t no, char **buf) ...@@ -463,7 +509,7 @@ mu_address_aget_domain (mu_address_t addr, size_t no, char **buf)
463 509
464 int 510 int
465 mu_address_get_local_part (mu_address_t addr, size_t no, char *buf, size_t len, 511 mu_address_get_local_part (mu_address_t addr, size_t no, char *buf, size_t len,
466 size_t * n) 512 size_t * n)
467 { 513 {
468 size_t i; 514 size_t i;
469 mu_address_t subaddr; 515 mu_address_t subaddr;
...@@ -483,7 +529,7 @@ mu_address_get_local_part (mu_address_t addr, size_t no, char *buf, size_t len, ...@@ -483,7 +529,7 @@ mu_address_get_local_part (mu_address_t addr, size_t no, char *buf, size_t len,
483 529
484 int 530 int
485 mu_address_get_domain (mu_address_t addr, size_t no, char *buf, size_t len, 531 mu_address_get_domain (mu_address_t addr, size_t no, char *buf, size_t len,
486 size_t * n) 532 size_t * n)
487 { 533 {
488 size_t i; 534 size_t i;
489 mu_address_t subaddr; 535 mu_address_t subaddr;
...@@ -503,7 +549,7 @@ mu_address_get_domain (mu_address_t addr, size_t no, char *buf, size_t len, ...@@ -503,7 +549,7 @@ mu_address_get_domain (mu_address_t addr, size_t no, char *buf, size_t len,
503 549
504 int 550 int
505 mu_address_get_route (mu_address_t addr, size_t no, char *buf, size_t len, 551 mu_address_get_route (mu_address_t addr, size_t no, char *buf, size_t len,
506 size_t * n) 552 size_t * n)
507 { 553 {
508 size_t i; 554 size_t i;
509 mu_address_t subaddr; 555 mu_address_t subaddr;
......