]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Adding SMTP responses to TRATYP seems to be working
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 10 Jun 2025 13:10:29 +0000 (09:10 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 10 Jun 2025 13:10:29 +0000 (09:10 -0400)
lib/geseml.c
lib/geseml.h
lib/gestcp.c
lib/gestcp.h
lib/lvleml.c

index 530c4f5043e7de0fb3df697d821b0fca801d105a..589366acdfd2e170e3a0750d920eb0595534129c 100644 (file)
@@ -186,7 +186,6 @@ if (tra!=(TRATYP *)0) {
 
     ptr=tra->resp;
     while (*ptr!=(char *)0) {
-      (void) rou_alert(0,"%s JMPDBG ptr=<%s>",OPEP,*ptr);
       (void) snprintf(line,sizeof(line),"\t%s",*ptr);
       (void) print_tra(qfile,line,(char *)0);
       ptr++;
@@ -239,6 +238,22 @@ return action;
 */
 /********************************************************/
 /*                                                      */
+/*      Procedure to free memory used by the TRATYP     */
+/*      response part.                                  */
+/*                                                      */
+/********************************************************/
+PUBLIC void eml_freetra_resp(TRATYP *tra)
+
+{
+if (tra!=(TRATYP *)0) {
+  tra->resp=(char **)rou_freelist((void **)tra->resp,(genfree_t)rou_freestr);
+  }
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
 /*      Procedure to free memory used by a TRATYP record*/
 /*                                                      */
 /********************************************************/
@@ -246,10 +261,10 @@ PUBLIC TRATYP *eml_freetra(TRATYP *tra)
 
 {
 if (tra!=(TRATYP *)0) {
+  (void) eml_freetra_resp(tra);
   tra->rcptto=rou_freestr(tra->rcptto);
   tra->mailfrom=rou_freestr(tra->mailfrom);
   tra->sessid=rou_freestr(tra->sessid);
-  tra->resp=(char **)rou_freelist((void **)tra->resp,(genfree_t)rou_freestr);
   (void) free(tra);
   tra=(TRATYP *)0;
   }
@@ -333,7 +348,6 @@ while ((ptr=fgets(line,sizeof(line),qfile))!=(char *)0) {
       case 1    :       //scanning line contents
         switch (line[0]) {
           case '\t'     :       //extra response line
-            (void) rou_alert(0,"%s JMPDBG extra=<%s> cur='%p'",OPEP,line,cur);
             if ((cur!=(TRATYP *)0)&&(strlen(line)>1)) 
               cur->resp=(char **)rou_addlist((void **)cur->resp,strdup(line+1));
             phase=999;    //not a scanable trans line
index 209d56604e2ee013d12388c9ff8b04e3305bc497..47919448a1c27e568b4143f43402c95258424678 100644 (file)
@@ -32,6 +32,9 @@ extern _Bool eml_dump_one_tra(FILE *out,TRATYP *tra);
 //procedure to dump a list of transfert record 
 extern _Bool eml_dump_list_tra(FILE *out,TRATYP **tra);
 
+//procedure to fee memory used by the resp rercord within TRATYP structure
+extern void eml_freetra_resp(TRATYP *tra);
+
 //procedure to fee memory used by a TRATYP structure
 extern TRATYP *eml_freetra(TRATYP *tra);
 
index b251489bee6602b90cd4fe19e2fb1c2754417eb8..0f11251c1fde137d929cb8dcb5a5c24e3f334216 100644 (file)
@@ -122,7 +122,7 @@ return sent;
 /*      return an SMTP reply code.                      */
 /*                                                      */
 /********************************************************/
-PUBLIC int tcp_get_smtp_reply(RMTTYP *rmt,int wait)
+PUBLIC int tcp_get_smtp_reply(RMTTYP *rmt,int wait,char ***resp)
 
 {
 #define OPEP    "gestcp.c:tcp_get_smtp_reply,"
@@ -153,7 +153,10 @@ while (maxlines>0) {
     else
       code=ERRPROC;
     }
-  line=rou_freestr(line);
+  if (resp==(char ***)0) 
+    line=rou_freestr(line);
+  else
+    *resp=(char **)rou_addlist((void **)*resp,(void *)line);
   maxlines--;
   }
 return code;
@@ -170,7 +173,7 @@ return code;
 /*      remote response code.                           */
 /*                                                      */
 /********************************************************/
-PUBLIC int tcp_smtp_command(RMTTYP *rmt,char *fmt,...)
+PUBLIC int tcp_smtp_command(RMTTYP *rmt,char ***resp,char *fmt,...)
 
 {
 va_list args;
@@ -181,7 +184,7 @@ va_start(args,fmt);
 va_end(args);
 (void) tcp_write(rmt->socptr,strloc);
 (void) log_fprintlog(rmt->logptr,false,strloc);
-return tcp_get_smtp_reply(rmt,WAITRMT);
+return tcp_get_smtp_reply(rmt,WAITRMT,resp);
 }
 /*
 ^L
index 8115f969179cf40606803abff49d6b8768d5ec0e..e849aeea3c6697a788364a318c245ddd28e2bb77 100644 (file)
@@ -31,10 +31,10 @@ extern int tcp_getline(SOCPTR *socptr,u_int secwait,char **lineptr);
 extern int tcp_write(SOCPTR *socptr,char *buffer);
 
 //wait and answer from remote and return the reply code
-extern  int tcp_get_smtp_reply(RMTTYP *rmt,int wait);
+extern  int tcp_get_smtp_reply(RMTTYP *rmt,int wait,char ***resp);
 
 //Transmit a command to remote SMTP server
-extern int tcp_smtp_command(RMTTYP *rmt,char *fmt,...);
+extern int tcp_smtp_command(RMTTYP *rmt,char ***resp,char *fmt,...);
 
 //send the email data
 extern int tcp_send_smtp_data(RMTTYP *rmt,const char *qemail);
index ff816fedfeec9dc3fa5982f3650b7bced2ccd709..e3f9cc04a53f45197e271e63370273006ca850ec 100644 (file)
@@ -332,6 +332,26 @@ return status;
 */
 /************************************************/
 /*                                             */
+/*     Procedure to send a simple SMTP ccommand*/
+/*      (no need to have the response wording)  */
+/*                                             */
+/************************************************/
+static int simple_smtp_command(RMTTYP *rmt,char *fmt,...)
+
+{
+va_list args;
+char strloc[300];
+
+va_start(args,fmt);
+(void) vsnprintf(strloc,sizeof(strloc),fmt,args);
+va_end(args);
+return tcp_smtp_command(rmt,(char ***)0,strloc);
+}
+/*
+\f
+*/
+/************************************************/
+/*                                             */
 /*     Procedure to accept EMAIL contents from */
 /*      SMTP peers.                             */
 /*     Return true, if everything is fine      */
@@ -708,7 +728,7 @@ while (proceed==true) {
   rspcode=ERRPROC; 
   switch (phase) {
     case 0      :       //Sending EHLO
-      rspcode=tcp_smtp_command(rmt,"EHLO %s",rmt->orgdomain);
+      rspcode=simple_smtp_command(rmt,"EHLO %s",rmt->orgdomain);
       switch (rspcode) {
         case CMDOK      :       //So fare, so good
           break;
@@ -721,7 +741,7 @@ while (proceed==true) {
       break;
     case 1      :       //Stating starttls
       phase=999;        //No need to go futher
-      rspcode=tcp_smtp_command(rmt,"STARTTLS",rmt->orgdomain);
+      rspcode=simple_smtp_command(rmt,"STARTTLS",rmt->orgdomain);
       switch (rspcode) {
         case SIGNON      :       //link is now encrypted
           done=soc_starttls(rmt->socptr,false);
@@ -742,7 +762,7 @@ while (proceed==true) {
         }
       break;
     case 2      :       //Sending HELO
-      rspcode=tcp_smtp_command(rmt,"HELO %s",rmt->orgdomain);
+      rspcode=simple_smtp_command(rmt,"HELO %s",rmt->orgdomain);
       switch (rspcode) {
         case CMDOK      :       //So fare, so good
           done=true;
@@ -816,7 +836,7 @@ while (proceed==true) {
     case 2      :       //waiting for signon
       int res;
 
-      res=tcp_get_smtp_reply(rmt,WAITRMT);
+      res=tcp_get_smtp_reply(rmt,WAITRMT,(char ***)0);
       switch (res) {
         case SIGNON     :       //everything fine
           break;
@@ -866,7 +886,7 @@ proceed=true;
 while (proceed==true) {
   switch (phase) {
     case 0      :       //Sendig data request
-      rspcode=tcp_smtp_command(rmt,"DATA");
+      rspcode=simple_smtp_command(rmt,"DATA");
       switch (rspcode) {
         case DATAOK     :       //data accepted
           break;
@@ -882,7 +902,7 @@ while (proceed==true) {
       break;
     case 2      :       //send the text termination
       (void) tcp_write(rmt->socptr,".");
-      rspcode= tcp_get_smtp_reply(rmt,WAITRMT);
+      rspcode= tcp_get_smtp_reply(rmt,WAITRMT,(char ***)0);
       break;
     case 3      :       //sending session data
       const char *fmt;
@@ -1020,7 +1040,7 @@ while (proceed==true) {
     case 5      :  {    //sending originator
       int rspcode;
 
-      rspcode=tcp_smtp_command(&rmt,"MAIL FROM: <%s>",(*tosend)->mailfrom);
+      rspcode=simple_smtp_command(&rmt,"MAIL FROM: <%s>",(*tosend)->mailfrom);
       switch (rspcode) {
         case CMDOK      :       //originator accepted
           break;
@@ -1039,7 +1059,11 @@ while (proceed==true) {
       tobesend=0;
       dest=tosend;
       while (*dest!=(TRATYP *)0) {
-        rspcode=tcp_smtp_command(&rmt,"RCPT TO: <%s>",(*dest)->rcptto);
+        char ***resp;
+
+        (void) eml_freetra_resp(*dest);
+        resp=&((*dest)->resp);
+        rspcode=tcp_smtp_command(&rmt,resp,"RCPT TO: <%s>",(*dest)->rcptto);
         switch (rspcode) {
           case CMDOK      :     //originator accepted
             tobesend++;
@@ -1048,7 +1072,6 @@ while (proceed==true) {
           case UKNUSER    :     //originator accepted
             (*dest)->code='W';  //Need to send a Warning
             (*dest)->sendcode=rspcode;
-            (*dest)->resp=(char **)rou_addlist((void **)(*dest)->resp,strdup("bigre"));
             break;
           default         :     //Not accepted recipient
             (void) rou_alert(0,"%s sessid=<%s>, unknwon code='%d'",