From: Jean-Marc Pigeon (Delson) Date: Sun, 29 Jun 2025 14:08:28 +0000 (-0400) Subject: Session sql entry seems to be working fine X-Git-Tag: tag-0.11~20 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=2e0d557f83911bde62663d45ff723e1e5574091a;p=jmp%2Fmailleur Session sql entry seems to be working fine --- diff --git a/lib/Makefile b/lib/Makefile index e0f8e00..143d386 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -121,6 +121,9 @@ lvleml.h: \ devsoc.h devsql.h \ geseml.h gestcp.h +geseml.h: \ + unisql.h + gestcp.h: \ subrou.h \ unidns.h \ diff --git a/lib/devsql.c b/lib/devsql.c index 9853ad5..32d3e47 100644 --- a/lib/devsql.c +++ b/lib/devsql.c @@ -48,9 +48,11 @@ const char *usrfield[]={ //field available in table "sessions" const char *sesfield[]={ "sessid", + "sesstitle", "sessfrom", "emailfrom", "taille", + "duration", (char *)0 }; @@ -402,12 +404,7 @@ static _Bool insert_ses(SQLTYP *sql,char *seskey,SESTYP **ses) #define OPEP "devseql.c:insert_ses," #define INSSES "INSERT INTO "SESSIONS" (sessid) VALUES(%s)" -_Bool isok; - -isok=true; -(void) rou_alert(0,"%s JMPDBG Inserting session <%s>",OPEP,seskey); -isok=(sqlrequest(sql,INSSES,seskey)==1); -return isok; +return (sqlrequest(sql,INSSES,seskey)==1); #undef INSSES #undef OPEP @@ -440,15 +437,21 @@ for (int i=0;(isok==true)&&(sesfield[i]!=(char *)0);i++) { switch (i) { case 0 : //session ID break; //nothing to do - case 1 : //sfrom + case 1 : //title + data=sql_gooddata(sql,(*ses)->title); + break; //nothing to do + case 2 : //sfrom data=sql_gooddata(sql,(*ses)->sfrom); break; //nothing to do - case 2 : //efrom - data=sql_gooddata(sql,(*ses)->efrom); + case 3 : //efrom + data=sql_gooddata(sql,(*ses)->hfrom); break; - case 3 : //taille + case 4 : //taille (void) rou_asprintf(&data,"%lu",(*ses)->taille); break; + case 5 : //duration + data=sql_gooddata(sql,(*ses)->duration); + break; default : isok=false; (void) rou_alert(0,"%s Unexpected field <%s> (Bug?)",OPEP,sesfield[i]); @@ -463,9 +466,9 @@ for (int i=0;(isok==true)&&(sesfield[i]!=(char *)0);i++) { if (strlen(cmtset)>0) sep=","; (void) rou_asprintf(&newset,"%s%s%s=%s",cmtset,sep,sesfield[i],data); - data=rou_freestr(data); cmtset=rou_freestr(cmtset); cmtset=newset; + data=rou_freestr(data); } } if (isok==true) diff --git a/lib/geseml.c b/lib/geseml.c index 624471f..cb184ff 100644 --- a/lib/geseml.c +++ b/lib/geseml.c @@ -830,10 +830,10 @@ while (proceed==true) { } break; case 1 : //Preparing attachement email - (void) fprintf(qout,"%s%s Email daemon <%s>\n",EFROM,APPNAME,orig); + (void) fprintf(qout,"%s%s Email daemon <%s>\n",HFROM,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,"%s%s\n",HTITLE,*(tra->resp)+4); break; case 2 : //attaching (200 line at most) from email itself done=eml_attache(qout,tra->sessid,tra->resp,200); @@ -920,3 +920,50 @@ return done; #undef OPEP } +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to check email header and extract */ +/* session data. */ +/* Return true if data was extracted. */ +/* */ +/********************************************************/ +PUBLIC _Bool eml_scan_headerline(SESTYP *session,const char *line) + +{ +#define OPEP "geseml.c:eml_scan_headerline," +_Bool extracted; + +const char *look[]={HFROM,HTITLE,(char *)0}; + +extracted=false; +if ((line!=(char *)0)&&(strlen(line)>0)) { + for (int i=0;(extracted==false)&&(look[i]!=(char *)0);i++) { + int max; + + max=strlen(look[i]); + if (strncasecmp(line,look[i],max)==0) { + extracted=true; + switch (i) { + case 0 : //Inserting the header from in session + session->hfrom=rou_freestr(session->hfrom); + session->hfrom=strdup(line+max); + break; + case 1 : //Inserting the header from in session + session->title=rou_freestr(session->title); + session->title=strdup(line+max); + break; + default : + (void) rou_alert(0,"%s Code missing for Head entrey <%s> (Bug?!)", + OPEP,look[i]); + break; + } + } + } + } +return extracted; + +#undef OPEP +} diff --git a/lib/geseml.h b/lib/geseml.h index df3206e..88aa42b 100644 --- a/lib/geseml.h +++ b/lib/geseml.h @@ -12,6 +12,8 @@ #include #include +#include "unisql.h" + //structure to define an email transport directive typedef struct { char code; //Transaction code @@ -66,4 +68,7 @@ extern _Bool eml_sort_list(TRATYP **List); //procedure to build a warning/reply from the transfer record extern _Bool eml_do_warning(TRATYP *tra); +//procedure to scan on line from email header +extern _Bool eml_scan_headerline(SESTYP *session,const char *line); + #endif diff --git a/lib/lvleml.c b/lib/lvleml.c index 0aca99c..a25fa07 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -605,17 +605,9 @@ while (proceed==true) { } total+=got; if (inheader==true) { + (void) eml_scan_headerline(contact->session,line); if (strlen(line)==0) inheader=false; - else { //extracting the sfrom - int max; - - max=strlen(EFROM); - if (strncasecmp(line,EFROM,max)==0) { - contact->session->efrom=rou_freestr(contact->session->efrom); - contact->session->efrom=strdup(line+max); - } - } } if (strcmp(line,".")==0) { completed=true; @@ -644,14 +636,17 @@ while (proceed==true) { case 8 : //everything fine const char *fmt; unsigned int delta; + char duration[40]; total+=1023; total/=1024; //KBytes delta=rou_getdifftime(&start); + (void) snprintf(duration,sizeof(duration),"%d.%03d",delta/1000,delta%1000); + contact->session->duration=strdup(duration);; fmt="%d-3.5.3 Session ID=<%s>"; (void) transmit(contact,false,fmt,CMDOK,contact->session->sessid); - fmt="%d-3.5.3 data stream received: %d Kbytes within %d.%03d seconds)"; - (void) transmit(contact,false,fmt,CMDOK,total,delta/1000,delta%1000); + fmt="%d-3.5.3 data stream received: %d Kbytes within %s seconds)"; + (void) transmit(contact,false,fmt,CMDOK,total,duration); fmt="%d 3.5.3 Message accepted for delivery"; (void) transmit(contact,true,fmt,CMDOK,contact->session->sessid); done=true; diff --git a/lib/unieml.h b/lib/unieml.h index 962240d..96180b3 100644 --- a/lib/unieml.h +++ b/lib/unieml.h @@ -10,7 +10,8 @@ #include -#define EFROM "From: " //Then email header from +#define HFROM "From: " //Then email header header from +#define HTITLE "Subject: " //Then email subject entry #define MXMSIZE 52428800 //52 Megabytes #define CRLF "\r\n" //EOL within SMTP protocol diff --git a/lib/unisql.c b/lib/unisql.c index 217c826..e3796ce 100644 --- a/lib/unisql.c +++ b/lib/unisql.c @@ -126,7 +126,8 @@ PUBLIC SESTYP *sql_freeses(SESTYP *ses) { if (ses!=(SESTYP *)0) { - ses->efrom=rou_freestr(ses->efrom); + ses->duration=rou_freestr(ses->duration); + ses->hfrom=rou_freestr(ses->hfrom); ses->sfrom=rou_freestr(ses->sfrom); ses->sessid=rou_freestr(ses->sessid); (void) free(ses); diff --git a/lib/unisql.h b/lib/unisql.h index 67400d7..ba874e6 100644 --- a/lib/unisql.h +++ b/lib/unisql.h @@ -31,8 +31,10 @@ typedef struct { //with a remote server typedef struct { char *sessid; //session id + char *title; //the email title char *sfrom; //the "mail from" comming from SMTP exchange - char *efrom; //the "mail from" as within the email itself + char *hfrom; //the "mail from" as within the email header + char *duration; //Session duration un millisec u_long taille; //Email size }SESTYP; diff --git a/sql/mailleur.sql b/sql/mailleur.sql index de7edb3..130693d 100644 --- a/sql/mailleur.sql +++ b/sql/mailleur.sql @@ -67,9 +67,12 @@ GRANT SELECT ON emails TO maildove; //table about session CREATE TABLE sessions ( sessid TEXTUNIQUE, //Session id + sesstitle TEXT, //The session email title sessfrom TEXT, //The session from emailfrom TEXT, //The from within the email itself taille INTEGER //The email size - DFLT 0 + DFLT 0, + duration TEXT //email transfer duration + DFLT 'NULL' ); GRANT SELECT ON sessions TO mailapache;