]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Session sql entry seems to be working fine
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 29 Jun 2025 14:08:28 +0000 (10:08 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 29 Jun 2025 14:08:28 +0000 (10:08 -0400)
lib/Makefile
lib/devsql.c
lib/geseml.c
lib/geseml.h
lib/lvleml.c
lib/unieml.h
lib/unisql.c
lib/unisql.h
sql/mailleur.sql

index e0f8e0038683a388c01674c73450107d8e4641c3..143d38699656937c220a0fb966828006053d4877 100644 (file)
@@ -121,6 +121,9 @@ lvleml.h:                                   \
           devsoc.h devsql.h                    \
           geseml.h gestcp.h
 
+geseml.h:                                      \
+          unisql.h
+
 gestcp.h:                                      \
           subrou.h                             \
           unidns.h                             \
index 9853ad50605af6bafe3e08f73ed457b8a59d715a..32d3e47ce90a2b8d9100830feb2c6cf1d2265e30 100644 (file)
@@ -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)
index 624471f5fb04f4b8b0c405606cd9172baeb6ed35..cb184ff38e5d341e243550bb77827390cd086355 100644 (file)
@@ -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
+}
index df3206ec620d9d8d0fc1d37e4ae56d3dfaca8462..88aa42b9b792bdd48f8f1859131ccc98d4faaad0 100644 (file)
@@ -12,6 +12,8 @@
 #include        <stdio.h>
 #include        <time.h>
 
+#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
index 0aca99ce00f084c02956b713bbd1df41322fc333..a25fa07362f891950fe074312c7c74542d1a471b 100644 (file)
@@ -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;
index 962240d1cb6d875f5039c110cd0d43be9ceec6bd..96180b30e9e7b90f41e8fdf47d02d4109c928b87 100644 (file)
@@ -10,7 +10,8 @@
 
 #include        <stdio.h>
 
-#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
index 217c826ad69ff9971c08c52d35649486994357ef..e3796ce9d55116b74cd80726415bed85c78d51ca 100644 (file)
@@ -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);
index 67400d75105f3e1310de9568b608cd5aee6c39e1..ba874e66255db1b428f6d07dade8e4bf8c725a71 100644 (file)
@@ -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;
 
index de7edb34f0a07abbcd72f7bedc672f5d7237595a..130693d2c8f1503a1a7984c650ed9f4b74991eb2 100644 (file)
@@ -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;