From 01ac687c952f00692404b51f1abfe413c120176d Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 14 Nov 2003 03:49:54 +0000 Subject: [PATCH] * MUCH faster implementation of rfc822_fetch_field() --- citadel/ChangeLog | 4 +- citadel/imap_fetch.c | 6 --- citadel/internet_addressing.c | 78 ++++++++++++++--------------------- 3 files changed, 34 insertions(+), 54 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 09e618943..bfa90993f 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,7 @@ $Log$ + Revision 611.6 2003/11/14 03:49:54 ajc + * MUCH faster implementation of rfc822_fetch_field() + Revision 611.5 2003/11/13 04:25:38 ajc * mime_parser.c: handle multipart *much* more efficiently now. Instead of scanning line by line, we snag the boundaries using the Boyer-Moore @@ -5078,4 +5081,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import - diff --git a/citadel/imap_fetch.c b/citadel/imap_fetch.c index db543c894..cf4c7ebdf 100644 --- a/citadel/imap_fetch.c +++ b/citadel/imap_fetch.c @@ -782,20 +782,14 @@ void imap_do_fetch_msg(int seq, struct CtdlMessage *msg, 1, msg); } else if (!strcasecmp(itemlist[i], "BODYSTRUCTURE")) { - buffer_output(); imap_fetch_bodystructure(IMAP->msgids[seq-1], itemlist[i], msg); - unbuffer_output(); } else if (!strcasecmp(itemlist[i], "ENVELOPE")) { - buffer_output(); imap_fetch_envelope(IMAP->msgids[seq-1], msg); - unbuffer_output(); } else if (!strcasecmp(itemlist[i], "FLAGS")) { - buffer_output(); imap_fetch_flags(seq-1); - unbuffer_output(); } else if (!strcasecmp(itemlist[i], "INTERNALDATE")) { imap_fetch_internaldate(msg); diff --git a/citadel/internet_addressing.c b/citadel/internet_addressing.c index fd16a6f18..2ee155077 100644 --- a/citadel/internet_addressing.c +++ b/citadel/internet_addressing.c @@ -483,62 +483,46 @@ struct CtdlMessage *convert_internet_message(char *rfc822) { * field is not present, or anything else goes wrong, it returns NULL. */ char *rfc822_fetch_field(char *rfc822, char *fieldname) { - int pos = 0; - int beg, end; - int done = 0; - int colonpos, i; char *fieldbuf = NULL; + char *end_of_headers; + char *field_start; + char *ptr; + char *cont; + char fieldhdr[SIZ]; /* Should never happen, but sometimes we get stupid */ if (rfc822 == NULL) return(NULL); if (fieldname == NULL) return(NULL); - while (!done) { - - /* Locate beginning and end of field, keeping in mind that - * some fields might be multiline - */ - beg = pos; - end = (-1); - for (pos=beg; ((pos<=strlen(rfc822))&&(end<0)); ++pos) { - if ((rfc822[pos]=='\n') - && (!isspace(rfc822[pos+1]))) { - end = pos; - } - if ( (rfc822[pos]=='\n') /* done w. headers? */ - && ( (rfc822[pos+1]=='\n') - ||(rfc822[pos+1]=='\r'))) { - end = pos; - done = 1; - } + snprintf(fieldhdr, sizeof fieldhdr, "%s:", fieldname); - } + /* Locate the end of the headers, so we don't run past that point */ + end_of_headers = bmstrstr(rfc822, "\n\r\n", strncmp); + if (end_of_headers == NULL) { + end_of_headers = bmstrstr(rfc822, "\n\n", strncmp); + } + if (end_of_headers == NULL) return (NULL); + + field_start = bmstrstr(rfc822, fieldhdr, strncasecmp); + if (field_start == NULL) return(NULL); + if (field_start > end_of_headers) return(NULL); + + fieldbuf = mallok(SIZ); + strcpy(fieldbuf, ""); + + ptr = field_start; + ptr = memreadline(ptr, fieldbuf, SIZ-strlen(fieldbuf) ); + while ( (isspace(ptr[0])) && (ptr < end_of_headers) ) { + strcat(fieldbuf, " "); + cont = &fieldbuf[strlen(fieldbuf)]; + ptr = memreadline(ptr, cont, SIZ-strlen(fieldbuf) ); + striplt(cont); + } - /* At this point we have a field. Is it The One? */ - if (end > beg) { - fieldbuf = mallok((end-beg)+3); - if (fieldbuf == NULL) return(NULL); - safestrncpy(fieldbuf, &rfc822[beg], (end-beg)+1); - unfold_rfc822_field(fieldbuf); - colonpos = (-1); - for (i = strlen(fieldbuf); i >= 0; --i) { - if (fieldbuf[i] == ':') colonpos = i; - } - if (colonpos > 0) { - fieldbuf[colonpos] = 0; - if (!strcasecmp(fieldbuf, fieldname)) { - strcpy(fieldbuf, &fieldbuf[colonpos+1]); - striplt(fieldbuf); - return(fieldbuf); - } - } - phree(fieldbuf); - } + strcpy(fieldbuf, &fieldbuf[strlen(fieldhdr)]); + striplt(fieldbuf); - /* If we've hit the end of the message, bail out */ - if (pos > strlen(rfc822)) done = 1; - } - return(NULL); + return(fieldbuf); } -- 2.39.2