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

Kezdőlap
Üzenet törlése
Válasz az üzenetre
Szerző: David S. Madole
Dátum:  
Címzett: exim-users
Tárgy: Re: [exim] Required... A snippit of code...
From: ". kibble ." <jelly_bean_junky@???>
>
> Has anyone got a snippet of C code I can whack into my local_scan
> function that will split a variable containing an email ( char
> emailaddress[] ) into the local_part and domain section and put them
> into their own variables please? (char local_part[] & char domain[] ).
>
> I made one using strtok like this:
>
> ...
>
> sprintf(lpart_domain->localpart, "%s", strtok(emailaddr, "@"));
> sprintf(lpart_domain->domain, "%s", strtok(NULL, "@"));
>
> ...
>
> And it returns the error in the [exim_mainlog]:
> Format error in spool file 1CfPxP-0003SJ-4l-H: size=513


Almost certainly your problem is that you are using strtok(), which
modifies the source string in place by writing null characters over the
delimiters. I am guessing that you didn't copy the email address into
your own storage first, and so are modifying exim's copy which it later
uses to write the spool file.

Why not use something like this instead (or one of the millions of other
possible variations):

    int i = strcspn(emailaddr, "@");


    strncpy(lpart_domain->localpart, emailaddr, i);
    lpart_domain->localpart[i] = '\0';


    strcpy(lpart_domain->domain, emailaddr + i + 1);


And zeroing out the full string buffers first is almost certainly
unnecessary.

David


**