From: Jean-Marc Pigeon (Delson) Date: Mon, 19 May 2025 20:30:11 +0000 (-0400) Subject: Starting to store email in recipient directory X-Git-Tag: tag-0.8~94 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=19d7262f0540a81cf31d33c72bbf77e5ba34ae60;p=jmp%2Fmailleur Starting to store email in recipient directory --- diff --git a/Makefile b/Makefile index 78805e3..7611105 100644 --- a/Makefile +++ b/Makefile @@ -41,26 +41,27 @@ TESTITER= 4 sorter : clean debug @ bin/sorter \ -d 2 \ - -c ./conf/feeder.conf.dvl \ + -c ./conf/mailleur.conf.dvl \ -r $(TESTDIR) #-------------------------------------------------------------------- #To test sender -sender : clean debug newtest - @ bin/$@ \ +sender : clean debug newtest + @ bin/$@ \ -d 2 \ - -c ./conf/feeder.conf.dvl \ + -c ./conf/mailleur.conf.dvl \ -r $(TESTDIR) \ example.com-1747663900-0002.todo -dbgsend : clean debug +dbgsend : clean debug @ gdb \ --args \ bin/sender \ -f \ -d2 \ - -c ./conf/feeder.conf.dvl \ + -c ./conf/mailleur.conf.dvl \ -r $(TESTDIR) + #-------------------------------------------------------------------- #testing feed FEEDPAR = \ @@ -258,6 +259,7 @@ newtest : deltest @ mkdir -p $(TESTDIR)/var/run @ mkdir -p $(TESTDIR)/var/spool/$(APPNAME)/{in,out}-logs @ mkdir -p $(TESTDIR)/var/spool/$(APPNAME)/queue + @ mkdir -p $(TESTDIR)/var/spool/$(APPNAME)/mails @ mkdir -p $(TESTDIR)/usr @ cp -a \ bin \ diff --git a/Notes b/Notes index 76e9953..021cfd3 100644 --- a/Notes +++ b/Notes @@ -7,7 +7,8 @@ MA-0.6-dvl, certificat exchange is working properly status date delta session from rcpt Char long int char * char * char * status can be: - D delayed - R Ready - S Sent + C completed ;email dispatched + D default ;email can not be dispatched + L local ;Email stay on local serveur + R Remote ;email is to be sent on remote site #----------------------------------------------------------- diff --git a/app/sender.c b/app/sender.c index d0404d0..663d901 100644 --- a/app/sender.c +++ b/app/sender.c @@ -45,7 +45,12 @@ if (tra!=(TRATYP **)0) { while (*ptr!=(TRATYP *)0) { switch ((*ptr)->code) { case 'L' : //local delivery - (*ptr)->code='D'; //delivery done + (*ptr)->code='C'; //delivery done + if (eml_store_email(*ptr)==false) { + (*ptr)->code='D'; //delivery done + (void) rou_alert(0,"%s Unable to deliver email <%s> to <%s>", + OPEP,(*ptr)->sessid,(*ptr)->rcptto); + } break; default : (void) eml_dumptra((FILE *)0,*ptr); diff --git a/conf/mailleur.conf.dvl b/conf/mailleur.conf.dvl index 99f80ab..9fbc63d 100644 --- a/conf/mailleur.conf.dvl +++ b/conf/mailleur.conf.dvl @@ -13,3 +13,6 @@ DB_NAME = mailleur DB_HOST = localhost DB_PORT = 5432 #------------------------------------------------ +#Dovecot storage directory +DOV_MAILDIR = "/var/spool/mailleur/mails" +#------------------------------------------------ diff --git a/lib/geseml.c b/lib/geseml.c index 2cf65de..c307fc5 100644 --- a/lib/geseml.c +++ b/lib/geseml.c @@ -5,12 +5,16 @@ /* exchange. */ /* */ /********************************************************/ +#include #include #include "subrou.h" #include "unieml.h" #include "geseml.h" +//dovecot local storage directory +#define DIRDOV "DOV_MAILDIR" + typedef struct { char *domain; //common domain TRATYP **todo; //Transfer reference @@ -308,3 +312,83 @@ return done; #undef EXTOBE #undef OPEP } +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to store an email contents with the */ +/* recipient email area. */ +/* Return tru if successful, false otherwise */ +/* */ +/********************************************************/ +PUBLIC _Bool eml_store_email(TRATYP *tra) + +{ +#define OPEP "geseml.c:eml_store_email," + +_Bool done; +char *locdom; +char dirname[300]; +int phase; +_Bool proceed; + +done=false; +locdom=(char *)0; +phase=0; +proceed=true; +while (proceed==true) { + switch (phase) { + case 0 : //Extracting recipient email + 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); + phase=999; //Big trouble + } + else + locdom++; + break; + case 1 : //creating recipient directory if needed + DIR *dir; + char *path; + + path=rou_apppath(getenv(DIRDOV)); + (void) snprintf(dirname,sizeof(dirname),"%s/%s/%s/",path,locdom,tra->rcptto); + *(strrchr(dirname,'@'))='\000'; //keeping username only + if ((dir=opendir(dirname))==(DIR *)0) { + int status; + char cmd[400]; + + (void) snprintf(cmd,sizeof(cmd),"mkdir -p %s",dirname); + if ((status=system(cmd))!=0) { + (void) rou_alert(0,"%s Unable to create <%s> directory (system?/bug?)", + OPEP,dirname); + phase=999; //big trouble, No need to go further + } + } + else + closedir(dir); + (void) free(path); + break; + case 2 : //duplicating session file to the recipient directory + if (eml_dupqfile(tra->sessid,dirname)==false) { + (void) rou_alert(0,"%s Unable to store email <%s> to user directory <%s>", + OPEP,tra->sessid,dirname); + phase=999; //big trouble. + } + break; + case 3 : //everything fine + done=true; + break; + default : //SAFE Guard + proceed=false; + break; + } + phase++; + } +return done; + +#undef OPEP +} diff --git a/lib/geseml.h b/lib/geseml.h index 06fb58e..7b73238 100644 --- a/lib/geseml.h +++ b/lib/geseml.h @@ -33,4 +33,7 @@ extern TRATYP **eml_scanqfile(TRATYP **list,FILE *qfile); //procedure to Generate todolist file within queue extern _Bool eml_todoqfile(TRATYP **list); +//procedure to store an email to the local email storage area +extern _Bool eml_store_email(TRATYP *tra); + #endif diff --git a/lib/unieml.c b/lib/unieml.c index 17dfbc2..40ab120 100644 --- a/lib/unieml.c +++ b/lib/unieml.c @@ -497,6 +497,24 @@ return status; */ /********************************************************/ /* */ +/* Procedure to duplication a sessid file (email) */ +/* to user directory. */ +/* Return true if successful, false otherwise */ +/* */ +/********************************************************/ +PUBLIC _Bool eml_dupqfile(char *qfilename,const char *dest) + +{ +_Bool status; + +status=false; +return status; +} +/* +^L +*/ +/********************************************************/ +/* */ /* Procedure to check if email address is */ /* acceptable. */ /* */ diff --git a/lib/unieml.h b/lib/unieml.h index 213b142..a1b38f2 100644 --- a/lib/unieml.h +++ b/lib/unieml.h @@ -88,6 +88,9 @@ extern char **eml_getqfilelist(char **dnames,char *ext); //procedure to open a specific qfile extern FILE *eml_openqfile(char *qfilename,const char *ext); +//procedure to duplicate a specific qfile to another file +extern _Bool eml_dupqfile(char *qfilename,const char *dest); + //procedure to check email address format //of an email address extern RCPTYP *eml_isemailok(char *email,char **report); diff --git a/lib/uniprc.c b/lib/uniprc.c index 76ba303..830ad52 100644 --- a/lib/uniprc.c +++ b/lib/uniprc.c @@ -230,7 +230,7 @@ while (proceed==true) { } } else - (void) closedir(dir); + (void) closedir(dir); (void) free(fullname); break; case 2 : //setting lock filename