pop client and movemail: bugfixes
* libproto/pop/mbox.c (pop_close): Destroy the cached data. (pop_destroy): Avoid freeing the same data twice. (pop_body_get_stream,pop_body_size,pop_body_lines): Owner is mu_message_t. (pop_create_body): Change the owner of the created mu_body_t object. * movemail/movemail.c: Correctly close both mailboxes if unhandled errors occur.
Showing
2 changed files
with
28 additions
and
25 deletions
... | @@ -198,21 +198,11 @@ pop_close (mu_mailbox_t mbox) | ... | @@ -198,21 +198,11 @@ pop_close (mu_mailbox_t mbox) |
198 | status = mu_pop3_disconnect (mpd->pop3); | 198 | status = mu_pop3_disconnect (mpd->pop3); |
199 | if (status) | 199 | if (status) |
200 | mu_error ("mu_pop3_disconnect failed: %s", mu_strerror (status)); | 200 | mu_error ("mu_pop3_disconnect failed: %s", mu_strerror (status)); |
201 | mu_pop3_destroy (&mpd->pop3); | 201 | if (mpd->msg) |
202 | mu_stream_destroy (&mpd->cache); | ||
203 | return 0; | ||
204 | } | ||
205 | |||
206 | static void | ||
207 | pop_destroy (mu_mailbox_t mbox) | ||
208 | { | ||
209 | struct _pop3_mailbox *mpd = mbox->data; | ||
210 | if (mpd) | ||
211 | { | 202 | { |
212 | size_t i; | 203 | size_t i; |
204 | |||
213 | mu_monitor_wrlock (mbox->monitor); | 205 | mu_monitor_wrlock (mbox->monitor); |
214 | if (mpd->msg) | ||
215 | { | ||
216 | /* Destroy the pop messages and resources associated to them. */ | 206 | /* Destroy the pop messages and resources associated to them. */ |
217 | for (i = 0; i < mpd->msg_count; i++) | 207 | for (i = 0; i < mpd->msg_count; i++) |
218 | { | 208 | { |
... | @@ -224,13 +214,23 @@ pop_destroy (mu_mailbox_t mbox) | ... | @@ -224,13 +214,23 @@ pop_destroy (mu_mailbox_t mbox) |
224 | free (mpd->msg[i]); | 214 | free (mpd->msg[i]); |
225 | } | 215 | } |
226 | } | 216 | } |
217 | mu_monitor_unlock (mbox->monitor); | ||
227 | } | 218 | } |
219 | mu_stream_destroy (&mpd->cache); | ||
220 | return 0; | ||
221 | } | ||
222 | |||
223 | static void | ||
224 | pop_destroy (mu_mailbox_t mbox) | ||
225 | { | ||
226 | struct _pop3_mailbox *mpd = mbox->data; | ||
227 | if (mpd) | ||
228 | { | ||
228 | mu_pop3_destroy (&mpd->pop3); | 229 | mu_pop3_destroy (&mpd->pop3); |
229 | if (mpd->user) | 230 | if (mpd->user) |
230 | free (mpd->user); | 231 | free (mpd->user); |
231 | if (mpd->secret) | 232 | if (mpd->secret) |
232 | mu_secret_unref (mpd->secret); | 233 | mu_secret_unref (mpd->secret); |
233 | mu_stream_destroy (&mpd->cache); | ||
234 | } | 234 | } |
235 | } | 235 | } |
236 | 236 | ||
... | @@ -682,7 +682,8 @@ pop_create_attribute (struct _pop3_message *mpm) | ... | @@ -682,7 +682,8 @@ pop_create_attribute (struct _pop3_message *mpm) |
682 | int | 682 | int |
683 | pop_body_get_stream (mu_body_t body, mu_stream_t *pstr) | 683 | pop_body_get_stream (mu_body_t body, mu_stream_t *pstr) |
684 | { | 684 | { |
685 | struct _pop3_message *mpm = mu_body_get_owner (body); | 685 | mu_message_t msg = mu_body_get_owner (body); |
686 | struct _pop3_message *mpm = mu_message_get_owner (msg); | ||
686 | struct _pop3_mailbox *mpd = mpm->mpd; | 687 | struct _pop3_mailbox *mpd = mpm->mpd; |
687 | int status = pop_scan_message (mpm); | 688 | int status = pop_scan_message (mpm); |
688 | if (status) | 689 | if (status) |
... | @@ -695,7 +696,8 @@ pop_body_get_stream (mu_body_t body, mu_stream_t *pstr) | ... | @@ -695,7 +696,8 @@ pop_body_get_stream (mu_body_t body, mu_stream_t *pstr) |
695 | static int | 696 | static int |
696 | pop_body_size (mu_body_t body, size_t *psize) | 697 | pop_body_size (mu_body_t body, size_t *psize) |
697 | { | 698 | { |
698 | struct _pop3_message *mpm = mu_body_get_owner (body); | 699 | mu_message_t msg = mu_body_get_owner (body); |
700 | struct _pop3_message *mpm = mu_message_get_owner (msg); | ||
699 | int status = pop_scan_message (mpm); | 701 | int status = pop_scan_message (mpm); |
700 | if (status) | 702 | if (status) |
701 | return status; | 703 | return status; |
... | @@ -706,7 +708,8 @@ pop_body_size (mu_body_t body, size_t *psize) | ... | @@ -706,7 +708,8 @@ pop_body_size (mu_body_t body, size_t *psize) |
706 | static int | 708 | static int |
707 | pop_body_lines (mu_body_t body, size_t *plines) | 709 | pop_body_lines (mu_body_t body, size_t *plines) |
708 | { | 710 | { |
709 | struct _pop3_message *mpm = mu_body_get_owner (body); | 711 | mu_message_t msg = mu_body_get_owner (body); |
712 | struct _pop3_message *mpm = mu_message_get_owner (msg); | ||
710 | int status = pop_scan_message (mpm); | 713 | int status = pop_scan_message (mpm); |
711 | if (status) | 714 | if (status) |
712 | return status; | 715 | return status; |
... | @@ -719,14 +722,16 @@ pop_create_body (struct _pop3_message *mpm) | ... | @@ -719,14 +722,16 @@ pop_create_body (struct _pop3_message *mpm) |
719 | { | 722 | { |
720 | int status; | 723 | int status; |
721 | mu_body_t body = NULL; | 724 | mu_body_t body = NULL; |
725 | mu_message_t msg = mpm->message; | ||
722 | 726 | ||
723 | status = mu_body_create (&body, mpm); | 727 | /* FIXME: The owner of the body *must* be the message it belongs to. */ |
728 | status = mu_body_create (&body, msg); | ||
724 | if (status) | 729 | if (status) |
725 | return status; | 730 | return status; |
726 | 731 | ||
727 | mu_body_set_get_stream (body, pop_body_get_stream, mpm); | 732 | mu_body_set_get_stream (body, pop_body_get_stream, msg); |
728 | mu_body_set_size (body, pop_body_size, mpm); | 733 | mu_body_set_size (body, pop_body_size, msg); |
729 | mu_body_set_lines (body, pop_body_lines, mpm); | 734 | mu_body_set_lines (body, pop_body_lines, msg); |
730 | 735 | ||
731 | mu_message_set_body (mpm->message, body, mpm); | 736 | mu_message_set_body (mpm->message, body, mpm); |
732 | 737 | ... | ... |
... | @@ -1032,8 +1032,9 @@ main (int argc, char **argv) | ... | @@ -1032,8 +1032,9 @@ main (int argc, char **argv) |
1032 | } | 1032 | } |
1033 | 1033 | ||
1034 | if (app_err_count && !(onerror_flags & (ONERROR_DELETE|ONERROR_COUNT))) | 1034 | if (app_err_count && !(onerror_flags & (ONERROR_DELETE|ONERROR_COUNT))) |
1035 | /* FIXME: mailboxes are not properly closed */ | 1035 | preserve_mail = 1; |
1036 | return 1; | 1036 | if (onerror_flags & ONERROR_COUNT) |
1037 | app_err_count = 0; | ||
1037 | 1038 | ||
1038 | mu_mailbox_sync (dest); | 1039 | mu_mailbox_sync (dest); |
1039 | rc = mu_mailbox_close (dest); | 1040 | rc = mu_mailbox_close (dest); |
... | @@ -1046,8 +1047,5 @@ main (int argc, char **argv) | ... | @@ -1046,8 +1047,5 @@ main (int argc, char **argv) |
1046 | mu_mailbox_close (source); | 1047 | mu_mailbox_close (source); |
1047 | mu_mailbox_destroy (&source); | 1048 | mu_mailbox_destroy (&source); |
1048 | 1049 | ||
1049 | if (onerror_flags & ONERROR_COUNT) | ||
1050 | app_err_count = 0; | ||
1051 | |||
1052 | return !(rc == 0 && (app_err_count + get_err_count) == 0); | 1050 | return !(rc == 0 && (app_err_count + get_err_count) == 0); |
1053 | } | 1051 | } | ... | ... |
-
Please register or sign in to post a comment