From c1c36e54f1189899d55c36582fd4583e7687a60a Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Sun, 15 Jun 2025 08:22:02 -0400 Subject: [PATCH] Ready to check code about sending multiple email session --- lib/lvleml.c | 135 ++++++++++++++++++++++++++++----------------------- 1 file changed, 75 insertions(+), 60 deletions(-) diff --git a/lib/lvleml.c b/lib/lvleml.c index de9e911..8a3322d 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -1050,7 +1050,7 @@ return ok; /* Procedure to send the data to the remote server */ /* */ /********************************************************/ -static void senddata(RMTTYP *rmt,TRATYP **tosend,const char *sessid) +static void senddata(RMTTYP *rmt,TRATYP **tosend) { #define OPEP "lvleml.c:senddata," @@ -1058,11 +1058,13 @@ static void senddata(RMTTYP *rmt,TRATYP **tosend,const char *sessid) int rspcode; int sent; TIMESPEC start; +char *sessid; int phase; _Bool proceed; rspcode=0; sent=0; +sessid=(*tosend)->sessid; phase=0; proceed=true; (void) clock_gettime(CLOCK_REALTIME,&start); @@ -1148,33 +1150,46 @@ while (proceed==true) { /* recipient. */ /* */ /********************************************************/ -static TRATYP **send_to_mx(RMTTYP *rmt,TRATYP **list) +static void send_to_mx(RMTTYP *rmt,TRATYP **tosend) { +#define OPEP "lvleml.c:send_to_mx," + int tobesend; -TRATYP **tosend; char *sessid; -int phase; -_Bool proceed; +TRATYP **dest; tobesend=0; -tosend=(TRATYP **)0; -sessid=(*list)->sessid; -phase=0; -proceed=true; -while (proceed==true) { - switch (phase) { - case 3 : //sending data - if (tobesend>0) - (void) senddata(rmt,tosend,sessid); - break; - default : //SAFE Guard - proceed=false; - break; - } - phase++; - } -return list; +sessid=(*tosend)->sessid; +dest=tosend; +while (*dest!=(TRATYP *)0) { + int rspcode; + 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++; + (*dest)->sendcode=rspcode; + break; + default : //Not accepted recipient + (void) rou_alert(0,"%s sessid=<%s>, unknwon code='%d' (Bug?)", + OPEP,sessid,rspcode); + //NO BREAK + case UKNUSER : //recipient is unknown + case NORELAY : //email no relayed + (*dest)->code='W'; //Need to send a Warning + (*dest)->sendcode=rspcode; + break; + } + dest++; + } +if (tobesend>0) + (void) senddata(rmt,tosend); + +#undef OPEP } /* ^L @@ -1205,11 +1220,25 @@ proceed=true; while (proceed==true) { //(void) rou_alert(0,"%s JMPDBG phase='%d'",OPEP,phase); switch (phase) { - case 0 : //process completed? + case 0 : //do we have a email request + if ((tra)==(TRATYP **)0) { + (void) rou_alert(0,"%s No email to send to remote! (Bug?)",OPEP); + phase=999; //all scanning done + } + break; + case 1 : //process completed? if ((*tra)==(TRATYP *)0) phase=999; //all scanning done break; - case 1 : //collecting email to be sent + case 2 : //do a remote reset if needed + if (rmt!=(RMTTYP *)0) { + if (reset_mx(rmt)==false) { + rmt=close_mx(rmt); + phase=999; //Trouble Trouble + } + } + break; + case 3 : //collecting email to be sent sessid=(*tra)->sessid; while (*tra!=(TRATYP *)0) { if (strcmp((*tra)->sessid,sessid)!=0) { @@ -1230,35 +1259,36 @@ while (proceed==true) { tra++; } break; - case 2 : //Checking if we have email to be sent + case 4 : //Checking if we have email to be sent if (tosend==(TRATYP **)0) - phase=-1; //lets continue to see other email + phase=0; //lets continue to see other email break; - case 3 : //Opening connection if not open + case 5 : //is MX link already open?? + if (rmt!=(RMTTYP *)0) + phase++; //No need to open MX link (again); + break; + case 6 : //Opening connection if not open if ((rmt=connect_mx(logptr,*tosend))==(RMTTYP *)0) { + TRATYP **ptr; char cmt[100]; + char note[150]; + ptr=tosend; (void) snprintf(cmt,sizeof(cmt),"Unable to contact ANY MX to reach <%s>", (*tosend)->rcptto); (void) log_fprintlog(logptr,false,cmt); - if (tosend!=(TRATYP **)0) { - TRATYP **ptr; - char note[150]; - - (void) snprintf(note,sizeof(note),"%d %s",NOANSWR,cmt); - ptr=tosend; - while (*ptr!=(TRATYP *)0) { - (void) eml_freetra_resp(*ptr); - (*ptr)->resp=(char **)rou_addlist((void **)(*ptr)->resp, - (void *)strdup(note)); - ptr++; - } - (void) free(tosend); + (void) snprintf(note,sizeof(note),"%d %s",NOANSWR,cmt); + while (*ptr!=(TRATYP *)0) { + (void) eml_freetra_resp(*ptr); + (*ptr)->resp=(char **)rou_addlist((void **)(*ptr)->resp, + (void *)strdup(note)); + ptr++; } + (void) free(tosend); phase=999; //No need to go further } break; - case 4 : { //sending originator + case 7 : { //sending originator int rspcode; rspcode=simple_smtp_command(rmt,"MAIL FROM: <%s>",(*tosend)->mailfrom); @@ -1273,29 +1303,14 @@ while (proceed==true) { } break; } - case 5 : { //sending recipient list - TRATYP **dest; - - dest=tosend; - while (*dest!=(TRATYP *)0) { - dest=send_to_mx(rmt,dest); - if (*dest==(TRATYP *)0) - break; //no more to send; - if (reset_mx(rmt)==false) { - break; //can not send more - } - } - break; - } - case 6 : //closing current connection with MX - (void) close_mx(rmt); - break; - case 7 : //cleaning recipient list + case 8 : //sending recipient list + (void) send_to_mx(rmt,tosend); (void) free(tosend); tosend=(TRATYP **)0; - phase=0; //Lets see if we have other recipient + phase=0; //Trying to send NEXT sequence of email to be sent break; default : //SAFE Guard + rmt=close_mx(rmt); proceed=false; break; } -- 2.47.3