Commit 920daf3b 920daf3b3206c3ffb39fe9662c6d0e95110451bb by Alain Magloire

mbx_unix.c message.c message.h message0.h rfc822.c

message_get_size.
1 parent de5a84ae
......@@ -1265,9 +1265,9 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg)
off_t offset = 0;
mailbox_unix_data_t mud;
mailbox_unix_message_t mum;
message_t msg;
istream_t is;
header_t header;
message_t msg = NULL;
istream_t is = NULL;
header_t header = NULL;
if (mbox == NULL || pmsg == NULL ||
(mud = (mailbox_unix_data_t)mbox->data) == NULL ||
......@@ -1294,6 +1294,9 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg)
return status;
}
if (nread == 0)
break;
tbuf = realloc (pbuf, offset + nread);
if (tbuf == NULL)
{
......@@ -1315,8 +1318,9 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg)
}
/* set the header */
status = header_init (&header, pbuf, offset, MU_HEADER_RFC822, mum);
if (status != 0)
if ((status = header_init (&header, pbuf,
offset, MU_HEADER_RFC822, mum)) != 0 ||
(status = message_set_header (msg, header, mum)) != 0)
{
free (pbuf);
message_destroy (&msg, mum);
......@@ -1327,9 +1331,9 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg)
/* prepare the istream */
status = istream_init (&is, mailbox_unix_readstream, mum);
if (status != 0)
if ((status = istream_init (&is, mailbox_unix_readstream, mum)) != 0 ||
(status = message_set_istream (msg, is, mum)) != 0)
{
free (pbuf);
message_destroy (&msg, mum);
return status;
}
......@@ -1337,6 +1341,19 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg)
/* set the attribute */
status = message_set_attribute (msg, mum->new_attr, mum);
if (status != 0)
{
message_destroy (&msg, mum);
return status;
}
/* set the size */
status = message_set_size (msg, mum->body_end - mum->body, mum);
if (status != 0)
{
message_destroy (&msg, mum);
return status;
}
if (pmsg)
*pmsg = msg;
......
......@@ -157,7 +157,7 @@ message_destroy (message_t *pmsg, void *owner)
message_t msg = *pmsg;
msg->ref_count--;
if ((msg->owner && msg->owner != owner) ||
if ((msg->owner && msg->owner == owner) ||
(msg->owner == NULL && msg->ref_count <= 0))
{
/* header */
......@@ -247,13 +247,24 @@ message_set_ostream (message_t msg, ostream_t os, void *owner)
}
int
message_size (message_t msg, size_t *size)
message_get_size (message_t msg, size_t *psize)
{
if (msg == NULL)
return EINVAL;
if (msg->_size)
return msg->_size (msg, size);
return ENOSYS;
if (psize)
*psize = msg->size;
return 0;
}
int
message_set_size (message_t msg, size_t size, void *owner)
{
if (msg == NULL)
return EINVAL;
if (msg->owner != owner)
return EACCES;
msg->size = size;
return 0;
}
int
......
......@@ -54,6 +54,7 @@ extern int message_set_ostream __P ((message_t, ostream_t, void *owner));
extern int message_is_multipart __P ((message_t));
extern int message_get_size __P ((message_t, size_t *));
extern int message_set_size __P ((message_t, size_t, void *owner));
extern int message_get_attribute __P ((message_t, attribute_t *));
extern int message_set_attribute __P ((message_t, attribute_t, void *owner));
......
......@@ -48,6 +48,7 @@ struct _message
body_t body;
attribute_t attribute;
size_t num;
size_t size;
/* who is the owner */
void *owner;
......