[ Index ]

MailPress 7.1

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


Generated: Mon Mar 11 18:33:33 2019 Cross-referenced by PHPXref 0.7.1