]> SAFE projects GIT repository - jmp/mailleur/commitdiff
IMproving trans file dump procedure
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 26 May 2025 23:55:09 +0000 (19:55 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 26 May 2025 23:55:09 +0000 (19:55 -0400)
app/feeder.c
app/sender.c
lib/geseml.c
lib/geseml.h
lib/lvleml.c
lib/unieml.c
lib/unieml.h

index 1c56f8cb47be6261ba897315c088b5285b752696..20b5d7e55438a2a8f11e73f99bc6e4757fdc00d5 100644 (file)
@@ -631,7 +631,7 @@ while (proceed==true) {
       while (fgets(line,sizeof(line),fd->datatst)!=(char *)0) {
         char *ptr;
 
-        (void) rou_alert(0,"%s num='%02d' <%s>","sender",numline,line);
+        (void) rou_alert(5,"%s num='%02d' <%s>","feeder",numline,line);
         while ((ptr=strrchr(line,'\n'))!=(char *)0)
           *ptr='\000';
         if ((fd->commented==true)&&(strncmp(line,"C:",2)!=0)) {
index a17dcd501331c65a165b1f46477c5e38a9228021..7296aeb73a3be70db75b36d222e818a484bb772b 100644 (file)
@@ -45,21 +45,24 @@ if (tra!=(TRATYP **)0) {
   while (*ptr!=(TRATYP *)0) {
     switch ((*ptr)->code) {
       case 'L'  :       //local delivery
-        (*ptr)->code='C';       //delivery done
+        (*ptr)->code='C';       //delivery done 'C'ompleted
         if (eml_store_email(*ptr)==false) {
-          (*ptr)->code='D';       //delivery done
+          (*ptr)->code='D';       //delivery done 'D'elayed
           (void) rou_alert(0,"%s Unable to deliver email <%s> to <%s>",
                               OPEP,(*ptr)->sessid,(*ptr)->rcptto);
           }
         break;
+      case 'R'  :       //remote delivery
+        (*ptr)->code='C';       //delivery completed Temporary JMPDBG
+        break;
       default   :
-        (void) eml_dumptra((FILE *)0,*ptr);
         (void) rou_alert(0,"%s unexpected code '%c'",OPEP,(*ptr)->code);
         status=false;
         break;
       }
     ptr++;
     }
+  (void) eml_dumptra((FILE *)0,tra);
   }
 return status;
 #undef  OPEP
@@ -118,29 +121,23 @@ while (proceed==true) {
         }
       break;
     case 4      :       //updating transfile 
-      if (tra!=(TRATYP **)0) { //record to update
-        TRATYP **ptr;
+      (void) eml_dumptra(qfile,tra);
+      break;
 
-        ptr=tra;
-        (void) rewind(qfile);
-        while (*ptr!=(TRATYP *)0) {
-          (void) eml_dumptra(qfile,*ptr);
-          ptr++;
-          }
-        }
+    case 5      :       //closing file
+      qfile=eml_closeqfile(qfile);
       break;
-    case 5      :       //job completed renameing file
+    case 6      :       //job completed renameing file
       if (eml_renameqfile(fname,EXDOING,EXDONE)==false) {
         (void) rou_alert(0,"%s Unable to rename file <%s.%s>",OPEP,fname,EXDONE);
         phase=999;      //No need to go further
         }
       break;
-    case 6      :       //job fully compltedt, good
+    case 7      :       //job fully compltedt, good
       status=true;
       break;
     default     :       //SAFE Guard
-      if (qfile!=(FILE *)0)
-        (void) eml_closeqfile(qfile);
+      qfile=eml_closeqfile(qfile);
       proceed=false;
       break;
     }
index 6187669e4d5dec4466c562396d76ce78cd8f99af..b603b19758104bde64b027d5eb586e170ed044e2 100644 (file)
@@ -119,26 +119,34 @@ return reflist;
 /*      Procedure to display/debug TRATYP record content*/
 /*                                                      */
 /********************************************************/
-PUBLIC void eml_dumptra(FILE *out,TRATYP *tra)
+PUBLIC void eml_dumptra(FILE *qfile,TRATYP **tra)
 
 {
-char line[300];
+if (tra!=(TRATYP **)0) {
+  if (qfile!=(FILE *)0) {
+    (void) fprintf(qfile,"#'C', completed email task\n");
+    (void) fprintf(qfile,"#'D', delayed email\n");
+    (void) fprintf(qfile,"#'L', Local email\n");
+    (void) fprintf(qfile,"#'R', Remote email\n");
+    }
+  while (*tra!=(TRATYP *)0) {
+    char line[300];
 
-(void) strcpy(line,"Empty");
-if (tra!=(TRATYP *)0) {
-  (void) snprintf(line,sizeof(line),"%c %lu %u %s %s %s",
-                                    tra->code,
-                                    tra->date,
-                                    tra->delay,
-                                    tra->sessid,
-                                    tra->mailfrom,
-                                    tra->rcptto
-                                    );
+    (void) snprintf(line,sizeof(line),"%c %lu %u %s %s %s",
+                                      (*tra)->code,
+                                      (*tra)->date,
+                                      (*tra)->delay,
+                                      (*tra)->sessid,
+                                      (*tra)->mailfrom,
+                                      (*tra)->rcptto
+                                      );
+    if (qfile==(FILE *)0) 
+      (void) rou_alert(0,"TRA=<%s>",line);
+    else
+      (void) fprintf(qfile,"%s\n",line);
+    tra++;
+    }
   }
-if (out==(FILE *)0) 
-  (void) rou_alert(0,"TRA=<%s>",line);
-else
-  (void) fprintf(out,"%s\n",line);
 }
 /*
 \f
@@ -279,16 +287,8 @@ if (domlist!=(REFTYP **)0) {
           if ((qfile=eml_createqfile(qname,EXTOBE))==(FILE *)0) 
             phase=999;  //Trouble trouble
           break;
-        case 1  :       //Opening qfile
-          if ((*ptr)->todo!=(TRATYP **)0) {
-            TRATYP **todo;
-
-            todo=(*ptr)->todo;
-            while (*todo!=(TRATYP *)0) {
-              (void) eml_dumptra(qfile,*todo);
-              todo++;
-              }
-            }
+        case 1  :       //dumping TRANS data to file
+          (void) eml_dumptra(qfile,(*ptr)->todo);
           break;
         case 2  :       //Closing file
           (void) eml_closeqfile(qfile);
@@ -343,8 +343,8 @@ while (proceed==true) {
       if ((tra!=(TRATYP *)0)&&(tra->rcptto!=(char *)0)&&(strlen(tra->rcptto)>0))
         locdom=strrchr(tra->rcptto,'@');
       if (locdom==(char *)0) {
-        (void) rou_alert(0,"%s Unable to extract recipient domain! (Bug?)",OPEP);
-        (void) eml_dumptra((FILE *)0,tra);
+        (void) rou_alert(0,"%s Unable to get recipient domain in <%s> (Bug?)",
+                            OPEP,tra->rcptto);
         phase=999;      //Big trouble
         }
       else
index 7b732382238de57c210b9023f35ccf97ac53c3ab..59ca0c639946b8336b13b844eec6e383a7dcc505 100644 (file)
@@ -14,7 +14,7 @@
 //structure to define an email transport directive
 typedef struct  {
         char code;      //Transaction code
-        u_long date;    //Transaction date
+        time_t date;    //Transaction date
         u_int delay;    //Transaction execution delay
         char *sessid;   //session id
         char *mailfrom; //EMail Originator
@@ -22,7 +22,7 @@ typedef struct  {
         }TRATYP;
 
 //procedure to dump a transfert record (debug purpose)
-extern void eml_dumptra(FILE *out,TRATYP *tra);
+extern void eml_dumptra(FILE *out,TRATYP **tra);
 
 //procedure to fee memory used by a TRATYP structure
 extern TRATYP *eml_freetra(TRATYP *tra);
index 010403d264f7bbd08718623e7abb2902371e87f3..f830bf26ef7544f53f76199f8e248698e02f903c 100644 (file)
@@ -21,6 +21,7 @@
 #include       "unidns.h"
 #include       "unieml.h"
 #include       "devlog.h"
+#include       "geseml.h"
 #include       "lvleml.h"
 
 /*
@@ -357,7 +358,7 @@ while (proceed==true) {
       if ((queue=eml_createqfile(contact->cursesid,""))==(FILE *)0) 
         phase=999;      //trouble trouble
       break;
-    case 1      :       //sending go ahed to remote
+    case 1      :       //sending go ahaed to remote
       if (addreceived(contact,queue)==false) 
         phase=999;      //trouble trouble
       break;
@@ -961,28 +962,30 @@ _Bool status;
 status=true;
 if ((contact!=(CONTYP *)0)&&(contact->recipients!=(RCPTYP **)0)) {
   RCPTYP **ptr;
+  TRATYP **tralist;
   time_t isnow;
 
   ptr=contact->recipients;
+  tralist=(TRATYP **)0;
   isnow=time((time_t *)0);
   while (*ptr!=(RCPTYP *)0) {
+    TRATYP *tra;
     char data[300];
 
-    (void) snprintf(data,sizeof(data),"%c %ld %d %s %s %s@%s",
-                                      (*ptr)->code,
-                                      isnow,
-                                      0,
-                                      contact->cursesid,
-                                      contact->mailfrom,
-                                      (*ptr)->userid,
-                                      (*ptr)->domain);
-    if (fprintf(qfile,"%s\n",data)<0) {
-      (void) rou_alert(0,"%s Unable to write transfile (error=<%s>)",
-                          OPEP,strerror(errno));
-      status=false;
-      }
+    
+    (void) snprintf(data,sizeof(data),"%s@%s",(*ptr)->userid,(*ptr)->domain);
+    tra=(TRATYP *)calloc(1,sizeof(TRATYP));
+    tra->code=(*ptr)->code;
+    tra->date=isnow;
+    tra->delay=0;
+    tra->sessid=strdup(contact->cursesid);
+    tra->mailfrom=strdup(contact->mailfrom);
+    tra->rcptto=strdup(data);
+    tralist=(TRATYP **)rou_addlist((void **)tralist,(void *)tra);
     ptr++;
     }
+  (void) eml_dumptra(qfile,tralist);
+  tralist=(TRATYP **)rou_freelist((void **)tralist,(genfree_t)eml_freetra);
   }
 return status;
 #undef  OPEP
index 845035e392021b93033e47f56a155d2c4a8a4318..b9e266316c40c676673b4bca9d80169a544cc353 100644 (file)
@@ -344,17 +344,20 @@ return qfile;
 /*      stored within queue.                            */
 /*                                                      */
 /********************************************************/
-PUBLIC int eml_closeqfile(FILE *qfile)
+PUBLIC FILE *eml_closeqfile(FILE *qfile)
 
 {
 #define OPEP    "unieml.c:eml_closeqfile,"
-int status;
 
-if ((status=fclose(qfile))<0) {
-  (void) rou_alert(0,"%s Unable to close qfile (error=<%s>)",
-                           OPEP,strerror(errno));
+if (qfile!=(FILE *)0) {
+  if (fclose(qfile)<0) {
+      (void) rou_alert(0,"%s Unable to close qfile (error=<%s>)",
+                             OPEP,strerror(errno));
+    }
+  else
+    qfile=(FILE *)0;
   }
-return status;
+return qfile;
 #undef OPEP
 }
 /*
index a1b38f29ae44e68471eeb85cb34b6fcd02e9458c..55b7ec8318b3d7b4423f2aca1776034d63fd01f1 100644 (file)
@@ -79,7 +79,7 @@ extern _Bool eml_renameqfile(char *qfilename,const char *oldext,const char *newe
 extern FILE *eml_createqfile(char *qfilename,const char *ext);
 
 //procedure to close a file within the queue directory
-extern int eml_closeqfile(FILE *qfile);
+extern FILE *eml_closeqfile(FILE *qfile);
 
 //Procedure to list all file within queue directory
 //and with a specific extenstion