/** * Method to validate one ore more email addresses * * @access public * * @param array $cid Subscriber/Test-recipient IDs * @param boolean $showProgress * @return array $res associative array of result data */ public function validate_mail($cid = array(), $showProgress = false) { $_db = $this->_db; $query = $_db->getQuery(true); $config = Jfactory::getConfig(); $validator = new emailValidation(); $tmp = explode('@', $config->get('mailfrom')); $mailuser = $tmp[0]; $mailserver = $tmp[1]; $validator->timeout = 5; $validator->data_timeout = 0; $validator->localuser = $mailuser; $validator->localhost = $mailserver; $validator->debug = 0; $validator->html_debug = 1; $validator->exclude_address = ""; $query->select('*'); $query->from($_db->quoteName('#__bwpostman_subscribers')); $query->where($_db->quoteName('id') . ' IN (' . implode(',', $cid) . ')'); // $query->order($_db->escape($listOrdering).' '.$listDirn); $_db->setQuery($query); $subscribers = $_db->loadObjectList(); // After the validation process we want to show the results // --> therefore we store the results into an array $res = array(); $i = 0; foreach ($subscribers as $subscriber) { if ($showProgress) { echo "\n<br>{$subscriber->email} ... "; ob_flush(); flush(); } $res[$i]['id'] = $subscriber->id; $res[$i]['email'] = $subscriber->email; $res[$i]['name'] = $subscriber->name; $res[$i]['firstname'] = $subscriber->firstname; // Skip confirmed email address if they still passed the confirmation process and where identified as invalid if (strstr($subscriber->name, 'INVALID_')) { // Skipped $res[$i]['result'] = 2; $res[$i]['result_txt'] = JText::_('COM_BWPOSTMAN_SUB_ERROR_VALIDATION_SKIPPED'); $i++; if ($showProgress) { echo JText::_('COM_BWPOSTMAN_SUB_ERROR_VALIDATION_SKIPPED'); ob_flush(); flush(); } continue; } $result = $validator->ValidateEmailBox($subscriber->email); if ($result === -1) { // Unable to validate the address with this host $res[$i]['result'] = -1; $res[$i]['result_txt'] = JText::_('COM_BWPOSTMAN_SUB_ERROR_VALIDATING_HOST'); $i++; if ($showProgress) { echo JText::_('COM_BWPOSTMAN_SUB_ERROR_VALIDATING_HOST'); ob_flush(); flush(); } } elseif ($result) { // The host is able to receive email. The address could be valid. $res[$i]['result'] = 1; $res[$i]['result_txt'] = JText::_('COM_BWPOSTMAN_SUB_VALIDATING_EMAIL'); $i++; if ($showProgress) { echo JText::_('COM_BWPOSTMAN_SUB_VALIDATING_EMAIL'); ob_flush(); flush(); } // Activate this account $date = JFactory::getDate(); $time = $date->toSql(); $user = JFactory::getUser(); $query = $_db->getQuery(true); $query->update($_db->quoteName('#__bwpostman_subscribers')); $query->set($_db->quoteName('status') . " = " . (int) 1); $query->set($_db->quoteName('confirmation_date') . " = " . $_db->Quote($time, false)); $query->set($_db->quoteName('confirmed_by') . " = " . (int) $user->get('id')); $query->where($_db->quoteName('id') . ' = ' . (int) $subscriber->id); $_db->setQuery($query); if (!$_db->query()) { $this->setError($_db->getErrorMsg()); return false; } } else { // The host can\'t receive email or this mailbox doesn\'t exist. The address is NOT valid. $res[$i]['result'] = 0; $res[$i]['result_txt'] = JText::_('COM_BWPOSTMAN_SUB_ERROR_VALIDATING_EMAIL'); $i++; if ($showProgress) { echo JText::_('COM_BWPOSTMAN_SUB_ERROR_VALIDATING_EMAIL'); ob_flush(); flush(); } // Prepend an INVALID_ to the subscriber name $query = $_db->getQuery(true); $query->update($_db->quoteName('#__bwpostman_subscribers')); $query->set($_db->quoteName('name') . " = " . $_db->Quote('INVALID_' . $subscriber->name)); $query->where($_db->quoteName('id') . ' = ' . (int) $subscriber->id); $_db->setQuery($query); if (!$_db->query()) { $this->setError($_db->getErrorMsg()); return false; } } } return $res; }