]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Starting to implement session_id trans file.
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Thu, 8 May 2025 11:19:15 +0000 (07:19 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Thu, 8 May 2025 11:19:15 +0000 (07:19 -0400)
lib/lvleml.c
lib/unieml.c
lib/unieml.h

index 34c31e84959e35f9ea4052b48db549affd6a7593..becf33ef4032e7e79998a14e167bab2c9c830cb3 100644 (file)
@@ -168,6 +168,54 @@ return done;
 */
 /************************************************/
 /*                                             */
+/*     Procedure to set RCPT directive to      */
+/*      forward email to SMTP peers.            */
+/*                                             */
+/************************************************/
+static _Bool setdirectives(CONTYP *contact,char *ext)
+
+{
+#define        OPEP    "lvleml.c:setdirectives,"
+
+_Bool status;
+FILE *trans;
+int phase;
+_Bool proceed;
+
+status=false;
+trans=(FILE *)0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+  //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
+  switch (phase) {
+    case 0      :       //Creating the file
+      if ((trans=eml_createqfile(contact->cursesid,ext))==(FILE *)0) 
+        phase=999;      //trouble trouble
+      break;
+    case 1      :       //write data to trans file;
+      break;
+    case 2      :       //closing transfile
+      if (eml_closeqfile(trans)<0)
+        phase=999;              //Trouble trouble
+      break;
+    case 3      :       //everythin fine
+      status=true;
+      break;
+    default     :       //SAFE guard
+      proceed=false;
+      break;
+    }
+  phase++;
+  }
+#undef  OPEP
+return status;
+}
+/*
+\f
+*/
+/************************************************/
+/*                                             */
 /*     Procedure to accept EMAIL contents from */
 /*      SMTP peers.                             */
 /*     Return true, if everything is fine      */
@@ -192,12 +240,12 @@ empty=false;
 queue=(FILE *)0;
 got=0;
 phase=0;
-proceed=true;
+proceed=setdirectives(contact,"tmp");
 while (proceed==true) {
   //(void) rou_alert(0,"JMPDBG %s phase='%d' empty='%d'",OPEP,phase,empty);
   switch (phase) {
     case 0      :       //opening the queue email
-      if ((queue=eml_opennewqueue(contact->cursesid))==(FILE *)0) 
+      if ((queue=eml_createqfile(contact->cursesid,""))==(FILE *)0) 
         phase=999;      //trouble trouble
       break;
     case 1      :       //Do we have a parameter
@@ -219,9 +267,14 @@ while (proceed==true) {
       line=rou_freestr(line);
       break;
     case 4      :       //got all data
-      if (eml_closenewqueue(queue)<0)
+      if (eml_closeqfile(queue)<0)
+        phase=999;              //Trouble trouble
+      break;
+    case 5      :       //renameing directive
+      if (eml_renameqfile(contact->cursesid,"tmp","trans")==false)
         phase=999;              //Trouble trouble
-    case 5      :       //everything fine
+      break;
+    case 6      :       //everything fine
       (void) transmit(contact,"%d 3.5.3 %s",
                               CMDOK,"Message accepted for delivery");
       done=true;
index 4f3a7ee6cb0c12dec182cf83e86b161f734295cf..f7f2d30623fd77444ff76a795e28db41560cb927 100644 (file)
@@ -6,6 +6,7 @@
 /*                                                     */
 /********************************************************/
 #include        <errno.h>
+#include        <fcntl.h>
 #include        <stdbool.h>
 #include        <stdio.h>
 #include        <stdlib.h>
@@ -153,21 +154,55 @@ return done;
 */
 /********************************************************/
 /*                                                      */
-/*     Procedure to open a file to store the email in  */
-/*      within the spool queue.                         */
+/*     Procedure to change qfile extension             */
+/*      directory.                                      */
 /*                                                      */
 /********************************************************/
-PUBLIC FILE *eml_opennewqueue(char *sessionid)
+PUBLIC _Bool eml_renameqfile(char *qfilename,char *oldext,char *newext)
 
 {
-#define OPEP    "unieml.c:eml_opennewqueue,"
+#define OPEP    "unieml.c:eml_renameqfile,"
 
-FILE *newqueue;
+_Bool status;
+char *filename;
+char fold[300];
+char fnew[300];
+
+status=true;
+filename=rou_apppath(QDIR);
+(void) snprintf(fold,sizeof(fold),"%s/%s.%s",filename,qfilename,oldext);
+(void) snprintf(fnew,sizeof(fnew),"%s/%s.%s",filename,qfilename,newext);
+if (rename(fold,fnew)<0) {
+  (void) rou_alert(0,"%s Unable to rename file <%s>  to <%s> (error=<%s>)",
+                           OPEP,fold,fnew,strerror(errno));
+  status=false;
+  }
+filename=rou_freestr(filename);
+return status;
+#undef  OPEP
+}
+/*
+^L
+*/
+/********************************************************/
+/*                                                      */
+/*     Procedure to open a file within the queue       */
+/*      directory.                                      */
+/*                                                      */
+/********************************************************/
+PUBLIC FILE *eml_createqfile(char *qfilename,char *ext)
+
+{
+#define OPEP    "unieml.c:eml_createqfile,"
+
+FILE *qfile;
+int handle;
 char *filename;
 int phase;
 int proceed;
 
-newqueue=(FILE *)0;
+qfile=(FILE *)0;
+handle=-1;
 filename=(char *)0;
 phase=0;
 proceed=true;
@@ -175,29 +210,43 @@ 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)) {
+      if ((qfilename==(char *)0)||(strlen(qfilename)==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);
+      filename=(char *)realloc(filename,strlen(filename)+strlen(qfilename)+10);
       (void) strcat(filename,"/");
-      (void) strcat(filename,sessionid);
-      if ((newqueue=fopen(filename,"w"))==(FILE *)0) {
+      (void) strcat(filename,qfilename);
+      if ((ext!=(char *)0)&&(strlen(ext)>0)) {
+        filename=(char *)realloc(filename,strlen(filename)+strlen(ext)+10);
+        (void) strcat(filename,".");
+        (void) strcat(filename,ext);
+        }
+      break;
+    case 2      :       //creating and opening the file
+      if ((handle=open(filename,O_EXCL|O_CREAT|O_WRONLY|O_TRUNC,0640))<0) {
         (void) rou_alert(0,"%s Unable to open file <%s> (error=<%s>)",
                            OPEP,filename,strerror(errno));
+        phase=999;      //Trouble trouble
+        }
+      break;
+    case 3      :       //convert handle to FILE *
+      if ((qfile=fdopen(handle,"w"))==(FILE *)0) {
+        (void) rou_alert(0,"%s Unable to fdopen file <%s> (error=<%s>)",
+                           OPEP,filename,strerror(errno));
         }
-      filename=rou_freestr(filename);
       break;
     default     :       //SAFE guard
+      filename=rou_freestr(filename);
       proceed=false;
       break;
     }
   phase++;
   }
-return newqueue;
+return qfile;
 #undef  OPEP
 }
 /*
@@ -209,14 +258,14 @@ return newqueue;
 /*      stored within queue.                            */
 /*                                                      */
 /********************************************************/
-PUBLIC int eml_closenewqueue(FILE *newqueue)
+PUBLIC int eml_closeqfile(FILE *qfile)
 
 {
-#define OPEP    "unieml.c:eml_closenewqueue,"
+#define OPEP    "unieml.c:eml_closeqfile,"
 int status;
 
-if ((status=fclose(newqueue))<0) {
-  (void) rou_alert(0,"%s Unable to close queuefile (error=<%s>)",
+if ((status=fclose(qfile))<0) {
+  (void) rou_alert(0,"%s Unable to close qfile (error=<%s>)",
                            OPEP,strerror(errno));
   }
 return status;
index fb8e93ab1df9fc7647506c209f335c786ece1723..6b4015138d30cad8219cccad041eec5c714e47a8 100644 (file)
@@ -47,10 +47,13 @@ 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 change qfile extension
+extern _Bool eml_renameqfile(char *qfilename,char *oldext,char *newext);
 
-//procedure to open a queue file
-extern int eml_closenewqueue(FILE *queue);
+//procedure to open a file within queue directory
+extern FILE *eml_createqfile(char *qfilename,char *ext);
+
+//procedure to close a file within the queue directory
+extern int eml_closeqfile(FILE *qfile);
 
 #endif