* More header parsing stuff. Still needs work.
authorArt Cancro <ajc@citadel.org>
Fri, 17 Dec 1999 22:42:04 +0000 (22:42 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 17 Dec 1999 22:42:04 +0000 (22:42 +0000)
citadel/internet_addressing.c
citadel/internet_addressing.h
citadel/serv_smtp.c

index 6dc5a1fc683efe4c6cecc8c775e97e84d6c95f28..80c7e05aea844d51367313510390dde9e8f55a09 100644 (file)
@@ -10,6 +10,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <fcntl.h>
+#include <ctype.h>
 #include <signal.h>
 #include <pwd.h>
 #include <errno.h>
@@ -263,12 +264,12 @@ int convert_internet_address(char *destuser, char *desthost, char *source)
 struct CtdlMessage *convert_internet_message(char *rfc822) {
 
        struct CtdlMessage *msg;
-       char *buf;
-       int pos;
+       int pos, beg, end;
        int msglen;
        int done;
-       char *field;
        char buf[256];
+       char field[256];
+       int i;
 
        msg = mallok(sizeof(struct CtdlMessage));
        if (msg == NULL) return msg;
@@ -283,15 +284,42 @@ struct CtdlMessage *convert_internet_message(char *rfc822) {
        msglen = strlen(rfc822);
        pos = 0;
        done = 0;
-       field = NULL;
 
        while (!done) {
 
-               for (i=pos; i<=strlen(rfc822); ++i) {
+               /* 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;
+                       }
+
+               }
 
-               
+               /* At this point we have a field.  Are we interested in it? */
+               strcpy(field, "");
+               for (i = beg; i <= end; ++i) {
+                       if ((rfc822[i] == ':') && ((i-beg)<sizeof(field))) {
+                               safestrncpy(field, &rfc822[beg], i-beg+1);
+                       }
+               }
+               fprintf(stderr,
+                       "Field: %6d .. %-6d ... <%s>\n",
+                       beg, end, field);
 
 
+               /* If we've hit the end of the message, bail out */
+               if (pos > strlen(rfc822)) done = 1;
        }
 
 
index 81913878b1a60d78920633e7645831db151a3e5f..7ce714a2c60d9c0c150154c0382a9a5a676ed502 100644 (file)
@@ -1,8 +1,8 @@
 int fuzzy_match(struct usersupp *us, char *matchstring);
 void process_rfc822_addr(char *rfc822, char *user, char *node, char *name);
-int convert_internet_address(char *destuser, char *desthost, char *source);
 
 
+int convert_internet_address(char *destuser, char *desthost, char *source);
 enum {
        rfc822_address_locally_validated,
        rfc822_no_such_user,
@@ -10,3 +10,5 @@ enum {
        rfc822_address_invalid
 };
 
+
+struct CtdlMessage *convert_internet_message(char *rfc822);
index d370d03feedbcd69c5485dd7ab997522c388399d..fe78592880f2579947df6272b069b8c32dc1f07f 100644 (file)
@@ -368,7 +368,9 @@ void smtp_rcpt(char *argbuf) {
  */
 void smtp_data(void) {
        char *body;
+       struct CtdlMessage *msg;
 
+/*
        if (strlen(SMTP->from) == 0) {
                cprintf("503 Need MAIL command first.\n");
                return;
@@ -379,6 +381,8 @@ void smtp_data(void) {
                return;
        }
 
+*/
+
        cprintf("354 Transmit message now; terminate with '.' by itself\n");
        body = CtdlReadMessageBody(".", config.c_maxmsglen);
        if (body == NULL) {
@@ -386,6 +390,9 @@ void smtp_data(void) {
                return;
        }
 
+       fprintf(stderr, "Converting message...\n");
+       msg = convert_internet_message(body);
+
        phree(body);
        cprintf("599 command unfinished\n");
 }