* Renamed CtdlLocalHost() to CtdlHostAlias() and worked it a little deeper into
authorArt Cancro <ajc@citadel.org>
Mon, 7 Feb 2000 05:15:01 +0000 (05:15 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 7 Feb 2000 05:15:01 +0000 (05:15 +0000)
  the message routing logic.  Still needs some work on the gateway-domain
  stuff.
* Twiddled CtdlOutputMsg() a bit for 'all Internet' situations.  Still needs
  some work to avoid printing dual headers when both Cit and RFC822 exist.

citadel/ChangeLog
citadel/internet_addressing.c
citadel/internet_addressing.h
citadel/msgbase.c
citadel/serv_smtp.c

index 27fcd20246f76bcaa4615adbda8e4da7c280570c..03de74fef23269abe13c6785a0210486ece979d6 100644 (file)
@@ -1,4 +1,11 @@
 $Log$
+Revision 1.456  2000/02/07 05:15:00  ajc
+* Renamed CtdlLocalHost() to CtdlHostAlias() and worked it a little deeper into
+  the message routing logic.  Still needs some work on the gateway-domain
+  stuff.
+* Twiddled CtdlOutputMsg() a bit for 'all Internet' situations.  Still needs
+  some work to avoid printing dual headers when both Cit and RFC822 exist.
+
 Revision 1.455  2000/02/03 03:57:35  ajc
 * Formalized the 'Internet Configuration' logistics.  Added new API call
   CtdlLocalHost() to detect aliases for the local host.  Used in SMTP listener.
@@ -1600,4 +1607,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Initial CVS import 
-
index 16e24233348e29d08bf8d006e74d2bba286fc594..ed19a0cc02f8294c33b1d1491e2ca5a1ca746ae6 100644 (file)
@@ -45,25 +45,32 @@ char *inetcfg = NULL;
 /*
  * Return nonzero if the supplied name is an alias for this host.
  */
-int CtdlLocalHost(char *fqdn) {
+int CtdlHostAlias(char *fqdn) {
        int config_lines;
        int i;
        char buf[256];
        char host[256], type[256];
 
-       if (!strcasecmp(fqdn, config.c_fqdn)) return(1);
-       if (inetcfg == NULL) return(0);
+       if (!strcasecmp(fqdn, config.c_fqdn)) return(hostalias_localhost);
+       if (inetcfg == NULL) return(hostalias_nomatch);
 
        config_lines = num_tokens(inetcfg, '\n');
        for (i=0; i<config_lines; ++i) {
                extract_token(buf, inetcfg, i, '\n');
                extract_token(host, buf, 0, '|');
                extract_token(type, buf, 1, '|');
+
                if ( (!strcasecmp(type, "localhost"))
-                  && (!strcasecmp(fqdn, host)))  return(1);
+                  && (!strcasecmp(fqdn, host)))
+                       return(hostalias_localhost);
+
+               if ( (!strcasecmp(type, "gatewaydomain"))
+                  && (!strcasecmp(&fqdn[strlen(fqdn)-strlen(host)], host)))
+                       return(hostalias_gatewaydomain);
+
        }
 
-       return(0);
+       return(hostalias_nomatch);
 }
 
 
@@ -75,11 +82,17 @@ int CtdlLocalHost(char *fqdn) {
 /*
  * Return 0 if a given string fuzzy-matches a Citadel user account
  *
- * FIX ... this needs to be updated to match any and all address syntaxes.
+ * FIX ... this needs to be updated to handle aliases.
  */
 int fuzzy_match(struct usersupp *us, char *matchstring) {
        int a;
 
+       if ( (!strncasecmp(matchstring, "cit", 3)) 
+          && (atol(&matchstring[3]) == us->usernum)) {
+               return 0;
+       }
+
+
        for (a=0; a<strlen(us->fullname); ++a) {
                if (!strncasecmp(&us->fullname[a],
                   matchstring, strlen(matchstring))) {
@@ -283,16 +296,24 @@ int convert_internet_address(char *destuser, char *desthost, char *source)
        char name[256];
        struct quickroom qrbuf;
        int i;
+       int hostalias;
        struct trynamebuf tnb;
+       char buf[256];
 
        /* Split it up */
        process_rfc822_addr(source, user, node, name);
 
        /* Map the FQDN to a Citadel node name
-        * FIX ... we have to check for gateway domains
         */
-       if (CtdlLocalHost(node)) {
-               strcpy(node, config.c_nodename);
+       hostalias =  CtdlHostAlias(node);
+       switch(hostalias) {
+               case hostalias_localhost:
+                       strcpy(node, config.c_nodename);
+                       break;
+
+               case hostalias_gatewaydomain:
+                       extract_token(buf, node, 0, '.');
+                       safestrncpy(node, buf, sizeof buf);
        }
 
        /* Now try to resolve the name
index 86aa0d019bd8cb81d333f7e8ca7d5684f61aa3dd..7f08de119753d190546e99c4d0cf0e794fe639d1 100644 (file)
@@ -13,6 +13,16 @@ enum {
 
 
 struct CtdlMessage *convert_internet_message(char *rfc822);
-int CtdlLocalHost(char *fqdn);
+
+int CtdlHostAlias(char *fqdn);
+
+/* 
+ * Values that can be returned by CtdlHostAlias()
+ */
+enum {
+       hostalias_nomatch,
+       hostalias_localhost,
+       hostalias_gatewaydomain
+};
 
 extern char *inetcfg;
index 867ff964a8b57089e965ffb2a66b42aca2b054f3..47664be6d5ae502b370bba821cdf93a7b87cc654 100644 (file)
@@ -680,7 +680,7 @@ void CtdlFreeMessage(struct CtdlMessage *msg)
 
 
 /*
- * Get a message off disk.  (return value is the message's timestamp)
+ * Get a message off disk.  (returns om_* values found in msgbase.h)
  * 
  */
 int CtdlOutputMsg(long msg_num,                /* message number (local) to fetch */
@@ -821,7 +821,8 @@ FMTEND:             omprintf("%s%s", aaa, nl);
        
                ma->did_print = 1;
        
-               if (!strcasecmp(cbtype, "text/plain")) {
+               if ( (!strcasecmp(cbtype, "text/plain")) 
+                  || (strlen(cbtype)==0) ) {
                        wlen = length;
                        wptr = content;
                        while (wlen--) {
@@ -849,6 +850,8 @@ FMTEND:             omprintf("%s%s", aaa, nl);
 
        /* END NESTED FUNCTION fixed_output() */
 
+       lprintf(7, "CtdlOutputMsg() msgnum=%ld, mode=%d\n", 
+               msg_num, mode);
 
        TheMessage = NULL;
        sprintf(mid, "%ld", msg_num);
@@ -1034,7 +1037,7 @@ FMTEND:           omprintf("%s%s", aaa, nl);
        mptr = TheMessage->cm_fields['M'];
 
        /* Tell the client about the MIME parts in this message */
-       if (TheMessage->cm_format_type == FMT_RFC822) { /* legacy text dump */
+       if (TheMessage->cm_format_type == FMT_RFC822) {
                if (mode == MT_CITADEL) {
                        mime_parser(mptr, NULL, *list_this_part);
                }
@@ -1044,6 +1047,21 @@ FMTEND:          omprintf("%s%s", aaa, nl);
                        CtdlFreeMessage(TheMessage);
                        return(om_ok);
                }
+               else if (mode == MT_RFC822) {   /* unparsed RFC822 dump */
+                       /* FIX ... we have to put some code in here to avoid
+                        * printing duplicate header information when both
+                        * Citadel and RFC822 headers exist.  Preference should
+                        * probably be given to the RFC822 headers.
+                        */
+                       while (ch=*(mptr++), ch!=0) {
+                               if (ch==13) ;
+                               else if (ch==10) omprintf("%s", nl);
+                               else omprintf("%c", ch);
+                       }
+                       if (do_proto) cprintf("000\n");
+                       CtdlFreeMessage(TheMessage);
+                       return(om_ok);
+               }
        }
 
        if (headers_only) {
@@ -1055,7 +1073,6 @@ FMTEND:           omprintf("%s%s", aaa, nl);
        /* signify start of msg text */
        if (mode == MT_CITADEL)
                if (do_proto) cprintf("text\n");
-       /* if ((mode == MT_RFC822) && (TheMessage->cm_format_type != FMT_RFC822)) { */
        if (mode == MT_RFC822) {
                omprintf("%s", nl);
        }
index 287a993bf7ee2708613a3bf318480aa5125da86a..b90f7f45faab3c92520620b5d9ecce1acd5379e1 100644 (file)
@@ -35,6 +35,7 @@
 
 struct citsmtp {               /* Information about the current session */
        int command_state;
+       char helo_node[256];
        struct usersupp vrfy_buffer;
        int vrfy_count;
        char vrfy_match[256];
@@ -91,6 +92,8 @@ void smtp_greeting(void) {
  */
 void smtp_hello(char *argbuf, int is_esmtp) {
 
+       safestrncpy(SMTP->helo_node, argbuf, sizeof SMTP->helo_node);
+
        if (!is_esmtp) {
                cprintf("250 Greetings and joyous salutations.\r\n");
        }
@@ -328,9 +331,9 @@ void smtp_mail(char *argbuf) {
        else {
                cvt = convert_internet_address(user, node, SMTP->from);
                lprintf(9, "cvt=%d, citaddr=<%s@%s>\n", cvt, user, node);
-               if (!strcasecmp(node, config.c_nodename)) { /* FIX use fcn */
+               if (CtdlHostAlias(node) == hostalias_localhost) {
                        cprintf("550 You must log in to send mail from %s\r\n",
-                               config.c_fqdn);
+                               node);
                        strcpy(SMTP->from, "");
                        return;
                }
@@ -541,11 +544,12 @@ void smtp_data(void) {
        
        generate_rfc822_datestamp(nowstamp, time(NULL));
        body = mallok(4096);
+
        if (body != NULL) sprintf(body,
                "Received: from %s\n"
                "       by %s;\n"
                "       %s\n",
-                       "FIX.FIX.com",
+                       SMTP->helo_node,
                        config.c_fqdn,
                        nowstamp);