[ Index ]

MailPress 544

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/class/ -> MP_Bounce_II.class.php (source)

   1  <?php
   2  class MP_Bounce_II extends MP_bounce_
   3  {
   4      public $option_name    = MailPress_bounce_handling_II::option_name;
   5      public $option_name_pop3= MailPress_bounce_handling_II::option_name_pop3;
   6      public $meta_key    = MailPress_bounce_handling_II::meta_key;
   7  
   8      public $class        = __CLASS__;
   9      public $log_name     = 'mp_process_bounce_handling_II';
  10      public $log_option_name = 'bounce_handling_II';
  11      public $log_title     = 'Bounce Handling II Report (Bounce in mailbox : %1$s )';
  12  
  13      public $cron_name     = 'MailPress_schedule_bounce_handling_II';
  14  
  15  
  16      private $subject_bounce= array();
  17      private $subject_regex = '';
  18  
  19      private $body_bounce   = array();
  20      private $body_regex    = '';
  21  
  22  	function __construct()
  23      {
  24          $root = MP_CONTENT_DIR . 'advanced/bounces';
  25          $root = apply_filters('MailPress_advanced_bounces_root', $root);
  26          $file    = "$root/II.xml";
  27  
  28          $y = '';
  29  
  30          if (!is_file($file)) return;
  31  
  32          $x = file_get_contents($file);
  33          if ($xml = simplexml_load_string($x))
  34  
  35          foreach ($xml->subject->text as $text) $this->subject_bounce[] = preg_quote((string) $text, '~');
  36          $this->subject_regex = '~(' . implode('|', $this->subject_bounce) . ')~i';
  37  
  38          $this->body_regex = (string) $xml->body->regex;
  39          foreach ($xml->body->text as $text) $this->body_bounce[] = (string) $text;
  40  
  41          parent::__construct();
  42      }
  43  
  44  	function is_bounce()
  45      {
  46          $tags = array('Subject', 'X-MailPress-blog-id', 'X-MailPress-mail-id', 'X-MailPress-user-id');
  47          $this->pop3->get_headers_deep($this->message_id, $tags);
  48  
  49          $blog_id = $this->get_tag('X-MailPress-blog-id', 1);
  50          if (false === $blog_id) return false;
  51          global $wpdb;
  52          if ($blog_id != $wpdb->blogid) return false;
  53  
  54          $mail_id = $this->get_tag('X-MailPress-mail-id', 1);
  55          if (false === $mail_id) return false;
  56  
  57          $mp_user_id = $this->get_tag('X-MailPress-user-id', 1);
  58          if (false === $mp_user_id)
  59          {
  60              if (!$mail = MP_Mail::get($mail_id)) return false;
  61  
  62              if (!is_email($mail->toemail)) return false;
  63  
  64              $mp_user_id = MP_User::get_id_by_email($mail->toemail);
  65                  
  66              if (!$mp_user_id) return false;
  67          }
  68  
  69          // detect message is bounce
  70  
  71          $subject = $this->get_tag('Subject');
  72          $subject = trim($subject);
  73          $subject = strtolower($subject);
  74          if (empty($subject) || !preg_match($this->subject_regex, $subject)) return false;
  75  
  76          if (!$this->parse_body($this->get_body(0))) return false;
  77  
  78          $this->process_mailbox_status();
  79  
  80          return array($mail_id, $mp_user_id, "mail : $mail_id & user : $mp_user_id");
  81      }
  82  
  83  	function parse_body($body)
  84      {
  85          $status = array();
  86          if (preg_match($this->body_regex, $body, $matches)) 
  87          {
  88              if (3 == count($matches)) preg_match('/Status\s*?\:\s*?([2|4|5]+)\.(\d{1,3}).(\d{1,3})/is', $matches[2], $status);
  89              unset($matches);
  90          }
  91  
  92          if (4 == count($status)) 
  93          {
  94              $bounce = false;
  95              switch ($status[1]) 
  96              {
  97                  case 2:
  98                      $bounce = true;
  99                      break;
 100                  case 4:
 101                      $bounce = $this->RFC_3463_4($status[2], $status[3]);
 102                      break;
 103                  case 5:
 104                      if (5 == $status[2] && 0 == $status[3]) break;
 105                      $bounce = $this->RFC_3463_5($status[2], $status[3]);
 106                      break;
 107              }
 108              if ($bounce) return true;
 109          }
 110          // -----
 111  
 112          foreach ($this->body_bounce as $rule) if (preg_match('%' . preg_quote($rule) . '%is', $body)) return true;
 113  
 114          return false;
 115      }
 116  
 117      // RFC 3463 - Enhanced Mail System Status Codes
 118  
 119  	function RFC_3463_4($code, $subcode)
 120      {
 121          if ((5 == $code) && (3 == $subcode)) return true;
 122          return false;
 123      }
 124  
 125  	function RFC_3463_5($code, $subcode)
 126      {
 127          switch ($code)
 128          {
 129              case '1': 
 130                  if (in_array($subcode, array('0','1','2','3','4','5','6'))) return true;
 131                  break;
 132              default :
 133                  if (in_array($code, array('2','3','4','5','6','7'))) return true;
 134                  break;
 135          }
 136          return false;
 137      }
 138  }


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1