3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Mailing_BAO_BouncePattern
extends CRM_Mailing_DAO_BouncePattern
{
20 * Pseudo-constant pattern array.
23 public static $_patterns = NULL;
28 public function __construct() {
29 parent
::__construct();
33 * Build the static pattern array.
35 public static function buildPatterns() {
36 self
::$_patterns = [];
37 $bp = new CRM_Mailing_BAO_BouncePattern();
40 while ($bp->fetch()) {
41 self
::$_patterns[$bp->bounce_type_id
][] = $bp->pattern
;
44 foreach (self
::$_patterns as $type => $patterns) {
45 if (count($patterns) == 1) {
46 self
::$_patterns[$type] = '{(' . $patterns[0] . ')}im';
49 self
::$_patterns[$type] = '{(' . implode(')|(', $patterns) . ')}im';
55 * Try to match the string to a bounce type.
57 * @param string $message
58 * The message to be matched.
61 * Tuple (bounce_type, bounce_reason)
63 public static function &match(&$message) {
64 // clean up $message and replace all white space by a single space, CRM-4767
65 $message = preg_replace('/\s+/', ' ', $message);
67 if (self
::$_patterns == NULL) {
68 self
::buildPatterns();
71 foreach (self
::$_patterns as $type => $re) {
72 if (preg_match($re, $message, $matches)) {
74 'bounce_type_id' => $type,
75 'bounce_reason' => $message,
82 'bounce_type_id' => NULL,
83 'bounce_reason' => $message,