Commit dfe52103 dfe52103c3bae56d7711b0629535c1f808a05c89 by Alain Magloire

General bug fixes to get Imap working. It is getting good but still more

general cleanup need to be done.
1 parent ead97a4b
2001-02-20 Alain Magloire
* mailbox/mailbox.c (mailbox_set_ticket mailbox_set_authority
mailbox_set_stream) : Those objects are now part of th folder
if a folder is attached to the mailbox.
* mailbox/mbx_imap.c (imap_message_read imap_body_read) :
If offset == 0, reset the lines to 0.
2001-02-19 Alain Magloire
* mailbox/mbx_pop.c (pop_body_read) : Move the CHECK_BUSY higher
it should be the first thing done. If the state is POP_NO_STATE
reset the offset and the size to 0 i.e we are starting fresh.
(pop_header_read) : Likewise.
(pop_message_read) : Likewise.
* mailbox/stream.c (stream_write) : Don't call stream_flush().
2001-02-04 Alain Magloire
* mailbox/message.c (message_get_uid) : Add message_get_uid() for
......
......@@ -1150,6 +1150,13 @@ imap_flags (f_imap_t f_imap, char **ptr)
else
f_imap->flags |= MU_ATTRIBUTE_DRAFT;
}
else if (strcasecmp (flag, "\\Read") == 0)
{
if (msg_imap)
msg_imap->flags |= MU_ATTRIBUTE_READ;
else
f_imap->flags |= MU_ATTRIBUTE_READ;
}
}
return 0;
}
......@@ -1260,12 +1267,20 @@ imap_fetch (f_imap_t f_imap)
{
status = imap_internaldate (f_imap, &sp);
}
else if (strncmp (command, "RFC822.SIZE", 10) == 0)
else if (strncmp (command, "RFC822", 10) == 0)
{
if (*sp == '.')
{
sp++;
imap_token (command, &sp);
if (strcasecmp (command, "SIZE") == 0)
{
imap_token (command, &sp);
if (f_imap->callback.msg_imap)
f_imap->callback.msg_imap->message_size = strtoul (command,
NULL, 10);
f_imap->callback.msg_imap->message_size =
strtoul (command, NULL, 10);
}
}
}
else if (strncmp (command, "UID", 3) == 0)
{
......@@ -1281,6 +1296,7 @@ static int
imap_token (char *buf, char **ptr)
{
char *start = *ptr;
/* Skip leading space. */
while (**ptr && **ptr == ' ')
(*ptr)++;
for (; **ptr; (*ptr)++, buf++)
......@@ -1297,6 +1313,9 @@ imap_token (char *buf, char **ptr)
*buf = **ptr;
}
*buf = '\0';
/* Skip tail space. */
while (**ptr && **ptr == ' ')
(*ptr)++;
return *ptr - start;;
}
......
......@@ -424,10 +424,12 @@ header_get_value (header_t header, const char *name, char *buffer,
buflen = (len < buflen) ? len : buflen;
memcpy (buffer, buf, buflen);
buffer[buflen] = '\0';
}
else
buflen = len;
if (pn)
*pn = buflen;
}
}
return err;
}
......
......@@ -308,6 +308,8 @@ mailbox_set_authority (mailbox_t mbox, authority_t authority)
{
if (mbox == NULL)
return EINVAL;
if (mbox->folder)
return folder_set_authority (mbox->folder, authority);
if (mbox->authority)
authority_destroy (&(mbox->authority), mbox);
mbox->authority = authority;
......@@ -319,6 +321,8 @@ mailbox_get_authority (mailbox_t mbox, authority_t *pauthority)
{
if (mbox == NULL || pauthority == NULL)
return EINVAL;
if (mbox->folder)
return folder_get_authority (mbox->folder, pauthority);
*pauthority = mbox->authority;
return 0;
}
......@@ -328,6 +332,8 @@ mailbox_set_ticket (mailbox_t mbox, ticket_t ticket)
{
if (mbox == NULL)
return EINVAL;
if (mbox->folder)
return folder_set_ticket (mbox->folder, ticket);
if (mbox->ticket)
ticket_destroy (&(mbox->ticket), mbox);
mbox->ticket = ticket;
......@@ -339,6 +345,8 @@ mailbox_get_ticket (mailbox_t mbox, ticket_t *pticket)
{
if (mbox == NULL || pticket == NULL)
return EINVAL;
if (mbox->folder)
return folder_get_ticket (mbox->folder, pticket);
*pticket = mbox->ticket;
return 0;
}
......@@ -348,6 +356,8 @@ mailbox_set_stream (mailbox_t mbox, stream_t stream)
{
if (mbox == NULL)
return EINVAL;
if (mbox->folder)
return folder_set_stream (mbox->folder, stream);
if (mbox->stream)
stream_destroy (&(mbox->stream), mbox);
mbox->stream = stream;
......@@ -359,6 +369,8 @@ mailbox_get_stream (mailbox_t mbox, stream_t *pstream)
{
if (mbox == NULL || pstream)
return EINVAL;
if (mbox->folder)
return folder_get_stream (mbox->folder, pstream);
*pstream = mbox->stream;
return 0;
}
......
......@@ -649,6 +649,10 @@ imap_message_read (stream_t stream, char *buffer, size_t buflen,
m_imap_t m_imap = msg_imap->m_imap;
f_imap_t f_imap = m_imap->f_imap;
/* Start over. */
if (offset == 0)
msg_imap->message_lines = 0;
/* Select first. */
if (f_imap->state == IMAP_NO_STATE)
{
......@@ -1007,8 +1011,10 @@ imap_attr_set_flags (attribute_t attribute, int flags)
{
status = imap_writeline (f_imap, "g%d STORE %d +FLAGS.SILENT (%s %s %s %s)\r\n",
f_imap->seq++, msg_imap->num,
(flags & MU_ATTRIBUTE_SEEN) ? "\\Seen" : "",
(flags & MU_ATTRIBUTE_ANSWERED) ? "\\Answered" : "",
(flags & MU_ATTRIBUTE_RECENT) ? "\\Recent" : "",
(flags & MU_ATTRIBUTE_READ) ? "\\Read" : "",
(flags & MU_ATTRIBUTE_SEEN) ? "\\Seen" : "",
(flags & MU_ATTRIBUTE_DRAFT) ? "\\Draft" : "",
(flags & MU_ATTRIBUTE_FLAGGED) ? "\\Flagged" : "");
CHECK_ERROR (f_imap, status);
......@@ -1128,6 +1134,10 @@ imap_header_read (header_t header, char *buffer, size_t buflen, off_t offset,
m_imap_t m_imap = msg_imap->m_imap;
f_imap_t f_imap = m_imap->f_imap;
/* Start over. */
if (offset == 0)
msg_imap->header_lines = 0;
/* Select first. */
if (f_imap->state == IMAP_NO_STATE)
{
......@@ -1168,7 +1178,15 @@ imap_body_size (body_t body, size_t *psize)
message_t msg = body_get_owner (body);
msg_imap_t msg_imap = message_get_owner (msg);
if (psize && msg_imap)
{
if (msg_imap->body_size)
*psize = msg_imap->body_size;
else if (msg_imap->message_size)
*psize = msg_imap->message_size
- (msg_imap->header_size + msg_imap->header_lines);
else
*psize = 0;
}
return 0;
}
......@@ -1200,7 +1218,7 @@ imap_body_read (stream_t stream, char *buffer, size_t buflen, off_t offset,
example "\n" to retrieve from the server, IMAP will transform this to
"\r\n" and since you ask for only 1, the server will send '\r' only.
And ... '\r' will be stripped by (imap_readline()) the number of char
read will be 0 which means we're done .... sigh ... So we guard to at
read will be 0 which means we're done .... sigh ... So we guard by at
least ask for 2 chars. */
if (buflen == 1)
{
......@@ -1208,6 +1226,11 @@ imap_body_read (stream_t stream, char *buffer, size_t buflen, off_t offset,
buffer = newbuf;
buflen = 2;
}
/* Start over. */
if (offset == 0)
msg_imap->body_lines = 0;
/* Select first. */
if (f_imap->state == IMAP_NO_STATE)
{
......