You are absolutely right about the 'trailing' space. I'd prefer

PHP Code:
=trim(LEFT(A1,FIND("@",SUBSTITUTE(A1," ","@",3)))) 
Correct me if I'm wrong but shouldn't you use

PHP Code:
=TRIM(RIGHT(SUBSTITUTE(TRIM(A1)," ",REPT(" ",99)),N*99)) 
just to exclude a textstring that contains two adjacent spaces ?