#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <uuid/uuid.h>
#include "subrou.h"
#include "unieml.h"
/* 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,"
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