Exemplo n.º 1
0
 public static function sendMail($to, $subject, $message, $skipblacklistcheck = 0)
 {
     if (Config::TEST) {
         return 1;
     }
     # do a quick check on mail injection attempt, @@@ needs more work
     if (preg_match("/\n/", $to)) {
         //TODO: convert to new logger
         phpList::log()->notice('Error: invalid recipient, containing newlines, email blocked');
         return 0;
     }
     if (preg_match("/\n/", $subject)) {
         phpList::log()->notice('Error: invalid subject, containing newlines, email blocked');
         return 0;
     }
     if (!$to) {
         phpList::log()->notice("Error: empty To: in message with subject {$subject} to send");
         return 0;
     } elseif (!$subject) {
         phpList::log()->notice("Error: empty Subject: in message to send to {$to}");
         return 0;
     }
     if (!$skipblacklistcheck && Util::isEmailBlacklisted($to)) {
         phpList::log()->notice("Error, {$to} is blacklisted, not sending");
         Util::blacklistSubscriberByEmail($to);
         Subscriber::addHistory('Marked Blacklisted', 'Found subscriber in blacklist while trying to send an email, marked black listed', Subscriber::getSubscriberByEmailAddress($to)->id);
         return 0;
     }
     return phpListMailer::sendMailPhpMailer($to, $subject, $message);
 }
Exemplo n.º 2
0
 /**
  * Find which subscriber this message was sent to
  * @param string $text
  * @return bool|Subscriber
  */
 private function findSubscriber($text)
 {
     $subscriber = false;
     $subscriber_id = '';
     preg_match('/X-ListMember: (.*)\\R/iU', $text, $match);
     if (is_array($match) && isset($match[1])) {
         $subscriber_id = trim($match[1]);
     } else {
         # older version use X-User
         preg_match('/X-User: (.*)\\R/iU', $text, $match);
         if (is_array($match) && isset($match[1])) {
             $subscriber_id = trim($match[1]);
         }
     }
     if ($subscriber_id != '') {
         # some versions used the email to identify the subscribers, some the userid and others the uniqid
         # use backward compatible way to find subscriber
         if (strpos($subscriber_id, '@') !== false) {
             $subscriber = Subscriber::getSubscriberByEmailAddress($subscriber_id);
         } elseif (preg_match('/^\\d$/', $subscriber_id)) {
             $subscriber = Subscriber::getSubscriber($subscriber_id);
         } elseif (!empty($subscriber_id)) {
             $subscriber = Subscriber::getSubscriberByUniqueId($subscriber_id);
         }
     }
     if ($subscriber === false) {
         ### if we didn't find any, parse anything looking like an email address and check if it's a subscriber.
         ## this is probably fairly time consuming, but as the process is only done once every so often
         ## that should not be too bad
         preg_match_all('/[\\S]+@[\\S\\.]+/', $text, $regs);
         foreach ($regs[0] as $match) {
             $subscriberObj = Subscriber::getSubscriberByEmailAddress(Util::cleanEmail($match));
             if ($subscriberObj !== false) {
                 return $subscriberObj;
             }
         }
     }
     return $subscriber;
 }