* Moved memreadline() to tools.c
authorArt Cancro <ajc@citadel.org>
Wed, 6 Jun 2001 04:22:25 +0000 (04:22 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 6 Jun 2001 04:22:25 +0000 (04:22 +0000)
* internet_addressing.c: fixed conversion of fields to (hopefully) never get
  into an active loop when encountering badly formed headers

citadel/ChangeLog
citadel/internet_addressing.c
citadel/mime_parser.c
citadel/mime_parser.h
citadel/tools.c
citadel/tools.h

index 3fb030447df99516a2834943baa48c7bd2a2194d..1de81e9bc003d1048297dcd30024897a8c51bf50 100644 (file)
@@ -1,4 +1,9 @@
  $Log$
+ Revision 573.135  2001/06/06 04:22:25  ajc
+ * Moved memreadline() to tools.c
+ * internet_addressing.c: fixed conversion of fields to (hopefully) never get
+   into an active loop when encountering badly formed headers
+
  Revision 573.134  2001/05/27 05:23:03  ajc
  * Added a "no new messages" response in the client, displayed when a read
    command turns up a zero message count.
@@ -2526,4 +2531,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import 
-
index 389000713f78db483d7ce552c7cca14d703341ec..182fa023c7ff53d7dbdc7f6e36756932bcb5679a 100644 (file)
@@ -463,19 +463,13 @@ int convert_field(struct CtdlMessage *msg, int beg, int end) {
                        msg->cm_fields['I'] = strdoop(value);
 
                        /* Strip angle brackets */
-                       if ((haschar(msg->cm_fields['I'], '<') == 1)
-                          && (haschar(msg->cm_fields['I'], '>') == 1)) {
-                               while ((strlen(msg->cm_fields['I']) > 0)
-                                     && (msg->cm_fields['I'][0] != '<')) {
-                                       strcpy(&msg->cm_fields['I'][0],
-                                               &msg->cm_fields['I'][1]);
-                               }
+                       while (haschar(msg->cm_fields['I'], '<') > 0) {
                                strcpy(&msg->cm_fields['I'][0],
                                        &msg->cm_fields['I'][1]);
-                               for (i = 0; i<strlen(msg->cm_fields['I']); ++i)
-                                       if (msg->cm_fields['I'][i] == '>')
-                                               msg->cm_fields['I'][i] = 0;
                        }
+                       for (i = 0; i<strlen(msg->cm_fields['I']); ++i)
+                               if (msg->cm_fields['I'][i] == '>')
+                                       msg->cm_fields['I'][i] = 0;
                }
 
                processed = 1;
@@ -497,7 +491,7 @@ int convert_field(struct CtdlMessage *msg, int beg, int end) {
 struct CtdlMessage *convert_internet_message(char *rfc822) {
 
        struct CtdlMessage *msg;
-       int pos, beg, end;
+       int pos, beg, end, msglen;
        int done;
        char buf[SIZ];
        int converted;
@@ -522,18 +516,31 @@ struct CtdlMessage *convert_internet_message(char *rfc822) {
                 */
                beg = pos;
                end = (-1);
-               for (pos=beg; ((pos<=strlen(rfc822))&&(end<0)); ++pos) {
+
+               msglen = strlen(rfc822);        
+               while ( (end < 0) && (done == 0) ) {
+
                        if ((rfc822[pos]=='\n')
                           && (!isspace(rfc822[pos+1]))) {
                                end = pos;
                        }
-                       if ( (rfc822[pos]=='\n')        /* done w. headers? */
+
+                       /* done with headers? */
+                       if (   ((rfc822[pos]=='\n')
+                             ||(rfc822[pos]=='\r') )
                           && ( (rfc822[pos+1]=='\n')
-                             ||(rfc822[pos+1]=='\r'))) {
+                             ||(rfc822[pos+1]=='\r')) ) {
+                               end = pos;
+                               done = 1;
+                       }
+
+                       if (pos >= (msglen-1) ) {
                                end = pos;
                                done = 1;
                        }
 
+                       ++pos;
+
                }
 
                /* At this point we have a field.  Are we interested in it? */
index f1aec5fbd49fcdf518e5e1851380b57f2eeb9677..daf6333c27cc391b8ccd39d1b80f6fb4b0af49cd 100644 (file)
@@ -48,33 +48,6 @@ void extract_key(char *target, char *source, char *key)
 
 
 
-/* 
- * Utility function to "readline" from memory
- * (returns new pointer)
- */
-char *memreadline(char *start, char *buf, int maxlen)
-{
-       char ch;
-       char *ptr;
-       int len = 0;    /* tally our own length to avoid strlen() delays */
-
-       ptr = start;
-       memset(buf, 0, maxlen);
-
-       while (1) {
-               ch = *ptr++;
-               if ( (len < (maxlen - 1)) && (ch != 13) && (ch != 10) ) {
-                       buf[strlen(buf) + 1] = 0;
-                       buf[strlen(buf)] = ch;
-                       ++len;
-               }
-               if ((ch == 10) || (ch == 0)) {
-                       return ptr;
-               }
-       }
-}
-
-
 /*
  * For non-multipart messages, we need to generate a quickie partnum of "1"
  * to return to callback functions.  Some callbacks demand it.
index 7f8be5cd97511bda28c838a0787c1fe0677e18cf..78ed3cbff1ba4517effe65b45426e052b1bf2e15 100644 (file)
@@ -4,7 +4,6 @@
  */
 
 void extract_key(char *target, char *source, char *key);
-
 void mime_parser(char *content_start, char *content_end,
                void (*CallBack)
                        (char *cbname,
index edf78219592a94da780b1f8c19eb482a327f8d75..2c0063a3485d9a95cf1b86fb99b16d8f34521c8c 100644 (file)
@@ -420,3 +420,32 @@ int is_msg_in_mset(char *mset, long msgnum) {
 
        return(0);
 }
+
+
+/*
+ * Utility function to "readline" from memory
+ * (returns new pointer)
+ */
+char *memreadline(char *start, char *buf, int maxlen)
+{
+        char ch;
+        char *ptr;
+        int len = 0;    /* tally our own length to avoid strlen() delays */
+
+        ptr = start;
+        memset(buf, 0, maxlen);
+
+        while (1) {
+                ch = *ptr++;
+                if ( (len < (maxlen - 1)) && (ch != 13) && (ch != 10) ) {
+                        buf[strlen(buf) + 1] = 0;
+                        buf[strlen(buf)] = ch;
+                        ++len;
+                }
+                if ((ch == 10) || (ch == 0)) {
+                        return ptr;
+                }
+        }
+}
+
+
index 9dfbc845b2095f44952867f8ceb0de47bf1f64ed..0ea1e16198197473f099995f73145ddaad39be64 100644 (file)
@@ -12,6 +12,7 @@ int collapsed_strcmp(char *s1, char *s2);
 void remove_token(char *source, int parmnum, char separator);
 void fmt_date(char *buf, time_t thetime);
 int is_msg_in_mset(char *mset, long msgnum);
+char *memreadline(char *start, char *buf, int maxlen);
 
 #ifndef HAVE_STRNCASECMP
 int strncasecmp(char *, char *, int)