From: Jean-Marc Pigeon (Delson) Date: Sun, 8 Jun 2025 07:18:04 +0000 (-0400) Subject: get_smtp_reply function is working X-Git-Tag: tag-0.8~58 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=475fdc6838a4dca6582aa7cde6c09abb7cd9ed80;p=jmp%2Fmailleur get_smtp_reply function is working --- diff --git a/lib/lvleml.c b/lib/lvleml.c index f8362d8..274e04c 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -28,6 +28,7 @@ typedef struct { SOCPTR *socptr; //socket to remote pointer LOGPTR *logptr; //Log pointer const char *domain; //Domain to be reached + MXTYP *curmx; //Current MX number MXTYP **mxs; //MX list form domain }RMTTYP; /* @@ -681,6 +682,48 @@ return true; */ /********************************************************/ /* */ +/* Procedure to check answer from remote SMTP */ +/* MX server. */ +/* Return the SMTP status code. */ +/* */ +/********************************************************/ +static _Bool get_smtp_reply(RMTTYP *rmt,int wait) + +{ +int code; +int maxlines; + +code=ERRPROC; +maxlines=20; //maximun number of line error +while (maxlines>0) { + char *line; + int sofar; + + line=(char *)0; + if (tcp_getline(rmt->socptr,wait,&line)<0) { + char cmt[100]; + + (void) snprintf(cmt,sizeof(cmt),"%d Timeout waiting '%d' sec for MX <%s>", + ERRPROC,wait,rmt->curmx->mxname); + line=strdup(cmt); + } + (void) log_fprintlog(rmt->logptr,false,line); + if (sscanf(line,"%d%n",&code,&sofar)==1) { + if (line[sofar]==' ') + maxlines=0; //found remote status + else + code=ERRPROC; + } + line=rou_freestr(line); + maxlines--; + } +return code; +} +/* +^L +*/ +/********************************************************/ +/* */ /* Procedure to connect to the remote SMTP server */ /* */ /********************************************************/ @@ -691,7 +734,6 @@ _Bool done; int phase; int proceed; - done=false; phase=0; proceed=true; @@ -711,12 +753,13 @@ while (proceed==true) { mxs=rmt->mxs; srcip=(const char *)0; while (*mxs!=(MXTYP *)0) { - rmt->socptr=soc_openfeedsock(pro_smtp,srcip,(*mxs)->mxname,EMLPORT); + rmt->curmx=*mxs; + rmt->socptr=soc_openfeedsock(pro_smtp,srcip,rmt->curmx->mxname,EMLPORT); if (rmt->socptr!=(SOCPTR *)0) { char cmt[100]; (void) snprintf(cmt,sizeof(cmt),"Now Connected to MX <%s>", - (*mxs)->mxname); + rmt->curmx->mxname); (void) log_fprintlog(rmt->logptr,false,cmt); break; } @@ -725,6 +768,20 @@ while (proceed==true) { if (rmt->socptr==(SOCPTR *)0) phase=999; break; + case 2 : //waiting for signon + int res; + + res=get_smtp_reply(rmt,WAITRMT); + switch (res) { + case SIGNON : //everything fine + break; + default : //not getting the right signon + phase=999; //No need to go further + break; + } + break; + case 3 : //establishing secured link + break; default : //SAFE Guard proceed=false; break; @@ -790,7 +847,7 @@ while (proceed==true) { case 2 : //Checking if we have email to be sent char cmt[100]; - (void) strncpy(cmt,sessid,sizeof(cmt)); + (void) snprintf(cmt,sizeof(cmt),"session-id=%s",sessid); rmt.logptr=log_openlog(sessid,false,cmt); if (tosend==(TRATYP **)0) phase=-1; //lets continue to see other email diff --git a/lib/unieml.h b/lib/unieml.h index 31890e4..a1ed727 100644 --- a/lib/unieml.h +++ b/lib/unieml.h @@ -16,6 +16,7 @@ #define QUITOK 221 //status on quit #define CMDOK 250 //Everything OK #define DATAOK 354 //Ready to accept EMAIL data +#define ERRPROC 451 //local processing error #define BADPAR 501 //error in parameters #define CMDBAD 502 //command not implemented #define DATRJC 521 //Data Rejected @@ -33,6 +34,7 @@ #define SORTER "sorter" //application email sorter #define EMLPORT "25" //Default SMTP email port +#define WAITRMT 60 //how long to wait answer from remote SMTP //list of keyword typedef enum { //list of SMTP protocol keyword