From: Jean-Marc Pigeon (Delson) Date: Sun, 18 May 2025 19:25:42 +0000 (-0400) Subject: Improving domain local/remote detection X-Git-Tag: tag-0.8~100 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=409beb552454c9f95ef9d5a4a113ba39293ee78c;p=jmp%2Fmailleur Improving domain local/remote detection --- diff --git a/app/sender.c b/app/sender.c index 6a54954..25a015a 100644 --- a/app/sender.c +++ b/app/sender.c @@ -65,7 +65,7 @@ while (proceed==true) { } ptr++; } - fname=(char **)rou_freelist((void *)fname,(freehandler_t)rou_freestr); + fname=(char **)rou_freelist((void *)fname,(genfree_t)rou_freestr); } break; case 2 : //scanning translit @@ -74,7 +74,7 @@ while (proceed==true) { ptr=trans; (void) eml_todoqfile(ptr); - trans=(TRATYP **)rou_freelist((void **)trans,(freehandler_t)eml_freetra); + trans=(TRATYP **)rou_freelist((void **)trans,(genfree_t)eml_freetra); status=true; } break; diff --git a/app/sorter.c b/app/sorter.c index f1aead5..ff427f4 100644 --- a/app/sorter.c +++ b/app/sorter.c @@ -64,7 +64,7 @@ while (proceed==true) { } ptr++; } - fname=(char **)rou_freelist((void *)fname,(freehandler_t)rou_freestr); + fname=(char **)rou_freelist((void *)fname,(genfree_t)rou_freestr); } break; case 2 : //scanning translit @@ -73,7 +73,7 @@ while (proceed==true) { ptr=trans; (void) eml_todoqfile(ptr); - trans=(TRATYP **)rou_freelist((void **)trans,(freehandler_t)eml_freetra); + trans=(TRATYP **)rou_freelist((void **)trans,(genfree_t)eml_freetra); status=true; } break; diff --git a/data-feed/xxfeed.tst b/data-feed/xxfeed.tst index 2dcf94f..038bd15 100644 --- a/data-feed/xxfeed.tst +++ b/data-feed/xxfeed.tst @@ -2,12 +2,8 @@ #==================================================== 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 @@ -31,63 +27,3 @@ 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 f1d1ac5..e4b89dd 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -39,7 +39,8 @@ static CONTYP *freecontact(CONTYP *contact) if (contact!=(CONTYP *)0) { contact->sqlptr=sql_closesql(contact->sqlptr); contact->logptr=log_closelog(contact->logptr); - contact->recipients=eml_freerecipients(contact->recipients); + contact->recipients=(RCPTYP **)rou_freelist((void **)contact->recipients, + (genfree_t)eml_freerecipient); contact->mailfrom=rou_freestr(contact->mailfrom); contact->cursesid=rou_freestr(contact->cursesid); contact->mainsesid=rou_freestr(contact->mainsesid); @@ -460,15 +461,15 @@ static _Bool checkto(CONTYP *contact,char *rcptto) { #define OPEP "lvleml.c:checkto," _Bool success; +RCPTYP *neu; const char *detail; -const char *domain; char *report; _Bool proceed; int phase; success=false; +neu=(RCPTYP *)0; detail="Address accepted"; -domain=(const char *)0; report=(char *)0; proceed=true; phase=0; @@ -492,29 +493,32 @@ while (proceed==true) { (void) memmove(rcptto,rcptto+1,strlen(rcptto)); break; case 2 : //checking rcptto format - if (eml_isemailok(rcptto,&domain,&report)==false) { + neu=eml_isemailok(rcptto,&report); + if (neu==(RCPTYP *)0) { (void) transmit(contact,"%d 5.6.2 %s",NOTEML,report); report=rou_freestr(report); phase=999; //no need to go further } break; case 3 : //Do we have a domain MX - if (domain!=(const char *)0) { //always + if (neu->domain!=(const char *)0) { //always MXTYP **mx; - if ((mx=dns_getmx(domain))==(MXTYP **)0) { + if ((mx=dns_getmx(neu->domain))==(MXTYP **)0) { (void) transmit(contact,"%d 5.6.3 %s (rcpt=%s)", MISSMX, "No valid MX found for recipient domain name", - domain); + neu->domain); + neu=eml_freerecipient(neu); phase=999; //no need to go further } mx=dns_freemxlist(mx); } break; case 4 : //Storing rcpt to - if (eml_addrecipient(&(contact->recipients),'L',rcptto)==false) { + if (eml_addrecipient(&(contact->recipients),neu)==false) { detail="duplicate recipients will be consolidated"; + neu=eml_freerecipient(neu); } break; case 5 : //everything ok @@ -837,13 +841,14 @@ if ((contact!=(CONTYP *)0)&&(contact->recipients!=(RCPTYP **)0)) { while (*ptr!=(RCPTYP *)0) { char data[300]; - (void) snprintf(data,sizeof(data),"%c %ld %d %s %s %s", + (void) snprintf(data,sizeof(data),"%c %ld %d %s %s %s@%s", (*ptr)->code, isnow, 0, contact->cursesid, contact->mailfrom, - (*ptr)->rcpt); + (*ptr)->userid, + (*ptr)->domain); if (fprintf(qfile,"%s\n",data)<0) { (void) rou_alert(0,"%s Unable to write transfile (error=<%s>)", OPEP,strerror(errno)); diff --git a/lib/subrou.c b/lib/subrou.c index 7319908..99b2c91 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -323,7 +323,7 @@ return list; /* return true if found, false otherwize. */ /* */ /********************************************************/ -PUBLIC _Bool rou_rmlist(void **list,void *entry,freehandler_t handler) +PUBLIC _Bool rou_rmlist(void **list,void *entry,genfree_t handler) { _Bool found; @@ -338,7 +338,7 @@ if ((list!=(void **)0)&&(entry!=(void **)0)) { void **nxt; nxt=ptr+1; - if (handler!=(freehandler_t)0) + if (handler!=(genfree_t)0) (void) handler(*ptr); while (*ptr!=(void *)0) { *ptr=*nxt; @@ -362,7 +362,7 @@ return found; /* NULL pointer. */ /* */ /********************************************************/ -PUBLIC void **rou_freelist(void **list,freehandler_t handler) +PUBLIC void **rou_freelist(void **list,genfree_t handler) { if (list!=(void **)0) { diff --git a/lib/subrou.h b/lib/subrou.h index 81b2d4f..9bf33fb 100644 --- a/lib/subrou.h +++ b/lib/subrou.h @@ -19,7 +19,7 @@ #define ITSOK 0 //to check errno against no error -typedef void (*freehandler_t)(void *); +typedef void (*genfree_t)(void *); typedef struct timespec TIMESPEC; @@ -66,10 +66,10 @@ extern void **rou_addlist(void **list,void *entry); //Procedure to free one entry part of list //return true if found, false otherwise. -extern _Bool rou_rmlist(void **list,void *entry,freehandler_t handler); +extern _Bool rou_rmlist(void **list,void *entry,genfree_t handler); //Procedure to free all entries of list -extern void **rou_freelist(void **list,freehandler_t handler); +extern void **rou_freelist(void **list,genfree_t handler); //change the application name extern char *rou_setappname(const char *newname); diff --git a/lib/unidns.c b/lib/unidns.c index c775fac..f98c596 100644 --- a/lib/unidns.c +++ b/lib/unidns.c @@ -277,7 +277,7 @@ if (list!=(char **)0) { } ptr++; } - list=(char **)rou_freelist((void **)list,(freehandler_t)rou_freestr); + list=(char **)rou_freelist((void **)list,(genfree_t)rou_freestr); } return spfrec; } @@ -383,7 +383,7 @@ while (proceed==true) { } if (answer>0) (void) qsort((void *)mxlist,answer,sizeof(MXTYP *),cmpmx); - list=(char **)rou_freelist((void **)list,(freehandler_t)rou_freestr); + list=(char **)rou_freelist((void **)list,(genfree_t)rou_freestr); break; default : //SAFE guard proceed=false; diff --git a/lib/unieml.c b/lib/unieml.c index 60a22b3..49190d8 100644 --- a/lib/unieml.c +++ b/lib/unieml.c @@ -46,22 +46,16 @@ static VOCTYP vocsmtp[]={ /* recipient. */ /* */ /********************************************************/ -PUBLIC RCPTYP **eml_freerecipients(RCPTYP **list) +PUBLIC RCPTYP *eml_freerecipient(RCPTYP *info) { -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; +if (info!=(RCPTYP *)0) { + info->userid=rou_freestr(info->userid); + info->domain=rou_freestr(info->domain); + (void) free(info); + info=(RCPTYP *)0; } -return list; +return info; } /* ^L @@ -73,7 +67,7 @@ return list; /* retuurn RCPTYP ** if successful, NULL otherwise.*/ /* */ /********************************************************/ -PUBLIC _Bool eml_addrecipient(RCPTYP ***list,char code,char *rcpt) +PUBLIC _Bool eml_addrecipient(RCPTYP ***list,RCPTYP *rcpt) { _Bool todo; @@ -84,7 +78,8 @@ if (*list!=(RCPTYP **)0) { ptr=*list; while (*ptr!=(RCPTYP *)0) { - if (strcasecmp((*ptr)->rcpt,rcpt)==0) { + if ((strcasecmp((*ptr)->userid,rcpt->userid)==0) && + (strcasecmp((*ptr)->domain,rcpt->domain)==0)) { todo=false; break; //already within list } @@ -92,12 +87,7 @@ if (*list!=(RCPTYP **)0) { } } 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); + *list=(RCPTYP **)rou_addlist((void **)(*list),(void *)rcpt); } return todo; } @@ -474,7 +464,7 @@ return qfile; /********************************************************/ /* */ /* Procedure to store an email to a list of email */ -/* retune true if successful, false otherwise. */ +/* return true if successful, false otherwise. */ /* */ /********************************************************/ PUBLIC _Bool eml_addemail(char ***emails,char *email) @@ -507,19 +497,21 @@ return status; /* acceptable. */ /* */ /********************************************************/ -PUBLIC _Bool eml_isemailok(char *email,const char **domain,char **rapport) +PUBLIC RCPTYP *eml_isemailok(char *email,char **report) { #define OPEP "unieml.c:eml_isemailok" -int status; +RCPTYP *info; char *localpart; +char *domain; int phase; _Bool proceed; -status=false; +info=(RCPTYP *)0; +*report=(char *)0; localpart=(char *)0; -*domain=(const char *)0; +domain=(char *)0; phase=0; proceed=true; while (proceed==true) { @@ -532,17 +524,15 @@ while (proceed==true) { } break; case 1 : //splitting local domain part - if ((*domain=strchr(email,'@'))!=(const char *)0) - (*domain)++; - if ((*domain)==(char *)0) { - *rapport=strdup("Missing domain part"); + if ((domain=strchr(email,'@'))==(char *)0) { + *report=strdup("Missing domain part"); phase=999; //trouble trouble } break; case 2 : //double checking domain part - if (strchr(*domain,'@')!=(char *)0) { - *rapport=strdup("malformed domain part"); - *domain=(const char *)0; + domain++; + if (strchr(domain,'@')!=(char *)0) { + *report=strdup("malformed domain part"); phase=999; //trouble trouble } break; @@ -550,7 +540,7 @@ while (proceed==true) { localpart=strdup(email); *(strchr(localpart,'@'))='\000'; //removing domain if (strlen(localpart)==0) { - *rapport=strdup("email address is empty"); + *report=strdup("email address is empty"); phase=999; //trouble trouble } break; @@ -571,7 +561,7 @@ while (proceed==true) { case ';' : case ':' : (void) snprintf(cmt,sizeof(cmt),"'%c' not allowed in email",*ptr); - *rapport=strdup(cmt); + *report=strdup(cmt); *(ptr+1)='\000'; //exiting; phase=999; //No need to go further break; @@ -581,7 +571,10 @@ while (proceed==true) { } break; case 5 : //everythin fine - status=true; + info=(RCPTYP *)calloc(1,sizeof(RCPTYP)); + info->code='N'; //Not assigned code + info->domain=strdup(domain); + info->userid=strdup(localpart); break; default : //SAFE guard localpart=rou_freestr(localpart); @@ -590,6 +583,6 @@ while (proceed==true) { } phase++; } -return status; +return info; #undef OPEP } diff --git a/lib/unieml.h b/lib/unieml.h index 088464c..0b33d62 100644 --- a/lib/unieml.h +++ b/lib/unieml.h @@ -39,14 +39,18 @@ typedef enum { //list of SMTP protocol keyword typedef struct { //*definition of recipient char code; //'L' rcipient local, 'R' recipient remote - char *rcpt; //recipient email address + char *domain; //Recipient domain + char *userid; //recipient email userid }RCPTYP; -//procedure to Free a recipient list -extern RCPTYP **eml_freerecipients(RCPTYP **list); +//procedure to Free one recipient info +extern RCPTYP *eml_freerecipient(RCPTYP *info); + +//get a session unique id +extern char *eml_getmainsesid(); //procedure to add recipient to a recipient list -extern _Bool eml_addrecipient(RCPTYP ***list,char code,char *rcpt); +extern _Bool eml_addrecipient(RCPTYP ***list,RCPTYP *rcpt); //get a session unique id extern char *eml_getmainsesid(); @@ -81,6 +85,6 @@ extern FILE *eml_openqfile(char *qfilename); //procedure to check email address format //of an email address -extern _Bool eml_isemailok(char *email,const char **domain,char **report); +extern RCPTYP *eml_isemailok(char *email,char **report); #endif