コード例 #1
0
ファイル: BounceProcessor.php プロジェクト: jbeigh/phpList
 /**
  * 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;
 }