]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Able to scan the queue transfile
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 13 May 2025 18:47:53 +0000 (14:47 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 13 May 2025 18:47:53 +0000 (14:47 -0400)
app/Makefile
app/sorter.c
lib/Makefile
lib/geseml.c [new file with mode: 0644]
lib/geseml.h [new file with mode: 0644]
lib/gesspf.h
lib/unieml.c
lib/unieml.h

index 5cf068abd84e85d7e8619b46f3198587c2662014..2432df56aa814721a586b997b89529ebe2097565 100644 (file)
@@ -79,6 +79,7 @@ feeder.o:  feeder.c                           \
           ../lib/subrou.h
 
 sorter.o:  sorter.c                            \
+          ../lib/geseml.h                      \
           ../lib/subrou.h
 
 toremake:  Makefile $(LIBAI)
index 4bd855a183922966f235fdc023959509090f6967..03ff9876e954e3b400fbbc51bd7bb23982339e26 100644 (file)
 #include       "unieml.h"
 #include       "unipar.h"
 #include       "unisig.h"
+#include       "geseml.h"
 
 #define SORTER  "sorter"        //application name
 
-//structure to build a email directive
-typedef struct  {
-        char code;      //Transaction code
-        u_long date;    //Transaction date
-        u_int delay;    //Transaction execution delay
-        char *sessid;   //session id
-        char *mailfrom; //EMail Originator
-        char *recptto;  //EMail Recipient
-        }TRATYP;
-
 /********************************************************/
 /*                                                     */
 /*     procedure to scan all files                     */
@@ -38,18 +29,65 @@ typedef struct  {
 static _Bool scantrans()
 
 {
+#define OPEP    "sorter.c:scantrans,"
+
 _Bool status;
-char **list;
+char **fname;
+TRATYP **trans;
+int phase;
+_Bool proceed;
 
 status=false;
-list=(char **)0;
-(void) rou_alert(0,"JMPDBG sorter");
-if ((list=eml_getqfilelist(".trans"))!=(char **)0) {
-  list=(char **)rou_freelist((void *)list,(freehandler_t)rou_freestr); 
+fname=(char **)0;
+trans=(TRATYP **)0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+  switch (phase) {
+    case 0      :       //Getting the list of file
+      fname=eml_getqfilelist(fname,".trans");
+      fname=eml_getqfilelist(fname,".todo");
+      if (fname==(char **)0)
+        phase=999;      //Nothing to do
+      break;
+    case 1      :       //Building the "trans" list
+      if (fname!=(char **)0) {  //walways
+        char **ptr;
+
+        ptr=fname; 
+        while (*ptr!=(char *)0) {
+          FILE *qfile;
+
+          (void) rou_alert(0,"%s fame=<%s>",OPEP,*ptr);
+          if ((qfile=eml_openqfile(*ptr))!=(FILE *)0) {
+            trans=eml_scanqfile(trans,qfile);
+            }
+          ptr++;
+          }
+        fname=(char **)rou_freelist((void *)fname,(freehandler_t)rou_freestr); 
+        }
+      break;
+    case 2      :       //Cscanning translit
+      if (trans!=(TRATYP **)0) {
+        TRATYP **ptr;
+
+        ptr=trans;
+        while (*ptr!=(TRATYP *)0) {
+          (void) eml_dumptra(*ptr); 
+          ptr++;
+          }
+        trans=(TRATYP **)rou_freelist((void **)trans,(freehandler_t)eml_freetra);
+        status=true;
+        }
+      break;
+    default     :       //SAFE Guard
+      proceed=false;
+      break;
+    }
+  phase++;
   }
-status=true;
-(void) sleep(5);
 return status;
+#undef  OPEP
 }
 /*
 \f
index 6de9776320904c8d343cacafb16cc2095f32fffc..02764abc9c4d1cc85b6626ccdb125fbb06796c42 100644 (file)
@@ -18,7 +18,7 @@ clean :
 OBJS=                                          \
          modrec.o                              \
          lvleml.o                              \
-         gesspf.o gestcp.o                     \
+         gesspf.o gestcp.o geseml.o            \
          devlog.o devsoc.o devsql.o            \
          unidns.o unieml.o unipos.o            \
          unipar.o uniprc.o unisig.o unitls.o   \
@@ -46,6 +46,10 @@ gesspf.o:                                    \
           subrou.h                             \
           gesspf.h gesspf.h
 
+geseml.o:                                      \
+          subrou.h                             \
+          geseml.h geseml.h
+
 gestcp.o:                                      \
           subrou.h                             \
           unieml.h                             \
diff --git a/lib/geseml.c b/lib/geseml.c
new file mode 100644 (file)
index 0000000..33fdc87
--- /dev/null
@@ -0,0 +1,122 @@
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
+/********************************************************/
+/*                                                     */
+/*     Implement all routine to manage email transport */
+/*     exchange.                                       */
+/*                                                     */
+/********************************************************/
+#include        <string.h>
+
+#include       "subrou.h"
+#include       "geseml.h"
+
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*      Procedure to display/debug TRATYP record content*/
+/*                                                      */
+/********************************************************/
+PUBLIC void eml_dumptra(TRATYP *tra)
+
+{
+if (tra!=(TRATYP *)0) {
+  (void) rou_alert(0,"TRA-> %c,%lu,%u %s %s %s",
+                      tra->code,
+                      tra->date,
+                      tra->delay,
+                      tra->sessid,
+                      tra->mailfrom,
+                      tra->rcptto
+                  );
+  }
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*      Procedure to free memory used by a TRATYP record*/
+/*                                                      */
+/********************************************************/
+PUBLIC TRATYP *eml_freetra(TRATYP *trans)
+
+{
+if (trans!=(TRATYP *)0) {
+  trans->rcptto=rou_freestr(trans->rcptto);
+  trans->mailfrom=rou_freestr(trans->mailfrom);
+  trans->sessid=rou_freestr(trans->sessid);
+  (void) free(trans);
+  trans=(TRATYP *)0;
+  }
+return trans;
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*      Procedure to scan the a qfile and build a       */
+/*      list of email transport directive.              */
+/*                                                      */
+/********************************************************/
+PUBLIC TRATYP **eml_scanqfile(TRATYP **list,FILE *qfile)
+
+{
+#define OPEP    "geseml.c:eml_scanqfile,"
+
+char *ptr;
+char line[300];
+
+while ((ptr=fgets(line,sizeof(line),qfile))!=(char *)0) {
+  char id[300];
+  char from[100];
+  char to[100];
+  char code;
+  u_long date;
+  u_int delay;
+  int phase;
+  _Bool proceed;
+
+  phase=0;
+  proceed=true;
+  while (proceed==true) {
+    switch (phase) {
+      case 0    :       //Removing comment
+        if ((ptr=strchr(line,'#'))!=(char *)0)
+          *ptr='\000';
+        if (strlen(line)==0)
+          phase=999;    //No data within line
+        break;
+      case 1    :       //scanning line contents
+        if (sscanf(line,"%c %ld %d %s %s %s",&code,&date,&delay,id,from,to)!=6) {
+          (void) rou_alert(0,"%s, Unable to scan <%s> (config?)",OPEP,line);
+          phase=999;    //No data within line
+          }
+        break;
+      case 2    :       //scanning line contents
+        if (strlen(id)>0) {     //always?
+          TRATYP *tra;
+          tra=(TRATYP *)calloc(1,sizeof(TRATYP));
+          tra->code=code;
+          tra->date=date;
+          tra->delay=delay;
+          tra->sessid=strdup(id);
+          tra->mailfrom=strdup(from);
+          tra->rcptto=strdup(to);
+          (void) eml_dumptra(tra);
+          list=(TRATYP **)rou_addlist((void **)list,(void *)tra); 
+          }
+        break;
+      default   :       //SAFE Guard
+        proceed=false;
+        break;
+      }
+    phase++;
+    }
+  }
+return list;
+#undef  OEP
+}
diff --git a/lib/geseml.h b/lib/geseml.h
new file mode 100644 (file)
index 0000000..6c172f5
--- /dev/null
@@ -0,0 +1,33 @@
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
+/********************************************************/
+/*                                                     */
+/*     Define all procedure to manage email transport  */
+/*      data.                                           */
+/*                                                     */
+/********************************************************/
+#ifndef        GESEML
+#define GESEML
+
+#include        <stdlib.h>
+#include        <stdio.h>
+
+//structure to define an email transport directive
+typedef struct  {
+        char code;      //Transaction code
+        u_long date;    //Transaction date
+        u_int delay;    //Transaction execution delay
+        char *sessid;   //session id
+        char *mailfrom; //EMail Originator
+        char *rcptto;   //EMail Recipient
+        }TRATYP;
+
+//procedure to dump a transfert record (debug purpose)
+extern void eml_dumptra(TRATYP *tra);
+
+//procedure to fee memory used by a TRATYP structure
+extern TRATYP *eml_freetra(TRATYP *tra);
+
+//procedure to open a specific qfile
+extern TRATYP **eml_scanqfile(TRATYP **list,FILE *qfile);
+
+#endif
index 7eed2c0262de503e7af35834fa76475a208eed84..940e27b6d3eaa21f4512554b67979d44835c30b4 100644 (file)
@@ -5,8 +5,8 @@
 /*      DNS record.                                     */
 /*                                                     */
 /********************************************************/
-#ifndef        GESTSPF
-#define GESTSPF
+#ifndef        GESSPF
+#define GESSPF
 
 #include        "subafn.h"
 
index 1c7e1d6a0aafe882cf53584e740cb74e8952430a..a59d2ef3724b69b0f02a8050b5e21f1795aeb210 100644 (file)
@@ -312,17 +312,15 @@ return status;
 /*      Return a list or NULL if no file.               */
 /*                                                      */
 /********************************************************/
-PUBLIC char **eml_getqfilelist(char *ext)
+PUBLIC char **eml_getqfilelist(char **dnames,char *ext)
 
 {
 #define OPEP    "unieml.c:eml_getqfilelist"
 
-char **dirlst;
 DIR *dir;
 int phase;
 _Bool proceed;
 
-dirlst=(char **)0;
 dir=(DIR *)0;
 phase=0;
 proceed=true;
@@ -358,7 +356,7 @@ while (proceed==true) {
           }
         if (ptr!=(char *)0) {
           (void) rou_alert(0,"%s JMPDBG got <%s>",OPEP,data->d_name);
-          dirlst=(char **)rou_addlist((void **)dirlst,(void *)strdup(data->d_name));
+          dnames=(char **)rou_addlist((void **)dnames,(void *)strdup(data->d_name));
           }
         }
       break;
@@ -374,7 +372,36 @@ while (proceed==true) {
     }
   phase++;
   }
-return dirlst;
+return dnames;
+#undef  OPEP
+}
+/*
+^L
+*/
+/********************************************************/
+/*                                                      */
+/*     Procedure to open a fine within the MTA queue   */
+/*      directory.                                      */
+/*                                                      */
+/********************************************************/
+PUBLIC FILE *eml_openqfile(char *qfilename)
+
+{
+#define OPEP    "unieml.c:eml_openqfile,"
+
+FILE *qfile;
+char *dirname;
+char fullname[300];
+
+qfile=(FILE *)0;
+dirname=rou_apppath(QDIR);
+(void) snprintf(fullname,sizeof(fullname),"%s/%s",dirname,qfilename);
+if ((qfile=fopen(fullname,"r"))==(FILE *)0) {
+  (void) rou_alert(0,"%s Unable to open file <%s> (error-<%s> bug?)",
+                     OPEP,fullname,strerror(errno));
+  }
+dirname=rou_freestr(dirname);
+return qfile;
 #undef  OPEP
 }
 /*
index 5088d4b81a047d2ca1a9ba85a7423318dd32bee2..7982015645ff33df62c4e55d3a6f38bb4195e16d 100644 (file)
@@ -62,7 +62,7 @@ extern int eml_closeqfile(FILE *qfile);
 
 //Procedure to list all file within queue directory
 //and with a specific extenstion
-extern char **eml_getqfilelist(char *ext);
+extern char **eml_getqfilelist(char **dnames,char *ext);
 
 //procedure to open a specific qfile
 extern FILE *eml_openqfile(char *qfilename);