From 08fff18eecfb9eb2b22caba8fd8fb27ee2ffba9d Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Wed, 7 May 2025 18:38:26 -0400 Subject: [PATCH] Stating to implemented email queing process --- Makefile | 1 + lib/subrou.h | 3 +++ lib/unieml.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++- lib/unieml.h | 8 ++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index cdc7548..c31db87 100644 --- a/Makefile +++ b/Makefile @@ -229,6 +229,7 @@ DATA = chkaddr.spf.example.com 127.0.1.255 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)/usr @ cp -a \ bin \ diff --git a/lib/subrou.h b/lib/subrou.h index a647e8f..81b2d4f 100644 --- a/lib/subrou.h +++ b/lib/subrou.h @@ -77,6 +77,9 @@ extern char *rou_setappname(const char *newname); //to compute an application path with the root directory extern char *rou_apppath(const char *path); +//to compute an application path with the root directory +extern char *rou_apppath(const char *path); + //to display message on console (verbose mode) or //via syslog (LOG_INFO) using variable argument list macros void rou_valert(const int dlevel,const char *fmt,va_list ap); diff --git a/lib/unieml.c b/lib/unieml.c index 96ad03b..68d5868 100644 --- a/lib/unieml.c +++ b/lib/unieml.c @@ -5,14 +5,18 @@ /* exchange. */ /* */ /********************************************************/ +#include #include #include +#include #include #include #include "subrou.h" #include "unieml.h" +#define QDIR "/var/spool/"APPNAME"/queue" + typedef struct { CODTYP code; //keyword code const char *key; //keyword itself @@ -112,7 +116,6 @@ for (ptr=vocsmtp;ptr->key!=(char *)0;ptr++) { return code; #undef OPEP } - /* ^L */ @@ -145,4 +148,52 @@ if (string!=(char *)0) { } return done; } +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to open a file to store the email in */ +/* within the spool queue. */ +/* */ +/********************************************************/ +PUBLIC FILE *eml_opennewqueue(char *sessionid) +{ +#define OPEP "unieml.c:eml_opennewqueue," + +FILE *fichier; +char *filename; +int phase; +int proceed; + +fichier=(FILE *)0; +filename=(char *)0; +phase=0; +proceed=true; +while (proceed==true) { + //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase); + switch (phase) { + case 0 : //Do we have a session ID + if ((sessionid=(char *)0)||(strlen(sessionid)==0)) { + (void) rou_core_dump("%s sessionID is not set (bug?)",OPEP); + phase=999; //never reached + } + break; + case 1 : //"Computing" the file new queue filename + filename=rou_apppath(QDIR); + filename=(char *)realloc(filename,strlen(filename)+strlen(sessionid)+10); + if ((fichier=fopen(filename,"w"))==(FILE *)0) { + (void) rou_alert(0,"%s Unable to open file <%s> (error=<%s>)", + OPEP,filename,strerror(errno)); + } + filename=rou_freestr(filename); + break; + default : //SAFE guard + proceed=false; + break; + } + phase++; + } +return fichier; +} diff --git a/lib/unieml.h b/lib/unieml.h index 124e61d..29d20e4 100644 --- a/lib/unieml.h +++ b/lib/unieml.h @@ -8,6 +8,8 @@ #ifndef UNIEML #define UNIEML +#include + #define MXMSIZE 52428800 //52 Megabytes #define CRLF "\r\n" //EOL within SMTP protocol #define SIGNON 220 //signon information @@ -44,4 +46,10 @@ extern CODTYP eml_getcode(char *keyword); //remove CRLF from string extern int eml_removecrlf(char *string); +//procedure to open a queue file +extern FILE *eml_opennewqueue(char *sessid); + +//procedure to open a queue file +extern int eml_closenewqueue(FILE *queue); + #endif -- 2.47.3