function next($count = 10) { $max = $this->current + $count; $max = $max < count($this->objects) ? $max : count($this->objects); while ($this->current < $max) { $index = $this->current++; $member = $this->objects[$index]; // check to see if the user has unsubscribed from the mailing list // TODO Join in the above query first if (defined('DB::USE_ANSI_SQL')) { $unsubscribeRecord = DataObject::get_one('UnsubscribeRecord', "\"MemberID\"='{$member->ID}' AND \"NewsletterTypeID\"='{$this->nlType->ID}'"); } else { $unsubscribeRecord = DataObject::get_one('UnsubscribeRecord', "`MemberID`='{$member->ID}' AND `NewsletterTypeID`='{$this->nlType->ID}'"); } if (!$unsubscribeRecord) { $address = $member->Email; /** * Email Blacklisting Support */ if ($member->BlacklistedEmail && NewsletterEmailBlacklist::isBlocked($address)) { $bounceRecord = new Email_BounceRecord(); $bounceRecord->BounceEmail = $member->Email; $bounceRecord->BounceTime = date("Y-m-d H:i:s", time()); $bounceRecord->BounceMessage = "BlackListed Email"; $bounceRecord->MemberID = $member->ID; $bounceRecord->write(); // Log the blacklist for this specific Newsletter $newsletter = new Newsletter_SentRecipient(); $newsletter->Email = $address; $newsletter->MemberID = $member->ID; $newsletter->Result = 'BlackListed'; $newsletter->ParentID = $this->newsletter->ID; $newsletter->write(); } else { $e = new NewsletterEmail($this->newsletter, $this->nlType); $e->setSubject($this->subject); $e->setFrom($this->from); $e->setTemplate($this->nlType->Template); $nameForEmail = method_exists($member, "getNameForEmail") ? $member->getNameForEmail() : false; $e->populateTemplate(array('Member' => $member, 'FirstName' => $member->FirstName, 'NameForEmail' => $nameForEmail)); $this->sendToAddress($e, $address, $this->messageID, $member); } } } return $this->current >= count($this->objects) ? $this->complete() : parent::next(); }