Completed
Push — master ( d1881e...11bf71 )
by Lars
02:29
created

phpmailer-bmh_rules.php ➔ bmhBodyRules()   F

Complexity

Conditions 50
Paths 528

Size

Total Lines 449
Code Lines 169

Duplication

Lines 185
Ratio 41.2 %

Code Coverage

Tests 84
CRAP Score 615.5012

Importance

Changes 0
Metric Value
cc 50
eloc 169
nc 528
nop 3
dl 185
loc 449
ccs 84
cts 215
cp 0.3907
crap 615.5012
rs 2.6101
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 73 and the first side effect is on line 34.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/*~ phpmailer-bmh_rules.php
3
.---------------------------------------------------------------------------.
4
|  Software: PHPMailer-BMH (Bounce Mail Handler)                            |
5
|   Version: 5.2-dev                                                        |
6
|   Contact: [email protected]                             |
7
|      Info: http://phpmailer.codeworxtech.com                              |
8
| ------------------------------------------------------------------------- |
9
|    Author: Andy Prevost [email protected] (admin)                 |
10
| Copyright (c) 2002-2009, Andy Prevost. All Rights Reserved.               |
11
| ------------------------------------------------------------------------- |
12
|   License: Distributed under the General Public License (GPL)             |
13
|            (http://www.gnu.org/licenses/gpl.html)                         |
14
| This program is distributed in the hope that it will be useful - WITHOUT  |
15
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or     |
16
| FITNESS FOR A PARTICULAR PURPOSE.                                         |
17
| ------------------------------------------------------------------------- |
18
| This is a update of the original Bounce Mail Handler script               |
19
| http://sourceforge.net/projects/bmh/                                      |
20
| The script has been renamed from Bounce Mail Handler to PHPMailer-BMH     |
21
| ------------------------------------------------------------------------- |
22
| We offer a number of paid services:                                       |
23
| - Web Hosting on highly optimized fast and secure servers                 |
24
| - Technology Consulting                                                   |
25
| - Oursourcing (highly qualified programmers and graphic designers)        |
26
'---------------------------------------------------------------------------'
27
28
/**
29
* next rule number (BODY): 0257 <br />
30
* default category:        unrecognized: <br />
31
* default rule no.:        0000 <br />
32
*/
33
34
global $rule_categories;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
35
$rule_categories = array(
36
    'antispam'       => array('remove' => 0, 'bounce_type' => 'blocked'),
37
    'autoreply'      => array('remove' => 0, 'bounce_type' => 'autoreply'),
38
    'concurrent'     => array('remove' => 0, 'bounce_type' => 'soft'),
39
    'content_reject' => array('remove' => 0, 'bounce_type' => 'soft'),
40
    'command_reject' => array('remove' => 1, 'bounce_type' => 'hard'),
41
    'internal_error' => array('remove' => 0, 'bounce_type' => 'temporary'),
42
    'defer'          => array('remove' => 0, 'bounce_type' => 'soft'),
43
    'delayed'        => array('remove' => 0, 'bounce_type' => 'temporary'),
44
    'dns_loop'       => array('remove' => 1, 'bounce_type' => 'hard'),
45
    'dns_unknown'    => array('remove' => 1, 'bounce_type' => 'hard'),
46
    'full'           => array('remove' => 0, 'bounce_type' => 'soft'),
47
    'inactive'       => array('remove' => 1, 'bounce_type' => 'hard'),
48
    'latin_only'     => array('remove' => 0, 'bounce_type' => 'soft'),
49
    'other'          => array('remove' => 1, 'bounce_type' => 'generic'),
50
    'oversize'       => array('remove' => 0, 'bounce_type' => 'soft'),
51
    'outofoffice'    => array('remove' => 0, 'bounce_type' => 'soft'),
52
    'unknown'        => array('remove' => 1, 'bounce_type' => 'hard'),
53
    'unrecognized'   => array('remove' => 0, 'bounce_type' => false,),
54
    'user_reject'    => array('remove' => 1, 'bounce_type' => 'hard'),
55
    'warning'        => array('remove' => 0, 'bounce_type' => 'soft'),
56
);
57
58
/*
59
 * var for new line ending
60
 */
61
$bmh_newline = "<br />\n";
62
63
/**
64
 * Defined bounce parsing rules for non-standard DSN
65
 *
66
 * @param string  $body       body of the email
67
 * @param string  $structure  message structure
68
 * @param boolean $debug_mode show debug info. or not
69
 *
70
 * @return array    $result an array include the following fields: 'email', 'bounce_type','remove','rule_no','rule_cat'
71
 *                      if we could NOT detect the type of bounce, return rule_no = '0000'
72
 */
73
function bmhBodyRules($body, $structure, $debug_mode = false)
0 ignored issues
show
Unused Code introduced by
The parameter $structure is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
{
75
  // initialize the result array
76
  $result = array(
77 2
      'email'           => '',
78 2
      'bounce_type'     => false,
79 2
      'remove'          => 0,
80 2
      'rule_cat'        => 'unrecognized',
81 2
      'rule_no'         => '0000',
82 2
      'status_code'     => '',
83 2
      'action'          => '',
84 2
      'diagnostic_code' => '',
85 2
  );
86
87
  // ======== rules =========
88
89
  /* rule: dns_unknown
90
   * sample:
91
   *   Technical details of permanent failure:
92
   *   DNS Error: Domain name not found
93
   */
94 2
  if (preg_match("/domain\s+name\s+not\s+found/i", $body, $match)) {
95
    $result['rule_cat'] = 'dns_unknown';
96
    $result['rule_no'] = '0999';
97
  } /* rule: unknown
98
   * sample:
99
   *   [email protected]
100
   *   no such address here
101
   */
102 2
  elseif (preg_match("/no\s+such\s+address\s+here/i", $body, $match)) {
103
    $result['rule_cat'] = 'unknown';
104
    $result['rule_no'] = '0237';
105
  }
106
  /* Gmail Bounce Error
107
   * rule: unknown
108
   * sample:
109
   *   Delivery to the following recipient failed permanently:
110
   *   [email protected]
111
   */
112 2 View Code Duplication
  elseif (preg_match("/Delivery to the following (?:recipient|recipients) failed permanently\X*?(\S+@\S+\w)/i", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
113 1
    $result['rule_cat'] = 'unknown';
114 1
    $result['rule_no'] = '0998';
115 1
    $result['email'] = $match[1];
116 1
  }
117
  /* rule: unknown
118
   * sample:
119
   *   <[email protected]>:
120
   *   111.111.111.111 does not like recipient.
121
   *   Remote host said: 550 User unknown
122
   */
123 2 View Code Duplication
  elseif (preg_match("/user\s+unknown/i", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
124 1
    $result['rule_cat'] = 'unknown';
125 1
    $result['rule_no'] = '0236';
126 1
  } /* rule: unknown
127
   * sample:
128
   *
129
   */
130 2 View Code Duplication
  elseif (preg_match("/unknown\s+user/i", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
131 2
    $result['rule_cat'] = 'unknown';
132 2
    $result['rule_no'] = '0249';
133 2
  } /* rule: unknown
134
   * sample:
135
   *   <[email protected]>:
136
   *   Sorry, no mailbox here by that name. vpopmail (#5.1.1)
137
   */
138 1 View Code Duplication
  elseif (preg_match("/no\s+mailbox/i", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
139
    $result['rule_cat'] = 'unknown';
140
    $result['rule_no'] = '0157';
141
  } /* rule: unknown
142
   * sample:
143
   *   [email protected]<br>
144
   *   local: Sorry, can't find user's mailbox. (#5.1.1)<br>
145
   */
146 1 View Code Duplication
  elseif (preg_match("/can't\s+find.*mailbox/i", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
147
    $result['rule_cat'] = 'unknown';
148
    $result['rule_no'] = '0164';
149
  } /* rule: unknown
150
   * sample:
151
   *   ##########################################################
152
   *   #  This is an automated response from a mail delivery    #
153
   *   #  program.  Your message could not be delivered to      #
154
   *   #  the following address:                                #
155
   *   #                                                        #
156
   *   #      "|/usr/local/bin/mailfilt -u #dkms"               #
157
   *   #        (reason: Can't create output)                   #
158
   *   #        (expanded from: <[email protected]>)         #
159
   *   #                                                        #
160
   */
161 1 View Code Duplication
  elseif (preg_match("/Can't\s+create\s+output.*<(\S+@\S+\w)>/is", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
162
    $result['rule_cat'] = 'unknown';
163
    $result['rule_no'] = '0169';
164
    $result['email'] = $match[1];
165
  } /* rule: unknown
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
166
   * sample:
167
   *   ????????????????:
168
   *   [email protected] : ????, ?????.
169
   */
170 1 View Code Duplication
  elseif (preg_match('/=D5=CA=BA=C5=B2=BB=B4=E6=D4=DA/i', $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
171
    $result['rule_cat'] = 'unknown';
172
    $result['rule_no'] = '0174';
173
  } /* rule: unknown
174
   * sample:
175
   *   [email protected]
176
   *   Unrouteable address
177
   */
178 1 View Code Duplication
  elseif (preg_match("/Unrouteable\s+address/i", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
179
    $result['rule_cat'] = 'unknown';
180
    $result['rule_no'] = '0179';
181
  } /* rule: unknown
182
   * sample:
183
   *   Delivery to the following recipients failed.
184
   *   [email protected]
185
   */
186 1 View Code Duplication
  elseif (preg_match("/delivery[^\n\r]+failed\S*\s+(\S+@\S+\w)\s/is", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
187
    $result['rule_cat'] = 'unknown';
188
    $result['rule_no'] = '0013';
189
    $result['email'] = $match[1];
190
  } /* rule: unknown
191
   * sample:
192
   *   A message that you sent could not be delivered to one or more of its
193
   *   recipients. This is a permanent error. The following address(es) failed:
194
   *
195
   *   [email protected]
196
   *   unknown local-part "xxxxx" in domain "yourdomain.com"
197
   */
198 1 View Code Duplication
  elseif (preg_match("/unknown\s+local-part/i", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
199
    $result['rule_cat'] = 'unknown';
200
    $result['rule_no'] = '0232';
201
  } /* rule: unknown
202
   * sample:
203
   *   <[email protected]>:
204
   *   111.111.111.11 does not like recipient.
205
   *   Remote host said: 550 Invalid recipient: <[email protected]>
206
   */
207 1 View Code Duplication
  elseif (preg_match("/Invalid.*(?:alias|account|recipient|address|email|mailbox|user).*<(\S+@\S+\w)>/is", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
208
    $result['rule_cat'] = 'unknown';
209
    $result['rule_no'] = '0233';
210
    $result['email'] = $match[1];
211
  } /* rule: unknown
212
   * sample:
213
   *   Sent >>> RCPT TO: <[email protected]>
214
   *   Received <<< 550 [email protected]... No such user
215
   *
216
   *   Could not deliver mail to this user.
217
   *   [email protected]
218
   *   *****************     End of message     ***************
219
   */
220 1 View Code Duplication
  elseif (preg_match("/No\s+such.*(?:alias|account|recipient|address|email|mailbox|user).*<(\S+@\S+\w)>/is", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
221
    $result['rule_cat'] = 'unknown';
222
    $result['rule_no'] = '0234';
223
    $result['email'] = $match[1];
224
  } /* rule: unknown
225
   * sample:
226
   *   Diagnostic-Code: X-Notes; Recipient user name info ([email protected]) not unique.  Several matches found in Domino Directory.
227
   */
228 1 View Code Duplication
  elseif (preg_match('/not unique.\s+Several matches found/i', $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
229
    $result['rule_cat'] = 'unknown';
230
    $result['rule_no'] = '0254';
231
  } /* rule: full
232
   * sample 1:
233
   *   <[email protected]>:
234
   *   This account is over quota and unable to receive mail.
235
   *   sample 2:
236
   *   <[email protected]>:
237
   *   Warning: undefined mail delivery mode: normal (ignored).
238
   *   The users mailfolder is over the allowed quota (size). (#5.2.2)
239
   */
240 1 View Code Duplication
  elseif (preg_match('/over.*quota/i', $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
241
    $result['rule_cat'] = 'full';
242
    $result['rule_no'] = '0182';
243
  } /* rule: full
244
   * sample:
245
   *   ----- Transcript of session follows -----
246
   *   mail.local: /var/mail/2b/10/kellen.lee: Disc quota exceeded
247
   *   554 <[email protected]>... Service unavailable
248
   */
249 1 View Code Duplication
  elseif (preg_match("/quota\s+exceeded.*<(\S+@\S+\w)>/is", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
250
    $result['rule_cat'] = 'full';
251
    $result['rule_no'] = '0126';
252
    $result['email'] = $match[1];
253
  } /* rule: full
254
   * sample:
255
   *   Hi. This is the qmail-send program at 263.domain.com.
256
   *   <[email protected]>:
257
   *   - User disk quota exceeded. (#4.3.0)
258
   */
259 1 View Code Duplication
  elseif (preg_match("/quota\s+exceeded/i", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
260
    $result['rule_cat'] = 'full';
261
    $result['rule_no'] = '0158';
262
  } /* rule: full
263
   * sample:
264
   *   [email protected]
265
   *   mailbox is full (MTA-imposed quota exceeded while writing to file /mbx201/mbx011/A100/09/35/A1000935772/mail/.inbox):
266
   */
267 1 View Code Duplication
  elseif (preg_match('/mailbox.*full/i', $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
268
    $result['rule_cat'] = 'full';
269
    $result['rule_no'] = '0166';
270
  } /* rule: full
271
   * sample:
272
   *   The message to [email protected] is bounced because : Quota exceed the hard limit
273
   */
274 1 View Code Duplication
  elseif (preg_match("/The message to (\S+@\S+\w)\s.*bounce.*Quota exceed/i", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
275
    $result['rule_cat'] = 'full';
276
    $result['rule_no'] = '0168';
277
    $result['email'] = $match[1];
278
  } /* rule: full
279
   * sample:
280
   *   Message rejected. Not enough storage space in user's mailbox to accept message.
281
   */
282 1 View Code Duplication
  elseif (preg_match("/not\s+enough\s+storage\s+space/i", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
283
    $result['rule_cat'] = 'full';
284
    $result['rule_no'] = '0253';
285
  } /* rule: inactive
286
   * sample:
287
   *   [email protected]<br>
288
   *   553 user is inactive (eyou mta)
289
   */
290 1 View Code Duplication
  elseif (preg_match('/user is inactive/i', $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
291
    $result['rule_cat'] = 'inactive';
292
    $result['rule_no'] = '0171';
293
  } /*
294
   * <[email protected]> is restricted
295
   */
296 1 View Code Duplication
  elseif (preg_match("/(\S+@\S+\w).*n? is restricted/i", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
297
    $result['rule_cat'] = 'inactive';
298
    $result['rule_no'] = '0201';
299
    $result['email'] = $match[1];
300
  } /* rule: inactive
301
   * sample:
302
   *   [email protected] [Inactive account]
303
   */
304 1 View Code Duplication
  elseif (preg_match('/inactive account/i', $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
305
    $result['rule_cat'] = 'inactive';
306
    $result['rule_no'] = '0181';
307
  } /*
308
   *<[email protected]>: host mx3.HOTMAIL.COM said: 550
309
   * Requested action not taken: mailbox unavailable (in reply to RCPT TO command)
310
   */
311 1 View Code Duplication
  elseif (preg_match("/<(\S+@\S+\w)>.*\n.*mailbox unavailable/i", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
312
    $result['rule_cat'] = 'unknown';
313
    $result['rule_no'] = '124';
314
    $result['email'] = $match[1];
315
  } /*
316
   * rule: mailbox unknown;
317
   * sample:
318
   * [email protected]
319
   * 550-5.1.1 The email
320
   * account that you tried to reach does not exist. Please try 550-5.1.1
321
   * double-checking the recipient's email address for typos or 550-5.1.1
322
   * unnecessary spaces. Learn more at 550 5.1.1
323
   * http://support.google.com/mail/bin/answer.py?answer=6596 n7si4762785wiy.46
324
   * (in reply to RCPT TO command)
325
   */
326 1 View Code Duplication
  elseif (preg_match("/<(\S+@\S+\w)>.*\n?.*\n?.*account that you tried to reach does not exist/i", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
327
    $result['rule_cat'] = 'unknown';
328
    $result['rule_no'] = '7770';
329
    $result['email'] = $match[1];
330
  } /* rule: dns_unknown
331
   * sample1:
332
   *   Delivery to the following recipient failed permanently:
333
   *
334
   *     [email protected]
335
   *
336
   *   Technical details of permanent failure:
337
   *   TEMP_FAILURE: Could not initiate SMTP conversation with any hosts:
338
   *   [b.c (1): Connection timed out]
339
   * sample2:
340
   *   Delivery to the following recipient failed permanently:
341
   *
342
   *     [email protected]
343
   *
344
   *   Technical details of permanent failure:
345
   *   TEMP_FAILURE: Could not initiate SMTP conversation with any hosts:
346
   *   [pop.b.c (1): Connection dropped]
347
   */
348 1 View Code Duplication
  elseif (preg_match('/Technical details of permanent failure:\s+TEMP_FAILURE: Could not initiate SMTP conversation with any hosts/i', $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
349
    $result['rule_cat'] = 'dns_unknown';
350
    $result['rule_no'] = '0251';
351
  } /* rule: delayed
352
   * sample:
353
   *   Delivery to the following recipient has been delayed:
354
   *
355
   *     [email protected]
356
   *
357
   *   Message will be retried for 2 more day(s)
358
   *
359
   *   Technical details of temporary failure:
360
   *   TEMP_FAILURE: Could not initiate SMTP conversation with any hosts:
361
   *   [b.c (50): Connection timed out]
362
   */
363 1 View Code Duplication
  elseif (preg_match('/Technical details of temporary failure:\s+TEMP_FAILURE: Could not initiate SMTP conversation with any hosts/i', $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
364
    $result['rule_cat'] = 'delayed';
365
    $result['rule_no'] = '0252';
366
  } /* rule: delayed
367
   * sample:
368
   *   Delivery to the following recipient has been delayed:
369
   *
370
   *     [email protected]
371
   *
372
   *   Message will be retried for 2 more day(s)
373
   *
374
   *   Technical details of temporary failure:
375
   *   TEMP_FAILURE: The recipient server did not accept our requests to connect. Learn more at ...
376
   *   [b.c (10): Connection dropped]
377
   */
378 1 View Code Duplication
  elseif (preg_match('/Technical details of temporary failure:\s+TEMP_FAILURE: The recipient server did not accept our requests to connect./i', $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
379
    $result['rule_cat'] = 'delayed';
380
    $result['rule_no'] = '0256';
381
  } /* rule: internal_error
382
   * sample:
383
   *   <[email protected]>:
384
   *   Unable to switch to /var/vpopmail/domains/domain.com: input/output error. (#4.3.0)
385
   */
386 1 View Code Duplication
  elseif (preg_match("/input\/output error/i", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
387
    $result['rule_cat'] = 'internal_error';
388
    $result['rule_no'] = '0172';
389
    $result['bounce_type'] = 'hard';
390
    $result['remove'] = 1;
391
  } /* rule: internal_error
392
   * sample:
393
   *   <[email protected]>:
394
   *   can not open new email file errno=13 file=/home/vpopmail/domains/fromc.com/0/domain/Maildir/tmp/1155254417.28358.mx05,S=212350
395
   */
396 1 View Code Duplication
  elseif (preg_match('/can not open new email file/i', $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
397
    $result['rule_cat'] = 'internal_error';
398
    $result['rule_no'] = '0173';
399
    $result['bounce_type'] = 'hard';
400
    $result['remove'] = 1;
401
  } /* rule: defer
402
   * sample:
403
   *   <[email protected]>:
404
   *   111.111.111.111 failed after I sent the message.
405
   *   Remote host said: 451 mta283.mail.scd.yahoo.com Resources temporarily unavailable. Please try again later [#4.16.5].
406
   */
407 1 View Code Duplication
  elseif (preg_match('/Resources temporarily unavailable/i', $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
408
    $result['rule_cat'] = 'defer';
409
    $result['rule_no'] = '0163';
410
  } /* rule: autoreply
411
   * sample:
412
   *   AutoReply message from [email protected]
413
   */
414 1 View Code Duplication
  elseif (preg_match("/^AutoReply message from (\S+@\S+\w)/i", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
415
    $result['rule_cat'] = 'autoreply';
416
    $result['rule_no'] = '0167';
417
    $result['email'] = $match[1];
418
  } /* rule: block
419
   * sample:
420
   *   Delivery to the following recipient failed permanently:
421
   *     [email protected]
422
   *   Technical details of permanent failure:
423
   *   PERM_FAILURE: SMTP Error (state 9): 550 5.7.1 Your message (sent through 209.85.132.244) was blocked by ROTA DNSBL. If you are not a spammer, open http://www.rota.lv/DNSBL and follow instructions or call +371 7019029, or send an e-mail message from another address to [email protected] with the blocked sender e-mail name.
424
   */
425 1 View Code Duplication
  elseif (preg_match("/Your message \([^)]+\) was blocked by/i", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
426
    $result['rule_cat'] = 'antispam';
427
    $result['rule_no'] = '0250';
428
  } /* rule: content_reject
429
   * sample:
430
   *   Failed to deliver to '<[email protected]>'
431
   *   Messages without To: fields are not accepted here
432
   */
433 1 View Code Duplication
  elseif (preg_match("/Messages\s+without\s+\S+\s+fields\s+are\s+not\s+accepted\s+here/i", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
434 1
    $result['rule_cat'] = 'content_reject';
435 1
    $result['rule_no'] = '0248';
436 1
  }  /* rule: inactive
437
   * sample:
438
   *   <[email protected]>:
439
   *   This address no longer accepts mail.
440
   */
441 1 View Code Duplication
  elseif (preg_match("/(?:alias|account|recipient|address|email|mailbox|user).*no\s+longer\s+accepts\s+mail/i", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
442
    $result['rule_cat'] = 'inactive';
443
    $result['rule_no'] = '0235';
444
  } /* rule: western chars only
445
   * sample:
446
   *   <[email protected]>:
447
   *   The user does not accept email in non-Western (non-Latin) character sets.
448
   */
449 1 View Code Duplication
  elseif (preg_match("/does not accept[^\r\n]*non-Western/i", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
450
    $result['rule_cat'] = 'latin_only';
451
    $result['rule_no'] = '0043';
452
  } /* rule: unknown
453
   * sample:
454
   *   554 delivery error
455
   *   This user doesn't have a yahoo.com account
456
   */
457 1 View Code Duplication
  elseif (preg_match("/554.*delivery error.*this user.*doesn't have.*account/is", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
458
    $result['rule_cat'] = 'unknown';
459
    $result['rule_no'] = '0044';
460
  } /* rule: unknown
461
   * sample:
462
   *   550 hotmail.com
463
   */
464 1 View Code Duplication
  elseif (preg_match('/550.*Requested.*action.*not.*taken:.*mailbox.*unavailable/is', $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
465
    $result['rule_cat'] = 'unknown';
466
    $result['rule_no'] = '0045';
467
  } /* rule: unknown
468
   * sample:
469
   *   550 5.1.1 aim.com
470
   */
471 1 View Code Duplication
  elseif (preg_match("/550 5\.1\.1.*Recipient address rejected/is", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
472
    $result['rule_cat'] = 'unknown';
473
    $result['rule_no'] = '0046';
474
  } /* rule: unknown
475
   * sample:
476
   *   550 .* (in reply to end of DATA command)
477
   */
478 1 View Code Duplication
  elseif (preg_match('/550.*in reply to end of DATA command/i', $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
479
    $result['rule_cat'] = 'unknown';
480
    $result['rule_no'] = '0047';
481
  } /* rule: unknown
482
   * sample:
483
   *   550 .* (in reply to RCPT TO command)
484
   */
485 1 View Code Duplication
  elseif (preg_match('/550.*in reply to RCPT TO command/i', $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
486
    $result['rule_cat'] = 'unknown';
487
    $result['rule_no'] = '0048';
488
  } /* rule: dns_unknown
489
   * sample:
490
   *    [email protected]:
491
   *      unrouteable mail domain "b.c"
492
   */
493 1 View Code Duplication
  elseif (preg_match("/unrouteable\s+mail\s+domain/i", $body, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
494 1
    $result['rule_cat'] = 'dns_unknown';
495 1
    $result['rule_no'] = '0247';
496 1
  }
497
498 2
  if ($result['rule_no'] !== '0000' && $result['email'] === '') {
499 2
    $preBody = substr($body, 0, strpos($body, $match[0]));
500
501 2
    $count = preg_match_all('/(\S+@\S+)/', $preBody, $match);
502 2
    if ($count) {
503 2
      $result['email'] = trim($match[1][$count - 1], "'\"()<>.:; \t\r\n\0\x0B");
504 2
    }
505 2
  }
506
507 2
  global $rule_categories, $bmh_newline;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
508 2
  if ($result['rule_no'] == '0000') {
509 1
    if ($debug_mode) {
510
      echo 'Body:' . $bmh_newline . $body . $bmh_newline;
511
      echo $bmh_newline;
512
    }
513 1 View Code Duplication
  } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
514 2
    if ($result['bounce_type'] === false) {
515 2
      $result['bounce_type'] = $rule_categories[$result['rule_cat']]['bounce_type'];
516 2
      $result['remove'] = $rule_categories[$result['rule_cat']]['remove'];
517 2
    }
518
  }
519
520 2
  return $result;
521
}
522
523
/**
524
 * Defined bounce parsing rules for standard DSN (Delivery Status Notification)
525
 *
526
 * @param string  $dsn_msg    human-readable explanation
527
 * @param string  $dsn_report delivery-status report
528
 * @param boolean $debug_mode show debug info. or not
529
 *
530
 * @return array    $result an array include the following fields: 'email', 'bounce_type','remove','rule_no','rule_cat'
531
 *                      if we could NOT detect the type of bounce, return rule_no = '0000'
532
 */
533
function bmhDSNRules($dsn_msg, $dsn_report, $debug_mode = false)
534
{
535
  // initialize the result array
536
  $result = array(
537 2
      'email'           => '',
538 2
      'bounce_type'     => false,
539 2
      'remove'          => 0,
540 2
      'rule_cat'        => 'unrecognized',
541 2
      'rule_no'         => '0000',
542 2
      'status_code'     => '',
543 2
      'action'          => '',
544 2
      'diagnostic_code' => '',
545 2
  );
546 2
  $action = false;
547 2
  $status_code = false;
548 2
  $diag_code = false;
549
550
  // ======= parse $dsn_report ======
551
  // get the recipient email
552 2
  if (preg_match('/Original-Recipient: rfc822;(.*)/i', $dsn_report, $match)) {
553 1
    $email = trim($match[1], "<> \t\r\n\0\x0B");
554
    /** @noinspection PhpUsageOfSilenceOperatorInspection */
555 1
    $email_arr = @imap_rfc822_parse_adrlist($email, 'default.domain.name');
556 1 View Code Duplication
    if (isset($email_arr[0]->host) && $email_arr[0]->host != '.SYNTAX-ERROR.' && $email_arr[0]->host != 'default.domain.name') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
557 1
      $result['email'] = $email_arr[0]->mailbox . '@' . $email_arr[0]->host;
558 1
    }
559 2
  } elseif (preg_match('/Final-Recipient: rfc822;(.*)/i', $dsn_report, $match)) {
560 2
    $email = trim($match[1], "<> \t\r\n\0\x0B");
561
    /** @noinspection PhpUsageOfSilenceOperatorInspection */
562 2
    $email_arr = @imap_rfc822_parse_adrlist($email, 'default.domain.name');
563 2 View Code Duplication
    if (isset($email_arr[0]->host) && $email_arr[0]->host != '.SYNTAX-ERROR.' && $email_arr[0]->host != 'default.domain.name') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
564 2
      $result['email'] = $email_arr[0]->mailbox . '@' . $email_arr[0]->host;
565 2
    }
566 2
  }
567
568 2 View Code Duplication
  if (preg_match('/Action: (.+)/i', $dsn_report, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
569 2
    $action = strtolower(trim($match[1]));
570 2
    $result['action'] = $action;
571 2
  }
572
573 2 View Code Duplication
  if (preg_match("/Status: ([0-9\.]+)/i", $dsn_report, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
574 2
    $status_code = $match[1];
575 2
    $result['status_code'] = $status_code;
576 2
  }
577
578
  // Could be multi-line , if the new line is beginning with SPACE or HTAB
579 2
  if (preg_match("/Diagnostic-Code:((?:[^\n]|\n[\t ])+)(?:\n[^\t ]|$)/is", $dsn_report, $match)) {
580 2
    $diag_code = $match[1];
581 2
  }
582
583
  // No Diagnostic-Code in email, use dsn message
584 2
  if (empty($diag_code)) {
585 2
    $diag_code = $dsn_msg;
586 2
  }
587
588 2
  $result['diagnostic_code'] = $diag_code;
589
590
  // ======= rules ======
591
592 2
  if (empty($result['email'])) {
593
    /* email address is empty
594
     * rule: full
595
     * sample:   DSN Message only
596
     * User quota exceeded: SMTP <[email protected]>
597
     */
598 1 View Code Duplication
    if (preg_match("/quota exceed.*<(\S+@\S+\w)>/is", $dsn_msg, $match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
599
      $result['rule_cat'] = 'full';
600
      $result['rule_no'] = '0161';
601
      $result['email'] = $match[1];
602
    }
603 1
  } else {
604
    /* action could be one of them as RFC:1894
605
     * "failed" / "delayed" / "delivered" / "relayed" / "expanded"
606
     */
607
    switch ($action) {
608 2
      case 'failed':
609
        /* rule: full
610
         * sample:
611
         *   Diagnostic-Code: X-Postfix; me.domain.com platform: said: 552 5.2.2 Over
612
         *     quota (in reply to RCPT TO command)
613
         */
614 2
        if (preg_match('/over.*quota/is', $diag_code)) {
615 1
          $result['rule_cat'] = 'full';
616 1
          $result['rule_no'] = '0105';
617 1
        } /* rule: full
618
         * sample:
619
         *   Diagnostic-Code: SMTP; 552 Requested mailbox exceeds quota.
620
         */
621 2
        elseif (preg_match('/exceed.*quota/is', $diag_code)) {
622
          $result['rule_cat'] = 'full';
623
          $result['rule_no'] = '0129';
624
        } /* rule: full
625
         * sample 1:
626
         *   Diagnostic-Code: smtp;552 5.2.2 This message is larger than the current system limit or the recipient's mailbox is full. Create a shorter message body or remove attachments and try sending it again.
627
         * sample 2:
628
         *   Diagnostic-Code: X-Postfix; host mta5.us4.domain.com.int[111.111.111.111] said:
629
         *     552 recipient storage full, try again later (in reply to RCPT TO command)
630
         * sample 3:
631
         *   Diagnostic-Code: X-HERMES; host 127.0.0.1[127.0.0.1] said: 551 bounce as<the
632
         *     destination mailbox <[email protected]> is full> queue as
633
         *     [email protected] (in reply to end of
634
         *     DATA command)
635
         */
636 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*full/is', $diag_code)) {
637 1
          $result['rule_cat'] = 'full';
638 1
          $result['rule_no'] = '0145';
639 1
        } /* rule: full
640
         * sample:
641
         *   Diagnostic-Code: SMTP; 452 Insufficient system storage
642
         */
643 2
        elseif (preg_match('/Insufficient system storage/is', $diag_code)) {
644
          $result['rule_cat'] = 'full';
645
          $result['rule_no'] = '0134';
646
        } /* rule: full
647
         * sample:
648
         *   Diagnostic-Code: SMTP; 422 Benutzer hat zuviele Mails auf dem Server
649
         */
650 2
        elseif (preg_match('/Benutzer hat zuviele Mails auf dem Server/is', $diag_code)) {
651
          $result['rule_cat'] = 'full';
652
          $result['rule_no'] = '0998';
653
        } /* rule: full
654
         * sample:
655
         *   Diagnostic-Code: SMTP; 422 exceeded storage allocation
656
         */
657 2
        elseif (preg_match('/exceeded storage allocation/is', $diag_code)) {
658
          $result['rule_cat'] = 'full';
659
          $result['rule_no'] = '0997';
660
        } /* rule: full
661
         * sample:
662
         *   Diagnostic-Code: SMTP; 422 Mailbox quota usage exceeded
663
         */
664 2
        elseif (preg_match('/Mailbox quota usage exceeded/is', $diag_code)) {
665
          $result['rule_cat'] = 'full';
666
          $result['rule_no'] = '0996';
667
        } /* rule: full
668
         * sample:
669
         *   Diagnostic-Code: SMTP; 422 User has exhausted allowed storage space
670
         */
671 2
        elseif (preg_match('/User has exhausted allowed storage space/is', $diag_code)) {
672
          $result['rule_cat'] = 'full';
673
          $result['rule_no'] = '0995';
674
        } /* rule: full
675
         * sample:
676
         *   Diagnostic-Code: SMTP; 422 User mailbox exceeds allowed size
677
         */
678 2
        elseif (preg_match('/User mailbox exceeds allowed size/is', $diag_code)) {
679
          $result['rule_cat'] = 'full';
680
          $result['rule_no'] = '0994';
681
        } /* rule: full
682
         * sample:
683
         *   Diagnostic-Code: smpt; 552 Account(s) <[email protected]> does not have enough space
684
         */
685 2
        elseif (preg_match("/not.*enough\s+space/i", $diag_code)) {
686 1
          $result['rule_cat'] = 'full';
687 1
          $result['rule_no'] = '0246';
688 1
        } /* rule: full
689
         * sample 1:
690
         *   Diagnostic-Code: X-Postfix; cannot append message to destination file
691
         *     /var/mail/dale.me89g: error writing message: File too large
692
         * sample 2:
693
         *   Diagnostic-Code: X-Postfix; cannot access mailbox /var/spool/mail/b8843022 for
694
         *     user xxxxx. error writing message: File too large
695
         */
696 2
        elseif (preg_match('/File too large/is', $diag_code)) {
697
          $result['rule_cat'] = 'full';
698
          $result['rule_no'] = '0192';
699
        } /* rule: oversize
700
         * sample:
701
         *   Diagnostic-Code: smtp;552 5.2.2 This message is larger than the current system limit or the recipient's mailbox is full. Create a shorter message body or remove attachments and try sending it again.
702
         */
703 2
        elseif (preg_match('/larger than.*limit/is', $diag_code)) {
704
          $result['rule_cat'] = 'oversize';
705
          $result['rule_no'] = '0146';
706
        } /* rule: unknown
707
         * sample:
708
         *   Diagnostic-Code: X-Notes; User xxxxx ([email protected]) not listed in public Name & Address Book
709
         */
710 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user)(.*)not(.*)list/is', $diag_code)) {
711 1
          $result['rule_cat'] = 'unknown';
712 1
          $result['rule_no'] = '0103';
713 1
        } /* rule: unknown
714
         * sample:
715
         *   Diagnostic-Code: smtp; 450 user path no exist
716
         */
717 2
        elseif (preg_match('/user path no exist/is', $diag_code)) {
718
          $result['rule_cat'] = 'unknown';
719
          $result['rule_no'] = '0106';
720
        } /* rule: unknown
721
         * sample 1:
722
         *   Diagnostic-Code: SMTP; 550 Relaying denied.
723
         * sample 2:
724
         *   Diagnostic-Code: SMTP; 554 <[email protected]>: Relay access denied
725
         * sample 3:
726
         *   Diagnostic-Code: SMTP; 550 relaying to <[email protected]> prohibited by administrator
727
         */
728 2
        elseif (preg_match('/Relay.*(?:denied|prohibited)/is', $diag_code)) {
729 1
          $result['rule_cat'] = 'unknown';
730 1
          $result['rule_no'] = '0108';
731 1
        } /* rule: unknown
732
         * sample:
733
         *   Diagnostic-Code: SMTP; 554 qq Sorry, no valid recipients (#5.1.3)
734
         */
735 2
        elseif (preg_match('/no.*valid.*(?:alias|account|recipient|address|email|mailbox|user)/is', $diag_code)) {
736
          $result['rule_cat'] = 'unknown';
737
          $result['rule_no'] = '0185';
738
        } /* rule: unknown
739
         * sample 1:
740
         *   Diagnostic-Code: SMTP; 550 «Dªk¦a§} - invalid address (#5.5.0)
741
         * sample 2:
742
         *   Diagnostic-Code: SMTP; 550 Invalid recipient: <[email protected]>
743
         * sample 3:
744
         *   Diagnostic-Code: SMTP; 550 <[email protected]>: Invalid User
745
         */
746 2
        elseif (preg_match('/Invalid.*(?:alias|account|recipient|address|email|mailbox|user)/is', $diag_code)) {
747 1
          $result['rule_cat'] = 'unknown';
748 1
          $result['rule_no'] = '0111';
749 1
        } /* rule: unknown
750
         * sample:
751
         *   Diagnostic-Code: SMTP; 554 delivery error: dd Sorry your message to [email protected] cannot be delivered. This account has been disabled or discontinued [#102]. - mta173.mail.tpe.domain.com
752
         */
753 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*(?:disabled|discontinued)/is', $diag_code)) {
754 1
          $result['rule_cat'] = 'unknown';
755 1
          $result['rule_no'] = '0114';
756 1
        } /* rule: unknown
757
         * sample:
758
         *   Diagnostic-Code: SMTP; 554 delivery error: dd This user doesn't have a domain.com account ([email protected]) [0] - mta134.mail.tpe.domain.com
759
         */
760 2
        elseif (preg_match("/user doesn't have.*account/is", $diag_code)) {
761 2
          $result['rule_cat'] = 'unknown';
762 2
          $result['rule_no'] = '0127';
763 2
        } /* rule: unknown
764
         * sample:
765
         *   Diagnostic-Code: SMTP; 550 5.1.1 unknown or illegal alias: [email protected]
766
         */
767 2
        elseif (preg_match('/(?:unknown|illegal).*(?:alias|account|recipient|address|email|mailbox|user)/is', $diag_code)) {
768 2
          $result['rule_cat'] = 'unknown';
769 2
          $result['rule_no'] = '0128';
770 2
        } /* rule: unknown
771
         * sample 1:
772
         *   Diagnostic-Code: SMTP; 450 mailbox unavailable.
773
         * sample 2:
774
         *   Diagnostic-Code: SMTP; 550 5.7.1 Requested action not taken: mailbox not available
775
         */
776 2
        elseif (preg_match("/(?:alias|account|recipient|address|email|mailbox|user).*(?:un|not\s+)available/is", $diag_code)) {
777 1
          $result['rule_cat'] = 'unknown';
778 1
          $result['rule_no'] = '0122';
779 1
        } /* rule: unknown
780
         * sample:
781
         *   Diagnostic-Code: SMTP; 553 sorry, no mailbox here by that name (#5.7.1)
782
         */
783 2
        elseif (preg_match('/no (?:alias|account|recipient|address|email|mailbox|user)/is', $diag_code)) {
784 1
          $result['rule_cat'] = 'unknown';
785 1
          $result['rule_no'] = '0123';
786 1
        } /* rule: unknown
787
         * sample 1:
788
         *   Diagnostic-Code: SMTP; 550 User ([email protected]) unknown.
789
         * sample 2:
790
         *   Diagnostic-Code: SMTP; 553 5.3.0 <[email protected]>... Addressee unknown, relay=[111.111.111.000]
791
         */
792 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*unknown/is', $diag_code)) {
793 1
          $result['rule_cat'] = 'unknown';
794 1
          $result['rule_no'] = '0125';
795 1
        } /* rule: unknown
796
         * sample 1:
797
         *   Diagnostic-Code: SMTP; 550 user disabled
798
         * sample 2:
799
         *   Diagnostic-Code: SMTP; 452 4.2.1 mailbox temporarily disabled: [email protected]
800
         */
801 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*disabled/is', $diag_code)) {
802
          $result['rule_cat'] = 'unknown';
803
          $result['rule_no'] = '0133';
804
        } /* rule: unknown
805
         * sample:
806
         *   Diagnostic-Code: SMTP; 550 <[email protected]>: Recipient address rejected: No such user ([email protected])
807
         */
808 2
        elseif (preg_match('/No such (?:alias|account|recipient|address|email|mailbox|user)/is', $diag_code)) {
809
          $result['rule_cat'] = 'unknown';
810
          $result['rule_no'] = '0143';
811
        } /* rule: unknown
812
         * sample 1:
813
         *   Diagnostic-Code: SMTP; 550 MAILBOX NOT FOUND
814
         * sample 2:
815
         *   Diagnostic-Code: SMTP; 550 Mailbox ( [email protected] ) not found or inactivated
816
         */
817 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*NOT FOUND/is', $diag_code)) {
818
          $result['rule_cat'] = 'unknown';
819
          $result['rule_no'] = '0136';
820
        } /* rule: unknown
821
         * sample:
822
         *    Diagnostic-Code: X-Postfix; host m2w-in1.domain.com[111.111.111.000] said: 551
823
         *    <[email protected]> is a deactivated mailbox (in reply to RCPT TO
824
         *    command)
825
         */
826 2
        elseif (preg_match('/deactivated (?:alias|account|recipient|address|email|mailbox|user)/is', $diag_code)) {
827
          $result['rule_cat'] = 'unknown';
828
          $result['rule_no'] = '0138';
829
        } /* rule: unknown
830
         * sample:
831
         *   Diagnostic-Code: SMTP; 550 <[email protected]> recipient rejected
832
         *   ...
833
         *   <<< 550 <[email protected]> recipient rejected
834
         *   550 5.1.1 [email protected]... User unknown
835
         */
836 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*reject/is', $diag_code)) {
837 2
          $result['rule_cat'] = 'unknown';
838 2
          $result['rule_no'] = '0148';
839 2
        } /* rule: unknown
840
         * sample:
841
         *   Diagnostic-Code: smtp; 5.x.0 - Message bounced by administrator  (delivery attempts: 0)
842
         */
843 2
        elseif (preg_match('/bounce.*administrator/is', $diag_code)) {
844
          $result['rule_cat'] = 'unknown';
845
          $result['rule_no'] = '0151';
846
        } /* rule: unknown
847
         * sample:
848
         *   Diagnostic-Code: SMTP; 550 <maxqin> is now disabled with MTA service.
849
         */
850 2
        elseif (preg_match('/<.*>.*disabled/is', $diag_code)) {
851
          $result['rule_cat'] = 'unknown';
852
          $result['rule_no'] = '0152';
853
        } /* rule: unknown
854
         * sample:
855
         *   Diagnostic-Code: SMTP; 551 not our customer
856
         */
857 2
        elseif (preg_match('/not our customer/is', $diag_code)) {
858
          $result['rule_cat'] = 'unknown';
859
          $result['rule_no'] = '0154';
860
        } /* rule: unknown
861
         * sample:
862
         *   Diagnostic-Code: smtp; 5.1.0 - Unknown address error 540-'Error: Wrong recipients' (delivery attempts: 0)
863
         */
864 2
        elseif (preg_match('/Wrong (?:alias|account|recipient|address|email|mailbox|user)/is', $diag_code)) {
865
          $result['rule_cat'] = 'unknown';
866
          $result['rule_no'] = '0159';
867
        } /* rule: unknown
868
         * sample:
869
         *   Diagnostic-Code: smtp; 5.1.0 - Unknown address error 540-'Error: Wrong recipients' (delivery attempts: 0)
870
         * sample 2:
871
         *   Diagnostic-Code: SMTP; 501 #5.1.1 bad address [email protected]
872
         */
873 2
        elseif (preg_match('/(?:unknown|bad).*(?:alias|account|recipient|address|email|mailbox|user)/is', $diag_code)) {
874
          $result['rule_cat'] = 'unknown';
875
          $result['rule_no'] = '0160';
876
        } /* rule: unknown
877
         * sample:
878
         *   Status: 5.1.1 (bad destination mailbox address)
879
         */
880 2
        elseif (preg_match('/(?:unknown|bad).*(?:alias|account|recipient|address|email|mailbox|user)/is', $status_code)) {
881
          $result['rule_cat'] = 'unknown';
882
          $result['rule_no'] = '01601';
883
        } /* rule: unknown
884
         * sample:
885
         *   Diagnostic-Code: SMTP; 550 Command RCPT User <[email protected]> not OK
886
         */
887 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*not OK/is', $diag_code)) {
888
          $result['rule_cat'] = 'unknown';
889
          $result['rule_no'] = '0186';
890
        } /* rule: unknown
891
         * sample:
892
         *   Diagnostic-Code: SMTP; 550 5.7.1 Access-Denied-XM.SSR-001
893
         */
894 2
        elseif (preg_match('/Access.*Denied/is', $diag_code)) {
895
          $result['rule_cat'] = 'unknown';
896
          $result['rule_no'] = '0189';
897
        } /* rule: unknown
898
         * sample:
899
         *   Diagnostic-Code: SMTP; 550 5.1.1 <[email protected]>... email address lookup in domain map failed
900
         */
901 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*lookup.*fail/is', $diag_code)) {
902
          $result['rule_cat'] = 'unknown';
903
          $result['rule_no'] = '0195';
904
        } /* rule: unknown
905
         * sample:
906
         *   Diagnostic-Code: SMTP; 550 User not a member of domain: <[email protected]>
907
         */
908 2
        elseif (preg_match('/(?:recipient|address|email|mailbox|user).*not.*member of domain/is', $diag_code)) {
909
          $result['rule_cat'] = 'unknown';
910
          $result['rule_no'] = '0198';
911
        } /* rule: unknown
912
         * sample:
913
         *   Diagnostic-Code: SMTP; 550-"The recipient cannot be verified.  Please check all recipients of this
914
         */
915 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*cannot be verified/is', $diag_code)) {
916
          $result['rule_cat'] = 'unknown';
917
          $result['rule_no'] = '0202';
918
        } /* rule: unknown
919
         * sample:
920
         *   Diagnostic-Code: SMTP; 550 Unable to relay for [email protected]
921
         */
922 2
        elseif (preg_match('/Unable to relay/is', $diag_code)) {
923
          $result['rule_cat'] = 'unknown';
924
          $result['rule_no'] = '0203';
925
        } /* rule: unknown
926
         * sample 1:
927
         *   Diagnostic-Code: SMTP; 550 [email protected]:user not exist
928
         * sample 2:
929
         *   Diagnostic-Code: SMTP; 550 sorry, that recipient doesn't exist (#5.7.1)
930
         */
931 2
        elseif (preg_match("/(?:alias|account|recipient|address|email|mailbox|user).*(?:n't|not) exist/is", $diag_code)) {
932 2
          $result['rule_cat'] = 'unknown';
933 2
          $result['rule_no'] = '0205';
934 2
        } /* rule: unknown
935
         * sample:
936
         *   Diagnostic-Code: SMTP; 550-I'm sorry but [email protected] does not have an account here. I will not
937
         */
938 2
        elseif (preg_match('/not have an account/is', $diag_code)) {
939
          $result['rule_cat'] = 'unknown';
940
          $result['rule_no'] = '0207';
941
        } /* rule: unknown
942
         * sample:
943
         *   Diagnostic-Code: SMTP; 550 This account is not [email protected]
944
         */
945 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*is not allowed/is', $diag_code)) {
946
          $result['rule_cat'] = 'unknown';
947
          $result['rule_no'] = '0220';
948
        } /* rule: unknown
949
         * sample:
950
         *   Diagnostic-Code: X-Notes; Recipient user name info ([email protected]) not unique.  Several matches found in Domino Directory.
951
         */
952 2
        elseif (preg_match('/not unique.\s+Several matches found/i', $diag_code)) {
953
          $result['rule_cat'] = 'unknown';
954
          $result['rule_no'] = '0255';
955
        } /* rule: inactive
956
         * sample:
957
         *   Diagnostic-Code: SMTP; 550 <[email protected]>: inactive user
958
         */
959 2
        elseif (preg_match('/inactive.*(?:alias|account|recipient|address|email|mailbox|user)/is', $diag_code)) {
960
          $result['rule_cat'] = 'inactive';
961
          $result['rule_no'] = '0135';
962
        } /* rule: inactive
963
         * sample:
964
         *   Diagnostic-Code: SMTP; 550 [email protected] Account Inactive
965
         */
966 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*Inactive/is', $diag_code)) {
967
          $result['rule_cat'] = 'inactive';
968
          $result['rule_no'] = '0155';
969
        } /* rule: inactive
970
         * sample:
971
         *   Diagnostic-Code: SMTP; 550 <[email protected]>: Recipient address rejected: Account closed due to inactivity. No forwarding information is available.
972
         */
973 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user) closed due to inactivity/is', $diag_code)) {
974
          $result['rule_cat'] = 'inactive';
975
          $result['rule_no'] = '0170';
976
        } /* rule: inactive
977
         * sample:
978
         *   Diagnostic-Code: SMTP; 550 <[email protected]>... User account not activated
979
         */
980 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user) not activated/is', $diag_code)) {
981
          $result['rule_cat'] = 'inactive';
982
          $result['rule_no'] = '0177';
983
        } /* rule: inactive
984
         * sample 1:
985
         *   Diagnostic-Code: SMTP; 550 User suspended
986
         * sample 2:
987
         *   Diagnostic-Code: SMTP; 550 account expired
988
         */
989 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*(?:suspend|expire)/is', $diag_code)) {
990
          $result['rule_cat'] = 'inactive';
991
          $result['rule_no'] = '0183';
992
        } /* rule: inactive
993
         * sample:
994
         *   Diagnostic-Code: SMTP; 553 5.3.0 <[email protected]>... Recipient address no longer exists
995
         */
996 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*no longer exist/is', $diag_code)) {
997
          $result['rule_cat'] = 'inactive';
998
          $result['rule_no'] = '0184';
999
        } /* rule: inactive
1000
         * sample:
1001
         *   Diagnostic-Code: SMTP; 553 VS10-RT Possible forgery or deactivated due to abuse (#5.1.1) 111.111.111.211
1002
         */
1003 2
        elseif (preg_match('/(?:forgery|abuse)/is', $diag_code)) {
1004
          $result['rule_cat'] = 'inactive';
1005
          $result['rule_no'] = '0196';
1006
        } /* rule: inactive
1007
         * sample:
1008
         *   Diagnostic-Code: SMTP; 553 mailbox [email protected] is restricted
1009
         */
1010 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*restrict/is', $diag_code)) {
1011
          $result['rule_cat'] = 'inactive';
1012
          $result['rule_no'] = '0209';
1013
        } /* rule: inactive
1014
         * sample:
1015
         *   Diagnostic-Code: SMTP; 550 <[email protected]>: User status is locked.
1016
         */
1017 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*locked/is', $diag_code)) {
1018
          $result['rule_cat'] = 'inactive';
1019
          $result['rule_no'] = '0228';
1020
        } /* rule: user_reject
1021
         * sample:
1022
         *   Diagnostic-Code: SMTP; 553 User refused to receive this mail.
1023
         */
1024 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user) refused/is', $diag_code)) {
1025
          $result['rule_cat'] = 'user_reject';
1026
          $result['rule_no'] = '0156';
1027
        } /* rule: user_reject
1028
         * sample:
1029
         *   Diagnostic-Code: SMTP; 501 [email protected] Sender email is not in my domain
1030
         */
1031 2
        elseif (preg_match('/sender.*not/is', $diag_code)) {
1032
          $result['rule_cat'] = 'user_reject';
1033
          $result['rule_no'] = '0206';
1034
        } /* rule: command_reject
1035
         * sample:
1036
         *   Diagnostic-Code: SMTP; 554 Message refused
1037
         */
1038 2
        elseif (preg_match('/Message refused/is', $diag_code)) {
1039
          $result['rule_cat'] = 'command_reject';
1040
          $result['rule_no'] = '0175';
1041
        } /* rule: command_reject
1042
         * sample:
1043
         *   Diagnostic-Code: SMTP; 550 5.0.0 <[email protected]>... No permit
1044
         */
1045 2
        elseif (preg_match('/No permit/is', $diag_code)) {
1046
          $result['rule_cat'] = 'command_reject';
1047
          $result['rule_no'] = '0190';
1048
        } /* rule: command_reject
1049
         * sample:
1050
         *   Diagnostic-Code: SMTP; 553 sorry, that domain isn't in my list of allowed rcpthosts (#5.5.3 - chkuser)
1051
         */
1052 2
        elseif (preg_match("/domain isn't in.*allowed rcpthost/is", $diag_code)) {
1053
          $result['rule_cat'] = 'command_reject';
1054
          $result['rule_no'] = '0191';
1055
        } /* rule: command_reject
1056
         * sample:
1057
         *   Diagnostic-Code: SMTP; 553 AUTH FAILED - [email protected]
1058
         */
1059 2
        elseif (preg_match('/AUTH FAILED/is', $diag_code)) {
1060
          $result['rule_cat'] = 'command_reject';
1061
          $result['rule_no'] = '0197';
1062
        } /* rule: command_reject
1063
         * sample 1:
1064
         *   Diagnostic-Code: SMTP; 550 relay not permitted
1065
         * sample 2:
1066
         *   Diagnostic-Code: SMTP; 530 5.7.1 Relaying not allowed: [email protected]
1067
         */
1068 2
        elseif (preg_match('/relay.*not.*(?:permit|allow)/is', $diag_code)) {
1069
          $result['rule_cat'] = 'command_reject';
1070
          $result['rule_no'] = '0241';
1071
        } /* rule: command_reject
1072
         * sample:
1073
         *   Diagnostic-Code: SMTP; 550 not local host domain.com, not a gateway
1074
         */
1075 2
        elseif (preg_match('/not local host/is', $diag_code)) {
1076
          $result['rule_cat'] = 'command_reject';
1077
          $result['rule_no'] = '0204';
1078
        } /* rule: command_reject
1079
         * sample:
1080
         *   Diagnostic-Code: SMTP; 500 Unauthorized relay msg rejected
1081
         */
1082 2
        elseif (preg_match('/Unauthorized relay/is', $diag_code)) {
1083
          $result['rule_cat'] = 'command_reject';
1084
          $result['rule_no'] = '0215';
1085
        } /* rule: command_reject
1086
         * sample:
1087
         *   Diagnostic-Code: SMTP; 554 Transaction failed
1088
         */
1089 2
        elseif (preg_match('/Transaction.*fail/is', $diag_code)) {
1090
          $result['rule_cat'] = 'command_reject';
1091
          $result['rule_no'] = '0221';
1092
        } /* rule: command_reject
1093
         * sample:
1094
         *   Diagnostic-Code: smtp;554 5.5.2 Invalid data in message
1095
         */
1096 2
        elseif (preg_match('/Invalid data/is', $diag_code)) {
1097
          $result['rule_cat'] = 'command_reject';
1098
          $result['rule_no'] = '0223';
1099
        } /* rule: command_reject
1100
         * sample:
1101
         *   Diagnostic-Code: SMTP; 550 Local user only or Authentication mechanism
1102
         */
1103 2
        elseif (preg_match('/Local user only/is', $diag_code)) {
1104
          $result['rule_cat'] = 'command_reject';
1105
          $result['rule_no'] = '0224';
1106
        } /* rule: command_reject
1107
         * sample:
1108
         *   Diagnostic-Code: SMTP; 550-ds176.domain.com [111.111.111.211] is currently not permitted to
1109
         *   relay through this server. Perhaps you have not logged into the pop/imap
1110
         *   server in the last 30 minutes or do not have SMTP Authentication turned on
1111
         *   in your email client.
1112
         */
1113 2
        elseif (preg_match('/not.*permit.*to/is', $diag_code)) {
1114
          $result['rule_cat'] = 'command_reject';
1115
          $result['rule_no'] = '0225';
1116
        } /* rule: content_reject
1117
         * sample:
1118
         *   Diagnostic-Code: SMTP; 550 Content reject. FAAAANsG60M9BmDT.1
1119
         */
1120 2
        elseif (preg_match('/Content reject/is', $diag_code)) {
1121
          $result['rule_cat'] = 'content_reject';
1122
          $result['rule_no'] = '0165';
1123
        } /* rule: content_reject
1124
         * sample:
1125
         *   Diagnostic-Code: SMTP; 552 MessageWall: MIME/REJECT: Invalid structure
1126
         */
1127 2
        elseif (preg_match("/MIME\/REJECT/is", $diag_code)) {
1128
          $result['rule_cat'] = 'content_reject';
1129
          $result['rule_no'] = '0212';
1130
        } /* rule: content_reject
1131
         * sample:
1132
         *   Diagnostic-Code: smtp; 554 5.6.0 Message with invalid header rejected, id=13462-01 - MIME error: error: UnexpectedBound: part didn't end with expected boundary [in multipart message]; EOSToken: EOF; EOSType: EOF
1133
         */
1134 2
        elseif (preg_match('/MIME error/is', $diag_code)) {
1135
          $result['rule_cat'] = 'content_reject';
1136
          $result['rule_no'] = '0217';
1137
        } /* rule: content_reject
1138
         * sample:
1139
         *   Diagnostic-Code: SMTP; 553 Mail data refused by AISP, rule [169648].
1140
         */
1141 2
        elseif (preg_match('/Mail data refused.*AISP/is', $diag_code)) {
1142
          $result['rule_cat'] = 'content_reject';
1143
          $result['rule_no'] = '0218';
1144
        } /* rule: dns_unknown
1145
         * sample:
1146
         *   Diagnostic-Code: SMTP; 550 Host unknown
1147
         */
1148 2
        elseif (preg_match('/Host unknown/is', $diag_code)) {
1149 1
          $result['rule_cat'] = 'dns_unknown';
1150 1
          $result['rule_no'] = '0130';
1151 1
        } /* rule: dns_unknown
1152
         * sample:
1153
         *   Diagnostic-Code: SMTP; 553 Specified domain is not allowed.
1154
         */
1155 2
        elseif (preg_match('/Specified domain.*not.*allow/is', $diag_code)) {
1156
          $result['rule_cat'] = 'dns_unknown';
1157
          $result['rule_no'] = '0180';
1158
        } /* rule: dns_unknown
1159
         * sample:
1160
         *   Diagnostic-Code: X-Postfix; delivery temporarily suspended: connect to
1161
         *   111.111.11.112[111.111.11.112]: No route to host
1162
         */
1163 2
        elseif (preg_match('/No route to host/is', $diag_code)) {
1164
          $result['rule_cat'] = 'dns_unknown';
1165
          $result['rule_no'] = '0188';
1166
        } /* rule: dns_unknown
1167
         * sample:
1168
         *   Diagnostic-Code: SMTP; 550 unrouteable address
1169
         */
1170 2
        elseif (preg_match('/unrouteable address/is', $diag_code)) {
1171
          $result['rule_cat'] = 'dns_unknown';
1172
          $result['rule_no'] = '0208';
1173
        } /* rule: dns_unknown
1174
         * sample:
1175
         *   Diagnostic-Code: X-Postfix; Host or domain name not found. Name service error
1176
         *     for name=aaaaaaaaaaa type=A: Host not found
1177
         */
1178 2
        elseif (preg_match('/Host or domain name not found/is', $diag_code)) {
1179 1
          $result['rule_cat'] = 'dns_unknown';
1180 1
          $result['rule_no'] = '0238';
1181 1
        } /* rule: dns_loop
1182
         * sample:
1183
         *   Diagnostic-Code: X-Postfix; mail for mta.example.com loops back to myself
1184
         */
1185 2
        elseif (preg_match('/loops back to myself/i', $diag_code)) {
1186 1
          $result['rule_cat'] = 'dns_loop';
1187 1
          $result['rule_no'] = '0245';
1188 1
        } /* rule: defer
1189
         * sample:
1190
         *   Diagnostic-Code: SMTP; 451 System(u) busy, try again later.
1191
         */
1192 1
        elseif (preg_match('/System.*busy/is', $diag_code)) {
1193
          $result['rule_cat'] = 'defer';
1194
          $result['rule_no'] = '0112';
1195
        } /* rule: defer
1196
         * sample:
1197
         *   Diagnostic-Code: SMTP; 451 mta172.mail.tpe.domain.com Resources temporarily unavailable. Please try again later.  [#4.16.4:70].
1198
         */
1199 1
        elseif (preg_match('/Resources temporarily unavailable/is', $diag_code)) {
1200
          $result['rule_cat'] = 'defer';
1201
          $result['rule_no'] = '0116';
1202
        } /* rule: antispam, deny ip
1203
         * sample:
1204
         *   Diagnostic-Code: SMTP; 554 sender is rejected: 0,mx20,wKjR5bDrnoM2yNtEZVAkBg==.32467S2
1205
         */
1206 1
        elseif (preg_match('/sender is rejected/is', $diag_code)) {
1207
          $result['rule_cat'] = 'antispam';
1208
          $result['rule_no'] = '0101';
1209
        } /* rule: antispam, deny ip
1210
         * sample:
1211
         *   Diagnostic-Code: SMTP; 554 <unknown[111.111.111.000]>: Client host rejected: Access denied
1212
         */
1213 1
        elseif (preg_match('/Client host rejected/is', $diag_code)) {
1214
          $result['rule_cat'] = 'antispam';
1215
          $result['rule_no'] = '0102';
1216
        } /* rule: antispam, mismatch ip
1217
         * sample:
1218
         *   Diagnostic-Code: SMTP; 554 Connection refused(mx). MAIL FROM [[email protected]] mismatches client IP [111.111.111.000].
1219
         */
1220 1
        elseif (preg_match('/MAIL FROM(.*)mismatches client IP/is', $diag_code)) {
1221
          $result['rule_cat'] = 'antispam';
1222
          $result['rule_no'] = '0104';
1223
        } /* rule: antispam, deny ip
1224
         * sample:
1225
         *   Diagnostic-Code: SMTP; 554 Please visit http:// antispam.domain.com/denyip.php?IP=111.111.111.000 (#5.7.1)
1226
         */
1227 1
        elseif (preg_match('/denyip/is', $diag_code)) {
1228
          $result['rule_cat'] = 'antispam';
1229
          $result['rule_no'] = '0144';
1230
        } /* rule: antispam, deny ip
1231
         * sample:
1232
         *   Diagnostic-Code: SMTP; 554 Service unavailable; Client host [111.111.111.211] blocked using dynablock.domain.com; Your message could not be delivered due to complaints we received regarding the IP address you're using or your ISP. See http:// blackholes.domain.com/ Error: WS-02
1233
         */
1234 1
        elseif (preg_match('/client host.*blocked/is', $diag_code)) {
1235
          $result['rule_cat'] = 'antispam';
1236
          $result['rule_no'] = '0242';
1237
        } /* rule: antispam, reject
1238
         * sample:
1239
         *   Diagnostic-Code: SMTP; 550 Requested action not taken: mail IsCNAPF76kMDARUY.56621S2 is rejected,mx3,BM
1240
         */
1241 1
        elseif (preg_match('/mail.*reject/is', $diag_code)) {
1242
          $result['rule_cat'] = 'antispam';
1243
          $result['rule_no'] = '0147';
1244
        } /* rule: antispam
1245
         * sample:
1246
         *   Diagnostic-Code: SMTP; 552 sorry, the spam message is detected (#5.6.0)
1247
         */
1248 1
        elseif (preg_match('/spam.*detect/is', $diag_code)) {
1249
          $result['rule_cat'] = 'antispam';
1250
          $result['rule_no'] = '0162';
1251
        } /* rule: antispam
1252
         * sample:
1253
         *   Diagnostic-Code: SMTP; 554 5.7.1 Rejected as Spam see: http:// rejected.domain.com/help/spam/rejected.html
1254
         */
1255 1
        elseif (preg_match('/reject.*spam/is', $diag_code)) {
1256
          $result['rule_cat'] = 'antispam';
1257
          $result['rule_no'] = '0216';
1258
        } /* rule: antispam
1259
         * sample:
1260
         *   Diagnostic-Code: SMTP; 553 5.7.1 <[email protected]>... SpamTrap=reject mode, dsn=5.7.1, Message blocked by BOX Solutions (www.domain.com) SpamTrap Technology, please contact the domain.com site manager for help: (ctlusr8012).
1261
         */
1262 1
        elseif (preg_match('/SpamTrap/is', $diag_code)) {
1263
          $result['rule_cat'] = 'antispam';
1264
          $result['rule_no'] = '0200';
1265
        } /* rule: antispam, mailfrom mismatch
1266
         * sample:
1267
         *   Diagnostic-Code: SMTP; 550 Verify mailfrom failed,blocked
1268
         */
1269 1
        elseif (preg_match('/Verify mailfrom failed/is', $diag_code)) {
1270
          $result['rule_cat'] = 'antispam';
1271
          $result['rule_no'] = '0210';
1272
        } /* rule: antispam, mailfrom mismatch
1273
         * sample:
1274
         *   Diagnostic-Code: SMTP; 550 Error: MAIL FROM is mismatched with message header from address!
1275
         */
1276 1
        elseif (preg_match('/MAIL.*FROM.*mismatch/is', $diag_code)) {
1277
          $result['rule_cat'] = 'antispam';
1278
          $result['rule_no'] = '0226';
1279
        } /* rule: antispam
1280
         * sample:
1281
         *   Diagnostic-Code: SMTP; 554 5.7.1 Message scored too high on spam scale.  For help, please quote incident ID 22492290.
1282
         */
1283 1
        elseif (preg_match('/spam scale/is', $diag_code)) {
1284
          $result['rule_cat'] = 'antispam';
1285
          $result['rule_no'] = '0211';
1286
        } /* rule: antispam
1287
         * sample:
1288
         *   Diagnostic-Code: SMTP; 554 5.7.1 reject: Client host bypassing service provider's mail relay: ds176.domain.com
1289
         */
1290 1
        elseif (preg_match('/Client host bypass/is', $diag_code)) {
1291
          $result['rule_cat'] = 'antispam';
1292
          $result['rule_no'] = '0229';
1293
        } /* rule: antispam
1294
         * sample:
1295
         *   Diagnostic-Code: SMTP; 550 sorry, it seems as a junk mail
1296
         */
1297 1
        elseif (preg_match('/junk mail/is', $diag_code)) {
1298
          $result['rule_cat'] = 'antispam';
1299
          $result['rule_no'] = '0230';
1300
        } /* rule: antispam
1301
         * sample:
1302
         *   Diagnostic-Code: SMTP; 553-Message filtered. Please see the FAQs section on spam
1303
         */
1304 1
        elseif (preg_match('/message filtered/is', $diag_code)) {
1305
          $result['rule_cat'] = 'antispam';
1306
          $result['rule_no'] = '0243';
1307
        } /* rule: antispam, subject filter
1308
         * sample:
1309
         *   Diagnostic-Code: SMTP; 554 5.7.1 The message from (<[email protected]>) with the subject of ( *(ca2639) 7|-{%2E* : {2"(%EJ;y} (SBI$#$@<K*:7s1!=l~) matches a profile the Internet community may consider spam. Please revise your message before resending.
1310
         */
1311 1
        elseif (preg_match('/subject.*consider.*spam/is', $diag_code)) {
1312
          $result['rule_cat'] = 'antispam';
1313
          $result['rule_no'] = '0222';
1314
        } /* rule: internal_error
1315
         * sample:
1316
         *   Diagnostic-Code: SMTP; 451 Temporary local problem - please try later
1317
         */
1318 1
        elseif (preg_match('/Temporary local problem/is', $diag_code)) {
1319
          $result['rule_cat'] = 'internal_error';
1320
          $result['rule_no'] = '0142';
1321
        } /* rule: internal_error
1322
         * sample:
1323
         *   Diagnostic-Code: SMTP; 553 5.3.5 system config error
1324
         */
1325 1
        elseif (preg_match('/system config error/is', $diag_code)) {
1326
          $result['rule_cat'] = 'internal_error';
1327
          $result['rule_no'] = '0153';
1328
        } /* rule: delayed
1329
         * sample:
1330
         *   Diagnostic-Code: X-Postfix; delivery temporarily suspended: conversation with
1331
         *   111.111.111.11[111.111.111.11] timed out while sending end of data -- message may be
1332
         *   sent more than once
1333
         */
1334 1
        elseif (preg_match('/delivery.*suspend/is', $diag_code)) {
1335
          $result['rule_cat'] = 'delayed';
1336
          $result['rule_no'] = '0213';
1337
        }
1338
1339
        // =========== rules based on the dsn_msg ===============
1340
1341
        /* rule: unknown
1342
         * sample:
1343
         *   ----- The following addresses had permanent fatal errors -----
1344
         *   <[email protected]>
1345
         *   ----- Transcript of session follows -----
1346
         *   ... while talking to mta1.domain.com.:
1347
         *   >>> DATA
1348
         *   <<< 503 All recipients are invalid
1349
         *   554 5.0.0 Service unavailable
1350
         */
1351 1
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user)(.*)invalid/i', $dsn_msg)) {
1352
          $result['rule_cat'] = 'unknown';
1353
          $result['rule_no'] = '0107';
1354
        } /* rule: unknown
1355
         * sample:
1356
         *   ----- Transcript of session follows -----
1357
         *   [email protected]... Deferred: No such file or directory
1358
         */
1359 1
        elseif (preg_match('/Deferred.*No such.*(?:file|directory)/i', $dsn_msg)) {
1360
          $result['rule_cat'] = 'unknown';
1361
          $result['rule_no'] = '0141';
1362
        } /* rule: unknown
1363
         * sample:
1364
         *   Failed to deliver to '<[email protected]>'
1365
         *   LOCAL module(account xxxx) reports:
1366
         *   mail receiving disabled
1367
         */
1368 1
        elseif (preg_match('/mail receiving disabled/i', $dsn_msg)) {
1369
          $result['rule_cat'] = 'unknown';
1370
          $result['rule_no'] = '0194';
1371
        } /* rule: unknown
1372
         * sample:
1373
         *   - These recipients of your message have been processed by the mail server:
1374
         *   [email protected]; Failed; 5.1.1 (bad destination mailbox address)
1375
         */
1376 1
        elseif (preg_match('/bad.*(?:alias|account|recipient|address|email|mailbox|user)/i', $status_code)) {
1377
          $result['rule_cat'] = 'unknown';
1378
          $result['rule_no'] = '02441';
1379
        } /* rule: unknown
1380
         * sample:
1381
         *   - These recipients of your message have been processed by the mail server:
1382
         *   [email protected]; Failed; 5.1.1 (bad destination mailbox address)
1383
         */
1384 1
        elseif (preg_match('/bad.*(?:alias|account|recipient|address|email|mailbox|user)/i', $dsn_msg)) {
1385 1
          $result['rule_cat'] = 'unknown';
1386 1
          $result['rule_no'] = '0244';
1387 1
        } /* rule: full
1388
         * sample 1:
1389
         *   This Message was undeliverable due to the following reason:
1390
         *   The user(s) account is temporarily over quota.
1391
         *   <[email protected]>
1392
         * sample 2:
1393
         *   Recipient address: [email protected]
1394
         *   Reason: Over quota
1395
         */
1396 1
        elseif (preg_match('/over.*quota/i', $dsn_msg)) {
1397
          $result['rule_cat'] = 'full';
1398
          $result['rule_no'] = '0131';
1399
        } /* rule: full
1400
         * sample:
1401
         *   Sorry the recipient quota limit is exceeded.
1402
         *   This message is returned as an error.
1403
         */
1404 1
        elseif (preg_match('/quota.*exceeded/i', $dsn_msg)) {
1405
          $result['rule_cat'] = 'full';
1406
          $result['rule_no'] = '0150';
1407
        } /* rule: full
1408
         * sample:
1409
         *   The user to whom this message was addressed has exceeded the allowed mailbox
1410
         *   quota. Please resend the message at a later time.
1411
         */
1412 1
        elseif (preg_match("/exceed.*\n?.*quota/i", $dsn_msg)) {
1413
          $result['rule_cat'] = 'full';
1414
          $result['rule_no'] = '0187';
1415
        } /* rule: full
1416
         * sample 1:
1417
         *   Failed to deliver to '<[email protected]>'
1418
         *   LOCAL module(account xxxxxx) reports:
1419
         *   account is full (quota exceeded)
1420
         * sample 2:
1421
         *   Error in fabiomod_sql_glob_init: no data source specified - database access disabled
1422
         *   [Fri Feb 17 23:29:38 PST 2006] full error for caltsmy:
1423
         *   that member's mailbox is full
1424
         *   550 5.0.0 <[email protected]>... Can't create output
1425
         */
1426 1
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*full/i', $dsn_msg)) {
1427
          $result['rule_cat'] = 'full';
1428
          $result['rule_no'] = '0132';
1429
        } /* rule: full
1430
         * sample:
1431
         *   gaosong "(0), ErrMsg=Mailbox space not enough (space limit is 10240KB)
1432
         */
1433 1
        elseif (preg_match('/space.*not.*enough/i', $dsn_msg)) {
1434
          $result['rule_cat'] = 'full';
1435
          $result['rule_no'] = '0219';
1436
        } /* rule: defer
1437
         * sample 1:
1438
         *   ----- Transcript of session follows -----
1439
         *   [email protected]... Deferred: Connection refused by nomail.tpe.domain.com.
1440
         *   Message could not be delivered for 5 days
1441
         *   Message will be deleted from queue
1442
         * sample 2:
1443
         *   451 4.4.1 reply: read error from www.domain.com.
1444
         *   [email protected]... Deferred: Connection reset by www.domain.com.
1445
         */
1446 1
        elseif (preg_match('/Deferred.*Connection (?:refused|reset)/i', $dsn_msg)) {
1447
          $result['rule_cat'] = 'defer';
1448
          $result['rule_no'] = '0115';
1449
        } /* rule: dns_unknown
1450
         * sample:
1451
         *   ----- The following addresses had permanent fatal errors -----
1452
         *   Tan XXXX SSSS <[email protected]>
1453
         *   ----- Transcript of session follows -----
1454
         *   553 5.1.2 XXXX SSSS <[email protected]>... Invalid host name
1455
         */
1456 1
        elseif (preg_match('/Invalid host name/i', $dsn_msg)) {
1457
          $result['rule_cat'] = 'dns_unknown';
1458
          $result['rule_no'] = '0239';
1459
        } /* rule: dns_unknown
1460
         * sample:
1461
         *   ----- Transcript of session follows -----
1462
         *   [email protected]... Deferred: mail.domain.com.: No route to host
1463
         */
1464 1
        elseif (preg_match('/Deferred.*No route to host/i', $dsn_msg)) {
1465
          $result['rule_cat'] = 'dns_unknown';
1466
          $result['rule_no'] = '0240';
1467
        } /* rule: dns_unknown
1468
         * sample:
1469
         *   ----- Transcript of session follows -----
1470
         *   550 5.1.2 [email protected]... Host unknown (Name server: .: no data known)
1471
         */
1472 1
        elseif (preg_match('/Host unknown/i', $dsn_msg)) {
1473
          $result['rule_cat'] = 'dns_unknown';
1474
          $result['rule_no'] = '0140';
1475
        } /* rule: dns_unknown
1476
         * sample:
1477
         *   ----- Transcript of session follows -----
1478
         *   451 HOTMAIL.com.tw: Name server timeout
1479
         *   Message could not be delivered for 5 days
1480
         *   Message will be deleted from queue
1481
         */
1482 1
        elseif (preg_match('/Name server timeout/i', $dsn_msg)) {
1483
          $result['rule_cat'] = 'dns_unknown';
1484
          $result['rule_no'] = '0118';
1485
        } /* rule: dns_unknown
1486
         * sample:
1487
         *   ----- Transcript of session follows -----
1488
         *   [email protected]... Deferred: Connection timed out with hkfight.com.
1489
         *   Message could not be delivered for 5 days
1490
         *   Message will be deleted from queue
1491
         */
1492 1
        elseif (preg_match('/Deferred.*Connection.*tim(?:e|ed).*out/i', $dsn_msg)) {
1493
          $result['rule_cat'] = 'dns_unknown';
1494
          $result['rule_no'] = '0119';
1495
        } /* rule: dns_unknown
1496
         * sample:
1497
         *   ----- Transcript of session follows -----
1498
         *   [email protected]... Deferred: Name server: domain.com.: host name lookup failure
1499
         */
1500 1
        elseif (preg_match('/Deferred.*host name lookup failure/i', $dsn_msg)) {
1501
          $result['rule_cat'] = 'dns_unknown';
1502
          $result['rule_no'] = '0121';
1503
        } /* rule: dns_loop
1504
         * sample:
1505
         *   ----- Transcript of session follows -----
1506
         *   554 5.0.0 MX list for znet.ws. points back to mail01.domain.com
1507
         *   554 5.3.5 Local configuration error
1508
         */
1509 1
        elseif (preg_match('/MX list.*point.*back/i', $dsn_msg)) {
1510
          $result['rule_cat'] = 'dns_loop';
1511
          $result['rule_no'] = '0199';
1512
        } /* rule: internal_error
1513
         * sample:
1514
         *   ----- Transcript of session follows -----
1515
         *   451 4.0.0 I/O error
1516
         */
1517 1
        elseif (preg_match("/I\/O error/i", $dsn_msg)) {
1518
          $result['rule_cat'] = 'internal_error';
1519
          $result['rule_no'] = '0120';
1520
        } /* rule: internal_error
1521
         * sample:
1522
         *   Failed to deliver to '[email protected]'
1523
         *   SMTP module(domain domain.com) reports:
1524
         *   connection with mx1.mail.domain.com is broken
1525
         */
1526 1
        elseif (preg_match('/connection.*broken/i', $dsn_msg)) {
1527
          $result['rule_cat'] = 'internal_error';
1528
          $result['rule_no'] = '0231';
1529
        } /* rule: other
1530
         * sample:
1531
         *   Delivery to the following recipients failed.
1532
         *   [email protected]
1533
         */
1534 1
        elseif (preg_match("/Delivery to the following recipients failed.*\n.*\n.*" . $result['email'] . '/i', $dsn_msg)) {
1535
          $result['rule_cat'] = 'other';
1536
          $result['rule_no'] = '0176';
1537
        }
1538
1539
        // Followings are wind-up rule: must be the last one
1540
        //   many other rules msg end up with "550 5.1.1 ... User unknown"
1541
        //   many other rules msg end up with "554 5.0.0 Service unavailable"
1542
1543
        /* rule: unknown
1544
         * sample 1:
1545
         *   ----- The following addresses had permanent fatal errors -----
1546
         *   <[email protected]>
1547
         *   (reason: User unknown)
1548
         * sample 2:
1549
         *   550 5.1.1 [email protected]... User unknown
1550
         */
1551 1
        elseif (preg_match('/(?:User unknown|Unknown user)/i', $dsn_msg)) {
1552
          $result['rule_cat'] = 'unknown';
1553
          $result['rule_no'] = '0193';
1554
        } /* rule: unknown
1555
         * sample:
1556
         *   554 5.0.0 Service unavailable
1557
         */
1558 1
        elseif (preg_match('/Service unavailable/i', $dsn_msg)) {
1559 1
          $result['rule_cat'] = 'unknown';
1560 1
          $result['rule_no'] = '0214';
1561 1
        }
1562 2
        break;
1563
1564
      case 'delayed':
1565
        $result['rule_cat'] = 'delayed';
1566
        $result['rule_no'] = '0110';
1567
        break;
1568
1569
      case 'delivered':
1570
      case 'relayed':
1571
      case 'expanded': // unhandled cases
1572
        break;
1573
1574
      default:
1575
        break;
1576
    }
1577
  }
1578
1579 2
  global $rule_categories, $bmh_newline;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1580 2
  if ($result['rule_no'] == '0000') {
1581 1
    if ($debug_mode) {
1582
      echo 'email: ' . $result['email'] . $bmh_newline;
1583
      echo 'Action: ' . $action . $bmh_newline;
1584
      echo 'Status: ' . $status_code . $bmh_newline;
1585
      echo 'Diagnostic-Code: ' . $diag_code . $bmh_newline;
1586
      echo "DSN Message:<br />\n" . $dsn_msg . $bmh_newline;
1587
      echo $bmh_newline;
1588
    }
1589 1 View Code Duplication
  } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1590 2
    if ($result['bounce_type'] === false) {
1591 2
      $result['bounce_type'] = $rule_categories[$result['rule_cat']]['bounce_type'];
1592 2
      $result['remove'] = $rule_categories[$result['rule_cat']]['remove'];
1593 2
    }
1594
  }
1595
1596 2
  return $result;
1597
}
1598