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;
......
......@@ -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
......