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

Top Page
Delete this message
Reply to this message
Author: . kibble .
Date:  
To: paul.overell, exim-users
CC: 
Subject: Re: [exim] Required... A snippit of code...

----Original Message Follows----
From: Paul Overell <paul.overell@???>
To: exim-users@???
Subject: Re: [exim] Required... A snippit of code...
Date: Mon, 20 Dec 2004 12:37:10 +0000

In message <BAY103-F40A37F1B47A433040E21FAD2A00@???>, . kibble .
<jelly_bean_junky@???> writes
>
>From: "David S. Madole" <david@???>
> int i = strcspn(emailaddr, "@");
>
> strncpy(lpart_domain->localpart, emailaddr, i);
> lpart_domain->localpart[i] = '\0';
>
> strcpy(lpart_domain->domain, emailaddr + i + 1);
>
>---------------------------------------
>
>Cheers, that's done the trick... [star*]
>


Beware

"@???

Is a legal email address. The local-part stops at the last @ sign, not the
first. Suggest recasting your code to use the strrchr() function instead.

Regards
--
Paul Overell         Internet Platform Development Manager, Thus plc
<< signature.asc >>
--




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, "@");
        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 */


I'm zero'in out 'lscan.emailaddy' because I reuse the function a few times
in a ‘for’ loop [as recipient count as an attribute] and if I don't zero it
out, I have some left over characters at the end from the last iteration of
the loop. Had a few problems with casting but after a bit of tweaking it
worked nicely.

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

_________________________________________________________________
It's fast, it's easy and it's free. Get MSN Messenger today!
http://www.msn.co.uk/messenger