WYSIJA_help_rules

The MailPoet Newsletters WYSIJA help rules class.

Defined (1)

The class is defined in the following location(s).

/helpers/rules.php  
  1. class WYSIJA_help_rules extends WYSIJA_help{ 
  2. var $tables = array('rules'); 
  3. var $pkey = 'ruleid'; 
  4. var $errors = array(); 
  5. var $defaultrules=array(); 
  6. function __construct() { 
  7. $forwardEmail=""; 
  8. $forwardEmail=count(str_split($forwardEmail)).':"'.$forwardEmail.'"'; 
  9. /** 
  10. $this->defaultrules[]=array("name"=>__('Feedback loop', WYSIJA),  
  11. "title"=>__('When feedback loop', WYSIJA),  
  12. "regex"=>'feedback|staff@hotmail.com',  
  13. "executed_on"=>array( 
  14. "subject"=>1,  
  15. "senderinfo"=>1 
  16. ),  
  17. "action_message"=>array( 
  18. "delete"=>1,  
  19. "save"=>1 
  20. ),  
  21. "action_user"=>"unsub",  
  22. "action_user_min"=>0 
  23. );*/ 
  24.  
  25. $this->defaultrules[]=array("order_display"=>0, "key"=>"mailbox_full", "name"=>__('Mailbox Full', WYSIJA),  
  26. "title"=>__('When mailbox is full', WYSIJA),  
  27. "regex"=>'((mailbox|mailfolder|storage|quota|space) *(is)? *(over)? *(exceeded|size|storage|allocation|full|quota|maxi))|((over|exceeded|full) *(mail|storage|quota))',  
  28. "executed_on"=>array( 
  29. "subject"=>1,  
  30. "body"=>1 
  31. ),  
  32. "action_message"=>array( 
  33. "delete"=>1,  
  34. "save"=>1 
  35. ),  
  36. "action_user_min"=>3,  
  37. "action_user_stats"=>1); 
  38. $this->defaultrules[]=array("order_display"=>1, "key"=>"mailbox_na", "name"=>__('Mailbox not available', WYSIJA),  
  39. "title"=>__('When mailbox is not available', WYSIJA),  
  40. "regex"=>'(Invalid|no such|unknown|bad|des?activated|undelivered|inactive|unrouteable|delivery|mail ID|failed to|may not|no known user|email account) *(mail|destination|recipient|user|address|person|failure|has failed|does not exist|deliver to|exist|with this email|is closed)|RecipNotFound|status(-code)? *(:|=)? *5\.(1\.[1-6]|0\.0|4\.[0123467])|(user|mailbox|address|recipients?|host|account|domain) *(is|has been)? *(error|disabled|failed|unknown|unavailable|not *(found|available)|.{1, 30}inactiv)|recipient *address *rejected|does *not *like *recipient|no *mailbox *here|user does.?n.t have.{0, 20}account',  
  41. "executed_on"=>array( 
  42. "subject"=>1,  
  43. "body"=>1 
  44. ),  
  45. "action_message"=>array( 
  46. "delete"=>1,  
  47. "save"=>1 
  48. ),  
  49. "action_user_min"=>0,  
  50. "action_user_stats"=>1 
  51. ); 
  52.  
  53. $this->defaultrules[]=array("order_display"=>5, "behave"=>"mailbox_na", "key"=>"message_delayed", "name"=>__('Message delayed', WYSIJA),  
  54. "title"=>__('When message is delayed', WYSIJA),  
  55. "regex"=>'possible *mail *loop|too *many *hops|Action: *delayed|has.*been.*delayed|delayed *mail|temporary *failure',  
  56. "executed_on"=>array( 
  57. "subject"=>1,  
  58. "body"=>1 
  59. ),  
  60. "action_message"=>array( 
  61. "delete"=>1,  
  62. "save"=>1 
  63. ),  
  64. "action_user_min"=>3,  
  65. "action_user_stats"=>1); 
  66.  
  67.  
  68.  
  69. $this->defaultrules[]=array("order_display"=>6, "behave"=>"mailbox_na", "key"=>"failed_permanent", "name"=>__('Failed Permanently', WYSIJA),  
  70. "title"=>__('When failed permanently', WYSIJA),  
  71. "regex"=>'failed *permanently|permanent *(fatal)? *(failure|error)|Unrouteable *address|not *accepting *(any)? *mail',  
  72. "executed_on"=>array( 
  73. "subject"=>1,  
  74. "body"=>1 
  75. ),  
  76. "action_message"=>array( 
  77. "delete"=>1,  
  78. "save"=>1 
  79. ),  
  80. "action_user_min"=>0,  
  81. "action_user_stats"=>1 
  82. ); 
  83.  
  84. /** $this->defaultrules[]=array("order_display"=>2,  
  85. "name"=>__('Out of office', WYSIJA),  
  86. "title"=>__('When out of office detected', WYSIJA),  
  87. "key"=>"is_out_office",  
  88. "regex"=>'(out|away|on) .*(of|from|leave)|office|vacation|holiday|absen|cong*s|recept|acknowledg|thank you for',  
  89. "executed_on"=>array( 
  90. "subject"=>1,  
  91. "body"=>1 
  92. ),  
  93. "action_message"=>array( 
  94. "delete"=>1 
  95. ),  
  96. //"action_user_min"=>0 
  97. );*/ 
  98.  
  99. $this->defaultrules[]=array("order_display"=>3, "key"=>"action_required", "name"=>__('Action Required', WYSIJA),  
  100. "title"=>__('When you need to confirm you\'re a human being, forward to:', WYSIJA),  
  101. "regex"=>'action *required|verif',  
  102. "forward"=>1,  
  103. "executed_on"=>array( 
  104. "subject"=>1 
  105. ),  
  106. "action_message"=>array( 
  107. "delete"=>1 
  108. ),  
  109. "action_user_min"=>0); 
  110.  
  111. $this->defaultrules[]=array("order_display"=>4, "key"=>"blocked_ip", "name"=>__('Blocked IP', WYSIJA),  
  112. "forward"=>1,  
  113. "title"=>__('When you are flagged as a spammer forward the bounced message to', WYSIJA),  
  114. "regex"=>'is *(currently)? *blocked *by|block *list|spam *detected|(unacceptable|banned|offensive|filtered|blocked) *(content|message|e-?mail)|administratively *denied',  
  115. "executed_on"=>array( 
  116. "body"=>1 
  117. ),  
  118. "action_message"=>array( 
  119. "delete"=>1 
  120. ),  
  121. "action_user_min"=>0); 
  122.  
  123.  
  124.  
  125. $this->defaultrules[]=array("order_display"=>7, "key"=>"nohandle", "name"=>'Final Rule',  
  126. "title"=>__('When the bounce is weird and we\'re not sure what to do, forward to:', WYSIJA),  
  127. "forward"=>1,  
  128. "regex"=>'.',  
  129. "executed_on"=>array( 
  130. "senderinfo"=>1,  
  131. "subject"=>1 
  132. ),  
  133. "action_message"=>array( 
  134. "delete"=>1 
  135. ),  
  136. "action_user_min"=>0,  
  137. "action_user_stats"=>1); 
  138.  
  139. $model_config=WYSIJA::get('config', 'model'); 
  140. $prefix_ms=''; 
  141. if(is_multisite()) $prefix_ms='ms_'; 
  142. foreach($this->defaultrules as $ki =>$vi) { 
  143. //if a rule is defined 
  144. if(isset($model_config->values[$prefix_ms.'bounce_rule_'.$vi['key']])) { 
  145. if($model_config->values[$prefix_ms.'bounce_rule_'.$vi['key']]!='') { 
  146. $this->defaultrules[$ki]['action_user']=$model_config->values[$prefix_ms.'bounce_rule_'.$vi['key']]; 
  147.  
  148. //if a forwarded message is detected 
  149. if(isset($model_config->values[$prefix_ms.'bounce_rule_'.$vi['key'].'_forwardto'])) { 
  150. if($model_config->values[$prefix_ms.'bounce_rule_'.$vi['key'].'_forwardto']!='') { 
  151. $this->defaultrules[$ki]['action_message_forwardto']=$model_config->values[$prefix_ms.'bounce_rule_'.$vi['key'].'_forwardto']; 
  152.  
  153.  
  154. function getRules($single=false, $display=false) { 
  155. $rules = $this->defaultrules; 
  156. if($single) { 
  157. foreach($rules as $id => $rule) { 
  158. if($rule['key']==$single) return $this->_prepareRule($rule, $id); 
  159. }else{ 
  160. if($display) { 
  161. $newrules=array(); 
  162. foreach($rules as $id => $rule) { 
  163.  
  164. if(isset($rule['order_display'])) $newrules[$rule['order_display']] = $this->_prepareRule($rule, $id); 
  165. else $newrules[rand(99, 130)] = $this->_prepareRule($rule, $id); 
  166. $rules=$newrules; 
  167. ksort($rules); 
  168. }else{ 
  169. foreach($rules as $id => $rule) { 
  170. $rules[$id] = $this->_prepareRule($rule, $id); 
  171.  
  172. return $rules; 
  173.  
  174.  
  175. function _prepareRule($rule, $id) { 
  176. $vals = array('executed_on', 'action_message', 'action_user', 'action_user_min', 'action_user_stats', 'action_user_block'); 
  177.  
  178. foreach($vals as $oneVal) { 
  179. if(!empty($rule[$oneVal])) { 
  180. $rule[$oneVal] = $rule[$oneVal]; 
  181. $rule['id']=$id; 
  182. return $rule; 
  183.