message_t is a general structure that encapsulate envelope_t, header_t and
body_t etc ... Accessing member of the structure is thread-safe, a monitor/lock is use the downside the lock is grab for each modification.
Showing
20 changed files
with
301 additions
and
78 deletions
1 | @code{#include <mailutils/message.h>} | 1 | @code{#include <mailutils/message.h>} |
2 | 2 | ||
3 | The @code{message_t} object is a convenient way to manipulate messages. It | 3 | The @code{message_t} object is a convenient way to manipulate messages. It |
4 | encapsulates the @code{header_t}, the @code{attribute_t} and the @code{body_t}. | 4 | encapsulates the @code{envelope_t}, the @code{header_t} and the @code{body_t}. |
5 | 5 | ||
6 | @example | 6 | @example |
7 | @group | 7 | @group |
8 | __________ message_t | 8 | __________ message_t |
9 | (message[1]) +------>+-----------------------+ | 9 | (message[1]) +------>+-----------------------+ |
10 | ---------- | | header_t | | 10 | ---------- | | envelope_t | |
11 | (message[2]) | |-----------------------| | 11 | (message[2]) | |-----------------------| |
12 | ---------- | | attribute_t | | 12 | ---------- | | header_t | |
13 | (message[3])--------+ |-----------------------| | 13 | (message[3])--------+ |-----------------------| |
14 | ---------- | stream_t | | ||
15 | (message[n]) |-----------------------| | ||
16 | ---------- | body_t | | 14 | ---------- | body_t | |
15 | (message[n]) |-----------------------| | ||
16 | ---------- | attribute_t | | ||
17 | |-----------------------| | 17 | |-----------------------| |
18 | | from | | 18 | | stream_t | |
19 | |-----------------------| | 19 | |-----------------------| |
20 | | size | | 20 | | size | |
21 | |-----------------------| | 21 | |-----------------------| |
... | @@ -78,10 +78,10 @@ Return non-zero value if message is multi-part. | ... | @@ -78,10 +78,10 @@ Return non-zero value if message is multi-part. |
78 | @deftypefun int message_set_attribute (message_t @var{msg}, attribute_t @var{attribute}, void *owner) | 78 | @deftypefun int message_set_attribute (message_t @var{msg}, attribute_t @var{attribute}, void *owner) |
79 | @end deftypefun | 79 | @end deftypefun |
80 | 80 | ||
81 | @deftypefun int message_get_from (message_t @var{msg}, char *buffer, size_t len, size_t *n) | 81 | @deftypefun int message_get_envelope (message_t @var{msg}, envelope_t *penvelope) |
82 | @end deftypefun | 82 | @end deftypefun |
83 | 83 | ||
84 | @deftypefun int message_set_from (message_t @var{msg}, int (*@var{_from}) (message_t, char *, size_t, size_t *), void *@var{owner}) | 84 | @deftypefun int message_set_envelope (message_t @var{msg}, envelope_t envelope, void *@var{owner}) |
85 | @end deftypefun | 85 | @end deftypefun |
86 | 86 | ||
87 | @deftypefun int message_get_uidl (message_t @var{msg}, char *@var{buffer}, size_t @var{buflen}, size_t *@var{pwriten}) | 87 | @deftypefun int message_get_uidl (message_t @var{msg}, char *@var{buffer}, size_t @var{buflen}, size_t *@var{pwriten}) | ... | ... |
... | @@ -5,6 +5,7 @@ pkginclude_HEADERS = \ | ... | @@ -5,6 +5,7 @@ pkginclude_HEADERS = \ |
5 | auth.h \ | 5 | auth.h \ |
6 | body.h \ | 6 | body.h \ |
7 | debug.h \ | 7 | debug.h \ |
8 | envelope.h \ | ||
8 | folder.h \ | 9 | folder.h \ |
9 | header.h \ | 10 | header.h \ |
10 | iterator.h \ | 11 | iterator.h \ |
... | @@ -14,6 +15,7 @@ pkginclude_HEADERS = \ | ... | @@ -14,6 +15,7 @@ pkginclude_HEADERS = \ |
14 | mailer.h \ | 15 | mailer.h \ |
15 | message.h \ | 16 | message.h \ |
16 | mime.h \ | 17 | mime.h \ |
18 | monitor.h \ | ||
17 | observer.h \ | 19 | observer.h \ |
18 | registrar.h \ | 20 | registrar.h \ |
19 | stream.h \ | 21 | stream.h \ | ... | ... |
include/mailutils/envelope.h
0 → 100644
1 | /* GNU mailutils - a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Library Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | #ifndef _MAILUTILS_ENVELOPE_H | ||
19 | # define _MAILUTILS_ENVELOPE_H | ||
20 | |||
21 | #include <sys/types.h> | ||
22 | |||
23 | #ifdef __cplusplus | ||
24 | extern "C" { /*}*/ | ||
25 | #endif | ||
26 | |||
27 | #ifndef __P | ||
28 | # ifdef __STDC__ | ||
29 | # define __P(args) args | ||
30 | # else | ||
31 | # define __P(args) () | ||
32 | # endif | ||
33 | #endif /*__P */ | ||
34 | |||
35 | struct _envelope; | ||
36 | typedef struct _envelope *envelope_t; | ||
37 | |||
38 | int envelope_create (envelope_t *, void *); | ||
39 | void envelope_destroy (envelope_t *, void *); | ||
40 | void * envelope_get_owner (envelope_t); | ||
41 | int envelope_set_from (envelope_t, int (*_from) __P ((envelope_t, char *, size_t, size_t*)), void *); | ||
42 | int envelope_from (envelope_t, char *, size_t, size_t *); | ||
43 | int envelope_set_date (envelope_t, int (*_date) __P ((envelope_t, char *, size_t , size_t *)), void *); | ||
44 | int envelope_date (envelope_t, char *, size_t, size_t *); | ||
45 | |||
46 | #endif /* _MAILUTILS_ENVELOPE_H */ |
... | @@ -53,7 +53,7 @@ extern int folder_close __P ((folder_t)); | ... | @@ -53,7 +53,7 @@ extern int folder_close __P ((folder_t)); |
53 | 53 | ||
54 | extern int folder_delete_mailbox __P ((folder_t, const char *)); | 54 | extern int folder_delete_mailbox __P ((folder_t, const char *)); |
55 | 55 | ||
56 | extern int folder_list __P ((folder_t, list_t *list)); | 56 | extern int folder_list __P ((folder_t, char *vector[][], size_t *)); |
57 | 57 | ||
58 | /* Stream settings. */ | 58 | /* Stream settings. */ |
59 | extern int folder_get_stream __P ((folder_t, stream_t *)); | 59 | extern int folder_get_stream __P ((folder_t, stream_t *)); | ... | ... |
... | @@ -19,11 +19,13 @@ | ... | @@ -19,11 +19,13 @@ |
19 | #define _MAILUTILS_MESSAGE_H | 19 | #define _MAILUTILS_MESSAGE_H |
20 | 20 | ||
21 | #include <sys/types.h> | 21 | #include <sys/types.h> |
22 | #include <mailutils/stream.h> | 22 | #include <mailutils/envelope.h> |
23 | #include <mailutils/header.h> | 23 | #include <mailutils/header.h> |
24 | #include <mailutils/body.h> | 24 | #include <mailutils/body.h> |
25 | #include <mailutils/stream.h> | ||
25 | #include <mailutils/observer.h> | 26 | #include <mailutils/observer.h> |
26 | #include <mailutils/attribute.h> | 27 | #include <mailutils/attribute.h> |
28 | #include <mailutils/monitor.h> | ||
27 | 29 | ||
28 | 30 | ||
29 | #ifndef __P | 31 | #ifndef __P |
... | @@ -53,6 +55,9 @@ extern void * message_get_owner __P ((message_t)); | ... | @@ -53,6 +55,9 @@ extern void * message_get_owner __P ((message_t)); |
53 | extern int message_ref __P ((message_t)); | 55 | extern int message_ref __P ((message_t)); |
54 | #define message_unref(msg) message_destroy (&msg, NULL) | 56 | #define message_unref(msg) message_destroy (&msg, NULL) |
55 | 57 | ||
58 | extern int message_get_envelope __P ((message_t, envelope_t *)); | ||
59 | extern int message_set_envelope __P ((message_t, envelope_t, void *owner)); | ||
60 | |||
56 | extern int message_get_header __P ((message_t, header_t *)); | 61 | extern int message_get_header __P ((message_t, header_t *)); |
57 | extern int message_set_header __P ((message_t, header_t, void *owner)); | 62 | extern int message_set_header __P ((message_t, header_t, void *owner)); |
58 | 63 | ||
... | @@ -81,16 +86,6 @@ extern int message_set_lines __P ((message_t, int (*_lines) | ... | @@ -81,16 +86,6 @@ extern int message_set_lines __P ((message_t, int (*_lines) |
81 | __P ((message_t, size_t *)), | 86 | __P ((message_t, size_t *)), |
82 | void *owner)); | 87 | void *owner)); |
83 | 88 | ||
84 | extern int message_from __P ((message_t, char *, size_t, size_t *)); | ||
85 | extern int message_set_from __P ((message_t, int (*_from) | ||
86 | __P ((message_t, char *, size_t, | ||
87 | size_t *)), void *owner)); | ||
88 | |||
89 | extern int message_received __P ((message_t, char *, size_t, size_t *)); | ||
90 | extern int message_set_received __P ((message_t, int (*_received) | ||
91 | __P ((message_t, char *, size_t, | ||
92 | size_t *)), void *owner)); | ||
93 | |||
94 | extern int message_get_num_parts __P ((message_t, size_t *nparts)); | 89 | extern int message_get_num_parts __P ((message_t, size_t *nparts)); |
95 | extern int message_set_get_num_parts __P ((message_t, int (*_get_num_parts) | 90 | extern int message_set_get_num_parts __P ((message_t, int (*_get_num_parts) |
96 | __P ((message_t, size_t *)), | 91 | __P ((message_t, size_t *)), | ... | ... |
... | @@ -245,7 +245,7 @@ main (int argc, char **argv) | ... | @@ -245,7 +245,7 @@ main (int argc, char **argv) |
245 | { | 245 | { |
246 | int len; | 246 | int len; |
247 | free (command); | 247 | free (command); |
248 | command = readline (prompt->set && prompt->value != NULL ? prompt->value : ""); | 248 | command = readline (prompt->set && prompt->value != NULL ? prompt->value : " "); |
249 | len = strlen (command); | 249 | len = strlen (command); |
250 | while (command[len-1] == '\\') | 250 | while (command[len-1] == '\\') |
251 | { | 251 | { | ... | ... |
... | @@ -19,6 +19,7 @@ auth.c \ | ... | @@ -19,6 +19,7 @@ auth.c \ |
19 | bio.c \ | 19 | bio.c \ |
20 | body.c \ | 20 | body.c \ |
21 | debug.c \ | 21 | debug.c \ |
22 | envelope.c \ | ||
22 | file_stream.c \ | 23 | file_stream.c \ |
23 | folder.c \ | 24 | folder.c \ |
24 | header.c \ | 25 | header.c \ |
... | @@ -35,6 +36,7 @@ mbx_pop.c \ | ... | @@ -35,6 +36,7 @@ mbx_pop.c \ |
35 | message.c \ | 36 | message.c \ |
36 | mime.c \ | 37 | mime.c \ |
37 | misc.c | 38 | misc.c |
39 | monitor.c | ||
38 | observer.c \ | 40 | observer.c \ |
39 | registrar.c \ | 41 | registrar.c \ |
40 | sendmail.c \ | 42 | sendmail.c \ | ... | ... |
mailbox/envelope.c
0 → 100644
1 | /* GNU mailutils - a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Library Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | #include <errno.h> | ||
19 | #include <stdlib.h> | ||
20 | #include <envelope0.h> | ||
21 | |||
22 | int | ||
23 | envelope_create (envelope_t *penvelope, void *owner) | ||
24 | { | ||
25 | envelope_t envelope; | ||
26 | if (penvelope == NULL) | ||
27 | return EINVAL; | ||
28 | envelope = calloc (1, sizeof (*envelope)); | ||
29 | if (envelope == NULL) | ||
30 | return ENOMEM; | ||
31 | envelope->owner = owner; | ||
32 | *penvelope = envelope; | ||
33 | return 0; | ||
34 | } | ||
35 | |||
36 | void | ||
37 | envelope_destroy (envelope_t *penvelope, void *owner) | ||
38 | { | ||
39 | if (penvelope && *penvelope) | ||
40 | { | ||
41 | envelope_t envelope = *penvelope; | ||
42 | if (envelope->owner == owner) | ||
43 | { | ||
44 | if (envelope->_destroy) | ||
45 | envelope->_destroy (envelope); | ||
46 | free (envelope); | ||
47 | } | ||
48 | *penvelope = NULL; | ||
49 | } | ||
50 | } | ||
51 | |||
52 | void * | ||
53 | envelope_get_owner (envelope_t envelope) | ||
54 | { | ||
55 | return (envelope) ? envelope->owner : NULL; | ||
56 | } | ||
57 | |||
58 | int | ||
59 | envelope_set_from (envelope_t envelope, | ||
60 | int (*_from) __P ((envelope_t, char *, size_t, size_t*)), | ||
61 | void *owner) | ||
62 | { | ||
63 | if (envelope == NULL) | ||
64 | return EINVAL; | ||
65 | if (envelope->owner != owner) | ||
66 | return EACCES; | ||
67 | envelope->_from = _from; | ||
68 | return 0; | ||
69 | } | ||
70 | |||
71 | int | ||
72 | envelope_from (envelope_t envelope, char *buf, size_t len, size_t *pnwrite) | ||
73 | { | ||
74 | if (envelope == NULL) | ||
75 | return EINVAL; | ||
76 | if (envelope->_from) | ||
77 | return envelope->_from (envelope, buf, len, pnwrite); | ||
78 | if (buf && len) | ||
79 | *buf = '\0'; | ||
80 | if (pnwrite) | ||
81 | *pnwrite = 0; | ||
82 | return 0; | ||
83 | } | ||
84 | |||
85 | int | ||
86 | envelope_set_date (envelope_t envelope, | ||
87 | int (*_date) __P ((envelope_t, char *, size_t , size_t *)), | ||
88 | void *owner) | ||
89 | { | ||
90 | if (envelope == NULL) | ||
91 | return EINVAL; | ||
92 | if (envelope->owner != owner) | ||
93 | return EACCES; | ||
94 | envelope->_date = _date; | ||
95 | return 0; | ||
96 | } | ||
97 | |||
98 | int | ||
99 | envelope_date (envelope_t envelope, char *buf, size_t len, size_t *pnwrite) | ||
100 | { | ||
101 | if (envelope == NULL) | ||
102 | return EINVAL; | ||
103 | if (envelope->_date) | ||
104 | return envelope->_date (envelope, buf, len, pnwrite); | ||
105 | if (buf && len) | ||
106 | *buf = '\0'; | ||
107 | if (pnwrite) | ||
108 | *pnwrite = 0; | ||
109 | return 0; | ||
110 | } |
... | @@ -165,23 +165,19 @@ folder_destroy (folder_t *pfolder) | ... | @@ -165,23 +165,19 @@ folder_destroy (folder_t *pfolder) |
165 | folder_t folder = *pfolder; | 165 | folder_t folder = *pfolder; |
166 | int destroy_lock = 0; | 166 | int destroy_lock = 0; |
167 | monitor_t monitor = folder->monitor; | 167 | monitor_t monitor = folder->monitor; |
168 | size_t reference; | ||
169 | 168 | ||
170 | monitor_wrlock (monitor); | 169 | monitor_wrlock (monitor); |
171 | #ifdef WITH_PTHREAD | 170 | #ifdef WITH_PTHREAD |
172 | pthread_mutex_lock (&slock); | 171 | pthread_mutex_lock (&slock); |
173 | #endif | 172 | #endif |
174 | { | 173 | folder->ref--; |
175 | folder->ref--; | 174 | /* Remove the folder from the list of known folder. */ |
176 | reference = folder->ref; | 175 | if (folder->ref <= 0) |
177 | /* Remove the folder from the list of known folder. */ | 176 | list_remove (known_folder_list, folder); |
178 | if (reference == 0) | ||
179 | list_remove (known_folder_list, folder); | ||
180 | } | ||
181 | #ifdef WITH_PHTREAD | 177 | #ifdef WITH_PHTREAD |
182 | pthread_mutex_unlock (&slock); | 178 | pthread_mutex_unlock (&slock); |
183 | #endif | 179 | #endif |
184 | if (reference == 0) | 180 | if (folder->ref <= 0) |
185 | { | 181 | { |
186 | monitor_unlock (monitor); | 182 | monitor_unlock (monitor); |
187 | destroy_lock = 1; | 183 | destroy_lock = 1; |
... | @@ -328,13 +324,12 @@ folder_get_debug (folder_t folder, debug_t *pdebug) | ... | @@ -328,13 +324,12 @@ folder_get_debug (folder_t folder, debug_t *pdebug) |
328 | return 0; | 324 | return 0; |
329 | } | 325 | } |
330 | 326 | ||
331 | |||
332 | int | 327 | int |
333 | folder_list (folder_t folder, list_t *plist) | 328 | folder_list (folder_t folder, char *vector[][], size_t *pnum) |
334 | { | 329 | { |
335 | if (folder == NULL || folder->_list == NULL) | 330 | if (folder == NULL || folder->_list == NULL) |
336 | return ENOSYS; | 331 | return ENOSYS; |
337 | return folder->_list (folder, plist); | 332 | return folder->_list (folder, vector, pnum); |
338 | } | 333 | } |
339 | 334 | ||
340 | int | 335 | int |
... | @@ -380,7 +375,7 @@ static int is_known_folder (url_t url, folder_t *pfolder) | ... | @@ -380,7 +375,7 @@ static int is_known_folder (url_t url, folder_t *pfolder) |
380 | static int | 375 | static int |
381 | is_same_scheme (url_t url1, url_t url2) | 376 | is_same_scheme (url_t url1, url_t url2) |
382 | { | 377 | { |
383 | int i = 0, j = 0; | 378 | size_t i = 0, j = 0; |
384 | char *s1, *s2; | 379 | char *s1, *s2; |
385 | int ret = 1; | 380 | int ret = 1; |
386 | 381 | ||
... | @@ -405,7 +400,7 @@ is_same_scheme (url_t url1, url_t url2) | ... | @@ -405,7 +400,7 @@ is_same_scheme (url_t url1, url_t url2) |
405 | static int | 400 | static int |
406 | is_same_user (url_t url1, url_t url2) | 401 | is_same_user (url_t url1, url_t url2) |
407 | { | 402 | { |
408 | int i = 0, j = 0; | 403 | size_t i = 0, j = 0; |
409 | char *s1, *s2; | 404 | char *s1, *s2; |
410 | int ret = 0; | 405 | int ret = 0; |
411 | 406 | ||
... | @@ -430,7 +425,7 @@ is_same_user (url_t url1, url_t url2) | ... | @@ -430,7 +425,7 @@ is_same_user (url_t url1, url_t url2) |
430 | static int | 425 | static int |
431 | is_same_path (url_t url1, url_t url2) | 426 | is_same_path (url_t url1, url_t url2) |
432 | { | 427 | { |
433 | int i = 0, j = 0; | 428 | size_t i = 0, j = 0; |
434 | char *s1, *s2; | 429 | char *s1, *s2; |
435 | int ret = 0; | 430 | int ret = 0; |
436 | 431 | ||
... | @@ -455,7 +450,7 @@ is_same_path (url_t url1, url_t url2) | ... | @@ -455,7 +450,7 @@ is_same_path (url_t url1, url_t url2) |
455 | static int | 450 | static int |
456 | is_same_host (url_t url1, url_t url2) | 451 | is_same_host (url_t url1, url_t url2) |
457 | { | 452 | { |
458 | int i = 0, j = 0; | 453 | size_t i = 0, j = 0; |
459 | char *s1, *s2; | 454 | char *s1, *s2; |
460 | int ret = 0; | 455 | int ret = 0; |
461 | 456 | ... | ... |
... | @@ -5,6 +5,7 @@ auth0.h \ | ... | @@ -5,6 +5,7 @@ auth0.h \ |
5 | bio.h \ | 5 | bio.h \ |
6 | body0.h \ | 6 | body0.h \ |
7 | debug0.h \ | 7 | debug0.h \ |
8 | envelope0.h \ | ||
8 | folder0.h \ | 9 | folder0.h \ |
9 | header0.h \ | 10 | header0.h \ |
10 | iterator0.h \ | 11 | iterator0.h \ |
... | @@ -14,6 +15,7 @@ mailer0.h \ | ... | @@ -14,6 +15,7 @@ mailer0.h \ |
14 | message0.h \ | 15 | message0.h \ |
15 | mime0.h \ | 16 | mime0.h \ |
16 | misc.h \ | 17 | misc.h \ |
18 | monitor0.h \ | ||
17 | observer0.h \ | 19 | observer0.h \ |
18 | registrar0.h \ | 20 | registrar0.h \ |
19 | stream0.h \ | 21 | stream0.h \ | ... | ... |
mailbox/include/envelope0.h
0 → 100644
1 | /* GNU mailutils - a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Library Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | #ifndef _ENVELOPE0_H | ||
19 | #define _ENVELOPE0_H | ||
20 | |||
21 | #ifdef DMALLOC | ||
22 | #include <dmalloc.h> | ||
23 | #endif | ||
24 | |||
25 | #include <mailutils/envelope.h> | ||
26 | |||
27 | #ifdef __cplusplus | ||
28 | extern "C" { | ||
29 | #endif | ||
30 | |||
31 | #ifndef __P | ||
32 | # ifdef __STDC__ | ||
33 | # define __P(args) args | ||
34 | # else | ||
35 | # define __P(args) () | ||
36 | # endif | ||
37 | #endif /*__P */ | ||
38 | |||
39 | struct _envelope | ||
40 | { | ||
41 | void *owner; | ||
42 | int (*_destroy) __P ((envelope_t)); | ||
43 | int (*_from) __P ((envelope_t, char *, size_t, size_t*)); | ||
44 | int (*_date) __P ((envelope_t, char *, size_t , size_t *)); | ||
45 | }; | ||
46 | |||
47 | #endif /* _ENVELOPE0_H */ |
... | @@ -51,7 +51,7 @@ struct _folder | ... | @@ -51,7 +51,7 @@ struct _folder |
51 | monitor_t monitor; | 51 | monitor_t monitor; |
52 | url_t url; | 52 | url_t url; |
53 | int flags; | 53 | int flags; |
54 | size_t ref; | 54 | int ref; |
55 | size_t uid; | 55 | size_t uid; |
56 | 56 | ||
57 | /* Back pointer to the specific mailbox */ | 57 | /* Back pointer to the specific mailbox */ |
... | @@ -64,7 +64,7 @@ struct _folder | ... | @@ -64,7 +64,7 @@ struct _folder |
64 | 64 | ||
65 | int (*_open) __P ((folder_t, int flag)); | 65 | int (*_open) __P ((folder_t, int flag)); |
66 | int (*_close) __P ((folder_t)); | 66 | int (*_close) __P ((folder_t)); |
67 | int (*_list) __P ((folder_t, list_t *)); | 67 | int (*_list) __P ((folder_t, char *vector[][], size_t *num)); |
68 | int (*_delete_mailbox) __P ((folder_t, const char *)); | 68 | int (*_delete_mailbox) __P ((folder_t, const char *)); |
69 | }; | 69 | }; |
70 | 70 | ... | ... |
... | @@ -45,10 +45,13 @@ struct _message | ... | @@ -45,10 +45,13 @@ struct _message |
45 | /* Who is the owner. */ | 45 | /* Who is the owner. */ |
46 | void *owner; | 46 | void *owner; |
47 | 47 | ||
48 | envelope_t envelope; | ||
48 | header_t header; | 49 | header_t header; |
49 | stream_t stream; | ||
50 | body_t body; | 50 | body_t body; |
51 | |||
52 | stream_t stream; | ||
51 | attribute_t attribute; | 53 | attribute_t attribute; |
54 | monitor_t monitor; | ||
52 | mime_t mime; | 55 | mime_t mime; |
53 | observable_t observable; | 56 | observable_t observable; |
54 | 57 | ||
... | @@ -60,8 +63,6 @@ struct _message | ... | @@ -60,8 +63,6 @@ struct _message |
60 | size_t hdr_buflen; | 63 | size_t hdr_buflen; |
61 | int hdr_done; | 64 | int hdr_done; |
62 | 65 | ||
63 | int (*_from) __P ((message_t, char *, size_t, size_t *)); | ||
64 | int (*_received) __P ((message_t, char *, size_t, size_t *)); | ||
65 | int (*_get_uidl) __P ((message_t, char *, size_t, size_t *)); | 66 | int (*_get_uidl) __P ((message_t, char *, size_t, size_t *)); |
66 | int (*_get_num_parts) __P ((message_t, size_t *)); | 67 | int (*_get_num_parts) __P ((message_t, size_t *)); |
67 | int (*_get_part) __P ((message_t, size_t, message_t *)); | 68 | int (*_get_part) __P ((message_t, size_t, message_t *)); | ... | ... |
... | @@ -162,8 +162,8 @@ static int mbox_header_size (header_t, size_t *); | ... | @@ -162,8 +162,8 @@ static int mbox_header_size (header_t, size_t *); |
162 | static int mbox_header_lines (header_t, size_t *); | 162 | static int mbox_header_lines (header_t, size_t *); |
163 | static int mbox_body_size (body_t, size_t *); | 163 | static int mbox_body_size (body_t, size_t *); |
164 | static int mbox_body_lines (body_t, size_t *); | 164 | static int mbox_body_lines (body_t, size_t *); |
165 | static int mbox_msg_from (message_t, char *, size_t, size_t *); | 165 | static int mbox_envelope_from (envelope_t, char *, size_t, size_t *); |
166 | static int mbox_msg_received (message_t, char *, size_t, size_t *); | 166 | static int mbox_envelope_date (envelope_t, char *, size_t, size_t *); |
167 | static void mbox_cleanup (void *); | 167 | static void mbox_cleanup (void *); |
168 | 168 | ||
169 | /* We allocate the mbox_data_t struct, but don't do any parsing on the name or | 169 | /* We allocate the mbox_data_t struct, but don't do any parsing on the name or |
... | @@ -981,9 +981,10 @@ mbox_body_lines (body_t body, size_t *plines) | ... | @@ -981,9 +981,10 @@ mbox_body_lines (body_t body, size_t *plines) |
981 | } | 981 | } |
982 | 982 | ||
983 | static int | 983 | static int |
984 | mbox_msg_received (message_t msg, char *buf, size_t len, | 984 | mbox_envelope_date (envelope_t envelope, char *buf, size_t len, |
985 | size_t *pnwrite) | 985 | size_t *pnwrite) |
986 | { | 986 | { |
987 | message_t msg = envelope_get_owner (envelope); | ||
987 | mbox_message_t mum = message_get_owner (msg); | 988 | mbox_message_t mum = message_get_owner (msg); |
988 | size_t n = 0; | 989 | size_t n = 0; |
989 | int status; | 990 | int status; |
... | @@ -1026,8 +1027,10 @@ mbox_msg_received (message_t msg, char *buf, size_t len, | ... | @@ -1026,8 +1027,10 @@ mbox_msg_received (message_t msg, char *buf, size_t len, |
1026 | } | 1027 | } |
1027 | 1028 | ||
1028 | static int | 1029 | static int |
1029 | mbox_msg_from (message_t msg, char *buf, size_t len, size_t *pnwrite) | 1030 | mbox_envelope_from (envelope_t envelope, char *buf, size_t len, |
1031 | size_t *pnwrite) | ||
1030 | { | 1032 | { |
1033 | message_t msg = envelope_get_owner (envelope); | ||
1031 | mbox_message_t mum = message_get_owner (msg); | 1034 | mbox_message_t mum = message_get_owner (msg); |
1032 | size_t n = 0; | 1035 | size_t n = 0; |
1033 | int status; | 1036 | int status; |
... | @@ -1158,8 +1161,18 @@ mbox_get_message (mailbox_t mailbox, size_t msgno, message_t *pmsg) | ... | @@ -1158,8 +1161,18 @@ mbox_get_message (mailbox_t mailbox, size_t msgno, message_t *pmsg) |
1158 | } | 1161 | } |
1159 | 1162 | ||
1160 | /* Set the envelope. */ | 1163 | /* Set the envelope. */ |
1161 | message_set_from (msg, mbox_msg_from, mum); | 1164 | { |
1162 | message_set_received (msg, mbox_msg_received, mum); | 1165 | envelope_t envelope= NULL; |
1166 | status = envelope_create (&envelope, msg); | ||
1167 | if (status != 0) | ||
1168 | { | ||
1169 | message_destroy (&msg, mum); | ||
1170 | return status; | ||
1171 | } | ||
1172 | envelope_set_from (envelope, mbox_envelope_from, msg); | ||
1173 | envelope_set_date (envelope, mbox_envelope_date, msg); | ||
1174 | message_set_envelope (msg, envelope, mum); | ||
1175 | } | ||
1163 | 1176 | ||
1164 | /* Attach the message to the mailbox mbox data. */ | 1177 | /* Attach the message to the mailbox mbox data. */ |
1165 | mum->message = msg; | 1178 | mum->message = msg; |
... | @@ -1229,7 +1242,9 @@ mbox_append_message (mailbox_t mailbox, message_t msg) | ... | @@ -1229,7 +1242,9 @@ mbox_append_message (mailbox_t mailbox, message_t msg) |
1229 | { | 1242 | { |
1230 | char *s; | 1243 | char *s; |
1231 | size_t len = 0; | 1244 | size_t len = 0; |
1232 | status = message_from (msg, mud->from, 127, &len); | 1245 | envelope_t envelope; |
1246 | message_get_envelope (msg, &envelope); | ||
1247 | status = envelope_from (envelope, mud->from, 127, &len); | ||
1233 | if (status != 0) | 1248 | if (status != 0) |
1234 | { | 1249 | { |
1235 | if (status != EAGAIN) | 1250 | if (status != EAGAIN) |
... | @@ -1255,7 +1270,9 @@ mbox_append_message (mailbox_t mailbox, message_t msg) | ... | @@ -1255,7 +1270,9 @@ mbox_append_message (mailbox_t mailbox, message_t msg) |
1255 | { | 1270 | { |
1256 | char *s; | 1271 | char *s; |
1257 | size_t len = 0; | 1272 | size_t len = 0; |
1258 | status = message_received (msg, mud->date, 127, &len); | 1273 | envelope_t envelope; |
1274 | message_get_envelope (msg, &envelope); | ||
1275 | status = envelope_date (envelope, mud->date, 127, &len); | ||
1259 | if (status != 0) | 1276 | if (status != 0) |
1260 | { | 1277 | { |
1261 | if (status != EAGAIN) | 1278 | if (status != EAGAIN) | ... | ... |
... | @@ -352,7 +352,7 @@ mbox_scan0 (mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notif) | ... | @@ -352,7 +352,7 @@ mbox_scan0 (mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notif) |
352 | mum->mud = mud; | 352 | mum->mud = mud; |
353 | mum->header_from = total - n; | 353 | mum->header_from = total - n; |
354 | mum->header_from_end = total; | 354 | mum->header_from_end = total; |
355 | mum->body_end = 0; | 355 | mum->body_end = mum->body = 0; |
356 | lines = 0; | 356 | lines = 0; |
357 | } | 357 | } |
358 | else if ((n > 7) && ISSTATUS(buf)) | 358 | else if ((n > 7) && ISSTATUS(buf)) | ... | ... |
... | @@ -196,7 +196,7 @@ do \ | ... | @@ -196,7 +196,7 @@ do \ |
196 | || (mpd->id && mpd->id != (size_t)identity)) \ | 196 | || (mpd->id && mpd->id != (size_t)identity)) \ |
197 | { \ | 197 | { \ |
198 | mpd->id = 0; \ | 198 | mpd->id = 0; \ |
199 | mpd->func = pop_open; \ | 199 | mpd->func = (void *)pop_open; \ |
200 | mpd->state = POP_NO_STATE; \ | 200 | mpd->state = POP_NO_STATE; \ |
201 | monitor_unlock (mbox->monitor); \ | 201 | monitor_unlock (mbox->monitor); \ |
202 | err = pop_open (mbox, mbox->flags); \ | 202 | err = pop_open (mbox, mbox->flags); \ | ... | ... |
This diff is collapsed.
Click to expand it.
... | @@ -21,8 +21,8 @@ | ... | @@ -21,8 +21,8 @@ |
21 | #include <stdlib.h> | 21 | #include <stdlib.h> |
22 | #include <string.h> | 22 | #include <string.h> |
23 | #include <ctype.h> | 23 | #include <ctype.h> |
24 | #include <unistd.h> | ||
25 | #include <time.h> | 24 | #include <time.h> |
25 | #include <unistd.h> | ||
26 | 26 | ||
27 | #include <mailutils/message.h> | 27 | #include <mailutils/message.h> |
28 | #include <mailutils/stream.h> | 28 | #include <mailutils/stream.h> |
... | @@ -217,7 +217,7 @@ static void _mime_append_header_line(mime_t mime) | ... | @@ -217,7 +217,7 @@ static void _mime_append_header_line(mime_t mime) |
217 | static int _mime_parse_mpart_message(mime_t mime) | 217 | static int _mime_parse_mpart_message(mime_t mime) |
218 | { | 218 | { |
219 | char *cp, *cp2; | 219 | char *cp, *cp2; |
220 | int blength, body_length, body_offset, body_lines, ret; | 220 | int blength, mb_length, mb_offset, mb_lines, ret; |
221 | size_t nbytes; | 221 | size_t nbytes; |
222 | 222 | ||
223 | if ( !(mime->flags & MIME_PARSER_ACTIVE) ) { | 223 | if ( !(mime->flags & MIME_PARSER_ACTIVE) ) { |
... | @@ -237,9 +237,9 @@ static int _mime_parse_mpart_message(mime_t mime) | ... | @@ -237,9 +237,9 @@ static int _mime_parse_mpart_message(mime_t mime) |
237 | mime->parser_state = MIME_STATE_SCAN_BOUNDARY; | 237 | mime->parser_state = MIME_STATE_SCAN_BOUNDARY; |
238 | mime->flags |= MIME_PARSER_ACTIVE; | 238 | mime->flags |= MIME_PARSER_ACTIVE; |
239 | } | 239 | } |
240 | body_length = mime->body_length; | 240 | mb_length = mime->body_length; |
241 | body_offset = mime->body_offset; | 241 | mb_offset = mime->body_offset; |
242 | body_lines = mime->body_lines; | 242 | mb_lines = mime->body_lines; |
243 | 243 | ||
244 | while ( ( ret = stream_read(mime->stream, mime->cur_buf, mime->buf_size, mime->cur_offset, &nbytes) ) == 0 && nbytes ) { | 244 | while ( ( ret = stream_read(mime->stream, mime->cur_buf, mime->buf_size, mime->cur_offset, &nbytes) ) == 0 && nbytes ) { |
245 | cp = mime->cur_buf; | 245 | cp = mime->cur_buf; |
... | @@ -256,15 +256,15 @@ static int _mime_parse_mpart_message(mime_t mime) | ... | @@ -256,15 +256,15 @@ static int _mime_parse_mpart_message(mime_t mime) |
256 | cp2 = mime->cur_line[0] == '\n' ? mime->cur_line + 1 : mime->cur_line; | 256 | cp2 = mime->cur_line[0] == '\n' ? mime->cur_line + 1 : mime->cur_line; |
257 | blength = strlen(mime->boundary); | 257 | blength = strlen(mime->boundary); |
258 | if ( mime->header_length ) | 258 | if ( mime->header_length ) |
259 | body_lines++; | 259 | mb_lines++; |
260 | if ( mime->line_ndx >= blength ) { | 260 | if ( mime->line_ndx >= blength ) { |
261 | if ( ( !strncasecmp(cp2,"--", 2) && !strncasecmp(cp2+2, mime->boundary, blength) ) | 261 | if ( ( !strncasecmp(cp2,"--", 2) && !strncasecmp(cp2+2, mime->boundary, blength) ) |
262 | || !strncasecmp(cp2, mime->boundary, blength) ) { | 262 | || !strncasecmp(cp2, mime->boundary, blength) ) { |
263 | mime->parser_state = MIME_STATE_HEADERS; | 263 | mime->parser_state = MIME_STATE_HEADERS; |
264 | mime->flags &= ~MIME_PARSER_HAVE_CR; | 264 | mime->flags &= ~MIME_PARSER_HAVE_CR; |
265 | body_length = mime->cur_offset - body_offset - mime->line_ndx + 1; | 265 | mb_length = mime->cur_offset - mb_offset - mime->line_ndx + 1; |
266 | if ( mime->header_length ) /* this skips the preamble */ | 266 | if ( mime->header_length ) /* this skips the preamble */ |
267 | _mime_append_part(mime, NULL, body_offset, body_length, body_lines); | 267 | _mime_append_part(mime, NULL, mb_offset, mb_length, mb_lines); |
268 | if ( ( cp2 + blength + 2 < cp && !strncasecmp(cp2+2+blength, "--",2) ) || | 268 | if ( ( cp2 + blength + 2 < cp && !strncasecmp(cp2+2+blength, "--",2) ) || |
269 | !strncasecmp(cp2+blength, "--",2) ) { /* very last boundary */ | 269 | !strncasecmp(cp2+blength, "--",2) ) { /* very last boundary */ |
270 | mime->parser_state = MIME_STATE_BEGIN_LINE; | 270 | mime->parser_state = MIME_STATE_BEGIN_LINE; |
... | @@ -283,8 +283,8 @@ static int _mime_parse_mpart_message(mime_t mime) | ... | @@ -283,8 +283,8 @@ static int _mime_parse_mpart_message(mime_t mime) |
283 | _mime_append_header_line(mime); | 283 | _mime_append_header_line(mime); |
284 | if ( mime->line_ndx == 1 || mime->cur_line[0] == '\r' ) { | 284 | if ( mime->line_ndx == 1 || mime->cur_line[0] == '\r' ) { |
285 | mime->parser_state = MIME_STATE_BEGIN_LINE; | 285 | mime->parser_state = MIME_STATE_BEGIN_LINE; |
286 | body_offset = mime->cur_offset + 1; | 286 | mb_offset = mime->cur_offset + 1; |
287 | body_lines = 0; | 287 | mb_lines = 0; |
288 | } | 288 | } |
289 | mime->line_ndx = -1; | 289 | mime->line_ndx = -1; |
290 | break; | 290 | break; |
... | @@ -300,12 +300,12 @@ static int _mime_parse_mpart_message(mime_t mime) | ... | @@ -300,12 +300,12 @@ static int _mime_parse_mpart_message(mime_t mime) |
300 | cp++; | 300 | cp++; |
301 | } | 301 | } |
302 | } | 302 | } |
303 | mime->body_lines = body_lines; | 303 | mime->body_lines = mb_lines; |
304 | mime->body_length = body_length; | 304 | mime->body_length = mb_length; |
305 | mime->body_offset = body_offset; | 305 | mime->body_offset = mb_offset; |
306 | if ( ret != EAGAIN ) { /* finished cleanup */ | 306 | if ( ret != EAGAIN ) { /* finished cleanup */ |
307 | if ( mime->header_length ) /* this skips the preamble */ | 307 | if ( mime->header_length ) /* this skips the preamble */ |
308 | _mime_append_part(mime, NULL, body_offset, body_length, body_lines); | 308 | _mime_append_part(mime, NULL, mb_offset, mb_length, mb_lines); |
309 | mime->flags &= ~MIME_PARSER_ACTIVE; | 309 | mime->flags &= ~MIME_PARSER_ACTIVE; |
310 | mime->body_offset = mime->body_length = mime->header_length = mime->body_lines = 0; | 310 | mime->body_offset = mime->body_length = mime->header_length = mime->body_lines = 0; |
311 | } | 311 | } |
... | @@ -373,7 +373,7 @@ static int _mime_set_content_type(mime_t mime) | ... | @@ -373,7 +373,7 @@ static int _mime_set_content_type(mime_t mime) |
373 | char boundary[128]; | 373 | char boundary[128]; |
374 | header_t hdr = NULL; | 374 | header_t hdr = NULL; |
375 | size_t size; | 375 | size_t size; |
376 | 376 | ||
377 | if ( mime->nmtp_parts > 1 ) { | 377 | if ( mime->nmtp_parts > 1 ) { |
378 | if ( mime->flags & MIME_ADDED_MULTIPART_CT ) | 378 | if ( mime->flags & MIME_ADDED_MULTIPART_CT ) |
379 | return 0; | 379 | return 0; |
... | @@ -382,7 +382,7 @@ static int _mime_set_content_type(mime_t mime) | ... | @@ -382,7 +382,7 @@ static int _mime_set_content_type(mime_t mime) |
382 | else | 382 | else |
383 | strcpy(content_type, "multipart/alternative; boundary="); | 383 | strcpy(content_type, "multipart/alternative; boundary="); |
384 | if ( mime->boundary == NULL ) { | 384 | if ( mime->boundary == NULL ) { |
385 | sprintf (boundary,"%ld-%ld=:%ld",random (),time (0), getpid ()); | 385 | sprintf (boundary,"%ld-%ld=:%ld",(long)random (), (long)time (0), (long)getpid ()); |
386 | if ( ( mime->boundary = strdup(boundary) ) == NULL ) | 386 | if ( ( mime->boundary = strdup(boundary) ) == NULL ) |
387 | return ENOMEM; | 387 | return ENOMEM; |
388 | } | 388 | } |
... | @@ -455,7 +455,7 @@ static int _mime_body_read(stream_t stream, char *buf, size_t buflen, off_t off, | ... | @@ -455,7 +455,7 @@ static int _mime_body_read(stream_t stream, char *buf, size_t buflen, off_t off, |
455 | } | 455 | } |
456 | while(mime->postamble) { | 456 | while(mime->postamble) { |
457 | mime->postamble--; | 457 | mime->postamble--; |
458 | ADD_CHAR(buf, '-', mime->cur_offset, buflen, *nbytes); | 458 | ADD_CHAR(buf, '-', mime->cur_offset, buflen, *nbytes); |
459 | } | 459 | } |
460 | mime->flags &= ~(MIME_INSERT_BOUNDARY|MIME_ADDING_BOUNDARY); | 460 | mime->flags &= ~(MIME_INSERT_BOUNDARY|MIME_ADDING_BOUNDARY); |
461 | mime->part_offset = 0; | 461 | mime->part_offset = 0; |
... | @@ -465,9 +465,12 @@ static int _mime_body_read(stream_t stream, char *buf, size_t buflen, off_t off, | ... | @@ -465,9 +465,12 @@ static int _mime_body_read(stream_t stream, char *buf, size_t buflen, off_t off, |
465 | return 0; | 465 | return 0; |
466 | message_get_stream(mime->mtp_parts[mime->cur_part]->msg, &msg_stream); | 466 | message_get_stream(mime->mtp_parts[mime->cur_part]->msg, &msg_stream); |
467 | } else { | 467 | } else { |
468 | body_t b; | 468 | body_t part_body; |
469 | message_get_body(mime->mtp_parts[mime->cur_part]->msg, &b); | 469 | |
470 | body_get_stream(b, &msg_stream); | 470 | if ( mime->cur_part >= mime->nmtp_parts ) |
471 | return 0; | ||
472 | message_get_body(mime->mtp_parts[mime->cur_part]->msg, &part_body); | ||
473 | body_get_stream(part_body, &msg_stream); | ||
471 | } | 474 | } |
472 | ret = stream_read(msg_stream, buf, buflen, mime->part_offset, &part_nbytes ); | 475 | ret = stream_read(msg_stream, buf, buflen, mime->part_offset, &part_nbytes ); |
473 | len += part_nbytes; | 476 | len += part_nbytes; |
... | @@ -475,11 +478,11 @@ static int _mime_body_read(stream_t stream, char *buf, size_t buflen, off_t off, | ... | @@ -475,11 +478,11 @@ static int _mime_body_read(stream_t stream, char *buf, size_t buflen, off_t off, |
475 | if ( nbytes ) | 478 | if ( nbytes ) |
476 | *nbytes += len; | 479 | *nbytes += len; |
477 | mime->cur_offset += len; | 480 | mime->cur_offset += len; |
478 | if ( ret == 0 && part_nbytes == 0 && mime->nmtp_parts > 1 ) { | 481 | if ( ret == 0 && part_nbytes == 0 ) { |
479 | mime->flags |= MIME_INSERT_BOUNDARY; | 482 | mime->flags |= MIME_INSERT_BOUNDARY; |
480 | mime->cur_part++; | 483 | mime->cur_part++; |
481 | } | 484 | } |
482 | } while( ret == 0 && part_nbytes == 0 && mime->cur_part < mime->nmtp_parts ); | 485 | } while( ret == 0 && part_nbytes == 0 && mime->cur_part <= mime->nmtp_parts ); |
483 | } | 486 | } |
484 | return ret; | 487 | return ret; |
485 | } | 488 | } |
... | @@ -675,7 +678,7 @@ int mime_get_num_parts(mime_t mime, int *nmtp_parts) | ... | @@ -675,7 +678,7 @@ int mime_get_num_parts(mime_t mime, int *nmtp_parts) |
675 | int mime_add_part(mime_t mime, message_t msg) | 678 | int mime_add_part(mime_t mime, message_t msg) |
676 | { | 679 | { |
677 | int ret; | 680 | int ret; |
678 | 681 | ||
679 | if ( mime == NULL || msg == NULL || ( mime->flags & MIME_NEW_MESSAGE ) == 0 ) | 682 | if ( mime == NULL || msg == NULL || ( mime->flags & MIME_NEW_MESSAGE ) == 0 ) |
680 | return EINVAL; | 683 | return EINVAL; |
681 | if ( ( ret = _mime_append_part(mime, msg, 0, 0, 0) ) == 0 ) | 684 | if ( ( ret = _mime_append_part(mime, msg, 0, 0, 0) ) == 0 ) | ... | ... |
... | @@ -140,6 +140,7 @@ parseaddr (const char *addr, char *buf, size_t bufsz) | ... | @@ -140,6 +140,7 @@ parseaddr (const char *addr, char *buf, size_t bufsz) |
140 | struct token *t, *tok, *last; | 140 | struct token *t, *tok, *last; |
141 | struct token *brace = NULL; | 141 | struct token *brace = NULL; |
142 | int comment = 0; | 142 | int comment = 0; |
143 | int status = 0; | ||
143 | 144 | ||
144 | tok = last = NULL; | 145 | tok = last = NULL; |
145 | 146 | ||
... | @@ -171,7 +172,10 @@ parseaddr (const char *addr, char *buf, size_t bufsz) | ... | @@ -171,7 +172,10 @@ parseaddr (const char *addr, char *buf, size_t bufsz) |
171 | for (; t && t->word[0] != ',' && t->word[0] != '>'; t = t->next) | 172 | for (; t && t->word[0] != ',' && t->word[0] != '>'; t = t->next) |
172 | { | 173 | { |
173 | if (strlen (t->word) >= bufsz) | 174 | if (strlen (t->word) >= bufsz) |
174 | return -1; | 175 | { |
176 | status = -1; | ||
177 | break; | ||
178 | } | ||
175 | bufsz -= strlen (t->word); | 179 | bufsz -= strlen (t->word); |
176 | strcat (buf, t->word); | 180 | strcat (buf, t->word); |
177 | } | 181 | } |
... | @@ -183,5 +187,5 @@ parseaddr (const char *addr, char *buf, size_t bufsz) | ... | @@ -183,5 +187,5 @@ parseaddr (const char *addr, char *buf, size_t bufsz) |
183 | free (t); | 187 | free (t); |
184 | } | 188 | } |
185 | 189 | ||
186 | return 0; | 190 | return status; |
187 | } | 191 | } | ... | ... |
-
Please register or sign in to post a comment