]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Starting to store email in recipient directory
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 19 May 2025 20:30:11 +0000 (16:30 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 19 May 2025 20:30:11 +0000 (16:30 -0400)
Makefile
Notes
app/sender.c
conf/mailleur.conf.dvl
lib/geseml.c
lib/geseml.h
lib/unieml.c
lib/unieml.h
lib/uniprc.c

index 78805e3210f70a44a1a49e8544d09c9ee423c9a5..761110567b780f12bdab10269f9240a39b757084 100644 (file)
--- 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 76e99535a1042119f9e7ca2c8beb06b5a5cb365c..021cfd34080f086b340f8607d899967c7786eaaa 100644 (file)
--- 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
 #-----------------------------------------------------------
index d0404d041b306a641618975f6f0ab2d8146db4bf..663d9010baee7332788704ee49934c0d2d57efda 100644 (file)
@@ -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);
index 99f80ab6a1407378d3781695f624f09400c3f3de..9fbc63d1f36ce4d528e1c8973056026e0f869ed9 100644 (file)
@@ -13,3 +13,6 @@ DB_NAME               =       mailleur
 DB_HOST                =       localhost
 DB_PORT                =       5432
 #------------------------------------------------
+#Dovecot storage directory
+DOV_MAILDIR    =       "/var/spool/mailleur/mails"
+#------------------------------------------------
index 2cf65dee8f27538ba0bdaa25a93dd23232a879e4..c307fc5d859bf84388c4ec03027ab73591ea7aea 100644 (file)
@@ -5,12 +5,16 @@
 /*     exchange.                                       */
 /*                                                     */
 /********************************************************/
+#include        <dirent.h>
 #include        <string.h>
 
 #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
 }
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*      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
+}
index 06fb58ec0db71f88b408a44d78d5dbb2a8c03f7a..7b732382238de57c210b9023f35ccf97ac53c3ab 100644 (file)
@@ -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
index 17dfbc2d2a57dd9b71ced48cf56c5fe5e4896ff3..40ab120669e8b2cb2c282820529c1ff01bbff5ef 100644 (file)
@@ -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.                                     */
 /*                                                      */
index 213b142469466874e988c6954b6f1a40e3b00068..a1b38f29ae44e68471eeb85cb34b6fcd02e9458c 100644 (file)
@@ -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);
index 76ba303463b7640d80731d8178eaaebfdd7e64df..830ad523ed5deb7980dc803a14c30b59f720580d 100644 (file)
@@ -230,7 +230,7 @@ while (proceed==true) {
           }
         }
       else
-      (void) closedir(dir);
+        (void) closedir(dir);
       (void) free(fullname);
       break;
     case 2     :       //setting lock filename