Archive: Simple Email Parsing Code


Simple Email Parsing Code


VAR $USEREMAILADDRESS

Function CheckUserEmailAddress

StrCpy $R1 $USEREMAILADDRESS
StrCpy $R2 ""
StrCpy $R3 ""
#count the number of @'s more than one is invalid, less than one is invalid
${WordFind} "$USEREMAILADDRESS" "@" "*" $R1
StrCmp "1" "$R1" lbl_check2 lbl_error
lbl_check2:
#count the number of words delimited by @ it should be 2.
${WordFind} "$USEREMAILADDRESS" "@" "#" $R1
StrCmp "2" "$R1" lbl_check3 lbl_error
lbl_check3:
#Split the words into user and domain
${WordFind} "$USEREMAILADDRESS" "@" "0" $R2
${WordFind} "$USEREMAILADDRESS" "@" "1" $R3

#Determine if either of the fields contain special RFC822 characters
${StrFilter} "$R2" "" "" '()<>,;:\"[]' $R1
StrCmp "$R2" "$R1" 0 lbl_error

${StrFilter} "$R3" "" "" '()<>,;:\"[]' $R1
StrCmp "$R3" "$R1" 0 lbl_error

lbl_check4:
#Determine the number of fields in user and domain, check to see the number of delimiter is one less than the number of words.
${WordFind} "$R2" "." "*" $R5
${WordFind} "$R2" "." "#" $R6
IntOp $R5 $R5 + 1
StrCmp "$R5" "$R6" 0 lbl_error

${WordFind} "$R3" "." "*" $R5
${WordFind} "$R3" "." "#" $R6
IntOp $R5 $R5 + 1
StrCmp "$R5" "$R6" lbl_check5 lbl_error
lbl_check5:
# make sure there is at least one "." in the domain section.
${WordFind} "$R3" "." "*" $R1
IntCmp 1 $R1 lbl_end lbl_end lbl_error

goto lbl_end
lbl_error:
SetErrors
lbl_end:
FunctionEnd


This function takes the contents of "$USEREMAILADDRESS" and then sets the error flag, if the email address did not meet the simple validation rules. This covers pretty much all you could check, just by looking at an email address as a text string, and without any online verification.

Cool :)
If you post the example at wiki, would be easily accessible by everyone.


Great function, thanks for contributing :)


While I have an account on the Wiki, I don't seem to be able to add pages to it.

Originally posted by Red Wine
Cool :)
If you post the example at wiki, would be easily accessible by everyone.

Everyone can add pages. See the following FAQ item:

http://nsis.sourceforge.net/Starting_a_new_page


Allrighty it's at http://nsis.sourceforge.net/Email_Validation_Function now. Bit spoiled by the Wiki we have here at work. :)


URL:
http://nsis.sourceforge.net/Email_Validation_Function

I think would be nice if you add a complete example of usage as well :)

edit: Also you need to add it in a category.


Quote:


Thanks for converting this for me RedWine. I happened to look here for this type of code, and couldn't find it, so I just wanted to give back to you use for your help.

Originally posted by Red Wine
URL:
http://nsis.sourceforge.net/Email_Validation_Function

I think would be nice if you add a complete example of usage as well :)

edit: Also you need to add it in a category.


well, this function is still to be optimized :)

(write the checks on your own, without using the WordFind stuff, they add a lot of overhead by unused functionality)

maybe i'll do that some time ;)