]> SAFE projects GIT repository - jmp/mailleur/commitdiff
attachement almost working
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 13 Jun 2025 20:44:48 +0000 (16:44 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 13 Jun 2025 20:44:48 +0000 (16:44 -0400)
lib/geseml.c
lib/unieml.c
lib/unieml.h

index c5c192f9adbcb1f2031065080c4fb302e0e99186..cd4b3b9616e2093d29a0407aab542bb8429881ff 100644 (file)
@@ -798,8 +798,8 @@ while (proceed==true) {
       (void) fprintf(qout,"Date: %s\n",rou_ascsysstamp(time((time_t *)0)));
       (void) fprintf(qout,"Subject: %s\n",*(tra->resp)+4);
       break;
-    case 2      :       //attaching email itself
-      done=eml_attache(qout,tra->sessid);
+    case 2      :       //attaching (200 line at most) from email itself
+      done=eml_attache(qout,tra->sessid,200);
       qout=eml_closeqfile(qout);
       if (done==false) {
         (void) rou_alert(0,"%s Unable to create attachement session (system?)",
index 4bccd247a1e15300fe3d83db1bdf4cc1e2d340fd..4bad24ef4caac2d539e0a76a2407d47398b4a48f 100644 (file)
@@ -14,6 +14,7 @@
 #include        <stdlib.h>
 #include        <string.h>
 #include        <unistd.h>
+#include        <uuid/uuid.h>
 
 #include       "subrou.h"
 #include       "unieml.h"
@@ -820,7 +821,7 @@ return info;
 /*      acceptable.                                     */
 /*                                                      */
 /********************************************************/
-PUBLIC int eml_attache(FILE *qout,char *toaddfile)
+PUBLIC int eml_attache(FILE *qout,char *toaddfile,int nbrlines)
 
 {
 #define OPEP    "unieml.c:eml_attache,"
@@ -828,32 +829,73 @@ PUBLIC int eml_attache(FILE *qout,char *toaddfile)
 
 
 int success;
-char *marker;
-
-success=true;
-marker="ABC123";
-//starting part
-(void) fprintf(qout,"MIME-Version: 1.0\n");
-(void) fprintf(qout,"%sType: multipart/mixed; boundary=\"%s\"\n",CNT,marker);
-(void) fprintf(qout,"\nThis is a multi-part message in MIME format.\n\n");
-(void) fprintf(qout,"--%s\n",marker);
-(void) fprintf(qout,"%sType: text/plain; charset=\"iso-8859-1\"\n",CNT);
-(void) fprintf(qout,"%sTransfer-Encoding: 8bit\n\n",CNT);
-
-//explain part
-(void) fprintf(qout,"No comment\n");
-
-//Middle part
-(void) fprintf(qout,"--%s%s",marker,CRLF);
-(void) fprintf(qout,"%sType: message/rfc822;\n\tname=\"%s\"\n",CNT,"ABC");
-(void) fprintf(qout,"%sTransfer-Encoding: 8bit\n",CNT);
-(void) fprintf(qout,"%sDisposition: attachment;\n\tfilename=\"%s\"\n\n",CNT,"ABC");
-
-//corps part
-(void) fprintf(qout,"This is the corps\n");
-
-//end part
-(void) fprintf(qout,"\n--%s--\n\n",marker);
+FILE *qfile;
+uuid_t id;
+char marker[40];
+int phase;
+_Bool proceed;
+
+success=false;
+qfile=(FILE *)0;
+(void) uuid_generate(id);
+(void) uuid_unparse(id,marker);
+phase=0;
+proceed=true;
+while (proceed==true) {
+  (void) rou_alert(0,"%s JMPDBG phase='%d'",OPEP,phase);
+  switch (phase) {
+    case 0      :       //Open the file
+      if ((qfile=eml_openqfile(toaddfile,(char *)0))==(FILE *)0) {
+        (void) rou_alert(0,"%s unable to open file <%s> to be attached",
+                           OPEP,toaddfile);
+        phase=999;      //No need to go further
+        }
+      break;
+    case 1      :       //mime starting part
+      (void) fprintf(qout,"MIME-Version: 1.0\n");
+      (void) fprintf(qout,"%sType: multipart/mixed; boundary=\"%s\"\n",CNT,marker);
+      (void) fprintf(qout,"\nThis is a multi-part message in MIME format.\n\n");
+      (void) fprintf(qout,"--%s\n",marker);
+      (void) fprintf(qout,"%sType: text/plain; charset=\"iso-8859-1\"\n",CNT);
+      (void) fprintf(qout,"%sTransfer-Encoding: 8bit\n\n",CNT);
+      break;
+    case 2      :       //mime starting part
+      (void) fprintf(qout,"Sending Email was not successful\n");
+      break;
+    case 3      :       //mime starting part
+      (void) fprintf(qout,"--%s%s",marker,CRLF);
+      (void) fprintf(qout,"%sType: message/rfc822;\n\tname=\"%s\"\n",
+                          CNT,toaddfile);
+      (void) fprintf(qout,"%sTransfer-Encoding: 8bit\n",CNT);
+      (void) fprintf(qout,"%sDisposition: attachment;\n\tfilename=\"%s\"\n\n",
+                          CNT,toaddfile);
+      break;
+    case 4      :       //appending addfile
+      _Bool count;      //reading at most nbrlines
+      char line[300]; 
+
+      count=false;
+      while (fgets(line,sizeof(line),qfile)!=(char *)0) {
+        if (count==true) 
+          nbrlines--;
+        (void) fprintf(qout,"%s",line);
+        if (strlen(line)<1)
+          count=true;
+        if (nbrlines==0)
+          break;
+        }
+      break;
+    case 5      :       //end attachement marker
+      (void) fprintf(qout,"\n--%s--\n\n",marker);
+      qfile=eml_closeqfile(qfile);
+      success=true;
+      break;
+    default     :       //SAFE Guard
+      proceed=false;
+      break;
+    }
+  phase++;
+  }
 return success;
 
 #undef  CNT
index eaf2331162fa20cf19acaf217254aa1e7cd69616..8259b11f3acbdab7a99f87c9291251912eeb0597 100644 (file)
@@ -113,6 +113,6 @@ extern int eml_countqfile(char *qfilename,int count);
 extern RCPTYP *eml_isemailok(char *email,char **report);
 
 //procedure to create an attachement for email data part.
-extern int eml_attache(FILE *qout,char *toaddfile);
+extern int eml_attache(FILE *qout,char *toaddfile,int nbrlines);
 
 #endif