| version 1.2, 2005/03/25 23:32:42 |
version 1.3, 2005/03/30 12:53:55 |
|
|
| <?
|
<? |
|
|
|
| // $Platon$
|
// $Platon: mylist/backend/receiver/line2emails.php,v 1.2 2005/03/25 23:32:42 nepto Exp $ |
|
|
|
| // processes input text line containing email addresses
|
// processes input text line containing email addresses |
| // returns array of email addresses in valid format
|
// returns array of email addresses in valid format |
| // <username> @ <domain> . <suffix>
|
// <username> @ <domain> . <suffix> |
| // into array $arr_valid_emails
|
// into array $arr_valid_emails |
|
|
|
| // USAGE
|
// USAGE |
| // $lineParser = new CLine2Emails();
|
// $lineParser = new CLine2Emails(); |
| // $lineParser->inputLine = "webmaster, admin@hotmail.com, "Your Name" master@domain.com";
|
// $lineParser->inputLine = "webmaster, admin@hotmail.com, "Your Name" master@domain.com"; |
| // $lineParser->processLine();
|
// $lineParser->processLine(); |
|
|
// |
|
|
// output is in $arr_valid_emails |
| require_once "../shared/mlist.config.php";
|
|
|
|
require_once "../../mylist.config.php"; |
| class CLine2Emails
|
require_once "../shared/RFC822.php"; |
| {
|
|
| // input text line to process
|
class CLine2Emails |
| var $inputLine;
|
{ |
|
|
// input text line to process |
| // temporary array of emails
|
var $inputLine; |
| var $arr_temp_emails = Array();
|
|
|
|
// output array of emails in valid format |
| // output array of emails in valid format
|
var $arr_valid_emails = Array(); |
| var $arr_valid_emails = Array();
|
|
|
|
|
|
|
// returns true if input email address is in format |
| // returns true if input email address is in format
|
// <username> @ <domain> . <suffix> |
| // <username> @ <domain> . <suffix>
|
// or |
| // or
|
// <username> @ <subnet> . <domain> . <suffix> |
| // <username> @ <subnet> . <domain> . <suffix>
|
function validAddressFormat($emailAddress) |
| function validAddressFormat($emailAddress)
|
{ |
| {
|
return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$",$emailAddress); |
| return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$",$emailAddress);
|
} |
| }
|
|
|
|
|
|
|
function processLine() |
| // transforms input email address to valid format
|
{ |
| // set of emails format:
|
global $localDomain; |
| // username@domain.suffix, <username@domain.suffix>,
|
$structure = Mail_RFC822::parseAddressList($this->inputLine, $localDomain, true); |
| // Name Surname <username@domain.suffix>,
|
for($i = 0; $i < Count($structure); $i++) |
| // "Name Surname" <username@domain.suffix>,
|
if (isset($structure[$i]->mailbox) && isset($structure[$i]->host)) |
| // username
|
$this->arr_valid_emails[$i] = $structure[$i]->mailbox."@".$structure[$i]->host; |
| function getEmailAddress($emailLine)
|
} |
| {
|
|
| global $localDomain;
|
} |
|
|
?> |
| if ( $this->validAddressFormat($emailLine) )
|
|
| return $emailLine;
|
|
|
|
|
| if ( eregi("^.*<(.+)@(.+)>$", $emailLine, $textParts))
|
|
| return $textParts[1]."@".$textParts[2];
|
|
|
|
|
| // local sendmail
|
|
| if ( eregi("@", $emailLine) == false && StrLen($emailLine) !=0 )
|
|
| return $emailLine."@".$localDomain;
|
|
|
|
|
|
|
|
| return -1;
|
|
|
|
|
| }
|
|
|
|
|
| // splits input line into array of emails
|
|
| // and removes spaces
|
|
| function splitInputLine()
|
|
| {
|
|
| $this->arr_temp_emails = split(",", $this->inputLine);
|
|
|
|
|
| for ($i=0; $i < Count($this->arr_temp_emails); $i++)
|
|
| $this->arr_temp_emails[$i] = preg_replace("( )","",$this->arr_temp_emails[$i]);
|
|
| }
|
|
|
|
|
| // transfers email address into valid format
|
|
| // <username> @ <domain> . <suffix>
|
|
| // or sets it to -1
|
|
| function formatEachAddress()
|
|
| {
|
|
| for ($i=0; $i < Count($this->arr_temp_emails); $i++)
|
|
| $this->arr_temp_emails[$i] = $this->getEmailAddress($this->arr_temp_emails[$i]);
|
|
| }
|
|
|
|
|
| // prepares the output list ($arr_valid_emails)
|
|
| // of valid email addresses
|
|
| function prepareValidAddresses()
|
|
| {
|
|
| $numOfValid = Count($this->arr_valid_emails);
|
|
| for ($i=0; $i < Count($this->arr_temp_emails); $i++)
|
|
| {
|
|
| if ( $this->arr_temp_emails[$i] != -1 )
|
|
| {
|
|
| $this->arr_valid_emails[$numOfValid] = $this->arr_temp_emails[$i];
|
|
| $numOfValid++;
|
|
| }
|
|
| }
|
|
| }
|
|
|
|
|
| // runs all necessary functions to process input text line
|
|
| // and sets the output array only with valid emails
|
|
| function processLine()
|
|
| {
|
|
| $this->splitInputLine();
|
|
| $this->formatEachAddress();
|
|
| $this->prepareValidAddresses();
|
|
|
|
|
| }
|
|
| }
|
|
|
|
|
| ?>
|
|