]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Attachement is almost fully working
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 13 Jun 2025 19:21:51 +0000 (15:21 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 13 Jun 2025 19:21:51 +0000 (15:21 -0400)
lib/geseml.c
lib/unieml.c
lib/unieml.h

index 02829f1933ecf631c4e1cec9c63526204a2e4b7c..2ce1289872080c2b8b2e8782fc3d1b0f68359753 100644 (file)
@@ -509,7 +509,6 @@ if (list!=(TRATYP **)0) {
           char fname[200];
 
           (void) rou_alert(0,"%s JMPDBG need to remove <%s>",OPEP,(*ptr)->sessid);
-          (void) eml_deleteqfile((*ptr)->sessid);
           (void) snprintf(fname,sizeof(fname),"%s.%s",(*ptr)->sessid,EXTCNT);
           (void) eml_deleteqfile(fname);
           }
@@ -770,16 +769,76 @@ PUBLIC _Bool eml_do_warning(TRATYP *tra)
 #define OPEP    "geseml.c:eml_do_warning,"
 
 _Bool done;
+char *sessata;  //attachement session number
+FILE *qout;
+char orig[100];
+char cmt[200];
 int phase;
 _Bool proceed;
 
 done=false;
+sessata=eml_getmainsesid();
+(void) snprintf(orig,sizeof(orig),"%s@%s","noreply",getenv("DFLTDOMAIN"));
+qout=(FILE *)0;
 phase=0;
 proceed=true;
 while (proceed==true) {
   //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
   switch (phase) {
-    case 0      :       //check if email is FROM local or remote
+    case 0      :       //create the new attachement file
+      if ((qout=eml_createqfile(sessata,(char *)0))==(FILE *)0) {
+        (void) rou_alert(0,"%s Unable to create attachement file (system?)",
+                              OPEP);
+        phase=999;
+        }
+      break;
+    case 1      :       //Preparing attachement email
+      (void) fprintf(qout,"From: %s Email daemon <%s>\n",APPNAME,orig);
+      (void) fprintf(qout,"To: <%s>\n",tra->mailfrom);
+      (void) fprintf(qout,"Date: %s\n",rou_ascsysstamp(time((time_t *)0)));
+      (void) fprintf(qout,"Subject: %s\n",*(tra->resp)+4);
+      (void) fprintf(qout,"\n");
+      (void) fprintf(qout,"Bigre\n");
+      (void) fprintf(qout,"Bigre\n");
+      break;
+    case 2      :       //attaching email itself
+      done=eml_attache(qout,tra->sessid);
+      qout=eml_closeqfile(qout);
+      if (done==false) {
+        (void) rou_alert(0,"%s Unable to create attachement session (system?)",
+                              OPEP);
+        phase=999;
+        }
+      break;
+    case 3      :       //creating a count file for attachement file
+      if ((qout=eml_createqfile(sessata,EXTCNT))==(FILE *)0) {
+        (void) rou_alert(0,"%s Unable to open 'count' qfile <%s> (error=<%s>)",
+                            OPEP,sessata,strerror(errno));
+        (void) eml_deleteqfile(sessata);
+        done=false;
+        phase=999;
+        }
+      break;
+    case 4      :       //set number winthin sessata count file
+      (void) fprintf(qout,"1\n");
+      (void) eml_closeqfile(qout);
+      break;
+    case 5      :       //counting original session
+      switch (eml_countqfile(tra->sessid,-1)) {
+        case -1 :
+          (void) rou_alert(0,"%s Unable to count down sessid <%s>",
+                              OPEP,tra->sessid);
+          phase=999;
+          break;
+        case 0  :       //session file is not needed anymore
+          (void) snprintf(cmt,sizeof(cmt),"%s.%s",tra->sessid,EXTCNT);
+          (void) eml_deleteqfile(cmt);
+          break;
+        default :       //Nothing to do
+          break;
+        }
+      break;
+    case 6      :       //check if email is FROM local or remote
       char *domain;
       int status;
 
@@ -804,17 +863,16 @@ while (proceed==true) {
           break;                
         }
       break;
-    case 1      :       //reversing originator/recipient
-      char orig[100];
-
-      (void) snprintf(orig,sizeof(orig),"%s@%s","noreply",getenv("DFLTDOMAIN"));
+    case 7      :       //reversing originator/recipient
+      tra->delay=0;
+      tra->sessid=rou_freestr(tra->sessid);
+      tra->sessid=strdup(sessata);
       tra->rcptto=rou_freestr(tra->rcptto);
       tra->rcptto=tra->mailfrom;
       tra->mailfrom=strdup(orig);
-      tra->delay=0;
       done=true;
       break;
-    case 2      :       //building the new sessid file
+    case 8      :       //building the new sessid file
       tra->resp=(char **)rou_freelist((void **)tra->resp,(genfree_t)rou_freestr);
       break;
     default     :       //SAFE Guard
@@ -823,6 +881,7 @@ while (proceed==true) {
     }
   phase++;
   }
+sessata=rou_freestr(sessata);
 return done;
 
 #undef  OPEP
index 93a03b037a432cf1cf570ecd3a58933b92a731fa..16df7ef1be4a58349be42c6b4ff3a9bf0a417892 100644 (file)
@@ -698,6 +698,10 @@ while (proceed==true) {
         }
       (void) fclose(fcount);
       break;
+    case 5      :       //removing file count if result is zero
+      if (result==0)
+        (void) eml_deleteqfile(qfilename);
+      break;
     default     :       //SAFE Guard
       proceed=false;
       break;
@@ -807,3 +811,20 @@ while (proceed==true) {
 return info;
 #undef  OPEP
 }
+/*
+^L
+*/
+/********************************************************/
+/*                                                      */
+/*     Procedure to attach a part of text to a file    */
+/*      acceptable.                                     */
+/*                                                      */
+/********************************************************/
+PUBLIC int eml_attache(FILE *fout,char *toaddfile)
+
+{
+int success;
+
+success=true;
+return success;
+}
index 2fe17f3bddcd69bcf3ec5d66f2070fc4a81ccda9..3a3c46423721268b0cb338996fcc1e35b8d60785 100644 (file)
@@ -112,4 +112,7 @@ extern int eml_countqfile(char *qfilename,int count);
 //of an email address
 extern RCPTYP *eml_isemailok(char *email,char **report);
 
+//procedure to create an attachement for email data part.
+extern int eml_attache(FILE *fout,char *toaddfile);
+
 #endif