[dovecot-cvs] dovecot/src/lib-index/mbox mbox-append.c,1.30,1.31 mbox-from.c,1.6,1.7 mbox-fsck.c,1.29,1.30 mbox-index.c,1.38,1.39
cras at procontrol.fi
cras at procontrol.fi
Fri Oct 25 06:31:21 EEST 2002
Update of /home/cvs/dovecot/src/lib-index/mbox
In directory danu:/tmp/cvs-serv31739
Modified Files:
mbox-append.c mbox-from.c mbox-fsck.c mbox-index.c
Log Message:
Small mbox tweaks, hopefully resulting in a bit better performance.
Index: mbox-append.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-append.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- mbox-append.c 24 Oct 2002 00:15:39 -0000 1.30
+++ mbox-append.c 25 Oct 2002 02:31:19 -0000 1.31
@@ -48,7 +48,7 @@
}
if (pos == size || size <= 5 ||
- strncmp((char *) data, "From ", 5) != 0) {
+ strncmp((const char *) data, "From ", 5) != 0) {
/* a) no \n found, or line too long
b) not a From-line */
index_set_error(index, "Error indexing mbox file %s: "
@@ -59,7 +59,7 @@
}
/* parse the From-line */
- internal_date = mbox_from_parse_date((char *) data, size);
+ internal_date = mbox_from_parse_date((const char *) data + 5, size - 5);
if (internal_date == (time_t)-1)
internal_date = ioloop_time;
@@ -84,7 +84,11 @@
/* parse the header and cache wanted fields. get the message flags
from Status and X-Status fields. temporarily limit the buffer size
- so the message body is parsed properly */
+ so the message body is parsed properly.
+
+ the buffer limit is raised again by mbox_header_func after reading
+ the headers. it uses Content-Length if available or finds the next
+ From-line. */
mbox_header_init_context(&ctx, index, inbuf);
ctx.set_read_limit = TRUE;
Index: mbox-from.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-from.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- mbox-from.c 24 Oct 2002 00:15:39 -0000 1.6
+++ mbox-from.c 25 Oct 2002 02:31:19 -0000 1.7
@@ -22,16 +22,10 @@
struct tm tm;
int i;
- i_assert(size > 5);
-
- /* From <sender> <date> <moreinfo> */
- if (strncmp(msg, "From ", 5) != 0)
- return (time_t)-1;
-
+ /* <sender> <date> <moreinfo> */
msg_end = msg + size;
/* skip sender */
- msg += 5;
while (*msg != ' ' && msg < msg_end) msg++;
while (*msg == ' ' && msg < msg_end) msg++;
Index: mbox-fsck.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-fsck.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- mbox-fsck.c 13 Oct 2002 23:49:11 -0000 1.29
+++ mbox-fsck.c 25 Oct 2002 02:31:19 -0000 1.30
@@ -100,8 +100,8 @@
header_offset = inbuf->v_offset;
if (rec->body_size == 0) {
- /* possibly broken message, find the From-line to make sure
- header parser won't pass it. */
+ /* possibly broken message, find the next From-line and make
+ sure header parser won't pass it. */
mbox_skip_header(inbuf);
i_buffer_set_read_limit(inbuf, inbuf->v_offset);
i_buffer_seek(inbuf, header_offset);
Index: mbox-index.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-index.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- mbox-index.c 24 Oct 2002 00:15:39 -0000 1.38
+++ mbox-index.c 25 Oct 2002 02:31:19 -0000 1.39
@@ -302,6 +302,15 @@
size_t item_len;
int i;
+ /* the value is often empty, so check that first */
+ while (len > 0 && IS_LWSP(*value)) {
+ value++;
+ len--;
+ }
+
+ if (len == 0)
+ return;
+
for (i = 0; i < MAIL_CUSTOM_FLAGS_COUNT; i++) {
custom_len[i] = custom_flags[i] != NULL ?
strlen(custom_flags[i]) : 0;
@@ -374,12 +383,19 @@
void mbox_skip_empty_lines(IBuffer *inbuf)
{
const unsigned char *data;
- size_t size;
+ size_t i, size;
/* skip empty lines at beginning */
- while (i_buffer_read_data(inbuf, &data, &size, 0) > 0 &&
- (data[0] == '\r' || data[0] == '\n')) {
- i_buffer_skip(inbuf, 1);
+ while (i_buffer_read_data(inbuf, &data, &size, 0) > 0) {
+ for (i = 0; i < size; i++) {
+ if (data[i] != '\r' && data[i] != '\n')
+ break;
+ }
+
+ i_buffer_skip(inbuf, i);
+
+ if (i < size)
+ break;
}
}
@@ -394,7 +410,7 @@
if (msg[i] == '\n') {
msg += startpos;
i -= startpos;
- return mbox_from_parse_date((char *) msg,
+ return mbox_from_parse_date((const char *) msg,
size) != (time_t)-1;
}
}
@@ -407,63 +423,91 @@
{
const unsigned char *msg;
size_t i, size, startpos;
- int lastmsg;
+ int lastmsg, state, new_state;
- /* read until "[\r]\nFrom " is found */
+ /* read until "[\r]\nFrom " is found. assume '\n' at beginning of
+ buffer */
startpos = i = 0; lastmsg = TRUE;
+ state = '\n';
while (i_buffer_read_data(inbuf, &msg, &size, startpos) > 0) {
for (i = startpos; i < size; i++) {
- if (msg[i] == '\n' && header && i >= 1) {
- /* \n[\r]\n - end of header? */
- if (msg[i-1] == '\n' ||
- (msg[i-1] == '\r' && i >= 2 &&
- msg[i-2] == '\n')) {
- i++;
- break;
+ new_state = 0;
+ switch (state) {
+ case '\n':
+ if (msg[i] == 'F')
+ new_state = 'F';
+ else if (header) {
+ if (msg[i] == '\n') {
+ /* \n\n */
+ i_buffer_skip(inbuf, i+1);
+ return;
+ }
+
+ if (msg[i] == '\r')
+ new_state = '\r';
}
- }
+ break;
+ case '\r':
+ if (msg[i] == '\n') {
+ /* \n\r\n */
+ i_buffer_skip(inbuf, i+1);
+ return;
+ }
+ break;
+ case 'F':
+ if (msg[i] == 'r')
+ new_state = 'r';
+ break;
+ case 'r':
+ if (msg[i] == 'o')
+ new_state = 'o';
+ break;
+ case 'o':
+ if (msg[i] == 'm')
+ new_state = 'm';
+ break;
+ case 'm':
+ if (msg[i] == ' ') {
+ if (mbox_is_valid_from(inbuf, i+1)) {
+ /* Go back "From" */
+ i -= 4;
- if (msg[i] == ' ' && i >= 5) {
- /* See if it's space after "From" */
- if (msg[i-5] == '\n' && msg[i-4] == 'F' &&
- msg[i-3] == 'r' && msg[i-2] == 'o' &&
- msg[i-1] == 'm') {
- /* check still that the From-line looks
- actually valid, in outbox there
- might be some lines beginning with
- From. */
- if (mbox_is_valid_from(inbuf, i-4)) {
- /* see if we had \r too */
- i -= 5;
+ /* Go back \n, unless we're at
+ beginning of buffer */
+ if (i > 0)
+ i--;
+
+ /* Go back \r if it's there */
if (i > 0 && msg[i-1] == '\r')
i--;
- break;
+
+ i_buffer_skip(inbuf, i);
+ return;
}
}
+ break;
}
- }
- if (i < size) {
- startpos = i;
- lastmsg = FALSE;
- break;
+ if (new_state == 0 && msg[i] == '\n')
+ state = '\n';
+ else
+ state = new_state;
}
- startpos = i < 7 ? i : 7;
+ /* Leave enough space to go back "\r\nFrom" */
+ startpos = i < 6 ? i : 6;
i -= startpos;
i_buffer_skip(inbuf, i);
}
- if (lastmsg && startpos > 0) {
- /* end of file, remove the last [\r]\n */
- msg = i_buffer_get_data(inbuf, &size);
- if (size == startpos) {
- if (msg[startpos-1] == '\n')
- startpos--;
- if (startpos > 0 && msg[startpos-1] == '\r')
- startpos--;
- }
+ /* end of file, leave the last [\r]\n */
+ msg = i_buffer_get_data(inbuf, &size);
+ if (size == startpos && startpos > 0) {
+ if (msg[startpos-1] == '\n')
+ startpos--;
+ if (startpos > 0 && msg[startpos-1] == '\r')
+ startpos--;
}
i_buffer_skip(inbuf, startpos);
@@ -489,8 +533,6 @@
return FALSE;
}
- /* don't bother parsing the whole body, just make
- sure it ends properly */
i_buffer_seek(inbuf, end_offset);
if (inbuf->v_offset == inbuf->v_size) {
@@ -516,7 +558,7 @@
}
return size == 0 ||
- (size >= 5 && strncmp((char *) data, "From ", 5) == 0);
+ (size >= 5 && strncmp((const char *) data, "From ", 5) == 0);
}
int mbox_mail_get_start_offset(MailIndex *index, MailIndexRecord *rec,
More information about the dovecot-cvs
mailing list