From: Jean-Marc Pigeon (Delson) Date: Mon, 26 May 2025 23:55:09 +0000 (-0400) Subject: IMproving trans file dump procedure X-Git-Tag: tag-0.8~83 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=2d2feca4ac37b790ebd6aabac4aaf7af5192b3c1;p=jmp%2Fmailleur IMproving trans file dump procedure --- diff --git a/app/feeder.c b/app/feeder.c index 1c56f8c..20b5d7e 100644 --- a/app/feeder.c +++ b/app/feeder.c @@ -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)) { diff --git a/app/sender.c b/app/sender.c index a17dcd5..7296aeb 100644 --- a/app/sender.c +++ b/app/sender.c @@ -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; } diff --git a/lib/geseml.c b/lib/geseml.c index 6187669..b603b19 100644 --- a/lib/geseml.c +++ b/lib/geseml.c @@ -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); } /* @@ -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 diff --git a/lib/geseml.h b/lib/geseml.h index 7b73238..59ca0c6 100644 --- a/lib/geseml.h +++ b/lib/geseml.h @@ -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); diff --git a/lib/lvleml.c b/lib/lvleml.c index 010403d..f830bf2 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -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 diff --git a/lib/unieml.c b/lib/unieml.c index 845035e..b9e2663 100644 --- a/lib/unieml.c +++ b/lib/unieml.c @@ -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 } /* diff --git a/lib/unieml.h b/lib/unieml.h index a1b38f2..55b7ec8 100644 --- a/lib/unieml.h +++ b/lib/unieml.h @@ -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