]> SAFE projects GIT repository - jmp/mailleur/commitdiff
get_smtp_reply function is working
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 8 Jun 2025 07:18:04 +0000 (03:18 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 8 Jun 2025 07:18:04 +0000 (03:18 -0400)
lib/lvleml.c
lib/unieml.h

index f8362d8e375e551616be5f7f9efd679afa62aaba..274e04c02f52226e6ca56bf9f33cb7e81d568fa7 100644 (file)
@@ -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
index 31890e47c13d933397f4c910f0c255ee31d6a90c..a1ed727e1fe463f70d6e3e57d34295ccb974d094 100644 (file)
@@ -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