Commit c55e2241 c55e2241a6809305301e4a582564daac3e44fd6f by Sergey Poznyakoff

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.
1 parent f8834aef
...@@ -198,7 +198,24 @@ pop_close (mu_mailbox_t mbox) ...@@ -198,7 +198,24 @@ 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 {
203 size_t i;
204
205 mu_monitor_wrlock (mbox->monitor);
206 /* Destroy the pop messages and resources associated to them. */
207 for (i = 0; i < mpd->msg_count; i++)
208 {
209 if (mpd->msg[i])
210 {
211 mu_message_destroy (&mpd->msg[i]->message, mpd->msg[i]);
212 if (mpd->msg[i]->uidl)
213 free (mpd->msg[i]->uidl);
214 free (mpd->msg[i]);
215 }
216 }
217 mu_monitor_unlock (mbox->monitor);
218 }
202 mu_stream_destroy (&mpd->cache); 219 mu_stream_destroy (&mpd->cache);
203 return 0; 220 return 0;
204 } 221 }
...@@ -209,28 +226,11 @@ pop_destroy (mu_mailbox_t mbox) ...@@ -209,28 +226,11 @@ pop_destroy (mu_mailbox_t mbox)
209 struct _pop3_mailbox *mpd = mbox->data; 226 struct _pop3_mailbox *mpd = mbox->data;
210 if (mpd) 227 if (mpd)
211 { 228 {
212 size_t i;
213 mu_monitor_wrlock (mbox->monitor);
214 if (mpd->msg)
215 {
216 /* Destroy the pop messages and resources associated to them. */
217 for (i = 0; i < mpd->msg_count; i++)
218 {
219 if (mpd->msg[i])
220 {
221 mu_message_destroy (&mpd->msg[i]->message, mpd->msg[i]);
222 if (mpd->msg[i]->uidl)
223 free (mpd->msg[i]->uidl);
224 free (mpd->msg[i]);
225 }
226 }
227 }
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);
...@@ -1045,9 +1046,6 @@ main (int argc, char **argv) ...@@ -1045,9 +1046,6 @@ main (int argc, char **argv)
1045 1046
1046 mu_mailbox_close (source); 1047 mu_mailbox_close (source);
1047 mu_mailbox_destroy (&source); 1048 mu_mailbox_destroy (&source);
1048
1049 if (onerror_flags & ONERROR_COUNT)
1050 app_err_count = 0;
1051 1049
1052 return !(rc == 0 && (app_err_count + get_err_count) == 0); 1050 return !(rc == 0 && (app_err_count + get_err_count) == 0);
1053 } 1051 }
......