PageRenderTime 2055ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/wysija-newsletters/helpers/rules.php

https://gitlab.com/Gashler/sg
PHP | 202 lines | 149 code | 22 blank | 31 comment | 11 complexity | 10460b558ced3209eb8f44c58297a44d MD5 | raw file
  1. <?php
  2. defined('WYSIJA') or die('Restricted access');
  3. class WYSIJA_help_rules extends WYSIJA_help{
  4. var $tables = array('rules');
  5. var $pkey = 'ruleid';
  6. var $errors = array();
  7. var $defaultrules=array();
  8. function WYSIJA_help_rules(){
  9. $forwardEmail="";
  10. $forwardEmail=count(str_split($forwardEmail)).':"'.$forwardEmail.'"';
  11. /*
  12. $this->defaultrules[]=array("name"=>__('Feedback loop',WYSIJA),
  13. "title"=>__('When feedback loop',WYSIJA),
  14. "regex"=>'feedback|staff@hotmail.com',
  15. "executed_on"=>array(
  16. "subject"=>1,
  17. "senderinfo"=>1
  18. ),
  19. "action_message"=>array(
  20. "delete"=>1,
  21. "save"=>1
  22. ),
  23. "action_user"=>"unsub",
  24. "action_user_min"=>0
  25. );*/
  26. $this->defaultrules[]=array("order_display"=>0,"key"=>"mailbox_full","name"=>__('Mailbox Full',WYSIJA),
  27. "title"=>__('When mailbox is full',WYSIJA),
  28. "regex"=>'((mailbox|mailfolder|storage|quota|space) *(is)? *(over)? *(exceeded|size|storage|allocation|full|quota|maxi))|((over|exceeded|full) *(mail|storage|quota))',
  29. "executed_on"=>array(
  30. "subject"=>1,
  31. "body"=>1
  32. ),
  33. "action_message"=>array(
  34. "delete"=>1,
  35. "save"=>1
  36. ),
  37. "action_user_min"=>3,
  38. "action_user_stats"=>1);
  39. $this->defaultrules[]=array("order_display"=>1,"key"=>"mailbox_na","name"=>__('Mailbox not available',WYSIJA),
  40. "title"=>__('When mailbox is not available',WYSIJA),
  41. "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',
  42. "executed_on"=>array(
  43. "subject"=>1,
  44. "body"=>1
  45. ),
  46. "action_message"=>array(
  47. "delete"=>1,
  48. "save"=>1
  49. ),
  50. "action_user_min"=>0,
  51. "action_user_stats"=>1
  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. $this->defaultrules[]=array("order_display"=>6,"behave"=>"mailbox_na","key"=>"failed_permanent","name"=>__('Failed Permanently',WYSIJA),
  67. "title"=>__('When failed permanently',WYSIJA),
  68. "regex"=>'failed *permanently|permanent *(fatal)? *(failure|error)|Unrouteable *address|not *accepting *(any)? *mail',
  69. "executed_on"=>array(
  70. "subject"=>1,
  71. "body"=>1
  72. ),
  73. "action_message"=>array(
  74. "delete"=>1,
  75. "save"=>1
  76. ),
  77. "action_user_min"=>0,
  78. "action_user_stats"=>1
  79. );
  80. /* $this->defaultrules[]=array("order_display"=>2,
  81. "name"=>__('Out of office',WYSIJA),
  82. "title"=>__('When out of office detected',WYSIJA),
  83. "key"=>"is_out_office",
  84. "regex"=>'(out|away|on) .*(of|from|leave)|office|vacation|holiday|absen|congÈs|recept|acknowledg|thank you for',
  85. "executed_on"=>array(
  86. "subject"=>1,
  87. "body"=>1
  88. ),
  89. "action_message"=>array(
  90. "delete"=>1
  91. ),
  92. //"action_user_min"=>0
  93. );*/
  94. $this->defaultrules[]=array("order_display"=>3,"key"=>"action_required","name"=>__('Action Required',WYSIJA),
  95. "title"=>__('When you need to confirm you\'re a human being, forward to:',WYSIJA),
  96. "regex"=>'action *required|verif',
  97. "forward"=>1,
  98. "executed_on"=>array(
  99. "subject"=>1
  100. ),
  101. "action_message"=>array(
  102. "delete"=>1
  103. ),
  104. "action_user_min"=>0);
  105. $this->defaultrules[]=array("order_display"=>4,"key"=>"blocked_ip","name"=>__('Blocked IP',WYSIJA),
  106. "forward"=>1,
  107. "title"=>__('When you are flagged as a spammer forward the bounced message to',WYSIJA),
  108. "regex"=>'is *(currently)? *blocked *by|block *list|spam *detected|(unacceptable|banned|offensive|filtered|blocked) *(content|message|e-?mail)|administratively *denied',
  109. "executed_on"=>array(
  110. "body"=>1
  111. ),
  112. "action_message"=>array(
  113. "delete"=>1
  114. ),
  115. "action_user_min"=>0);
  116. $this->defaultrules[]=array("order_display"=>7,"key"=>"nohandle","name"=>'Final Rule',
  117. "title"=>__('When the bounce is weird and we\'re not sure what to do, forward to:',WYSIJA),
  118. "forward"=>1,
  119. "regex"=>'.',
  120. "executed_on"=>array(
  121. "senderinfo"=>1,
  122. "subject"=>1
  123. ),
  124. "action_message"=>array(
  125. "delete"=>1
  126. ),
  127. "action_user_min"=>0,
  128. "action_user_stats"=>1);
  129. $model_config=WYSIJA::get('config','model');
  130. $prefix_ms='';
  131. if(is_multisite()) $prefix_ms='ms_';
  132. foreach($this->defaultrules as $ki =>$vi){
  133. //if a rule is defined
  134. if(isset($model_config->values[$prefix_ms.'bounce_rule_'.$vi['key']])){
  135. if($model_config->values[$prefix_ms.'bounce_rule_'.$vi['key']]!=''){
  136. $this->defaultrules[$ki]['action_user']=$model_config->values[$prefix_ms.'bounce_rule_'.$vi['key']];
  137. }
  138. }
  139. //if a forwarded message is detected
  140. if(isset($model_config->values[$prefix_ms.'bounce_rule_'.$vi['key'].'_forwardto'])){
  141. if($model_config->values[$prefix_ms.'bounce_rule_'.$vi['key'].'_forwardto']!=''){
  142. $this->defaultrules[$ki]['action_message_forwardto']=$model_config->values[$prefix_ms.'bounce_rule_'.$vi['key'].'_forwardto'];
  143. }
  144. }
  145. }
  146. }
  147. function getRules($single=false,$display=false){
  148. $rules = $this->defaultrules;
  149. if($single){
  150. foreach($rules as $id => $rule){
  151. if($rule['key']==$single) return $this->_prepareRule($rule,$id);
  152. }
  153. }else{
  154. if($display){
  155. $newrules=array();
  156. foreach($rules as $id => $rule){
  157. if(isset($rule['order_display'])) $newrules[$rule['order_display']] = $this->_prepareRule($rule,$id);
  158. else $newrules[rand(99,130)] = $this->_prepareRule($rule,$id);
  159. }
  160. $rules=$newrules;
  161. ksort($rules);
  162. }else{
  163. foreach($rules as $id => $rule){
  164. $rules[$id] = $this->_prepareRule($rule,$id);
  165. }
  166. }
  167. return $rules;
  168. }
  169. }
  170. function _prepareRule($rule,$id){
  171. $vals = array('executed_on','action_message','action_user','action_user_min','action_user_stats','action_user_block');
  172. foreach($vals as $oneVal){
  173. if(!empty($rule[$oneVal])) {
  174. $rule[$oneVal] = $rule[$oneVal];
  175. }
  176. }
  177. $rule['id']=$id;
  178. return $rule;
  179. }
  180. }