Re: [exim] Required... A snippit of code...

Top Page
Delete this message
Reply to this message
Author: Paul Overell
Date:  
To: exim-users
Subject: Re: [exim] Required... A snippit of code...
In message <BAY103-F16FDEB380E922687489FA3D2A20@???>, . kibble .
<jelly_bean_junky@???> writes
>
>I'm currently using this:
>typedef struct email_struct {
>       char                    localpart[64];
>       char                    domain[64];
>} _email_struct;

>
>typedef struct lscan_structure {
>       ...
>       _email_struct           lpart_domain;
>       ...
>       char                    emailaddy[128];
>       ...
>} _lscan;

>
>/** this function returns the localpart and the domain section of an email
>in any given string */
>_email_struct getlocalp_domain(char * emailaddr, _email_struct
>lpart_domain) {
>
>       int i = 0;
>       memset(lscan.emailaddy, 0x0, sizeof(lscan.emailaddy));
>       sprintf(lscan.emailaddy, "%s", emailaddr);

>
>       if (!chk_email(lscan.emailaddy)) {      /** simple email validation check */
>               i = strrchr(lscan.emailaddy, "@");


This won't work. strrchr returns a pointer to the last occurrence of
the given char, not an offset.

You need something like

char * last_at = strrchr(lscan.emailaddy, '@');

if  (last_at) {
    i = last_at - lscan.emailaddy;


>               strncpy(lpart_domain.localpart, lscan.emailaddy, i);
>               lpart_domain.localpart[i] = '\0';
>               strcpy(lpart_domain.domain, lscan.emailaddy + i + 1);
>       } else {
>               /** tell user, email supplied is a non-valid email address */
>       }

>
>       return(lpart_domain);
>} /** getlocalp_domain */

>


>Thanks for that, I wouldn't have guessed such an obscure email would
>exist...



Regards
-- 
Paul Overell         Internet Platform Development Manager, Thus plc