]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Starting to implement rcpt Local/Remote dispatching
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 18 May 2025 14:50:17 +0000 (10:50 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 18 May 2025 14:50:17 +0000 (10:50 -0400)
data-feed/xxfeed.tst
lib/lvleml.c
lib/lvleml.h
lib/unidns.c
lib/unieml.c
lib/unieml.h

index acbacc46f5290de685082382e752567ae67844db..2dcf94f8d7612fd60048bfb63c77198f3c284e82 100644 (file)
@@ -1,17 +1,93 @@
 #very simple  test to feed SMTP server
 #====================================================
-T:Testing if MX is found
+T:Very Simple email sending
 R:220 mailleur.example.com ESMTP (cleartext) emlrcvr...
+C:ORGN 127.127.0.2
+R:220 mailleur.example.com ESMTP (cleartext) emlrcvr...
+#C:WAIT 100
 #====================================================
 S:HELO example.com
 #R:250-mailleur.example.com, link (cleartext) ready, your IP/FQDN=[127.127.0.2/feed2.example.com]
 R:250-mailleur.example.com, link (cleartext) ready,...
 S:MAIL FROM: <postmaster@example.com>
 R:250 2.1.3 postmaster@example.com.. sender ok
-S:RCPT TO: <dom1user1@subdom0.example.com>
-R:563 5.6.3 No valid MX found for recipient domain name (rcpt=subdom0.example.com)
 S:RCPT TO: <dom1user1@subdom1.example.com>
 R:250 2.6.4 Address accepted
+S:RCPT TO: <dom2user1@subdom2.example.com>
+R:250 2.6.4 Address accepted
+S:RCPT TO: <dom2user2@subdom2.example.com>
+R:250 2.6.4 Address accepted
+#-------------------------------------------------------------------------
+#-sending data
+C:DATA
+Subject: Very Simple email contents
+
+FIRST Line
+SECOND Line
+LAST Line
+
+.
+#-------------------------------------------------------------------------
+R:250 3.5.3 Message accepted for delivery
 S:QUIT
 R:221 2.0.0 Bye, closing connection...
 #-------------------------------------------------------------------------
+#prepare next test
+#waiting 1 sec
+C:WAIT 1
+#-restarting link
+C:RESTART
+R:220 mailleur.example.com ESMTP (cleartext) emlrcvr...
+S:MAIL FROM: <webmaster@example.com>
+R:250 2.1.3 webmaster@example.com.. sender ok
+S:RCPT TO: <dom1user1@subdom1.example.com>
+R:250 2.6.4 Address accepted
+S:RCPT TO: <dom1user2@subdom1.example.com>
+R:250 2.6.4 Address accepted
+S:RCPT TO: <dom2user1@subdom2.example.com>
+R:250 2.6.4 Address accepted
+S:RCPT TO: <dom2user2@subdom2.example.com>
+R:250 2.6.4 Address accepted
+#-------------------------------------------------------------------------
+#-sending data
+C:DATA
+Subject: Second email contents
+
+SECOND FIRST Line
+SECOND SECOND Line
+SECOND LAST Line
+
+.
+#-------------------------------------------------------------------------
+R:250 3.5.3 Message accepted for delivery
+S:QUIT
+#-------------------------------------------------------------------------
+#prepare next test
+#waiting 1 sec
+C:WAIT 1
+#-restarting link
+C:RESTART
+R:220 mailleur.example.com ESMTP (cleartext) emlrcvr...
+S:MAIL FROM: <noreply@example.com>
+R:250 2.1.3 noreply@example.com.. sender ok
+S:RCPT TO: <dom1user1@subdom1.example.com>
+R:250 2.6.4 Address accepted
+S:RCPT TO: <dom1user2@subdom1.example.com>
+R:250 2.6.4 Address accepted
+S:RCPT TO: <dom2user1@subdom2.example.com>
+R:250 2.6.4 Address accepted
+S:RCPT TO: <dom2user2@subdom2.example.com>
+R:250 2.6.4 Address accepted
+#-------------------------------------------------------------------------
+#-sending data
+C:DATA
+Subject: Third email contents
+
+THIRD FIRST Line
+THIRD SECOND Line
+THIRD LAST Line
+
+.
+#-------------------------------------------------------------------------
+R:250 3.5.3 Message accepted for delivery
+S:QUIT
index b00030145f6876d7677ce038452582efef9e8231..f1d1ac55e89e8c50ffec5f612a46e40b820129b5 100644 (file)
@@ -39,8 +39,7 @@ static CONTYP *freecontact(CONTYP *contact)
 if (contact!=(CONTYP *)0) {
   contact->sqlptr=sql_closesql(contact->sqlptr);
   contact->logptr=log_closelog(contact->logptr);
-  contact->rcptto=(char **)rou_freelist((void **)contact->rcptto,
-                                        (freehandler_t)rou_freestr);
+  contact->recipients=eml_freerecipients(contact->recipients);
   contact->mailfrom=rou_freestr(contact->mailfrom);
   contact->cursesid=rou_freestr(contact->cursesid);
   contact->mainsesid=rou_freestr(contact->mainsesid);
@@ -514,7 +513,7 @@ while (proceed==true) {
         }
       break;
     case 4      :       //Storing rcpt to
-      if (eml_addemail(&(contact->rcptto),rcptto)==false) {
+      if (eml_addrecipient(&(contact->recipients),'L',rcptto)==false) {
         detail="duplicate recipients will be consolidated";
         }
       break;
@@ -828,19 +827,26 @@ PUBLIC _Bool eml_mktransfile(CONTYP *contact,FILE *qfile)
 
 _Bool status;
 
-if ((contact!=(CONTYP *)0)&&(contact->rcptto!=(char **)0)) {
-  char **ptr;
-
-  ptr=contact->rcptto;
-  while (*ptr!=(char *)0) {
-    time_t isnow;
-
-    status=true;
-    isnow=time((time_t *)0);
-    if (fprintf(qfile,"%c %ld %d %s %s %s\n",
-                      'R',isnow,0,contact->cursesid,contact->mailfrom,*ptr)<0) {
+status=true;
+if ((contact!=(CONTYP *)0)&&(contact->recipients!=(RCPTYP **)0)) {
+  RCPTYP **ptr;
+  time_t isnow;
+
+  ptr=contact->recipients;
+  isnow=time((time_t *)0);
+  while (*ptr!=(RCPTYP *)0) {
+    char data[300];
+
+    (void) snprintf(data,sizeof(data),"%c %ld %d %s %s %s",
+                                      (*ptr)->code,
+                                      isnow,
+                                      0,
+                                      contact->cursesid,
+                                      contact->mailfrom,
+                                      (*ptr)->rcpt);
+    if (fprintf(qfile,"%s\n",data)<0) {
       (void) rou_alert(0,"%s Unable to write transfile (error=<%s>)",
-                           OPEP,strerror(errno));
+                          OPEP,strerror(errno));
       status=false;
       }
     ptr++;
index f1954db71e9363fc04f8598adf6fd304a672706c..bc49ba895476bd702492a0f8e31fb82dd3440533 100644 (file)
 #include        "gestcp.h"
 
 typedef struct  {
-        SOCPTR *socptr; //established contact socket context
-        SQLPTR *sqlptr; //established contact database access
-        char *fqdn;     //fully qualified domain from peer
-        char *locname;  //socket local hostname
-        char *locserv;  //local service port
-        char *peerip;   //socket remote peer IP
-        char *peername; //socket remote peer FQDN
-        int numreset;   //number of SMTP reset received
-        char *mainsesid;//session main ID
-        char *cursesid; //current session ID
-        char *mailfrom; //current mail from originator
-        char **rcptto;  //List of mail recipient
-        LOGPTR *logptr; //reference to session log
+        SOCPTR *socptr;         //established contact socket context
+        SQLPTR *sqlptr;         //established contact database access
+        char *fqdn;             //fully qualified domain from peer
+        char *locname;          //socket local hostname
+        char *locserv;          //local service port
+        char *peerip;           //socket remote peer IP
+        char *peername;         //socket remote peer FQDN
+        int numreset;           //number of SMTP reset received
+        char *mainsesid;        //session main ID
+        char *cursesid;         //current session ID
+        char *mailfrom;         //current mail from originator
+        RCPTYP **recipients;    //List of email recipient
+        LOGPTR *logptr;         //reference to session log
         }CONTYP;
 
 
index f418859963770819d9bf1e43934cd3cc6af74714..c775fac8d78b7b2da1398c404d4aa3e4e56e0cc4 100644 (file)
@@ -357,7 +357,6 @@ while (proceed==true) {
         }
       break;
     case 2      :       //Requesting MX for domain
-      (void) rou_alert(0,"%s JMPDBG domain=<%s>",OPEP,domain);
       answer=myquery(domain,C_IN,T_MX,rsp.buf,sizeof(rsp.buf));
       if (answer<=0) 
         phase=999;      //Trouble trouble to get MX
index 8aeab4e03fc1e465f6350b07a2ebf8da83ab8b88..60a22b367d9d4e08fd69af56c3430eb66d838c9a 100644 (file)
@@ -42,6 +42,70 @@ static VOCTYP vocsmtp[]={
 */
 /********************************************************/
 /*                                                      */
+/*     Procedure to free memory used by a list of      */
+/*      recipient.                                      */
+/*                                                      */
+/********************************************************/
+PUBLIC RCPTYP **eml_freerecipients(RCPTYP **list)
+
+{
+if (list!=(RCPTYP **)0) {
+  RCPTYP **ptr;
+
+  ptr=list;
+  while (*ptr!=(RCPTYP *)0) {
+    (*ptr)->rcpt=rou_freestr((*ptr)->rcpt);
+    (void) free(*ptr);
+    ptr++;
+    }
+  (void) free(list);
+  list=(RCPTYP **)0;
+  }
+return list;
+}
+/*
+^L
+*/
+/********************************************************/
+/*                                                      */
+/*     Procedure to store an recipient information     */
+/*      within the contact list.                        */
+/*      retuurn RCPTYP ** if successful, NULL otherwise.*/
+/*                                                      */
+/********************************************************/
+PUBLIC _Bool eml_addrecipient(RCPTYP ***list,char code,char *rcpt)
+
+{
+_Bool todo;
+
+todo=true;
+if (*list!=(RCPTYP **)0) {
+  RCPTYP **ptr;
+
+  ptr=*list;
+  while (*ptr!=(RCPTYP *)0) {
+    if (strcasecmp((*ptr)->rcpt,rcpt)==0) {
+      todo=false;
+      break;    //already within list
+      }
+    ptr++;
+    }
+  }
+if (todo==true) {
+  RCPTYP *neu;
+
+  neu=(RCPTYP *)calloc(1,sizeof(RCPTYP));
+  neu->code=code;
+  neu->rcpt=strdup(rcpt);
+  *list=(RCPTYP **)rou_addlist((void **)(*list),neu);
+  }
+return todo;
+}
+/*
+^L
+*/
+/********************************************************/
+/*                                                      */
 /*     Procedure to format and return a dynamicaly     */
 /*      allocated char array filled with uniq session ID*/
 /*                                                      */
index a680f3758d0dc156df53a9390c2c8679ae13818c..088464c620a681a2f27f09104b3f67afc3c284e9 100644 (file)
@@ -37,6 +37,17 @@ typedef enum    {               //list of SMTP protocol keyword
                 c_unknown       //key word unknown
                 }CODTYP;
 
+typedef struct  {               //*definition of recipient
+        char code;              //'L' rcipient local, 'R' recipient remote
+        char *rcpt;             //recipient email address
+        }RCPTYP;
+
+//procedure to Free a recipient list
+extern RCPTYP **eml_freerecipients(RCPTYP **list);
+
+//procedure to add recipient to a recipient list
+extern _Bool eml_addrecipient(RCPTYP ***list,char code,char *rcpt);
+
 //get a session unique id
 extern char *eml_getmainsesid();
 
@@ -68,10 +79,6 @@ extern char **eml_getqfilelist(char **dnames,char *ext);
 //procedure to open a specific qfile
 extern FILE *eml_openqfile(char *qfilename);
 
-//procedure to add an email address to a chain
-//of email address
-extern _Bool eml_addemail(char ***emails,char *email);
-
 //procedure to check email address format
 //of an email address
 extern _Bool eml_isemailok(char *email,const char **domain,char **report);