Commit c6eef46c c6eef46c15d976cac14815952cb49cb4f4069c1e by Alain Magloire

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

1 parent bbbdd3d8
......@@ -45,6 +45,7 @@ typedef struct _observable* observable_t;
#define MU_EVT_MAILBOX_PROGRESS 0x020
#define MU_EVT_AUTHORITY_FAILED 0x030
#define MU_EVT_MAILBOX_CORRUPT 0x040
#define MU_EVT_MAILER_MESSAGE_SENT 0x080
#define MU_OBSERVER_NO_CHECK 1
......
......@@ -743,23 +743,24 @@ mbox_expunge (mailbox_t mailbox)
{
size_t dlast;
for (j = dirty, dlast = mud->messages_count - 1;
j < mud->messages_count; j++)
j <= dlast; j++)
{
/* Clear all the references, any attach messages been already
destroy above. */
mum = mud->umessages[j];
if (mum->new_flags && ATTRIBUTE_IS_DELETED (mum->new_flags))
{
if ((j + 1) >= mud->messages_count)
if ((j + 1) <= dlast)
{
/* Move all the pointers up. So the message pointer
part of mum will be at the right position. */
memmove (mud->umessages + j, mud->umessages + j + 1,
(dlast - dirty) * sizeof (mum));
mum->header_from = mum->header_from_end = 0;
mum->header_status = mum->header_status_end = 0;
mum->body = mum->body_end = 0;
mum->header_lines = mum->body_lines = 0;
(dlast - j) * sizeof (mum));
//mum->header_from = mum->header_from_end = 0;
//mum->header_status = mum->header_status_end = 0;
//mum->body = mum->body_end = 0;
//mum->header_lines = mum->body_lines = 0;
memset (mum, 0, sizeof (*mum));
/* We are not free()ing the useless mum, but instead
we put it back in the pool, to be reuse. */
mud->umessages[dlast] = mum;
......@@ -768,6 +769,10 @@ mbox_expunge (mailbox_t mailbox)
gets cleared to. */
mum = mud->umessages[j];
}
else
{
memset (mum, 0, sizeof (*mum));
}
}
mum->header_from = mum->header_from_end = 0;
mum->header_status = mum->header_status_end = 0;
......
......@@ -384,6 +384,7 @@ message_get_attribute (message_t msg, attribute_t *pattribute)
{
if (msg == NULL || pattribute == NULL)
return EINVAL;
monitor_wrlock (msg->monitor);
if (msg->attribute == NULL)
{
......
......@@ -234,6 +234,7 @@ sendmail_send_message (mailer_t mailer, message_t msg)
status = errno;
else if (WIFEXITED(status))
status = WEXITSTATUS(status);
observable_notify (mailer->observable, MU_EVT_MAILER_MESSAGE_SENT);
}
default:
break;
......
......@@ -583,6 +583,7 @@ smtp_send_message(mailer_t mailer, message_t msg)
status = smtp_read_ack (smtp);
CHECK_EAGAIN (smtp, status);
MAILER_DEBUG0 (mailer, MU_DEBUG_PROT, smtp->buffer);
observable_notify (mailer->observable, MU_EVT_MAILER_MESSAGE_SENT);
if (smtp->buffer[0] != '2')
{
stream_close (mailer->stream);
......