Commit 9a23cb9f 9a23cb9fed48f2a7964ddcbe9c6401746ca0f5bd by Alain Magloire

header.c mailbox.c mailbox.h mailbox0.h mbx_unix.c message.c

Possibility to restart the scan.
1 parent 0b61ff71
......@@ -244,7 +244,8 @@ header_get_value (header_t header, const char *name, char *buffer,
for (name_len = strlen (name), i = 0; i < header->hdr_count; i++)
{
fn_len = header->hdr[i].fn_end - header->hdr[i].fn;
if (fn_len == name_len && memcmp (header->hdr[i].fn, name, fn_len) == 0)
if (fn_len == name_len &&
strncasecmp (header->hdr[i].fn, name, fn_len) == 0)
{
fv_len = (header->hdr[i].fv_end - header->hdr[i].fv);
total += fv_len;
......@@ -252,7 +253,7 @@ header_get_value (header_t header, const char *name, char *buffer,
if (buffer && threshold > 0)
{
threshold -= fv_len;
if (threshold > 0)
if (threshold >= 0)
{
memcpy (buffer, header->hdr[i].fv, fv_len);
buffer += fv_len;
......
......@@ -165,6 +165,14 @@ mailbox_is_updated (mailbox_t mbox)
return mbox->_is_updated (mbox);
}
int
mailbox_scan (mailbox_t mbox, size_t msgno, size_t *pcount)
{
if (mbox == NULL || mbox->_scan == NULL)
return 0;
return mbox->_scan (mbox, msgno, pcount);
}
/* locking */
int
mailbox_set_locker (mailbox_t mbox, locker_t locker)
......@@ -262,15 +270,17 @@ mailbox_deregister (mailbox_t mbox, void *action)
return ENOENT;
}
void
int
mailbox_notification (mailbox_t mbox, size_t type)
{
size_t i;
event_t event;
int status = 0;
for (i = 0; i < mbox->event_num; i++)
{
event = &(mbox->event[i]);
if ((event->_action) && (event->type & type))
event->_action (type, event->arg);
status |= event->_action (type, event->arg);
}
return status;
}
......
......@@ -72,9 +72,8 @@ extern int mailbox_get_auth __P ((mailbox_t, auth_t *auth));
extern int mailbox_set_auth __P ((mailbox_t, auth_t auth));
/* update and scanning*/
extern int mailbox_progress __P ((mailbox_t, int (*progress)
__P ((int, void *)), void *arg));
extern int mailbox_is_updated __P ((mailbox_t));
extern int mailbox_scan __P ((mailbox_t, size_t msgno, size_t *count));
/* mailbox size ? */
extern int mailbox_size __P ((mailbox_t, off_t size));
......
......@@ -65,6 +65,7 @@ struct _mailbox
int (*_messages_count) __P ((mailbox_t, size_t *num));
int (*_expunge) __P ((mailbox_t));
int (*_scan) __P ((mailbox_t, size_t msgno, size_t *count));
int (*_is_updated) __P ((mailbox_t));
int (*_size) __P ((mailbox_t, off_t *size));
......@@ -90,7 +91,7 @@ extern int mailbox_get_attribute __P ((mailbox_t mbox, size_t msgno,
attribute_t *attr));
extern int mailbox_set_attribute __P ((mailbox_t mbox, size_t msgno,
attribute_t attr));
extern void mailbox_notification __P ((mailbox_t mbox, size_t type));
extern int mailbox_notification __P ((mailbox_t mbox, size_t type));
#ifdef __cplusplus
......
......@@ -96,14 +96,15 @@ message_clone (message_t msg)
offset += nread;
} while (nread > 0);
status = header_init (&header, pbuf, offset, NULL);
if (status != 0)
{
free (pbuf);
return status;
}
free (pbuf);
}
/* set the new header */
status = header_init (&header, pbuf, offset, msg);
if (status != 0)
{
free (pbuf);
return status;
}
free (pbuf);
/* retrieve the body */
{
......@@ -111,7 +112,7 @@ message_clone (message_t msg)
file = tmpfile ();
if (file == NULL)
{
header_destroy (&header, NULL);
header_destroy (&header, msg);
return errno;
}
offset = 0;
......@@ -122,7 +123,7 @@ message_clone (message_t msg)
} while (status == EAGAIN);
if (status != 0)
{
header_destroy (&header, NULL);
header_destroy (&header, msg);
return status;
}
fwrite (buffer, sizeof (*buffer), nread, file);
......@@ -136,33 +137,33 @@ message_clone (message_t msg)
if (body == NULL)
{
fclose (file);
header_destroy (&header, NULL);
header_destroy (&header, msg);
return ENOMEM;
}
status = istream_init (&is, message_read, NULL);
status = istream_init (&is, message_read, msg);
if (status != 0)
{
fclose (file);
header_destroy (&header, NULL);
header_destroy (&header, msg);
return status;
}
status = ostream_init (&os, message_write, NULL);
status = ostream_init (&os, message_write, msg);
if (status != 0)
{
fclose (file);
header_destroy (&header, NULL);
istream_destroy (&is, NULL);
header_destroy (&header, msg);
istream_destroy (&is, msg);
return status;
}
/* attribute */
status = attribute_init (&attribute, NULL);
status = attribute_init (&attribute, msg);
if (status != 0)
{
fclose (file);
header_destroy (&header, NULL);
istream_destroy (&is, NULL);
ostream_destroy (&os, NULL);
header_destroy (&header, msg);
istream_destroy (&is, msg);
ostream_destroy (&os, msg);
}
attribute_copy (attribute, msg->attribute);
......@@ -229,6 +230,8 @@ message_destroy (message_t *pmsg, void *owner)
free (body->content);
free (body);
}
/* notifications are done */
free (msg->event);
/* check again for resurrection before free()ing
* the memory maybe it was clone, if yes we can not
* free the pointer.
......@@ -415,10 +418,10 @@ static int
message_read (istream_t is, char *buf, size_t buflen,
off_t off, ssize_t *pnread )
{
message_t msg = NULL;
message_t msg;
ssize_t nread = 0;
if (is == NULL)
if (is == NULL || (msg = is->owner) == NULL)
return EINVAL;
if (msg->body)
......@@ -469,10 +472,10 @@ static int
message_write (ostream_t os, const char *buf, size_t buflen,
off_t off, ssize_t *pnwrite)
{
message_t msg = NULL;
message_t msg;
ssize_t nwrite = 0;
if (os == NULL)
if (os == NULL || (msg = os->owner) == NULL)
return EINVAL;
if (msg->body)
......