Commit c6eef46c c6eef46c15d976cac14815952cb49cb4f4069c1e by Alain Magloire

Hunted down a nasty bug in the expunge code, bad bad.

1 parent bbbdd3d8
...@@ -37,14 +37,15 @@ struct _observable; ...@@ -37,14 +37,15 @@ struct _observable;
37 typedef struct _observer* observer_t; 37 typedef struct _observer* observer_t;
38 typedef struct _observable* observable_t; 38 typedef struct _observable* observable_t;
39 39
40 #define MU_EVT_MAILBOX_DESTROY 0x001 40 #define MU_EVT_MAILBOX_DESTROY 0x001
41 #define MU_EVT_FOLDER_DESTROY 0x002 41 #define MU_EVT_FOLDER_DESTROY 0x002
42 #define MU_EVT_MAILER_DESTROY 0x004 42 #define MU_EVT_MAILER_DESTROY 0x004
43 #define MU_EVT_MESSAGE_DESTROY 0x008 43 #define MU_EVT_MESSAGE_DESTROY 0x008
44 #define MU_EVT_MESSAGE_ADD 0x010 44 #define MU_EVT_MESSAGE_ADD 0x010
45 #define MU_EVT_MAILBOX_PROGRESS 0x020 45 #define MU_EVT_MAILBOX_PROGRESS 0x020
46 #define MU_EVT_AUTHORITY_FAILED 0x030 46 #define MU_EVT_AUTHORITY_FAILED 0x030
47 #define MU_EVT_MAILBOX_CORRUPT 0x040 47 #define MU_EVT_MAILBOX_CORRUPT 0x040
48 #define MU_EVT_MAILER_MESSAGE_SENT 0x080
48 49
49 #define MU_OBSERVER_NO_CHECK 1 50 #define MU_OBSERVER_NO_CHECK 1
50 51
......
...@@ -743,23 +743,24 @@ mbox_expunge (mailbox_t mailbox) ...@@ -743,23 +743,24 @@ mbox_expunge (mailbox_t mailbox)
743 { 743 {
744 size_t dlast; 744 size_t dlast;
745 for (j = dirty, dlast = mud->messages_count - 1; 745 for (j = dirty, dlast = mud->messages_count - 1;
746 j < mud->messages_count; j++) 746 j <= dlast; j++)
747 { 747 {
748 /* Clear all the references, any attach messages been already 748 /* Clear all the references, any attach messages been already
749 destroy above. */ 749 destroy above. */
750 mum = mud->umessages[j]; 750 mum = mud->umessages[j];
751 if (mum->new_flags && ATTRIBUTE_IS_DELETED (mum->new_flags)) 751 if (mum->new_flags && ATTRIBUTE_IS_DELETED (mum->new_flags))
752 { 752 {
753 if ((j + 1) >= mud->messages_count) 753 if ((j + 1) <= dlast)
754 { 754 {
755 /* Move all the pointers up. So the message pointer 755 /* Move all the pointers up. So the message pointer
756 part of mum will be at the right position. */ 756 part of mum will be at the right position. */
757 memmove (mud->umessages + j, mud->umessages + j + 1, 757 memmove (mud->umessages + j, mud->umessages + j + 1,
758 (dlast - dirty) * sizeof (mum)); 758 (dlast - j) * sizeof (mum));
759 mum->header_from = mum->header_from_end = 0; 759 //mum->header_from = mum->header_from_end = 0;
760 mum->header_status = mum->header_status_end = 0; 760 //mum->header_status = mum->header_status_end = 0;
761 mum->body = mum->body_end = 0; 761 //mum->body = mum->body_end = 0;
762 mum->header_lines = mum->body_lines = 0; 762 //mum->header_lines = mum->body_lines = 0;
763 memset (mum, 0, sizeof (*mum));
763 /* We are not free()ing the useless mum, but instead 764 /* We are not free()ing the useless mum, but instead
764 we put it back in the pool, to be reuse. */ 765 we put it back in the pool, to be reuse. */
765 mud->umessages[dlast] = mum; 766 mud->umessages[dlast] = mum;
...@@ -768,6 +769,10 @@ mbox_expunge (mailbox_t mailbox) ...@@ -768,6 +769,10 @@ mbox_expunge (mailbox_t mailbox)
768 gets cleared to. */ 769 gets cleared to. */
769 mum = mud->umessages[j]; 770 mum = mud->umessages[j];
770 } 771 }
772 else
773 {
774 memset (mum, 0, sizeof (*mum));
775 }
771 } 776 }
772 mum->header_from = mum->header_from_end = 0; 777 mum->header_from = mum->header_from_end = 0;
773 mum->header_status = mum->header_status_end = 0; 778 mum->header_status = mum->header_status_end = 0;
......
...@@ -384,6 +384,7 @@ message_get_attribute (message_t msg, attribute_t *pattribute) ...@@ -384,6 +384,7 @@ message_get_attribute (message_t msg, attribute_t *pattribute)
384 { 384 {
385 if (msg == NULL || pattribute == NULL) 385 if (msg == NULL || pattribute == NULL)
386 return EINVAL; 386 return EINVAL;
387
387 monitor_wrlock (msg->monitor); 388 monitor_wrlock (msg->monitor);
388 if (msg->attribute == NULL) 389 if (msg->attribute == NULL)
389 { 390 {
......
...@@ -234,6 +234,7 @@ sendmail_send_message (mailer_t mailer, message_t msg) ...@@ -234,6 +234,7 @@ sendmail_send_message (mailer_t mailer, message_t msg)
234 status = errno; 234 status = errno;
235 else if (WIFEXITED(status)) 235 else if (WIFEXITED(status))
236 status = WEXITSTATUS(status); 236 status = WEXITSTATUS(status);
237 observable_notify (mailer->observable, MU_EVT_MAILER_MESSAGE_SENT);
237 } 238 }
238 default: 239 default:
239 break; 240 break;
......
...@@ -583,6 +583,7 @@ smtp_send_message(mailer_t mailer, message_t msg) ...@@ -583,6 +583,7 @@ smtp_send_message(mailer_t mailer, message_t msg)
583 status = smtp_read_ack (smtp); 583 status = smtp_read_ack (smtp);
584 CHECK_EAGAIN (smtp, status); 584 CHECK_EAGAIN (smtp, status);
585 MAILER_DEBUG0 (mailer, MU_DEBUG_PROT, smtp->buffer); 585 MAILER_DEBUG0 (mailer, MU_DEBUG_PROT, smtp->buffer);
586 observable_notify (mailer->observable, MU_EVT_MAILER_MESSAGE_SENT);
586 if (smtp->buffer[0] != '2') 587 if (smtp->buffer[0] != '2')
587 { 588 {
588 stream_close (mailer->stream); 589 stream_close (mailer->stream);
......