]> code.citadel.org Git - citadel.git/blobdiff - citadel/internet_addressing.c
* Bug fixes
[citadel.git] / citadel / internet_addressing.c
index 6e3ccbdeaf62243791c6ce3d0a762f13d85717f4..f6e39e374ecf2c9f82b0e636c3bc190d05b3e54e 100644 (file)
@@ -29,6 +29,7 @@
 #include "tools.h"
 #include "internet_addressing.h"
 #include "user_ops.h"
+#include "room_ops.h"
 #include "parsedate.h"
 
 
@@ -232,7 +233,6 @@ void try_name(struct usersupp *us) {
 }
 
 
-
 /*
  * Convert an Internet email address to a Citadel user/host combination
  */
@@ -241,6 +241,8 @@ int convert_internet_address(char *destuser, char *desthost, char *source)
        char user[256];
        char node[256];
        char name[256];
+       struct quickroom qrbuf;
+       int i;
 
        /* Split it up */
        process_rfc822_addr(source, user, node, name);
@@ -253,17 +255,23 @@ int convert_internet_address(char *destuser, char *desthost, char *source)
                strcpy(node, config.c_nodename);
        }
 
-       /* Return an error condition if the node is not known.
-        * FIX ... make this work for non-local systems
-        */
-       if (strcasecmp(node, config.c_nodename)) {
-               return(rfc822_address_invalid);
-       }
-       
        /* Now try to resolve the name
         * FIX ... do the multiple-addresses thing
         */
        if (!strcasecmp(node, config.c_nodename)) {
+               /* Try all local rooms */
+               if (!strncasecmp(user, "room_", 5)) {
+                       strcpy(name, &user[5]);
+                       for (i=0; i<strlen(name); ++i) 
+                               if (name[i]=='_') name[i]=' ';
+                       if (getroom(&qrbuf, name) == 0) {
+                               strcpy(destuser, qrbuf.QRname);
+                               strcpy(desthost, config.c_nodename);
+                               return rfc822_room_delivery;
+                       }
+               }
+
+               /* Try all local users */
                strcpy(destuser, user);
                strcpy(desthost, config.c_nodename);
                strcpy(CC->buffer1, user);
@@ -274,6 +282,8 @@ int convert_internet_address(char *destuser, char *desthost, char *source)
                return(rfc822_address_locally_validated);
        }
 
+       strcpy(destuser, user);
+       strcpy(desthost, node);
        return(rfc822_address_invalid); /* unknown error */
 }
 
@@ -305,20 +315,19 @@ int convert_field(struct CtdlMessage *msg, int beg, int end) {
 
        if (colonpos < 0) return(0);    /* no colon? not a valid header line */
 
-       value = mallok((end - beg) + 2);
-       safestrncpy(value, &rfc822[beg], (end-beg)+1);
-       key = value;
+       key = mallok((end - beg) + 2);
+       safestrncpy(key, &rfc822[beg], (end-beg)+1);
        key[colonpos - beg] = 0;
        value = &key[(colonpos - beg) + 1];
        unfold_rfc822_field(value);
 
+       lprintf(9, "Key=<%s> Value=<%s>\n", key, value);
+
        /* Here's the big rfc822-to-citadel loop. */
 
        if (!strcasecmp(key, "Date")) {
-               lprintf(9, "converting date <%s>\n", value);
                sprintf(buf, "%ld", parsedate(value) );
-               lprintf(9, "parsed value is <%s>\n", buf);
-               if (msg->cm_fields['T'] != NULL)
+               if (msg->cm_fields['T'] == NULL)
                        msg->cm_fields['T'] = strdoop(buf);
                processed = 1;
        }
@@ -328,27 +337,29 @@ int convert_field(struct CtdlMessage *msg, int beg, int end) {
                node = mallok(strlen(value));
                name = mallok(strlen(value));
                process_rfc822_addr(value, user, node, name);
-               if (msg->cm_fields['A'] != NULL)
-                       msg->cm_fields['A'] = strdoop(user);
-               if (msg->cm_fields['N'] != NULL)
-                       msg->cm_fields['N'] = strdoop(node);
-               if (msg->cm_fields['H'] != NULL)
-                       msg->cm_fields['H'] = strdoop(name);
-               phree(user);
-               phree(node);
-               phree(name);
+               lprintf(9, "Converted to <%s@%s> (%s)\n", user, node, name);
+               if (msg->cm_fields['A'] == NULL)
+                       msg->cm_fields['A'] = user;
+               else
+                       phree(user);
+               if (msg->cm_fields['N'] == NULL)
+                       msg->cm_fields['N'] = node;
+               else
+                       phree(node);
+               if (msg->cm_fields['H'] == NULL)
+                       msg->cm_fields['H'] = name;
+               else
+                       phree(name);
                processed = 1;
        }
 
        else if (!strcasecmp(key, "Subject")) {
-               if (msg->cm_fields['U'] != NULL)
-                       msg->cm_fields['U'] = strdoop(key);
+               if (msg->cm_fields['U'] == NULL)
+                       msg->cm_fields['U'] = strdoop(value);
                processed = 1;
        }
 
        /* Clean up and move on. */
-       lprintf(9, "Field: key=<%s> value=<%s> processed=%d\n",
-               key, value, processed);
        phree(key);     /* Don't free 'value', it's actually the same buffer */
        return(processed);
 }
@@ -361,7 +372,6 @@ struct CtdlMessage *convert_internet_message(char *rfc822) {
 
        struct CtdlMessage *msg;
        int pos, beg, end;
-       int msglen;
        int done;
        char buf[256];
        int converted;
@@ -372,11 +382,10 @@ struct CtdlMessage *convert_internet_message(char *rfc822) {
        memset(msg, 0, sizeof(struct CtdlMessage));
        msg->cm_magic = CTDLMESSAGE_MAGIC;      /* self check */
        msg->cm_anon_type = 0;                  /* never anonymous */
-       msg->cm_format_type = 4;                /* always MIME */
+       msg->cm_format_type = FMT_RFC822;       /* internet message */
        msg->cm_fields['M'] = rfc822;
 
-       /* FIX   there's plenty to do here. */
-       msglen = strlen(rfc822);
+       lprintf(9, "Unconverted RFC822 message length = %d\n", strlen(rfc822));
        pos = 0;
        done = 0;
 
@@ -403,16 +412,18 @@ struct CtdlMessage *convert_internet_message(char *rfc822) {
 
                /* At this point we have a field.  Are we interested in it? */
                converted = convert_field(msg, beg, end);
+
+               /******
                if (converted) {
                        strcpy(&rfc822[beg], &rfc822[pos]);
                        pos = beg;
                }
+               ********/
 
                /* If we've hit the end of the message, bail out */
                if (pos > strlen(rfc822)) done = 1;
        }
 
-
        /* Follow-up sanity checks... */
 
        /* If there's no timestamp on this message, set it to now. */
@@ -421,6 +432,8 @@ struct CtdlMessage *convert_internet_message(char *rfc822) {
                msg->cm_fields['T'] = strdoop(buf);
        }
 
+       lprintf(9, "RFC822 length remaining after conversion = %d\n",
+               strlen(rfc822));
        return msg;
 }