email syntax validation needed

Nevin Pratt nevin at smalltalkpro.com
Tue Jul 22 12:24:26 UTC 2003



Ned Konz wrote:

>On Monday 21 July 2003 09:19 pm, Nevin Pratt wrote:
>  
>
>>Anybody know how to do MX record lookups from within Squeak rather
>>than DNS lookups?  Seems on my system, 'sbcglobal.net' resolves to
>>a good MX record, but fails as a DNS lookup.
>>    
>>
>
>Sure. Use OSProcess and call nslookup or dig.
>
>  
>

I thought 'nslookup' and 'dig' just did DNS checks, no?  I thought the 
only difference between Squeak's NetNameResolver class and them is that 
NetNameResolver uses the default DNS machines defined on the host 
machine, whereas with 'dig' (and I think 'nslookup' as well) allow you 
to specify which machine you want to use for the DNS lookup.

So, off hand, I don't see what 'nslookup' and/or 'dig' buy me for this 
application.

Anyway, I've expanded my emailAddress validation to the following (and 
this code handles the 'sbcglobal.net' case, because it prepends 'www.' 
for one of the tests, and 'www.sbcglobal.net' successfully resolves):


isValidEmailAddress: emailAddress
    | username host |
    emailAddress isNil
        ifTrue: [^ false].
    host _ emailAddress copyAfter: $@.
    username _ emailAddress copyUpTo: $@.
    (username includesAnyOf: ' ')
        ifTrue: [^ false].
    (NetNameResolver addressForName: host timeout: 5) notNil
        ifTrue: [^ true].
    (NetNameResolver addressForName: 'www.' , host timeout: 5) notNil
        ifTrue: [^ true].
    (NetNameResolver addressForName: 'mail.' , host timeout: 5) notNil
        ifTrue: [^ true].
    ^ false

-- 
Nevin Pratt
Bountiful Baby
http://www.bountifulbaby.com
(801) 992-3137





More information about the Squeak-dev mailing list