From: Jean-Marc Pigeon (Delson) Date: Sun, 18 May 2025 14:50:17 +0000 (-0400) Subject: Starting to implement rcpt Local/Remote dispatching X-Git-Tag: tag-0.8~101 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=280071b8b99ab8fbef284ae7beea4e2b0e682237;p=jmp%2Fmailleur Starting to implement rcpt Local/Remote dispatching --- diff --git a/data-feed/xxfeed.tst b/data-feed/xxfeed.tst index acbacc4..2dcf94f 100644 --- a/data-feed/xxfeed.tst +++ b/data-feed/xxfeed.tst @@ -1,17 +1,93 @@ #very simple test to feed SMTP server #==================================================== -T:Testing if MX is found +T:Very Simple email sending R:220 mailleur.example.com ESMTP (cleartext) emlrcvr... +C:ORGN 127.127.0.2 +R:220 mailleur.example.com ESMTP (cleartext) emlrcvr... +#C:WAIT 100 #==================================================== S:HELO example.com #R:250-mailleur.example.com, link (cleartext) ready, your IP/FQDN=[127.127.0.2/feed2.example.com] R:250-mailleur.example.com, link (cleartext) ready,... S:MAIL FROM: R:250 2.1.3 postmaster@example.com.. sender ok -S:RCPT TO: -R:563 5.6.3 No valid MX found for recipient domain name (rcpt=subdom0.example.com) S:RCPT TO: R:250 2.6.4 Address accepted +S:RCPT TO: +R:250 2.6.4 Address accepted +S:RCPT TO: +R:250 2.6.4 Address accepted +#------------------------------------------------------------------------- +#-sending data +C:DATA +Subject: Very Simple email contents + +FIRST Line +SECOND Line +LAST Line + +. +#------------------------------------------------------------------------- +R:250 3.5.3 Message accepted for delivery S:QUIT R:221 2.0.0 Bye, closing connection... #------------------------------------------------------------------------- +#prepare next test +#waiting 1 sec +C:WAIT 1 +#-restarting link +C:RESTART +R:220 mailleur.example.com ESMTP (cleartext) emlrcvr... +S:MAIL FROM: +R:250 2.1.3 webmaster@example.com.. sender ok +S:RCPT TO: +R:250 2.6.4 Address accepted +S:RCPT TO: +R:250 2.6.4 Address accepted +S:RCPT TO: +R:250 2.6.4 Address accepted +S:RCPT TO: +R:250 2.6.4 Address accepted +#------------------------------------------------------------------------- +#-sending data +C:DATA +Subject: Second email contents + +SECOND FIRST Line +SECOND SECOND Line +SECOND LAST Line + +. +#------------------------------------------------------------------------- +R:250 3.5.3 Message accepted for delivery +S:QUIT +#------------------------------------------------------------------------- +#prepare next test +#waiting 1 sec +C:WAIT 1 +#-restarting link +C:RESTART +R:220 mailleur.example.com ESMTP (cleartext) emlrcvr... +S:MAIL FROM: +R:250 2.1.3 noreply@example.com.. sender ok +S:RCPT TO: +R:250 2.6.4 Address accepted +S:RCPT TO: +R:250 2.6.4 Address accepted +S:RCPT TO: +R:250 2.6.4 Address accepted +S:RCPT TO: +R:250 2.6.4 Address accepted +#------------------------------------------------------------------------- +#-sending data +C:DATA +Subject: Third email contents + +THIRD FIRST Line +THIRD SECOND Line +THIRD LAST Line + +. +#------------------------------------------------------------------------- +R:250 3.5.3 Message accepted for delivery +S:QUIT diff --git a/lib/lvleml.c b/lib/lvleml.c index b000301..f1d1ac5 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -39,8 +39,7 @@ static CONTYP *freecontact(CONTYP *contact) if (contact!=(CONTYP *)0) { contact->sqlptr=sql_closesql(contact->sqlptr); contact->logptr=log_closelog(contact->logptr); - contact->rcptto=(char **)rou_freelist((void **)contact->rcptto, - (freehandler_t)rou_freestr); + contact->recipients=eml_freerecipients(contact->recipients); contact->mailfrom=rou_freestr(contact->mailfrom); contact->cursesid=rou_freestr(contact->cursesid); contact->mainsesid=rou_freestr(contact->mainsesid); @@ -514,7 +513,7 @@ while (proceed==true) { } break; case 4 : //Storing rcpt to - if (eml_addemail(&(contact->rcptto),rcptto)==false) { + if (eml_addrecipient(&(contact->recipients),'L',rcptto)==false) { detail="duplicate recipients will be consolidated"; } break; @@ -828,19 +827,26 @@ PUBLIC _Bool eml_mktransfile(CONTYP *contact,FILE *qfile) _Bool status; -if ((contact!=(CONTYP *)0)&&(contact->rcptto!=(char **)0)) { - char **ptr; - - ptr=contact->rcptto; - while (*ptr!=(char *)0) { - time_t isnow; - - status=true; - isnow=time((time_t *)0); - if (fprintf(qfile,"%c %ld %d %s %s %s\n", - 'R',isnow,0,contact->cursesid,contact->mailfrom,*ptr)<0) { +status=true; +if ((contact!=(CONTYP *)0)&&(contact->recipients!=(RCPTYP **)0)) { + RCPTYP **ptr; + time_t isnow; + + ptr=contact->recipients; + isnow=time((time_t *)0); + while (*ptr!=(RCPTYP *)0) { + char data[300]; + + (void) snprintf(data,sizeof(data),"%c %ld %d %s %s %s", + (*ptr)->code, + isnow, + 0, + contact->cursesid, + contact->mailfrom, + (*ptr)->rcpt); + if (fprintf(qfile,"%s\n",data)<0) { (void) rou_alert(0,"%s Unable to write transfile (error=<%s>)", - OPEP,strerror(errno)); + OPEP,strerror(errno)); status=false; } ptr++; diff --git a/lib/lvleml.h b/lib/lvleml.h index f1954db..bc49ba8 100644 --- a/lib/lvleml.h +++ b/lib/lvleml.h @@ -15,19 +15,19 @@ #include "gestcp.h" typedef struct { - SOCPTR *socptr; //established contact socket context - SQLPTR *sqlptr; //established contact database access - char *fqdn; //fully qualified domain from peer - char *locname; //socket local hostname - char *locserv; //local service port - char *peerip; //socket remote peer IP - char *peername; //socket remote peer FQDN - int numreset; //number of SMTP reset received - char *mainsesid;//session main ID - char *cursesid; //current session ID - char *mailfrom; //current mail from originator - char **rcptto; //List of mail recipient - LOGPTR *logptr; //reference to session log + SOCPTR *socptr; //established contact socket context + SQLPTR *sqlptr; //established contact database access + char *fqdn; //fully qualified domain from peer + char *locname; //socket local hostname + char *locserv; //local service port + char *peerip; //socket remote peer IP + char *peername; //socket remote peer FQDN + int numreset; //number of SMTP reset received + char *mainsesid; //session main ID + char *cursesid; //current session ID + char *mailfrom; //current mail from originator + RCPTYP **recipients; //List of email recipient + LOGPTR *logptr; //reference to session log }CONTYP; diff --git a/lib/unidns.c b/lib/unidns.c index f418859..c775fac 100644 --- a/lib/unidns.c +++ b/lib/unidns.c @@ -357,7 +357,6 @@ while (proceed==true) { } break; case 2 : //Requesting MX for domain - (void) rou_alert(0,"%s JMPDBG domain=<%s>",OPEP,domain); answer=myquery(domain,C_IN,T_MX,rsp.buf,sizeof(rsp.buf)); if (answer<=0) phase=999; //Trouble trouble to get MX diff --git a/lib/unieml.c b/lib/unieml.c index 8aeab4e..60a22b3 100644 --- a/lib/unieml.c +++ b/lib/unieml.c @@ -42,6 +42,70 @@ static VOCTYP vocsmtp[]={ */ /********************************************************/ /* */ +/* Procedure to free memory used by a list of */ +/* recipient. */ +/* */ +/********************************************************/ +PUBLIC RCPTYP **eml_freerecipients(RCPTYP **list) + +{ +if (list!=(RCPTYP **)0) { + RCPTYP **ptr; + + ptr=list; + while (*ptr!=(RCPTYP *)0) { + (*ptr)->rcpt=rou_freestr((*ptr)->rcpt); + (void) free(*ptr); + ptr++; + } + (void) free(list); + list=(RCPTYP **)0; + } +return list; +} +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to store an recipient information */ +/* within the contact list. */ +/* retuurn RCPTYP ** if successful, NULL otherwise.*/ +/* */ +/********************************************************/ +PUBLIC _Bool eml_addrecipient(RCPTYP ***list,char code,char *rcpt) + +{ +_Bool todo; + +todo=true; +if (*list!=(RCPTYP **)0) { + RCPTYP **ptr; + + ptr=*list; + while (*ptr!=(RCPTYP *)0) { + if (strcasecmp((*ptr)->rcpt,rcpt)==0) { + todo=false; + break; //already within list + } + ptr++; + } + } +if (todo==true) { + RCPTYP *neu; + + neu=(RCPTYP *)calloc(1,sizeof(RCPTYP)); + neu->code=code; + neu->rcpt=strdup(rcpt); + *list=(RCPTYP **)rou_addlist((void **)(*list),neu); + } +return todo; +} +/* +^L +*/ +/********************************************************/ +/* */ /* Procedure to format and return a dynamicaly */ /* allocated char array filled with uniq session ID*/ /* */ diff --git a/lib/unieml.h b/lib/unieml.h index a680f37..088464c 100644 --- a/lib/unieml.h +++ b/lib/unieml.h @@ -37,6 +37,17 @@ typedef enum { //list of SMTP protocol keyword c_unknown //key word unknown }CODTYP; +typedef struct { //*definition of recipient + char code; //'L' rcipient local, 'R' recipient remote + char *rcpt; //recipient email address + }RCPTYP; + +//procedure to Free a recipient list +extern RCPTYP **eml_freerecipients(RCPTYP **list); + +//procedure to add recipient to a recipient list +extern _Bool eml_addrecipient(RCPTYP ***list,char code,char *rcpt); + //get a session unique id extern char *eml_getmainsesid(); @@ -68,10 +79,6 @@ extern char **eml_getqfilelist(char **dnames,char *ext); //procedure to open a specific qfile extern FILE *eml_openqfile(char *qfilename); -//procedure to add an email address to a chain -//of email address -extern _Bool eml_addemail(char ***emails,char *email); - //procedure to check email address format //of an email address extern _Bool eml_isemailok(char *email,const char **domain,char **report);