From d216c7c576cbdfbe13e42a5d98792ca43062fa28 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Fri, 13 Jun 2025 16:44:48 -0400 Subject: [PATCH] attachement almost working --- lib/geseml.c | 4 +-- lib/unieml.c | 96 +++++++++++++++++++++++++++++++++++++--------------- lib/unieml.h | 2 +- 3 files changed, 72 insertions(+), 30 deletions(-) diff --git a/lib/geseml.c b/lib/geseml.c index c5c192f..cd4b3b9 100644 --- a/lib/geseml.c +++ b/lib/geseml.c @@ -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?)", diff --git a/lib/unieml.c b/lib/unieml.c index 4bccd24..4bad24e 100644 --- a/lib/unieml.c +++ b/lib/unieml.c @@ -14,6 +14,7 @@ #include #include #include +#include #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 diff --git a/lib/unieml.h b/lib/unieml.h index eaf2331..8259b11 100644 --- a/lib/unieml.h +++ b/lib/unieml.h @@ -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 -- 2.47.3