Commit c9b8e345 c9b8e3457b73143645054fc302c9be84b562b516 by Alain Magloire

ChangeLog : Updated

doc/mailbox.texi : Why is this always show? I did not touch it.
lib/strtok_r.c : Return NULL and save the old pointer.
mailbox/folder_imap.c mailbox/mbx_imap.c: Implement FETCH .. ye!!!
mailbox/mbx_mbox.c : some comments.
1 parent 9253cfd5
2001-02-25 Alain Magloire
* lib/strtok_r.c : If there are no delimiters left save the old string
and return NULL.
* mailbox/folder_imap.c (imap_fetch) : Finish imap FETCH command.
(imap_rfc822) : New Function.
(imap_rfc822_text) : New Function.
(imap_rfc822_size) : New Function.
(imap_rfc822_header) : New Function.
(imap_uid) : New Function.
(imap_body) : New Function.
(imap_bodystructure0) : Save the size.
2001-02-22 Alain Magloire
* mailbox/property.c : New file.
......
......@@ -43,7 +43,10 @@ strtok_r (s, delim, save_ptr)
/* Scan leading delimiters. */
s += strspn (s, delim);
if (*s == '\0')
return NULL;
{
*save_ptr = s;
return NULL;
}
/* Find the end of the token. */
token = s;
......
......@@ -20,6 +20,7 @@
#endif
#include <stdlib.h>
#include <ctype.h>
#include <stdarg.h>
#include <errno.h>
#include <string.h>
......@@ -62,14 +63,23 @@ static int folder_imap_unsubscribe __P ((folder_t, const char *));
/* Private */
/* static int imap_readline (f_imap_t); */
/* FETCH */
static int imap_fetch __P ((f_imap_t));
static int imap_rfc822 __P ((f_imap_t, char **));
static int imap_rfc822_size __P ((f_imap_t, char **));
static int imap_rfc822_header __P ((f_imap_t, char **));
static int imap_rfc822_text __P ((f_imap_t, char **));
static int imap_flags __P ((f_imap_t, char **));
static int imap_bodystructure __P ((f_imap_t, char **));
static int imap_body __P ((f_imap_t, char **));
static int imap_uid __P ((f_imap_t, char **));
/* String. */
static int imap_literal_string __P ((f_imap_t, char **));
static int imap_string __P ((f_imap_t, char **));
static int imap_quoted_string __P ((f_imap_t, char **));
#define TOKENLEN 32
static int imap_token __P ((char *, char **));
static int imap_token __P ((char *, size_t, char **));
/* Initialize the concrete IMAP mailbox: overload the folder functions */
int
......@@ -750,37 +760,37 @@ imap_literal_string (f_imap_t f_imap, char **ptr)
memcpy (f_imap->callback.buffer + f_imap->callback.total,
f_imap->buffer, x);
f_imap->callback.total += x;
}
/* Depending on the type of request we incremente the xxxx_lines
and xxxx_sizes. */
nl = (memchr (f_imap->buffer, '\n', len0)) ? 1 : 0;
if (f_imap->callback.msg_imap)
{
switch (f_imap->callback.type)
/* Depending on the type of request we incremente the xxxx_lines
and xxxx_sizes. */
nl = (memchr (f_imap->buffer, '\n', len0)) ? 1 : 0;
if (f_imap->callback.msg_imap)
{
case IMAP_HEADER:
f_imap->callback.msg_imap->header_lines += nl;
f_imap->callback.msg_imap->header_size += f_imap->callback.total;
break;
switch (f_imap->callback.type)
{
case IMAP_HEADER:
f_imap->callback.msg_imap->header_lines += nl;
f_imap->callback.msg_imap->header_size += x;
break;
case IMAP_BODY:
f_imap->callback.msg_imap->body_lines += nl;
f_imap->callback.msg_imap->body_size += f_imap->callback.total;
break;
case IMAP_BODY:
f_imap->callback.msg_imap->body_lines += nl;
f_imap->callback.msg_imap->body_size += x;
break;
case IMAP_MESSAGE:
f_imap->callback.msg_imap->message_lines += nl;
/* The message size is known by sending RFC822.SIZE. */
case IMAP_MESSAGE:
f_imap->callback.msg_imap->message_lines += nl;
/* The message size is known by sending RFC822.SIZE. */
default:
break;
default:
break;
}
}
}
}
f_imap->callback.nleft -= total;
/* Move the command buffer, or do a full readline. */
if (len == (f_imap->nl - f_imap->buffer))
if (len == (size_t)(f_imap->nl - f_imap->buffer))
{
len = 0;
status = imap_readline (f_imap);
......@@ -843,6 +853,7 @@ imap_string (f_imap_t f_imap, char **ptr)
/* NIL */
case 'N':
case 'n':
(*ptr)++; /* N|n */
(*ptr)++; /* I|i */
(*ptr)++; /* L|l */
break;
......@@ -992,22 +1003,49 @@ imap_bodystructure0 (msg_imap_t msg_imap, char **ptr)
int paren = 0;
int no_arg = 0;
int status = 0;
int have_size = 0;
/* Skip space. */
while (**ptr == ' ')
(*ptr)++;
if (**ptr != '(')
return 0; /* Something is wrong. */
/* Pass lparen. */
++(*ptr);
paren++;
no_arg++;
for (; **ptr; ++(*ptr))
if (**ptr == '(')
{
++(*ptr);
paren++;
no_arg++;
}
/* NOTE : this loop has side effects in strtol() and imap_string(), the
order of the if's are important. */
while (**ptr)
{
/* Skip the string argument. */
if (**ptr != '(' && **ptr != ')')
{
char *start = *ptr;
/* FIXME: set the command callback if EAGAIN to resume. */
status = imap_string (msg_imap->m_imap->f_imap, ptr);
if (status != 0)
return status;
if (start != *ptr)
no_arg = 0;
}
if (isdigit (**ptr))
{
char *start = *ptr;
size_t size = strtoul (*ptr, ptr, 10);
if (start != *ptr)
{
if (!have_size && msg_imap && msg_imap->parent)
msg_imap->message_size = size;
have_size = 1;
no_arg = 0;
}
}
if (**ptr == '(')
{
paren++;
if (no_arg)
{
msg_imap_t new_part;
......@@ -1016,10 +1054,10 @@ imap_bodystructure0 (msg_imap_t msg_imap, char **ptr)
((msg_imap->num_parts + 1) * sizeof (*tmp)));
if (tmp)
{
msg_imap->parts = tmp;
new_part = calloc (1, sizeof (*new_part));
if (new_part)
{
msg_imap->parts = tmp;
msg_imap->parts[msg_imap->num_parts] = new_part;
new_part->part = ++(msg_imap->num_parts);
new_part->parent = msg_imap;
......@@ -1027,36 +1065,44 @@ imap_bodystructure0 (msg_imap_t msg_imap, char **ptr)
new_part->m_imap = msg_imap->m_imap;
new_part->flags = msg_imap->flags;
status = imap_bodystructure0 (new_part, ptr);
/* Jump up, the rparen been swallen already. */
continue;
}
else
status = ENOMEM;
{
status = ENOMEM;
free (tmp);
break;
}
}
else
status = ENOMEM;
{
status = ENOMEM;
break;
}
}
paren++;
}
if (**ptr == ')')
{
no_arg = 1;
paren--;
/* Did we reach the same number of close paren ? */
if (paren <= 0)
break;
{
/* Swallow the rparen. */
(*ptr)++;
break;
}
}
/* Skip the rests */
else
{
/* FIXME: set the command callback if EAGAIN to resume. */
status = imap_string (msg_imap->m_imap->f_imap, ptr);
if (status != 0)
return status;
no_arg = 0;
}
if (**ptr == '\0')
break;
(*ptr)++;
}
return 0;
return status;
}
static int
......@@ -1164,14 +1210,39 @@ imap_flags (f_imap_t f_imap, char **ptr)
static int
imap_body (f_imap_t f_imap, char **ptr)
{
char *sep;
int status;
while (**ptr && **ptr == ' ')
(*ptr)++;
if (**ptr == '[')
{
sep = strchr (*ptr, ']');
char *sep = strchr (*ptr, ']');
if (sep)
{
size_t len = sep - *ptr;
char *section = alloca (len + 1);
char *p = section;
strncpy (section, *ptr, len);
section[len] = '\0';
/* strupper. */
for (; *p; p++)
if (isalpha((unsigned)*p))
*p = toupper ((unsigned)*p);
/* Check to see the callback type to update the line count. */
if (strstr (section, "MIME")
|| (strstr (section, "HEADER") && ! strstr (section, "FIELD")))
{
f_imap->callback.type = IMAP_HEADER;
}
else if (strstr (section, "TEXT"))
{
f_imap->callback.type = IMAP_BODY;
}
else if (len == 1) /* body[] */
{
f_imap->callback.type = IMAP_MESSAGE;
}
sep++;
*ptr = sep;
}
......@@ -1180,14 +1251,16 @@ imap_body (f_imap_t f_imap, char **ptr)
(*ptr)++;
if (**ptr == '<')
{
sep = strchr (*ptr, '>');
char *sep = strchr (*ptr, '>');
if (sep)
{
sep++;
*ptr = sep;
}
}
return imap_string (f_imap, ptr);
status = imap_string (f_imap, ptr);
f_imap->callback.type = IMAP_MESSAGE;
return status;
}
static int
......@@ -1196,15 +1269,80 @@ imap_internaldate (f_imap_t f_imap, char **ptr)
return imap_string (f_imap, ptr);
}
/* Parse imap unfortunately FETCH is use as response for many commands. */
static int
imap_uid (f_imap_t f_imap, char **ptr)
{
char token[128];
imap_token (token, sizeof (token), ptr);
if (f_imap->callback.msg_imap)
f_imap->callback.msg_imap->uid = strtoul (token, NULL, 10);
return 0;
}
static int
imap_rfc822 (f_imap_t f_imap, char **ptr)
{
int status;
f_imap->callback.type = IMAP_MESSAGE;
status = imap_body (f_imap, ptr);
f_imap->callback.type = 0;
return status;
}
static int
imap_rfc822_size (f_imap_t f_imap, char **ptr)
{
char token[128];
imap_token (token, sizeof (token), ptr);
if (f_imap->callback.msg_imap)
f_imap->callback.msg_imap->message_size = strtoul (token, NULL, 10);
return 0;
}
static int
imap_rfc822_header (f_imap_t f_imap, char **ptr)
{
int status;
f_imap->callback.type = IMAP_HEADER;
status = imap_string (f_imap, ptr);
f_imap->callback.type = 0;
return status;
}
static int
imap_rfc822_text (f_imap_t f_imap, char **ptr)
{
int status;
f_imap->callback.type = IMAP_HEADER;
status = imap_string (f_imap, ptr);
f_imap->callback.type = 0;
return status;
}
/* Parse imap unfortunately FETCH is use as response for many commands.
We just use a small set an ignore the other ones :
not use : ALL
use : BODY
not use : BODY[<section>]<<partial>>
use : BODY.PEEK[<section>]<<partial>>
not use : BODYSTRUCTURE
not use : ENVELOPE
not use : FAST
use : FLAGS
not use : FULL
use : INTERNALDATE
not use : RFC822
not use : RFC822.HEADER
use : RFC822.SIZE
not use : RFC822.TEXT
not use : UID
*/
static int
imap_fetch (f_imap_t f_imap)
{
char command[128];
char token[128];
size_t msgno = 0;
size_t len = f_imap->nl - f_imap->buffer;
m_imap_t m_imap = f_imap->selected;
const char *delim = " ";
int status = 0;
char *sp = NULL;
......@@ -1215,12 +1353,12 @@ imap_fetch (f_imap_t f_imap)
sp = f_imap->buffer;
/* Skip untag '*'. */
imap_token (command, &sp);
imap_token (token, sizeof (token), &sp);
/* Get msgno. */
imap_token (command, &sp);
msgno = strtol (command, NULL, 10);
imap_token (token, sizeof (token), &sp);
msgno = strtol (token, NULL, 10);
/* Skip FETCH . */
imap_token (command, &sp);
imap_token (token, sizeof (token), &sp);
/* It is actually possible, but higly unlikely that we do not have the
message yet, for example a "FETCH (FLAGS (\Recent))" notification
......@@ -1239,73 +1377,81 @@ imap_fetch (f_imap_t f_imap)
}
}
}
// assert (msg_imap != NULL);
#if 0
/* skip to '(' */
while (*sp && *sp != '(')
sp++;
#endif
/* Get the commands. */
while (*sp && *sp != ')')
{
imap_token (command, &sp);
if (strncmp (command, "FLAGS", 5) == 0)
/* Get the token. */
imap_token (token, sizeof (token), &sp);
if (strncmp (token, "FLAGS", 5) == 0)
{
status = imap_flags (f_imap, &sp);
}
else if (strcasecmp (command, "BODY") == 0
|| strcasecmp (command, "BODYSTRUCTURE") == 0)
else if (strcasecmp (token, "BODY") == 0)
{
if (*sp == '[')
status = imap_body (f_imap, &sp);
status = imap_body (f_imap, &sp);
else
status = imap_bodystructure (f_imap, &sp);
}
else if (strncmp (command, "INTERNALDATE", 12) == 0)
else if (strcasecmp (token, "BODYSTRUCTURE") == 0)
{
status = imap_bodystructure (f_imap, &sp);
}
else if (strncmp (token, "INTERNALDATE", 12) == 0)
{
status = imap_internaldate (f_imap, &sp);
}
else if (strncmp (command, "RFC822", 10) == 0)
else if (strncmp (token, "RFC822", 10) == 0)
{
if (*sp == '.')
{
sp++;
imap_token (command, &sp);
if (strcasecmp (command, "SIZE") == 0)
imap_token (token, sizeof (token), &sp);
if (strcasecmp (token, "SIZE") == 0)
{
status = imap_rfc822_size (f_imap, &sp);
}
else if (strcasecmp (token, "TEXT") == 0)
{
status = imap_rfc822_text (f_imap, &sp);
}
else if (strcasecmp (token, "HEADER") == 0)
{
imap_token (command, &sp);
if (f_imap->callback.msg_imap)
f_imap->callback.msg_imap->message_size =
strtoul (command, NULL, 10);
status = imap_rfc822_header (f_imap, &sp);
}
/* else fprintf (stderr, "not supported RFC822 option\n"); */
}
else
{
status = imap_rfc822 (f_imap, &sp);
}
}
else if (strncmp (command, "UID", 3) == 0)
else if (strncmp (token, "UID", 3) == 0)
{
imap_token (command, &sp);
if (f_imap->callback.msg_imap)
f_imap->callback.msg_imap->uid = strtoul (command, NULL, 10);
status = imap_uid (f_imap, &sp);
}
/* else fprintf (stderr, "not supported FETCH command\n"); */
}
return status;
}
static int
imap_token (char *buf, char **ptr)
imap_token (char *buf, size_t len, char **ptr)
{
char *start = *ptr;
size_t i;
/* Skip leading space. */
while (**ptr && **ptr == ' ')
(*ptr)++;
for (; **ptr; (*ptr)++, buf++)
for (i = 1; **ptr && i < len; (*ptr)++, buf++, i++)
{
if (**ptr == ' ' || **ptr == '.'
|| **ptr == '(' || **ptr == ')'
|| **ptr == '[' || **ptr == ']'
|| **ptr == '<' || **ptr == '>')
{
/* Advance. */
if (start == (*ptr))
(*ptr)++;
break;
......@@ -1313,7 +1459,7 @@ imap_token (char *buf, char **ptr)
*buf = **ptr;
}
*buf = '\0';
/* Skip tail space. */
/* Skip trailing space. */
while (**ptr && **ptr == ' ')
(*ptr)++;
return *ptr - start;;
......@@ -1498,8 +1644,10 @@ imap_parse (f_imap_t f_imap)
{
break;
}
#if 0
/* Comment out to see all reading traffic. */
/* fprintf (stderr, "\t\t%s", f_imap->buffer); */
fprintf (stderr, "\t\t%s", f_imap->buffer);
#endif
/* We do not want to step over f_imap->buffer since it can be use
further down the chain. */
......
......@@ -80,8 +80,7 @@ static int imap_body_fd (stream_t, int *);
/* Private. */
static int imap_get_fd (msg_imap_t, int *);
static int imap_get_message0 (msg_imap_t, message_t *);
static int message_operation (f_imap_t, msg_imap_t, enum imap_state, char *,
size_t, size_t *);
static int message_operation (f_imap_t, msg_imap_t, char *, size_t, size_t *);
static void free_subparts (msg_imap_t);
static const char *MONTHS[] =
......@@ -687,8 +686,7 @@ imap_message_read (stream_t stream, char *buffer, size_t buflen,
MAILBOX_DEBUG0 (m_imap->mailbox, MU_DEBUG_PROT, f_imap->buffer);
f_imap->state = IMAP_FETCH;
}
return message_operation (f_imap, msg_imap, IMAP_MESSAGE, buffer, buflen,
plen);
return message_operation (f_imap, msg_imap, buffer, buflen, plen);
}
static int
......@@ -708,6 +706,19 @@ imap_message_size (message_t msg, size_t *psize)
f_imap_t f_imap = m_imap->f_imap;
int status;
/* If there is a parent it means it is a sub message, IMAP does not give
the full size of mime messages, so the message_size was retrieve from
doing a bodystructure and represent rather the body_size. */
if (msg_imap->parent)
{
if (psize)
{
*psize = (msg_imap->message_size + msg_imap->header_size)
- msg_imap->message_lines;
}
return 0;
}
/* Select first. */
if (f_imap->state == IMAP_NO_STATE)
{
......@@ -723,7 +734,7 @@ imap_message_size (message_t msg, size_t *psize)
MAILBOX_DEBUG0 (m_imap->mailbox, MU_DEBUG_PROT, f_imap->buffer);
f_imap->state = IMAP_FETCH;
}
status = message_operation (f_imap, msg_imap, 0, 0, 0, 0);
status = message_operation (f_imap, msg_imap, 0, 0, 0);
if (status == 0)
{
if (psize)
......@@ -759,7 +770,7 @@ imap_message_uid (message_t msg, size_t *puid)
MAILBOX_DEBUG0 (m_imap->mailbox, MU_DEBUG_PROT, f_imap->buffer);
f_imap->state = IMAP_FETCH;
}
status = message_operation (f_imap, msg_imap, 0, 0, 0, 0);
status = message_operation (f_imap, msg_imap, 0, 0, 0);
if (status != 0)
return status;
*puid = msg_imap->uid;
......@@ -796,13 +807,13 @@ imap_is_multipart (message_t msg, int *ismulti)
if (status != 0)
return status;
status = imap_writeline (f_imap,
"g%d FETCH %d BODY\r\n",
"g%d FETCH %d BODYSTRUCTURE\r\n",
f_imap->seq++, msg_imap->num);
CHECK_ERROR (f_imap, status);
MAILBOX_DEBUG0 (m_imap->mailbox, MU_DEBUG_PROT, f_imap->buffer);
f_imap->state = IMAP_FETCH;
}
status = message_operation (f_imap, msg_imap, 0, 0, 0, 0);
status = message_operation (f_imap, msg_imap, 0, 0, 0);
if (status != 0)
return status;
if (ismulti)
......@@ -833,6 +844,7 @@ imap_get_part (message_t msg, size_t partno, message_t *pmsg)
{
msg_imap_t msg_imap = message_get_owner (msg);
int status = 0;
if (msg_imap->num_parts == 0)
{
status = imap_get_num_parts (msg, NULL);
......@@ -856,7 +868,8 @@ imap_get_part (message_t msg, size_t partno, message_t *pmsg)
header_t header;
message_get_header (message, &header);
header_set_get_value (header, NULL, message);
message_set_size (message, NULL, msg_imap->parts[partno - 1]);
message_set_stream (message, NULL, msg_imap->parts[partno - 1]);
//message_set_size (message, NULL, msg_imap->parts[partno - 1]);
msg_imap->parts[partno - 1]->message = message;
if (pmsg)
*pmsg = message;
......@@ -880,6 +893,9 @@ imap_envelope_sender (envelope_t envelope, char *buffer, size_t buflen,
header_t header;
int status;
if (buflen == 0)
return 0;
message_get_header (msg, &header);
status = imap_header_get_value (header, MU_HEADER_SENDER, buffer,
buflen, plen);
......@@ -897,6 +913,12 @@ imap_envelope_sender (envelope_t envelope, char *buffer, size_t buflen,
address_destroy (&address);
}
}
else if (status != EAGAIN)
{
strncpy (buffer, "Unknown", buflen)[buflen - 1] = '0';
if (plen)
*plen = strlen (buffer);
}
return status;
}
......@@ -928,7 +950,7 @@ imap_envelope_date (envelope_t envelope, char *buffer, size_t buflen,
MAILBOX_DEBUG0 (m_imap->mailbox, MU_DEBUG_PROT, f_imap->buffer);
f_imap->state = IMAP_FETCH;
}
status = message_operation (f_imap, msg_imap, 0, buffer, buflen, plen);
status = message_operation (f_imap, msg_imap, buffer, buflen, plen);
if (status != 0)
return status;
day = mon = year = hour = min = sec = offt = 0;
......@@ -994,7 +1016,7 @@ imap_attr_get_flags (attribute_t attribute, int *pflags)
MAILBOX_DEBUG0 (m_imap->mailbox, MU_DEBUG_PROT, f_imap->buffer);
f_imap->state = IMAP_FETCH;
}
status = message_operation (f_imap, msg_imap, 0, NULL, 0, NULL);
status = message_operation (f_imap, msg_imap, NULL, 0, NULL);
if (status == 0)
{
if (pflags)
......@@ -1028,7 +1050,7 @@ imap_attr_set_flags (attribute_t attribute, int flags)
msg_imap->flags |= flags;
f_imap->state = IMAP_FETCH;
}
return message_operation (f_imap, msg_imap, 0, NULL, 0, NULL);
return message_operation (f_imap, msg_imap, NULL, 0, NULL);
}
static int
......@@ -1053,7 +1075,7 @@ imap_attr_unset_flags (attribute_t attribute, int flags)
msg_imap->flags &= ~flags;
f_imap->state = IMAP_FETCH;
}
return message_operation (f_imap, msg_imap, 0, NULL, 0, NULL);
return message_operation (f_imap, msg_imap, NULL, 0, NULL);
}
/* Header. */
......@@ -1094,8 +1116,7 @@ imap_header_get_value (header_t header, const char *field, char * buffer,
f_imap->state = IMAP_FETCH;
}
status = message_operation (f_imap, msg_imap, IMAP_HEADER_FIELD, value, len,
&len);
status = message_operation (f_imap, msg_imap, value, len, &len);
if (status == 0)
{
char *colon;
......@@ -1173,8 +1194,7 @@ imap_header_read (header_t header, char *buffer, size_t buflen, off_t offset,
f_imap->state = IMAP_FETCH;
}
return message_operation (f_imap, msg_imap, IMAP_HEADER, buffer, buflen,
plen);
return message_operation (f_imap, msg_imap, buffer, buflen, plen);
}
/* Body. */
......@@ -1185,13 +1205,23 @@ imap_body_size (body_t body, size_t *psize)
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);
/* If there is a parent it means it is a sub message, IMAP does not give
the full size of mime messages, so the message_size was retrieve from
doing a bodystructure and represents rather the body_size. */
if (msg_imap->parent)
{
*psize = msg_imap->message_size - msg_imap->message_lines;
}
else
*psize = 0;
{
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;
}
......@@ -1266,7 +1296,7 @@ imap_body_read (stream_t stream, char *buffer, size_t buflen, off_t offset,
f_imap->state = IMAP_FETCH;
}
status = message_operation (f_imap, msg_imap, IMAP_BODY, buffer, buflen, plen);
status = message_operation (f_imap, msg_imap, buffer, buflen, plen);
if (oldbuf)
oldbuf[0] = buffer[0];
return status;
......@@ -1294,8 +1324,8 @@ imap_get_fd (msg_imap_t msg_imap, int *pfd)
}
static int
message_operation (f_imap_t f_imap, msg_imap_t msg_imap, enum imap_state type,
char *buffer, size_t buflen, size_t *plen)
message_operation (f_imap_t f_imap, msg_imap_t msg_imap, char *buffer,
size_t buflen, size_t *plen)
{
int status = 0;
......@@ -1308,7 +1338,6 @@ message_operation (f_imap_t f_imap, msg_imap_t msg_imap, enum imap_state type,
f_imap->callback.buffer = buffer;
f_imap->callback.buflen = buflen;
f_imap->callback.total = 0;
f_imap->callback.type = type;
f_imap->callback.msg_imap = msg_imap;
f_imap->state = IMAP_FETCH_ACK;
......
......@@ -107,8 +107,8 @@ struct _mbox_message
off_t body_end;
/* Fast header retrieve, we save here the most common header. This will
speed the header search. The header are copied when modified by the
header_t object, we should not worry about updating them. */
speed the header search. The entire headers are copied when modified
by the header_t object, we do not have to worry about updating them. */
char *fhdr[HDRSIZE];
/* IMAP uid. */
......@@ -205,9 +205,10 @@ static int mbox_tmpfile __P ((mailbox_t, char **pbox));
static void mbox_cleanup __P ((void *));
#endif
/* We allocate the mbox_data_t struct, but don't do any parsing on the name or
even test for existence. However we do strip any leading "mbox:" part of
the name, this is suppose to be the protocol/scheme name. */
/* Allocate the mbox_data_t struct(concrete mailbox), but don't do any
parsing on the name or even test for existence. However we do strip any
leading "mbox:" part of the name, this is suppose to be the
protocol/scheme name. */
int
_mailbox_mbox_init (mailbox_t mailbox)
{
......@@ -251,7 +252,7 @@ _mailbox_mbox_init (mailbox_t mailbox)
mailbox->_open = mbox_open;
mailbox->_close = mbox_close;
/* Messages. */
/* Overloading of the entire mailbox object methods. */
mailbox->_get_message = mbox_get_message;
mailbox->_append_message = mbox_append_message;
mailbox->_messages_count = mbox_messages_count;
......@@ -270,7 +271,7 @@ _mailbox_mbox_init (mailbox_t mailbox)
return 0; /* okdoke */
}
/* Free all ressources associated with Unix mailbox. */
/* Free all ressources associated with Unix concrete mailbox. */
static void
mbox_destroy (mailbox_t mailbox)
{
......@@ -348,6 +349,8 @@ mbox_open (mailbox_t mailbox, int flags)
/* All failed, bail out. */
if (status != 0)
return status;
/* Even on top, of normal FILE *, lets agressively cache. But this
may not be suitable for system tight on memory. */
stream_setbufsiz (mailbox->stream, BUFSIZ);
}
else
......@@ -360,6 +363,7 @@ mbox_open (mailbox_t mailbox, int flags)
MAILBOX_DEBUG2 (mailbox, MU_DEBUG_TRACE, "mbox_open(%s, 0x%x)\n",
mud->name, mailbox->flags);
/* Not of any use to try authenticate for a file mailbox. Do it anyways. */
if (mailbox->authority)
{
status = authority_authenticate (mailbox->authority);
......@@ -368,6 +372,7 @@ mbox_open (mailbox_t mailbox, int flags)
}
/* Give an appropriate way to file lock. */
/* FIXME: use dotlock external program: we may not be setgid. */
if (mailbox->locker == NULL)
locker_create (&(mailbox->locker), mud->name, strlen (mud->name),
MU_LOCKER_PID | MU_LOCKER_FCNTL);
......@@ -385,7 +390,7 @@ mbox_close (mailbox_t mailbox)
MAILBOX_DEBUG1 (mailbox, MU_DEBUG_TRACE, "mbox_close(%s)\n", mud->name);
/* Make sure that we do hold any file locking. */
/* Make sure that we do not hold any file locking. */
locker_unlock (mailbox->locker);
monitor_wrlock (mailbox->monitor);
......@@ -418,6 +423,8 @@ mbox_close (mailbox_t mailbox)
/* Mailbox Parsing. Routing was way to ugly to put here. */
#include "mbx_mboxscan.c"
/* Cover function that call the real thing, mbox_scan(), with
notification set. */
static int
mbox_scan (mailbox_t mailbox, size_t msgno, size_t *pcount)
{
......@@ -427,9 +434,10 @@ mbox_scan (mailbox_t mailbox, size_t msgno, size_t *pcount)
}
/* FIXME: How to handle a shrink ? meaning, the &^$^@%#@^& user start two
browsers and deleted emails in one. My views is that we should scream
bloody murder and hunt them with a machette. But for now just play dumb,
but maybe the best approach is to pack our things and leave .i.e exit(). */
browsers and deleted emails in one session. My views is that we should
scream bloody murder and hunt them with a machette. But for now just play
dumb, but maybe the best approach is to pack our things and leave
.i.e exit()/abort(). */
static int
mbox_is_updated (mailbox_t mailbox)
{
......@@ -440,15 +448,15 @@ mbox_is_updated (mailbox_t mailbox)
if (size < mud->size)
{
observable_notify (mailbox->observable, MU_EVT_MAILBOX_CORRUPT);
/* And be verbose. */
fprintf (stderr, "Mailbox corrupted, shrank size\n");
/* FIXME: I should crash. */
/* And be verbose. ? */
fprintf (stderr, "* BAD : Mailbox corrupted, shrank size\n");
/* FIXME: should I crash. */
return 1;
}
return (mud->size == size);
}
/* Try to create an uniq file. */
/* Try to create an uniq file, we no race conditions. */
static int
mbox_tmpfile (mailbox_t mailbox, char **pbox)
{
......@@ -457,7 +465,7 @@ mbox_tmpfile (mailbox_t mailbox, char **pbox)
const char *basename;
mbox_data_t mud = mailbox->data;
/* P_tmpdir should be define in <stdio.h>. */
/* P_tmpdir should be in <stdio.h>. */
#ifndef P_tmpdir
# define P_tmpdir "/tmp"
#endif
......