| core_net

# Class: Bs_EmailValidator Source Location: /core/net/email/Bs_EmailValidator.class.php
### Class Overview
    Bs_Object
       |
       --Bs_NetApplication
          |
          --Bs_EmailValidator
Validates email addresses. #### Author(s): Andrej Arn <at blueshoes dot org> #### Version: 4.3.$Revision: 1.3 $ $Date: 2003/10/29 17:48:41 $ #### Copyright: blueshoes.org | ### Variables $bsDb $Bs_EmailUtil $newAddress $port $regExp $senderAddress $serverName | ### Methods Bs_EmailValidator connect disconnect getErrorMessage usesFreemailProvider validateHost validateMailbox validateSyntax
### Inherited Variables #### Class: Bs_NetApplication Bs_NetApplication::$Bs_Url Bs_NetApplication::$host | ### Inherited Methods #### Class: Bs_NetApplication Bs_NetApplication::Bs_NetApplication() Bs_NetApplication::connect() Make the connection. Bs_NetApplication::disconnect() Close the connection if it was open. Bs_NetApplication::_raiseError() you have to overwrite this method. #### Class: Bs_Object Bs_Object::Bs_Object() Bs_Object::getErrors() Basic error handling: Get *all* errors as string array from the global Bs_Error-error stack. Bs_Object::getLastError() Basic error handling: Get last error string from the global Bs_Error-error stack. Bs_Object::getLastErrors() Basic error handling: Get last errors string array from the global Bs_Error-error stack sinc last call of getLastErrors(). Bs_Object::persist() Persists this object by serializing it and saving it to a file with unique name. Bs_Object::setError() Basic error handling: Push an error string on the global Bs_Error-error stack. Bs_Object::toHtml() Dumps the content of this object to a string using PHP's var_dump(). Bs_Object::toString() Dumps the content of this object to a string using PHP's var_dump(). Bs_Object::unpersist() Fetches an object that was persisted with persist()
### Class Details [line 85] Validates email addresses. features: validate syntax validate host validate mailbox missing: validate mailing lists? if you're looking for information about the smtp protocol, try these, have fun :) SIMPLE MAIL TRANSFER PROTOCOL ftp://ftp.isi.edu/in-notes/std/std10.txt (yes it's from 1982) note: these methods don't trim() the given email address. do it yourself... dependencies: Net/Bs_NetApplication (which uses Net/Bs_SocketClient and Net/Bs_Url), Util/Bs_System, Bs_Db for usesFreemailProvider(), Bs_EmailUtil, #### Tags:
pattern: | singleton: (pseudostatic)
access: | public
version: | 4.3.$Revision: 1.3 $ $Date: 2003/10/29 17:48:41 $
copyright: | blueshoes.org
author: | Andrej Arn <at blueshoes dot org>
[ Top ] ### Class Variables #### $bsDb = [line 114] reference to the db object. assigned in the constructor if there is one in the global scope. if there is none, and you want to use usesFreemailProvider() then you have to set a db object to this var yourself. #### Tags:
access: | public
Type: | object
[ Top ] #### $Bs_EmailUtil = [line 93] reference to the global pseudostatic instance #### Tags:
access: | public
Type: | object
[ Top ] #### $newAddress = [line 166] If the server suggests another email address to send to, this var is filled with it. it can be that the server just suggests it, but still accepts the old address, or it can be that you have to use this one. this var is used in validateMailbox().
Type: | string
[ Top ] #### $port = 25 [line 132] overwrite default value
Type: | mixed
Overrides: | Array
[ Top ] #### $regExp = '~^[0-9a-z_\-\.]+@[0-9a-z][\-\.0-9a-z]*\.[a-z]{2,4}\.?$~Ui' [line 126] regular expressions to check the email address. from manuel lemos: "^[-!#\$%&'*+./0-9=?A-Z^_`a-z{|}~ ]+@[-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~ ]+\\.+[a-zA-Z]{2,4}\$" #### Tags:
var: | regExp
access: | public
Type: | string
[ Top ] #### $senderAddress = [line 155] The email address from which we initiate a send of an email to validate the given email address. the transaction won't be finished so the receiving mailserver won't deliver anything. this var is used in validateMailbox() AND SET IN THE CONSTRUCTOR. #### Tags:
access: | public
Type: | string
[ Top ] #### $serverName = [line 144] The domain name as which we identify ourself to the mailserver. i'm not sure if the receiving mailserver does anything with it, eg compares it with our real ip/host address. but the mailserver sees our ip anyway, so why not send the same information here. this var is used in validateMailbox() AND SET IN THE CONSTRUCTOR. #### Tags:
access: | public
Type: | string
[ Top ] ### Class Methods ### constructor Bs_EmailValidator [line 173]
`Bs_EmailValidator Bs_EmailValidator( )`
Constructor #### Tags:
access: | public
[ Top ] ### method connect [line 357]
`void connect( mixed $host, [mixed $port = NULL], [mixed $persistent = FALSE], [mixed $timeOut = NULL], [mixed $blocking = TRUE])`
Overwrites the parent method, but still makes use of it. Overrides Bs_NetApplication::connect() (Make the connection.) [ Top ] ### method disconnect [line 383]
`void disconnect( )`
Overwrites the parent method, but still makes use of it. Overrides Bs_NetApplication::disconnect() (Close the connection if it was open.) [ Top ] ### method getErrorMessage [line 417]
`string getErrorMessage( long $errCode)`
Return a textual error message for a bs emailvalidator error code #### Tags:
return: | error message, or false if the error code was not recognized
#### Parameters:
long | $errCode | a bs error code (see constants)
[ Top ] ### method usesFreemailProvider [line 327]
`bool usesFreemailProvider( string $email)`
tells if the given email address (or domain) is from a freemail provider. freemail providers may become "paid services" or at least offer somme additional services for money. i still throw them into the same category. while an isp where ppl have their dialup account also is different. i think it's ok to have that method here in Bs_EmailValidator, it's kinda a validation too. but it may also go into a new Bs_Email[Util] class. dependencies: the BsKb.FreemailProvider table is needed. #### Tags:
return: | (TRUE if it does, FALSE if not or if we can't tell.)
#### Parameters:
string | $email | (email or domain)
[ Top ] ### method validateHost [line 214]
`bool validateHost( string $email)`
Validates the host part of a given email address with a connection to the host. a syntax check is done first also. windows hell: this method needs getMxRr() and checkDnsRr() which are broken on some win systems. there are workarounds, pure php implementations in Net/NetUtil.class.php called checkDnsRr_winNT() and getMxRr_winNT(). but since they need the exec() command, which again is broken on some win systems, this method validateHost() just returns BS_EMAILVALIDATOR_ERROR_NOT_CAPABLE for all windows systems (after the email address has been syntax-checked). check the mentioned Net/NetUtil.class.php file for further information. #### Tags:
return: | true if the host of the address is valid, an error code otherwise (see constants).
todo: | check if php's getMxRr() and checkDnsRr() OR exec() are fixed now for win and update the code/manual.
#### Parameters:
string | $email |
[ Top ] ### method validateMailbox [line 241]
`mixed validateMailbox( string $email)`
Validates the mailbox of a given email address with a connection to the mailserver. a syntax check is done first also. Identifies itself as server $this->serverName, uses email address $this->senderAddress and probably sets $this->newAddress if you should rather use another email address. #### Tags:
return: | (bool TRUE if the mailbox exists, an error code or warning code otherwise (see constants).)
see: | Bs_EmailValidator::$serverName, Bs_EmailValidator::$senderAddress, Bs_EmailValidator::$newAddress
throws: | bs_exception on connection problems, eg if the host was invalid. maybe use $this->validateHost() first.
#### Parameters:
string | $email |
[ Top ] ### method validateSyntax [line 191]
`bool validateSyntax( string $email)`
Validates the syntax of a given email address. if you want to validate AND parse it, use Bs_EmailUtil->parse(). #### Tags:
return: | true if the syntax of the address is valid, false otherwise.
see: | Bs_EmailUtil->parse()
#### Parameters:
string | $email |
[ Top ] Documentation generated on Mon, 29 Dec 2003 21:08:55 +0100 by phpDocumentor 1.2.3