From 22d1d98cc058225f77a3299f566a21fe24736b64 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Thu, 15 May 2025 09:35:55 -0400 Subject: [PATCH] generating todo file to transfer Email is working --- app/sorter.c | 4 +-- lib/Makefile | 1 + lib/geseml.c | 91 ++++++++++++++++++++++++++++++++++++++++------------ lib/geseml.h | 2 +- lib/unieml.c | 4 +-- 5 files changed, 76 insertions(+), 26 deletions(-) diff --git a/app/sorter.c b/app/sorter.c index c5b6aad..03ce0eb 100644 --- a/app/sorter.c +++ b/app/sorter.c @@ -46,7 +46,6 @@ 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; @@ -62,13 +61,14 @@ while (proceed==true) { if ((qfile=eml_openqfile(*ptr))!=(FILE *)0) { trans=eml_scanqfile(trans,qfile); (void) eml_closeqfile(qfile); + (void) eml_deleteqfile(*ptr); } ptr++; } fname=(char **)rou_freelist((void *)fname,(freehandler_t)rou_freestr); } break; - case 2 : //Cscanning translit + case 2 : //scanning translit if (trans!=(TRATYP **)0) { TRATYP **ptr; diff --git a/lib/Makefile b/lib/Makefile index 02764ab..1fe3def 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -48,6 +48,7 @@ gesspf.o: \ geseml.o: \ subrou.h \ + unieml.h \ geseml.h geseml.h gestcp.o: \ diff --git a/lib/geseml.c b/lib/geseml.c index cd575fe..6916ae0 100644 --- a/lib/geseml.c +++ b/lib/geseml.c @@ -8,6 +8,7 @@ #include #include "subrou.h" +#include "unieml.h" #include "geseml.h" typedef struct { @@ -77,16 +78,24 @@ while (proceed==true) { phase=999; //No dmain } break; - case 2 : //do we know domain + case 2 : //do we have domain + dom++; + if (strlen(dom)==0) { + (void) rou_alert(0,"%s Domain length from < <%s> is zero (Bug?)", + OPEP,trans->rcptto); + phase=999; //No dmain + } + break; + case 3 : //do we know domain if ((ref=findref(reflist,dom))!=(REFTYP *)0) phase++; //we have reference already break; - case 3 : //Adding reference + case 4 : //Adding reference ref=(REFTYP *)calloc(1,sizeof(REFTYP)); ref->domain=dom; reflist=(REFTYP **)rou_addlist((void **)reflist,(void *)ref); break; - case 4 : //Adding transaction within reference + case 5 : //Adding transaction within reference ref->todo=(TRATYP **)rou_addlist((void **)ref->todo,(void *)trans); break; default : //SAFE Guard @@ -106,19 +115,26 @@ return reflist; /* Procedure to display/debug TRATYP record content*/ /* */ /********************************************************/ -PUBLIC void eml_dumptra(TRATYP *tra) +PUBLIC void eml_dumptra(FILE *out,TRATYP *tra) { +char line[300]; + +(void) strcpy(line,"Empty"); 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 - ); + (void) snprintf(line,sizeof(line),"%c,%lu,%u %s %s %s", + tra->code, + tra->date, + tra->delay, + tra->sessid, + tra->mailfrom, + tra->rcptto + ); } +if (out==(FILE *)0) + (void) rou_alert(0,"TRA=<%s>",line); +else + (void) fprintf(out,"%s\n",line); } /* @@ -194,7 +210,6 @@ while ((ptr=fgets(line,sizeof(line),qfile))!=(char *)0) { 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; @@ -232,22 +247,56 @@ while (*list!=(TRATYP *)0) { list++; } if (domlist!=(REFTYP **)0) { + int iter; + time_t current; + struct tm *tinfo; + char buffer[80]; REFTYP **ptr; + iter=0; + (void) time(¤t ); + tinfo=localtime(¤t); + (void) strftime(buffer,sizeof(buffer),"%s",tinfo); ptr=domlist; while (*ptr!=(REFTYP *)0) { - (void) rou_alert(0,"%s JMPDBG refdomain=<%s>",OPEP,(*ptr)->domain); - if ((*ptr)->todo!=(TRATYP **)0) { - TRATYP **todo; + FILE *qfile; + char qname[150]; + int phase; + _Bool proceed; + + qfile=(FILE *)0; + (void) snprintf(qname,sizeof(qname),"%s-%s-%04d",(*ptr)->domain,buffer,iter); + phase=0; + proceed=true; + while (proceed==true) { + switch (phase) { + case 0 : //Opening qfile + if ((qfile=eml_createqfile(qname,"todo"))==(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(*todo); - todo++; + todo=(*ptr)->todo; + while (*todo!=(TRATYP *)0) { + (void) eml_dumptra(qfile,*todo); + todo++; + } + } + break; + case 2 : //Closing file + (void) eml_closeqfile(qfile); + break; + default : //SAFE Guard + proceed=false; + break; } - } + phase++; + } (void) free(*ptr); ptr++; + iter++; } (void) free(domlist); } diff --git a/lib/geseml.h b/lib/geseml.h index b242e2e..06fb58e 100644 --- a/lib/geseml.h +++ b/lib/geseml.h @@ -22,7 +22,7 @@ typedef struct { }TRATYP; //procedure to dump a transfert record (debug purpose) -extern void eml_dumptra(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); diff --git a/lib/unieml.c b/lib/unieml.c index a59d2ef..550c285 100644 --- a/lib/unieml.c +++ b/lib/unieml.c @@ -194,7 +194,7 @@ return status; PUBLIC _Bool eml_deleteqfile(char *qfilename) { -#define OPEP "unieml.c:eml_createqfile," +#define OPEP "unieml.c:eml_deleteqfile," _Bool done; char *filename; @@ -242,7 +242,7 @@ while (proceed==true) { switch (phase) { case 0 : //Do we have a session ID if ((qfilename==(char *)0)||(strlen(qfilename)==0)) { - (void) rou_core_dump("%s sessionID is not set (bug?)",OPEP); + (void) rou_core_dump("%s qfilename is not set (bug?)",OPEP); phase=999; //never reached } break; -- 2.47.3