public static function actionParse()
{
$tolist = '[email protected],
Michael Ferranti <[email protected]>
"Jeff Reifman" <[email protected]>, <[email protected]>,jeff <[email protected]>';
//Yii::import('ext.Mail_RFC822');
include 'Mail/RFC822.php';
$parser = new Mail_RFC822();
// replace the backslash quotes
$tolist = str_replace('\\"', '"', $tolist);
// split the elements by line and by comma
$to_email_array = preg_split("(\r|\n|,)", $tolist, -1, PREG_SPLIT_NO_EMPTY);
$num_emails = count($to_email_array);
echo $num_emails;
for ($count = 0; $count < $num_emails && $count <= 500; $count++) {
$toAddress = trim($to_email_array[$count]);
if ($toAddress != '') {
$addresses = $parser->parseAddressList('my group:' . $toAddress, 'bushsucks.com', false, true);
var_dump($addresses);
lb();
}
//$toAddress=$addresses[0]->mailbox.'@'.$addresses[0]->host;
//if ($this->utilObj->checkEmail($toAddress)) {
// store it or send it or whatever you want to do
//}
}
}
/**
* Send an email message.
*
* @param string $to Recipient email address
* @param string $from Sender email address
* @param string $subject Subject line for message
* @param string $body Message body
*
* @return mixed PEAR error on error, boolean true otherwise
* @access public
*/
public function send($to, $from, $subject, $body)
{
// Validate sender and recipient
if (!Mail_RFC822::isValidInetAddress($to)) {
return new PEAR_Error('Invalid Recipient Email Address');
}
if (!Mail_RFC822::isValidInetAddress($from)) {
return new PEAR_Error('Invalid Sender Email Address');
}
// Change error handling behavior to avoid termination during mail
// process....
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
// Get mail object
$mail =& Mail::factory('smtp', $this->settings);
if (PEAR::isError($mail)) {
return $mail;
}
// Send message
$headers = array('From' => $from, 'To' => $to, 'Subject' => $subject, 'Date' => date('D, d M Y H:i:s O'), 'Content-Type' => 'text/plain; charset="UTF-8"');
$result = $mail->send($to, $headers, $body);
return $result;
}
开发者ID:BSZBW,项目名称:ldu,代码行数:33,代码来源:Mailer.php
示例10: parseAddressList
/**
* Starts the whole process. The address must either be set here
* or when creating the object. One or the other.
*
* @access public
* @param string $address The address(es) to validate.
* @param string $default_domain Default domain/host etc.
* @param boolean $nest_groups Whether to return the structure with groups nested for easier viewing.
* @param boolean $validate Whether to validate atoms. Turn this off if you need to run addresses through before encoding the personal names, for instance.
*
* @return array A structured array of addresses.
*/
function parseAddressList($address = null, $default_domain = null, $nest_groups = null, $validate = null, $limit = null)
{
if (!isset($this->mailRFC822)) {
$obj = new Mail_RFC822($address, $default_domain, $nest_groups, $validate, $limit);
return $obj->parseAddressList();
}
if (isset($address)) {
$this->address = $address;
}
if (isset($default_domain)) {
$this->default_domain = $default_domain;
}
if (isset($nest_groups)) {
$this->nestGroups = $nest_groups;
}
if (isset($validate)) {
$this->validate = $validate;
}
if (isset($limit)) {
$this->limit = $limit;
}
$this->structure = array();
$this->addresses = array();
$this->error = null;
$this->index = null;
while ($this->address = $this->_splitAddresses($this->address)) {
continue;
}
if ($this->address === false || isset($this->error)) {
return $this->raiseError($this->error);
}
// Reset timer since large amounts of addresses can take a long time to
// get here
set_time_limit(30);
// Loop through all the addresses
for ($i = 0; $i < count($this->addresses); $i++) {
if (($return = $this->_validateAddress($this->addresses[$i])) === false || isset($this->error)) {
return $this->raiseError($this->error);
}
if (!$this->nestGroups) {
$this->structure = array_merge($this->structure, $return);
} else {
$this->structure[] = $return;
}
}
return $this->structure;
}
/**
* Take a set of recipients and parse them, returning an array of
* bare addresses (forward paths) that can be passed to sendmail
* or an smtp server with the rcpt to: command.
*
* @param mixed Either a comma-seperated list of recipients
* (RFC822 compliant), or an array of recipients,
* each RFC822 valid.
*
* @return array An array of forward paths (bare addresses).
* @access private
*/
function parseRecipients($recipients)
{
include_once 'Mail/RFC822.php';
// if we're passed an array, assume addresses are valid and
// implode them before parsing.
if (is_array($recipients)) {
$recipients = implode(', ', $recipients);
}
// Parse recipients, leaving out all personal info. This is
// for smtp recipients, etc. All relevant personal information
// should already be in the headers.
$addresses = Mail_RFC822::parseAddressList($recipients, 'localhost', false);
$recipients = array();
if (is_array($addresses)) {
foreach ($addresses as $ob) {
$recipients[] = $ob->mailbox . '@' . $ob->host;
}
}
return $recipients;
}
/**
* Starts the whole process. The address must either be set here
* or when creating the object. One or the other.
*
* @access public
* @param string $address The address(es) to validate.
* @param string $default_domain Default domain/host etc.
* @param boolean $nest_groups Whether to return the structure with groups nested for easier viewing.
* @param boolean $validate Whether to validate atoms. Turn this off if you need to run addresses through before encoding the personal names, for instance.
*
* @return array A structured array of addresses.
*/
function parseAddressList($address = null, $default_domain = null, $nest_groups = null, $validate = null, $limit = null)
{
if (!isset($this) || !isset($this->mailRFC822)) {
$obj = new Mail_RFC822($address, $default_domain, $nest_groups, $validate, $limit);
return $obj->parseAddressList();
}
if (isset($address)) {
$this->address = $address;
}
if (isset($default_domain)) {
$this->default_domain = $default_domain;
}
if (isset($nest_groups)) {
$this->nestGroups = $nest_groups;
}
if (isset($validate)) {
$this->validate = $validate;
}
if (isset($limit)) {
$this->limit = $limit;
}
$this->structure = array();
$this->addresses = array();
$this->error = null;
$this->index = null;
// Unfold any long lines in $this->address.
$this->address = preg_replace('/\\r?\\n/', "\r\n", $this->address);
$this->address = preg_replace('/\\r\\n(\\t| )+/', ' ', $this->address);
while ($this->address = $this->_splitAddresses($this->address)) {
}
if ($this->address === false || isset($this->error)) {
//require_once 'PEAR.php';
return $this->raiseError($this->error);
}
// Validate each address individually. If we encounter an invalid
// address, stop iterating and return an error immediately.
foreach ($this->addresses as $address) {
$valid = $this->_validateAddress($address);
if ($valid === false || isset($this->error)) {
//require_once 'PEAR.php';
return $this->raiseError($this->error);
}
if (!$this->nestGroups) {
$this->structure = array_merge($this->structure, $valid);
} else {
$this->structure[] = $valid;
}
}
return $this->structure;
}
/**
* Checks to see if email address is valid.
*
* This function checks to see if an email address is in the correct from.
*
* @param string $email Email address to verify
* @return boolean True if valid otherwise false
*
*/
function COM_isEmail($email)
{
require_once 'Mail/RFC822.php';
$rfc822 = new Mail_RFC822();
return $rfc822->isValidInetAddress($email) ? true : false;
}
}
//exit();
//get all the destined addresses from to,cc,bcc into the array $var_toaddress
//do check for duplicates and insert all valid addresses to $var_toaddress array
$var_toaddress = array();
for ($j = 0; $j < 3; $j++) {
$structure = "";
switch ($j) {
case 0:
$structure = Mail_RFC822::parseAddressList($mimedecoder->_mailheader->_headerto, 'example.com', true);
break;
case 1:
$structure = Mail_RFC822::parseAddressList($mimedecoder->_mailheader->_headercc, 'example.com', true);
break;
case 2:
$structure = Mail_RFC822::parseAddressList($mimedecoder->_mailheader->_headerbcc, 'example.com', true);
break;
}
$cnt = count($structure);
for ($i = 0; $i < $cnt; $i++) {
$var_temp = $structure[$i]->mailbox . "@" . strtolower($structure[$i]->host);
if ($structure[$i]->mailbox != "" && !isset($var_toaddress[$var_temp])) {
$var_toaddress[$var_temp] = $structure[$i]->mailbox;
}
}
}
//print_r($var_toaddress);
/*
*Case-sensitivity for isset - it is case sensitive
*so same email addresses with different case may create two tickets
*se we convert all domain names to lower case here
请发表评论