From bdd16d6bc6f4802df5b89ab461050c9ffbafea59 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Thu, 5 Jun 2025 17:00:56 -0400 Subject: [PATCH] Starting to implement remote connection --- Makefile | 17 ++++++--- app/Makefile | 8 ++++ app/sender.c | 56 +++++++--------------------- data-feed/feed00.tst | 2 +- data-feed/feed01.tst | 28 +++++++++++--- data-feed/feed04.tst | 17 +++++++++ lib/Makefile | 3 +- lib/geseml.c | 89 +++++++++++++++++++++++--------------------- lib/geseml.h | 7 +++- lib/lvleml.c | 63 ++++++++++++++++++++++++++++++- lib/lvleml.h | 8 ++++ 11 files changed, 198 insertions(+), 100 deletions(-) create mode 100644 data-feed/feed04.tst diff --git a/Makefile b/Makefile index b70b454..00bfc4c 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,12 @@ EXTPORT = 25 TESTITER= 4 #-------------------------------------------------------------------- #To test sorter +dosorter: debug + @ bin/sorter \ + -d 2 \ + -c ./conf/mailleur.conf.dvl \ + -r $(TESTDIR) + sorter : clean debug @ rm -fr $(TESTDIR)/var/spool/$(APPNAME)/queue @ mkdir -p $(TESTDIR)/var/spool/$(APPNAME)/queue @@ -45,6 +51,7 @@ sorter : clean debug data-$@/* \ $(TESTDIR)/var/spool/$(APPNAME)/queue @ bin/sorter \ + -f \ -d 2 \ -c ./conf/mailleur.conf.dvl \ -r $(TESTDIR) @@ -133,7 +140,7 @@ onefeed : debug -c ./conf/feeder.conf.dvl \ $(TESTIP) \ $(TESTPORT) \ - ./$(DATATST)/feed00.tst + ./$(DATATST)/feed01.tst @ rm -fr ./data-sorter/* @ cp -a \ $(TESTDIR)/var/spool/$(APPNAME)/queue/* \ @@ -244,13 +251,11 @@ EMLPAR = \ -d 3 \ $(TESTPROT):$(TESTIP):$(TESTPORT): -onercvr : debug - @ echo "starting $@" +dorcvr : debug @ bin/emlrcvr \ - -f \ - $(EMLPAR) + $(EMLPAR)$(TESTITER) -emlrcvr : prepare #starting email receiver +emlrcvr : #starting email receiver @ echo @ echo "--------------" @ echo "starting $@" diff --git a/app/Makefile b/app/Makefile index 99bb17a..0b084ae 100644 --- a/app/Makefile +++ b/app/Makefile @@ -88,6 +88,14 @@ sorter.o: sorter.c \ ../lib/geseml.h \ ../lib/subrou.h +sender.o: sender.c \ + ../lib/lvleml.h \ + ../lib/geseml.h \ + ../lib/unieml.h \ + ../lib/unipar.h \ + ../lib/unisig.h \ + ../lib/subrou.h + toremake: Makefile $(LIBAI) touch toremake - rm -f $(EXE) *.o diff --git a/app/sender.c b/app/sender.c index a0b2448..e16d01b 100644 --- a/app/sender.c +++ b/app/sender.c @@ -21,6 +21,7 @@ #include "unipar.h" #include "unisig.h" #include "geseml.h" +#include "lvleml.h" /* @@ -36,48 +37,19 @@ static _Bool dispatcher(TRATYP **tra) #define OPEP "sender.c:dispatcher," _Bool status; -status=false; +status=true; if (tra!=(TRATYP **)0) { - time_t isnow; - int count; - TRATYP **ptr; - - isnow=time((time_t *)0); - ptr=tra; - count=0; - status=true; - while (*ptr!=(TRATYP *)0) { - count++; - if (((*ptr)->date+(*ptr)->delay)<=isnow) { - (void) eml_add_delay(isnow,*ptr); - (void) rou_alert(0,"%s rcpt email <%s> count='%d' sessid=<%s>", - OPEP,(*ptr)->rcptto,count,(*ptr)->sessid); - switch ((*ptr)->code) { - case 'L' : //local delivery - (*ptr)->code='C'; //delivery done 'C'ompleted - if (eml_store_email(*ptr)==false) { - (*ptr)->code='L'; //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 -/* - char temps[40]; - - (void) strftime(temps,sizeof(temps),"%H:%M:%S",localtime(&isnow)); - //JMPDBG set as the remote email was not succesful - (void) rou_alert(0,"%s JMPDBG at '%s', Unable to deliver email <%s> to <%s>", - OPEP,temps,(*ptr)->sessid,(*ptr)->rcptto); -*/ - break; - default : - (void) rou_alert(0,"%s unexpected code '%c'",OPEP,(*ptr)->code); - status=false; - break; - } - } - ptr++; + switch ((*tra)->code) { + case 'L' : //local delivery + (void) eml_local_email(tra); + break; + case 'R' : //Remote delivery + (void) eml_remote_email(tra); + break; + default : + (void) rou_alert(0,"%s unexpected code '%c'",OPEP,(*tra)->code); + status=false; + break; } } return status; @@ -144,7 +116,7 @@ while (proceed==true) { } break; case 5 : //updating transfile - (void) eml_dumptra(qfile,tra); + (void) eml_dump_list_tra(qfile,tra); break; case 6 : //closing file qfile=eml_closeqfile(qfile); diff --git a/data-feed/feed00.tst b/data-feed/feed00.tst index af0a92b..4c0b941 100644 --- a/data-feed/feed00.tst +++ b/data-feed/feed00.tst @@ -24,7 +24,7 @@ C:COMMENT START #end of /etc/host addon #==================================================== C:COMMENT STOP -T:Sending a very Simple Email with local delivery +T:(feed00) Sending a very Simple Email with local delivery R:220 mailleur.example.com ESMTP (cleartext) emlrcvr... #==================================================== S:HELO example.com diff --git a/data-feed/feed01.tst b/data-feed/feed01.tst index acbacc4..c4c67e8 100644 --- a/data-feed/feed01.tst +++ b/data-feed/feed01.tst @@ -1,17 +1,35 @@ -#very simple test to feed SMTP server #==================================================== -T:Testing if MX is found +T:(feed01) Sending a a simple mail to remote server R:220 mailleur.example.com ESMTP (cleartext) emlrcvr... #==================================================== S:HELO example.com #R:250-mailleur.example.com, link (cleartext) ready, your IP/FQDN=[127.127.0.2/feed2.example.com] R:250-mailleur.example.com, link (cleartext) ready,... +C:GOTLS +R:250 Link now encryp... S:MAIL FROM: R:250 2.1.3 postmaster@example.com.. sender ok -S:RCPT TO: -R:563 5.6.3 No valid MX found for recipient domain name (rcpt=subdom0.example.com) S:RCPT TO: R:250 2.6.4 Address accepted +#------------------------------------------------------------------------- +#-sending data +C:DATA +D:Subject: Very Simple email contents +D:From: Maitre Post +D:To: Remote person +C:T +D: +D:FIRST Line +D:SECOND Line +D:LAST Line +D:. +D:this is a line with a dot +D: +D:. +D:end +D:ligne court| +C:. +#------------------------------------------------------------------------- +R:250 3.5.3 Message accepted for delivery S:QUIT R:221 2.0.0 Bye, closing connection... -#------------------------------------------------------------------------- diff --git a/data-feed/feed04.tst b/data-feed/feed04.tst new file mode 100644 index 0000000..acbacc4 --- /dev/null +++ b/data-feed/feed04.tst @@ -0,0 +1,17 @@ +#very simple test to feed SMTP server +#==================================================== +T:Testing if MX is found +R:220 mailleur.example.com ESMTP (cleartext) emlrcvr... +#==================================================== +S:HELO example.com +#R:250-mailleur.example.com, link (cleartext) ready, your IP/FQDN=[127.127.0.2/feed2.example.com] +R:250-mailleur.example.com, link (cleartext) ready,... +S:MAIL FROM: +R:250 2.1.3 postmaster@example.com.. sender ok +S:RCPT TO: +R:563 5.6.3 No valid MX found for recipient domain name (rcpt=subdom0.example.com) +S:RCPT TO: +R:250 2.6.4 Address accepted +S:QUIT +R:221 2.0.0 Bye, closing connection... +#------------------------------------------------------------------------- diff --git a/lib/Makefile b/lib/Makefile index dd27e33..86f9100 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -110,7 +110,8 @@ subafn.o: \ subafn.h subafn.c lvleml.h: \ - gestcp.h + devsoc.h devsql.h \ + geseml.h gestcp.h gestcp.h: \ subrou.h \ diff --git a/lib/geseml.c b/lib/geseml.c index 0c3ef1a..27462c4 100644 --- a/lib/geseml.c +++ b/lib/geseml.c @@ -86,7 +86,7 @@ ref=(REFTYP *)0; phase=0; proceed=true; while (proceed==true) { - switch (phase) { + switch (phase) { case 0 : //Firsy Check if we have data if (trans==(TRATYP *)0) { (void) rou_alert(0,"%s trans is NULL (Bug?)",OPEP); @@ -134,13 +134,53 @@ return reflist; */ /********************************************************/ /* */ +/* Procedure to display/debug ONE TRATYP record */ +/* content */ +/* */ +/********************************************************/ +PUBLIC _Bool eml_dump_one_tra(FILE *qfile,TRATYP *tra) + +{ +_Bool status; + +status=false; +if (tra!=(TRATYP *)0) { + char temps[50]; + char line[300]; + + status=true; + (void) strftime(temps,sizeof(temps),"#%Y-%m-%d %H:%M:%S", + localtime(&(tra->date))); + (void) snprintf(line,sizeof(line),"%c\t%lu\t%04u\t%s\t%s\t%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",temps); + (void) fprintf(qfile,"%s\n",line); + } + } +return status; +} +/* + +*/ +/********************************************************/ +/* */ /* Procedure to display/debug TRATYP record content*/ /* */ /********************************************************/ -PUBLIC _Bool eml_dumptra(FILE *qfile,TRATYP **tra) +PUBLIC _Bool eml_dump_list_tra(FILE *qfile,TRATYP **tra) { -#define OPEP "geseml.c:eml_dumptra," +#define OPEP "geseml.c:eml_dump_list_tra," _Bool action; @@ -157,44 +197,9 @@ if (tra!=(TRATYP **)0) { "originator\t\trecipient\n"); } while (*tra!=(TRATYP *)0) { - char temps[50]; - char line[300]; - - (void) strftime(temps,sizeof(temps),"#%Y-%m-%d %H:%M:%S", - localtime(&((*tra)->date))); - (void) snprintf(line,sizeof(line),"%c\t%lu\t%04u\t%s\t%s\t%s", - (*tra)->code, - (*tra)->date, - (*tra)->delay, - (*tra)->sessid, - (*tra)->mailfrom, - (*tra)->rcptto - ); - if (((*tra)->date+(*tra)->delay)<=isnow) { - time_t bigre; - char timer[50]; - char strnow[50]; - - (void) strftime(strnow,sizeof(strnow),"#%Y-%m-%d %H:%M:%S", - localtime(&isnow)); - (void) strftime(timer,sizeof(timer),"#%Y-%m-%d %H:%M:%S", - localtime(&((*tra)->date))); - (void) rou_alert(0,"%s JMPDBG date=<%s> delay='%04d'", - OPEP,timer,(*tra)->delay); - bigre=(*tra)->date+(*tra)->delay; - (void) strftime(timer,sizeof(temps),"#%Y-%m-%d %H:%M:%S", - localtime(&bigre)); - (void) rou_alert(0,"%s JMPDBG timer=<%s> iwnow=<%s>",OPEP,timer,strnow); - (void) rou_alert(0,"%s JMPDBG action=true",OPEP); + (void) eml_dump_one_tra(qfile,*tra); + if (((*tra)->date+(*tra)->delay)<=isnow) action=true; - } - if (qfile==(FILE *)0) { - (void) rou_alert(0,"TRA=<%s>",line); - } - else { - (void) fprintf(qfile,"%s\n",temps); - (void) fprintf(qfile,"%s\n",line); - } tra++; } } @@ -371,7 +376,7 @@ if (domlist!=(REFTYP **)0) { break; case 1 : //dumping TRANS data to file (void) eml_sort_list((*ptr)->todo); - if ((action=eml_dumptra(qfile,(*ptr)->todo))==true) { + if ((action=eml_dump_list_tra(qfile,(*ptr)->todo))==true) { ext=EXTODO; } break; @@ -472,7 +477,7 @@ if (next!=(TRATYP **)0) { phase=999; //Trouble trouble break; case 1 : //dumping TRANS data to file - (void) eml_dumptra(qfile,next); + (void) eml_dump_list_tra(qfile,next); break; case 2 : //Closing file (void) eml_closeqfile(qfile); diff --git a/lib/geseml.h b/lib/geseml.h index 2b9367c..11b88b3 100644 --- a/lib/geseml.h +++ b/lib/geseml.h @@ -24,8 +24,11 @@ typedef struct { char *rcptto; //EMail Recipient }TRATYP; -//procedure to dump a transfert record (debug purpose) -extern _Bool eml_dumptra(FILE *out,TRATYP **tra); +//procedure to dump a list of transfert record +extern _Bool eml_dump_one_tra(FILE *out,TRATYP *tra); + +//procedure to dump a list of transfert record +extern _Bool eml_dump_list_tra(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 f830bf2..aaf55b7 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -984,9 +984,70 @@ if ((contact!=(CONTYP *)0)&&(contact->recipients!=(RCPTYP **)0)) { tralist=(TRATYP **)rou_addlist((void **)tralist,(void *)tra); ptr++; } - (void) eml_dumptra(qfile,tralist); + (void) eml_dump_list_tra(qfile,tralist); tralist=(TRATYP **)rou_freelist((void **)tralist,(genfree_t)eml_freetra); } return status; #undef OPEP } +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to store local email (MX local) within*/ +/* the serveur right directory. */ +/* */ +/********************************************************/ +PUBLIC void eml_local_email(TRATYP **tra) + +{ +#define OPEP "lvleml.c:eml_local_email," + +time_t isnow; + +isnow=time((time_t *)0); +while (*tra!=(TRATYP *)0) { + if (((*tra)->date+(*tra)->delay)>isnow) + continue; + (void) eml_add_delay(isnow,*tra); + switch ((*tra)->code) { + case 'L' : //local email (MX is local) + (*tra)->code='C'; + if (eml_store_email(*tra)==false) { + (*tra)->code='L'; //Will try to deliver later one + (void) rou_alert(0,"%s Unable to deliver local email <%s> to <%s>", + OPEP,(*tra)->sessid,(*tra)->rcptto); + } + break; + default : //Unexpected local? email?? + (void) rou_alert(0,"%s Directive is not! local email (Bug?)",OPEP); + (void) rou_alert(0,"%s TRA=<%cs %lu %04u %s %s %s",OPEP, + (*tra)->code, + (*tra)->date, + (*tra)->delay, + (*tra)->sessid, + (*tra)->mailfrom, + (*tra)->rcptto); + break; + } + tra++; + } +#undef OPEP +} +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to send email to remote recipient */ +/* */ +/********************************************************/ +PUBLIC void eml_remote_email(TRATYP **tra) + +{ +#define OPEP "lvleml.c:eml_remote_email," + +(void) rou_alert(0,"%s JMPDBG",OPEP); +#undef OPEP +} diff --git a/lib/lvleml.h b/lib/lvleml.h index 6d6c216..966807b 100644 --- a/lib/lvleml.h +++ b/lib/lvleml.h @@ -13,6 +13,7 @@ #include "devsoc.h" #include "devsql.h" #include "gestcp.h" +#include "geseml.h" typedef struct { SOCPTR *socptr; //established contact socket context @@ -43,4 +44,11 @@ extern CONTYP *eml_dropcontact(CONTYP *contact); //generate trans file contents extern _Bool eml_mktransfile(CONTYP *contact,FILE *qfile); + +//store local email within domain proper directory +extern void eml_local_email(TRATYP **tra); + +//sending email to remote recipents +extern void eml_remote_email(TRATYP **tra); + #endif -- 2.47.3