* Reworked some of the data structures to handle multiple recipients
authorArt Cancro <ajc@citadel.org>
Sat, 8 Jan 2000 05:00:10 +0000 (05:00 +0000)
committerArt Cancro <ajc@citadel.org>
Sat, 8 Jan 2000 05:00:10 +0000 (05:00 +0000)
* Began implementation of the delivery queue
* Added CtdlReallocUserData()
* CtdlSaveMsg() now returns the local message ID in the database

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

index 677f6ed4132c06e3f2607bf71ec38fb11ff2539c..5c2688f39e4c66af4c98f0ad98dd547eda5593aa 100644 (file)
@@ -1,4 +1,10 @@
 $Log$
+Revision 1.436  2000/01/08 05:00:09  ajc
+* Reworked some of the data structures to handle multiple recipients
+* Began implementation of the delivery queue
+* Added CtdlReallocUserData()
+* CtdlSaveMsg() now returns the local message ID in the database
+
 Revision 1.435  2000/01/06 03:50:34  ajc
 * Replaced citmail.c with a new one that simply SMTP-forwards to Citadel
 * Started outbound SMTP queue work
@@ -1518,4 +1524,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 e9573ad588489b0284feea018bc1251db4924eeb..c61944d938ef597058d291965776d7a3cf5d7217 100644 (file)
@@ -254,6 +254,25 @@ void CtdlAllocUserData(unsigned long requested_sym, size_t num_bytes)
 }
 
 
+/* 
+ * Change the size of a buffer allocated with CtdlAllocUserData()
+ */
+void CtdlReallocUserData(unsigned long requested_sym, size_t num_bytes)
+{
+       struct CtdlSessData *ptr;
+
+       for (ptr = CC->FirstSessData; ptr != NULL; ptr = ptr->next)  {
+               if (ptr->sym_id == requested_sym) {
+                       ptr->sym_data = reallok(ptr->sym_data, num_bytes);
+                       return;
+               }
+       }
+
+       lprintf(2, "CtdlReallocUserData() ERROR: symbol %ld not found!\n",
+               requested_sym);
+}
+
+
 
 
 
index 2c9d2b35a7b09c5f352bb4d21c7d436164e605d5..e4f772d65c945a9e6580df05c153599e71aabc78 100644 (file)
@@ -25,6 +25,7 @@ void cmd_extn (char *argbuf);
 void deallocate_user_data(struct CitContext *con);
 void *CtdlGetUserData(unsigned long requested_sym);
 void CtdlAllocUserData(unsigned long requested_sym, size_t num_bytes);
+void CtdlReallocUserData(unsigned long requested_sym, size_t num_bytes);
 int CtdlGetDynamicSymbol(void);
 void enter_housekeeping_cmd(char *);
 void do_command_loop(void);
index 1eda2ae400d92fa8a0641474e4e95093bf366d1d..0068ee32f8ea2f314ada53d5cdb8bbb3f001f7b8 100644 (file)
@@ -252,13 +252,6 @@ 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
         */
@@ -273,6 +266,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 */
 }
 
index 091a92bb8a2205e69b29057620640dcb0bc69a57..6615cffc0107183e26f0d7a80f53b98d9de16f8d 100644 (file)
@@ -1393,7 +1393,7 @@ int ReplicationChecks(struct CtdlMessage *msg) {
 /*
  * Save a message to disk
  */
-void CtdlSaveMsg(struct CtdlMessage *msg,      /* message to save */
+long CtdlSaveMsg(struct CtdlMessage *msg,      /* message to save */
                char *rec,                      /* Recipient (mail) */
                char *force,                    /* force a particular room? */
                int mailtype,                   /* local or remote type */
@@ -1414,7 +1414,7 @@ void CtdlSaveMsg(struct CtdlMessage *msg, /* message to save */
        static int seqnum = 1;
 
        lprintf(9, "CtdlSaveMsg() called\n");
-       if (is_valid_message(msg) == 0) return;         /* self check */
+       if (is_valid_message(msg) == 0) return(-1);     /* self check */
 
        /* If this message has no timestamp, we take the liberty of
         * giving it one, right now.
@@ -1507,11 +1507,11 @@ void CtdlSaveMsg(struct CtdlMessage *msg,       /* message to save */
 
        /* Perform "before save" hooks (aborting if any return nonzero) */
        lprintf(9, "Performing before-save hooks\n");
-       if (PerformMessageHooks(msg, EVT_BEFORESAVE) > 0) return;
+       if (PerformMessageHooks(msg, EVT_BEFORESAVE) > 0) return(-1);
 
        /* If this message has an Extended ID, perform replication checks */
        lprintf(9, "Performing replication checks\n");
-       if (ReplicationChecks(msg) > 0) return;
+       if (ReplicationChecks(msg) > 0) return(-1);
 
        /* Network mail - send a copy to the network program. */
        if ((strlen(recipient) > 0) && (mailtype == MES_BINARY)) {
@@ -1532,7 +1532,7 @@ void CtdlSaveMsg(struct CtdlMessage *msg, /* message to save */
                system("exec nohup ./netproc -i >/dev/null 2>&1 &");
        }
 
-       if (newmsgid <= 0L) return;
+       if (newmsgid <= 0L) return(-1);
 
        /* Write a supplemental message info record.  This doesn't have to
         * be a critical section because nobody else knows about this message
@@ -1589,6 +1589,8 @@ void CtdlSaveMsg(struct CtdlMessage *msg, /* message to save */
        lprintf(9, "Returning to original room\n");
        if (strcasecmp(hold_rm, CC->quickroom.QRname))
                getroom(&CC->quickroom, hold_rm);
+
+       return(newmsgid);
 }
 
 
index 9cae5ab297f84d11f62d31960367acecb2661af9..4cfb0a1a366ca12ce29665d3262caf31cd76931a 100644 (file)
@@ -44,7 +44,7 @@ void cmd_msg4 (char *cmdbuf);
 void cmd_opna (char *cmdbuf);
 long send_message (struct CtdlMessage *, int, FILE *);
 void loadtroom (void);
-void CtdlSaveMsg(struct CtdlMessage *, char *, char *, int, int);
+long CtdlSaveMsg(struct CtdlMessage *, char *, char *, int, int);
 void quickie_message (char *, char *, char *, char *);
 struct CtdlMessage *make_message (struct usersupp *, char *,
                   char *, int, int, int, char *);
index cc3ce8f4dd594c14f0dd849af947279872878038..34a96804776b1b7ca620112d186ef62fc6d9f05b 100644 (file)
@@ -37,11 +37,11 @@ struct citsmtp {            /* Information about the current session */
        int vrfy_count;
        char vrfy_match[256];
        char from[256];
-       char recipient[256];
        int number_of_recipients;
        int delivery_mode;
 };
 
+
 enum {                         /* Command states for login authentication */
        smtp_command,
        smtp_user,
@@ -53,10 +53,11 @@ enum {                              /* Delivery modes */
        smtp_deliver_remote
 };
 
-#define SMTP ((struct citsmtp *)CtdlGetUserData(SYM_SMTP))
+#define SMTP           ((struct citsmtp *)CtdlGetUserData(SYM_SMTP))
+#define SMTP_RECP      ((char *)CtdlGetUserData(SYM_SMTP_RECP))
 
 long SYM_SMTP;
-
+long SYM_SMTP_RECP;
 
 /*
  * Here's where our SMTP session begins its happy day.
@@ -67,6 +68,8 @@ void smtp_greeting(void) {
        CC->internal_pgm = 1;
        CC->cs_flags |= CS_STEALTH;
        CtdlAllocUserData(SYM_SMTP, sizeof(struct citsmtp));
+       CtdlAllocUserData(SYM_SMTP_RECP, 256);
+       sprintf(SMTP_RECP, "%s", "");
 
        cprintf("220 Welcome to the Citadel/UX ESMTP server at %s\n",
                config.c_fqdn);
@@ -335,40 +338,60 @@ void smtp_rcpt(char *argbuf) {
        int cvt;
        char user[256];
        char node[256];
+       char recp[256];
+       int is_spam = 0;        /* FIX implement anti-spamming */
 
        if (strlen(SMTP->from) == 0) {
                cprintf("503 MAIL first, then RCPT.  Duh.\n");
                return;
        }
 
-       if (SMTP->number_of_recipients > 0) {
-               cprintf("552 Only one recipient allowed (FIX)\n");
-               return;
-       }
-
        if (strncasecmp(argbuf, "To:", 3)) {
                cprintf("501 Syntax error\n");
                return;
        }
 
-       strcpy(SMTP->recipient, &argbuf[3]);
-       striplt(SMTP->recipient);
-       alias(SMTP->recipient);
+       strcpy(recp, &argbuf[3]);
+       striplt(recp);
+       alias(recp);
+
+       cvt = convert_internet_address(user, node, recp);
+       sprintf(recp, "%s@%s", user, node);
+
 
-       cvt = convert_internet_address(user, node, SMTP->recipient);
        switch(cvt) {
                case rfc822_address_locally_validated:
                        cprintf("250 %s is a valid recipient.\n", user);
                        ++SMTP->number_of_recipients;
+                       CtdlReallocUserData(SYM_SMTP_RECP,
+                               strlen(SMTP_RECP) + 1024 );
+                       strcat(SMTP_RECP, "local|");
+                       strcat(SMTP_RECP, user);
+                       strcat(SMTP_RECP, "|0\n");
                        return;
+
                case rfc822_no_such_user:
-                       cprintf("550 %s: no such user\n", SMTP->recipient);
-                       strcpy(SMTP->recipient, "");
+                       cprintf("550 %s: no such user\n", recp);
+                       return;
+
+               case rfc822_address_invalid:
+                       if (is_spam) {
+                               cprintf("551 Away with thee, spammer!\n");
+                       }
+                       else {
+                               cprintf("250 Remote recipient %s ok\n", recp);
+                               ++SMTP->number_of_recipients;
+                               CtdlReallocUserData(SYM_SMTP_RECP,
+                                       strlen(SMTP_RECP) + 1024 );
+                               strcat(SMTP_RECP, "remote|");
+                               strcat(SMTP_RECP, recp);
+                               strcat(SMTP_RECP, "|0\n");
+                               return;
+                       }
                        return;
        }
 
-       strcpy(SMTP->recipient, "");
-       cprintf("599 Unknown error (FIX)\n");
+       cprintf("599 Unknown error\n");
 }
 
 
@@ -386,7 +409,6 @@ int smtp_message_delivery(struct CtdlMessage *msg) {
        int successful_saves = 0;
        int failed_saves = 0;
        long msgid = (-1L);
-       int cvt;
 
        lprintf(9, "smtp_message_delivery() called\n");
 
@@ -396,31 +418,18 @@ int smtp_message_delivery(struct CtdlMessage *msg) {
        if (msg->cm_fields['N']==NULL) msg->cm_fields['N'] = strdoop(node);
        if (msg->cm_fields['H']==NULL) msg->cm_fields['H'] = strdoop(name);
 
-       /* Stuff the boxes */
-       /* FIX modify to handle multiple recipients */
-       cvt = convert_internet_address(user, node, SMTP->recipient);
-       switch(cvt) {
-               case rfc822_address_locally_validated:
-                       lprintf(9, "Delivering to %s\n", user);
-
-                       if (msgid < 0L) {
-                               CtdlSaveMsg(msg,
-                                       user,
-                                       "",
-                                       MES_LOCAL,
-                                       1);
-                       }
-                       else {
-                               /* FIX copy the msgid to another room */
-                       }
-
-                       ++successful_saves;
-                       break;
+       /* Save the message in the queue */
+       msgid = CtdlSaveMsg(msg,
+               "",
+               SMTP_SPOOLOUT_ROOM,
+               MES_LOCAL,
+               1);
+       ++successful_saves;
 
-               case rfc822_no_such_user:
-                       ++failed_saves;
-                       break;
-       }
+               /* FIX go thru each local user and save to boxes
+                       then stuff remote users in queue list
+                       then delete from queue if num remote users is 0
+               */
 
        return(failed_saves);
 }
@@ -577,6 +586,7 @@ void smtp_command_loop(void) {
 char *Dynamic_Module_Init(void)
 {
        SYM_SMTP = CtdlGetDynamicSymbol();
+       SYM_SMTP_RECP = CtdlGetDynamicSymbol();
        CtdlRegisterServiceHook(SMTP_PORT,
                                smtp_greeting,
                                smtp_command_loop);