Completed
Push — master ( 300762...c9e6dc )
by Lars
03:10
created

phpmailer-bmh_rules.php ➔ bmhBodyRules()   F

Complexity

Conditions 52
Paths 540

Size

Total Lines 460
Code Lines 175

Duplication

Lines 180
Ratio 39.13 %

Code Coverage

Tests 86
CRAP Score 337.06

Importance

Changes 0
Metric Value
cc 52
eloc 175
nc 540
nop 3
dl 180
loc 460
ccs 86
cts 163
cp 0.5276
crap 337.06
rs 2.5217
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.5-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 1
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 1
    '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 1
$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, /** @noinspection PhpUnusedParameterInspection */ $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 3
      'email'           => '',
78
      'bounce_type'     => false,
79
      'remove'          => 0,
80
      'rule_cat'        => 'unrecognized',
81
      'rule_no'         => '0000',
82
      'status_code'     => '',
83
      'action'          => '',
84
      'diagnostic_code' => '',
85
  );
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 3
  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 3
  elseif (preg_match("/no\s+such\s+address\s+here/i", $body, $match)) {
103
    $result['rule_cat'] = 'unknown';
104
    $result['rule_no'] = '0237';
105
  } /* Gmail Bounce Error
106
   * rule: unknown
107
   * sample:
108
   *   Delivery to the following recipient failed permanently:
109
   *   [email protected]
110
   */
111
  elseif (
112 3
      strpos($body, 'Technical details of permanent failure') === false // if there are technical details, try another test-case
113
      &&
114 3
      preg_match("/Delivery to the following (?:recipient|recipients) failed permanently\X*?(\S+@\S+\w)/i", $body, $match)
115
  ) {
116
    $result['rule_cat'] = 'unknown';
117
    $result['rule_no'] = '0998';
118
    $result['email'] = $match[1];
119
  } /*
120
   * rule: unknown
121
   * sample:
122
   * <[email protected]>: host mail-host[111.111.111.111]
123
    said: 550 5.1.1 This user does not exist
124
   */
125 3
  elseif (preg_match("/user.+?not\s+exist/i", $body, $match)) {
126
    $result['rule_cat'] = 'unknown';
127
    $result['rule_no'] = '02361';
128
  } /* rule: unknown
129
   * sample:
130
   *   <[email protected]>:
131
   *   111.111.111.111 does not like recipient.
132
   *   Remote host said: 550 User unknown
133
   */
134 3 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...
135 2
    $result['rule_cat'] = 'unknown';
136 2
    $result['rule_no'] = '0236';
137
  } /* rule: unknown
138
   * sample:
139
   *
140
   */
141 3 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...
142 2
    $result['rule_cat'] = 'unknown';
143 2
    $result['rule_no'] = '0249';
144
  } /* rule: unknown
145
   * sample:
146
   *   <[email protected]>:
147
   *   Sorry, no mailbox here by that name. vpopmail (#5.1.1)
148
   */
149 2 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...
150 1
    $result['rule_cat'] = 'unknown';
151 1
    $result['rule_no'] = '0157';
152
  } /* rule: unknown
153
   * sample:
154
   *   [email protected]<br>
155
   *   local: Sorry, can't find user's mailbox. (#5.1.1)<br>
156
   */
157 2 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...
158
    $result['rule_cat'] = 'unknown';
159
    $result['rule_no'] = '0164';
160
  } /* rule: unknown
161
   * sample:
162
   *   ##########################################################
163
   *   #  This is an automated response from a mail delivery    #
164
   *   #  program.  Your message could not be delivered to      #
165
   *   #  the following address:                                #
166
   *   #                                                        #
167
   *   #      "|/usr/local/bin/mailfilt -u #dkms"               #
168
   *   #        (reason: Can't create output)                   #
169
   *   #        (expanded from: <[email protected]>)         #
170
   *   #                                                        #
171
   */
172 2 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...
173
    $result['rule_cat'] = 'unknown';
174
    $result['rule_no'] = '0169';
175
    $result['email'] = $match[1];
176
  } /* 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...
177
   * sample:
178
   *   ????????????????:
179
   *   [email protected] : ????, ?????.
180
   */
181 2 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...
182
    $result['rule_cat'] = 'unknown';
183
    $result['rule_no'] = '0174';
184
  } /* rule: unknown
185
   * sample:
186
   *   [email protected]
187
   *   Unrouteable address
188
   */
189 2 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...
190
    $result['rule_cat'] = 'unknown';
191
    $result['rule_no'] = '0179';
192
  } /* rule: unknown
193
   * sample:
194
   *   Delivery to the following recipients failed.
195
   *   [email protected]
196
   */
197 2 View Code Duplication
  elseif (preg_match("/delivery[^\n\r]+failed\S*\s+(\S+@\S+\w)\s/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...
198 1
    $result['rule_cat'] = 'unknown';
199 1
    $result['rule_no'] = '0013';
200 1
    $result['email'] = $match[1];
201
  } /* rule: unknown
202
   * sample:
203
   *   A message that you sent could not be delivered to one or more of its
204
   *   recipients. This is a permanent error. The following address(es) failed:
205
   *
206
   *   [email protected]
207
   *   unknown local-part "xxxxx" in domain "yourdomain.com"
208
   */
209 2 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...
210
    $result['rule_cat'] = 'unknown';
211
    $result['rule_no'] = '0232';
212
  } /* rule: unknown
213
   * sample:
214
   *   <[email protected]>:
215
   *   111.111.111.11 does not like recipient.
216
   *   Remote host said: 550 Invalid recipient: <[email protected]>
217
   */
218 2 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...
219
    $result['rule_cat'] = 'unknown';
220
    $result['rule_no'] = '0233';
221
    $result['email'] = $match[1];
222
  } /* rule: unknown
223
   * sample:
224
   *   Sent >>> RCPT TO: <[email protected]>
225
   *   Received <<< 550 [email protected]... No such user
226
   *
227
   *   Could not deliver mail to this user.
228
   *   [email protected]
229
   *   *****************     End of message     ***************
230
   */
231 2 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...
232
    $result['rule_cat'] = 'unknown';
233
    $result['rule_no'] = '0234';
234
    $result['email'] = $match[1];
235
  } /* rule: unknown
236
   * sample:
237
   *   Diagnostic-Code: X-Notes; Recipient user name info ([email protected]) not unique.  Several matches found in Domino Directory.
238
   */
239 2 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...
240 1
    $result['rule_cat'] = 'unknown';
241 1
    $result['rule_no'] = '0254';
242
  } /* rule: full
243
   * sample 1:
244
   *   <[email protected]>:
245
   *   This account is over quota and unable to receive mail.
246
   *   sample 2:
247
   *   <[email protected]>:
248
   *   Warning: undefined mail delivery mode: normal (ignored).
249
   *   The users mailfolder is over the allowed quota (size). (#5.2.2)
250
   */
251 2 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...
252 1
    $result['rule_cat'] = 'full';
253 1
    $result['rule_no'] = '0182';
254
  } /* rule: full
255
   * sample:
256
   *   ----- Transcript of session follows -----
257
   *   mail.local: /var/mail/2b/10/kellen.lee: Disc quota exceeded
258
   *   554 <[email protected]>... Service unavailable
259
   */
260 2 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...
261
    $result['rule_cat'] = 'full';
262
    $result['rule_no'] = '0126';
263
    $result['email'] = $match[1];
264
  } /* rule: full
265
   * sample:
266
   *   Hi. This is the qmail-send program at 263.domain.com.
267
   *   <[email protected]>:
268
   *   - User disk quota exceeded. (#4.3.0)
269
   */
270 2 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...
271
    $result['rule_cat'] = 'full';
272
    $result['rule_no'] = '0158';
273
  } /* rule: full
274
   * sample:
275
   *   [email protected]
276
   *   mailbox is full (MTA-imposed quota exceeded while writing to file /mbx201/mbx011/A100/09/35/A1000935772/mail/.inbox):
277
   */
278 2 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...
279
    $result['rule_cat'] = 'full';
280
    $result['rule_no'] = '0166';
281
  } /* rule: full
282
   * sample:
283
   *   The message to [email protected] is bounced because : Quota exceed the hard limit
284
   */
285 2 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...
286
    $result['rule_cat'] = 'full';
287
    $result['rule_no'] = '0168';
288
    $result['email'] = $match[1];
289
  } /* rule: full
290
   * sample:
291
   *   Message rejected. Not enough storage space in user's mailbox to accept message.
292
   */
293 2 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...
294 1
    $result['rule_cat'] = 'full';
295 1
    $result['rule_no'] = '0253';
296
  } /* rule: inactive
297
   * sample:
298
   *   [email protected]<br>
299
   *   553 user is inactive (eyou mta)
300
   */
301 2 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...
302
    $result['rule_cat'] = 'inactive';
303
    $result['rule_no'] = '0171';
304
  } /*
305
   * <[email protected]> is restricted
306
   */
307 2 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...
308
    $result['rule_cat'] = 'inactive';
309
    $result['rule_no'] = '0201';
310
    $result['email'] = $match[1];
311
  } /* rule: inactive
312
   * sample:
313
   *   [email protected] [Inactive account]
314
   */
315 2 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...
316
    $result['rule_cat'] = 'inactive';
317
    $result['rule_no'] = '0181';
318
  } /*
319
   *<[email protected]>: host mx3.HOTMAIL.COM said: 550
320
   * Requested action not taken: mailbox unavailable (in reply to RCPT TO command)
321
   */
322 2 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...
323
    $result['rule_cat'] = 'unknown';
324
    $result['rule_no'] = '124';
325
    $result['email'] = $match[1];
326
  } /*
327
   * rule: mailbox unknown;
328
   * sample:
329
   * [email protected]
330
   * 550-5.1.1 The email
331
   * account that you tried to reach does not exist. Please try 550-5.1.1
332
   * double-checking the recipient's email address for typos or 550-5.1.1
333
   * unnecessary spaces. Learn more at 550 5.1.1
334
   * http://support.google.com/mail/bin/answer.py?answer=6596 n7si4762785wiy.46
335
   * (in reply to RCPT TO command)
336
   */
337 2 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...
338
    $result['rule_cat'] = 'unknown';
339
    $result['rule_no'] = '7770';
340
    $result['email'] = $match[1];
341
  } /* rule: dns_unknown
342
   * sample1:
343
   *   Delivery to the following recipient failed permanently:
344
   *
345
   *     [email protected]
346
   *
347
   *   Technical details of permanent failure:
348
   *   TEMP_FAILURE: Could not initiate SMTP conversation with any hosts:
349
   *   [b.c (1): Connection timed out]
350
   * sample2:
351
   *   Delivery to the following recipient failed permanently:
352
   *
353
   *     [email protected]
354
   *
355
   *   Technical details of permanent failure:
356
   *   TEMP_FAILURE: Could not initiate SMTP conversation with any hosts:
357
   *   [pop.b.c (1): Connection dropped]
358
   */
359 2 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...
360 1
    $result['rule_cat'] = 'dns_unknown';
361 1
    $result['rule_no'] = '0251';
362
  } /* rule: delayed
363
   * sample:
364
   *   Delivery to the following recipient has been delayed:
365
   *
366
   *     [email protected]
367
   *
368
   *   Message will be retried for 2 more day(s)
369
   *
370
   *   Technical details of temporary failure:
371
   *   TEMP_FAILURE: Could not initiate SMTP conversation with any hosts:
372
   *   [b.c (50): Connection timed out]
373
   */
374 2 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...
375 1
    $result['rule_cat'] = 'delayed';
376 1
    $result['rule_no'] = '0252';
377
  } /* rule: delayed
378
   * sample:
379
   *   Delivery to the following recipient has been delayed:
380
   *
381
   *     [email protected]
382
   *
383
   *   Message will be retried for 2 more day(s)
384
   *
385
   *   Technical details of temporary failure:
386
   *   TEMP_FAILURE: The recipient server did not accept our requests to connect. Learn more at ...
387
   *   [b.c (10): Connection dropped]
388
   */
389 2 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...
390 1
    $result['rule_cat'] = 'delayed';
391 1
    $result['rule_no'] = '0256';
392
  } /* rule: internal_error
393
   * sample:
394
   *   <[email protected]>:
395
   *   Unable to switch to /var/vpopmail/domains/domain.com: input/output error. (#4.3.0)
396
   */
397 2 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...
398
    $result['rule_cat'] = 'internal_error';
399
    $result['rule_no'] = '0172';
400
    $result['bounce_type'] = 'hard';
401
    $result['remove'] = 1;
402
  } /* rule: internal_error
403
   * sample:
404
   *   <[email protected]>:
405
   *   can not open new email file errno=13 file=/home/vpopmail/domains/fromc.com/0/domain/Maildir/tmp/1155254417.28358.mx05,S=212350
406
   */
407 2 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...
408
    $result['rule_cat'] = 'internal_error';
409
    $result['rule_no'] = '0173';
410
    $result['bounce_type'] = 'hard';
411
    $result['remove'] = 1;
412
  } /* rule: defer
413
   * sample:
414
   *   <[email protected]>:
415
   *   111.111.111.111 failed after I sent the message.
416
   *   Remote host said: 451 mta283.mail.scd.yahoo.com Resources temporarily unavailable. Please try again later [#4.16.5].
417
   */
418 2 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...
419
    $result['rule_cat'] = 'defer';
420
    $result['rule_no'] = '0163';
421
  } /* rule: autoreply
422
   * sample:
423
   *   AutoReply message from [email protected]
424
   */
425 2 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...
426
    $result['rule_cat'] = 'autoreply';
427
    $result['rule_no'] = '0167';
428
    $result['email'] = $match[1];
429
  } /* rule: block
430
   * sample:
431
   *   Delivery to the following recipient failed permanently:
432
   *     [email protected]
433
   *   Technical details of permanent failure:
434
   *   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.
435
   */
436 2 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...
437 1
    $result['rule_cat'] = 'antispam';
438 1
    $result['rule_no'] = '0250';
439
  } /* rule: content_reject
440
   * sample:
441
   *   Failed to deliver to '<[email protected]>'
442
   *   Messages without To: fields are not accepted here
443
   */
444 2 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...
445 1
    $result['rule_cat'] = 'content_reject';
446 1
    $result['rule_no'] = '0248';
447
  }  /* rule: inactive
448
   * sample:
449
   *   <[email protected]>:
450
   *   This address no longer accepts mail.
451
   */
452 2 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...
453
    $result['rule_cat'] = 'inactive';
454
    $result['rule_no'] = '0235';
455
  } /* rule: western chars only
456
   * sample:
457
   *   <[email protected]>:
458
   *   The user does not accept email in non-Western (non-Latin) character sets.
459
   */
460 2 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...
461
    $result['rule_cat'] = 'latin_only';
462
    $result['rule_no'] = '0043';
463
  } /* rule: unknown
464
   * sample:
465
   *   554 delivery error
466
   *   This user doesn't have a yahoo.com account
467
   */
468 2 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...
469
    $result['rule_cat'] = 'unknown';
470
    $result['rule_no'] = '0044';
471
  } /* rule: unknown
472
   * sample:
473
   *   550 hotmail.com
474
   */
475 2 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...
476
    $result['rule_cat'] = 'unknown';
477
    $result['rule_no'] = '0045';
478
  } /* rule: unknown
479
   * sample:
480
   *   550 5.1.1 aim.com
481
   */
482 2 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...
483
    $result['rule_cat'] = 'unknown';
484
    $result['rule_no'] = '0046';
485
  } /* rule: unknown
486
   * sample:
487
   *   550 .* (in reply to end of DATA command)
488
   */
489 2 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...
490
    $result['rule_cat'] = 'unknown';
491
    $result['rule_no'] = '0047';
492
  } /* rule: unknown
493
   * sample:
494
   *   550 .* (in reply to RCPT TO command)
495
   */
496 2 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...
497
    $result['rule_cat'] = 'unknown';
498
    $result['rule_no'] = '0048';
499
  } /* rule: dns_unknown
500
   * sample:
501
   *    [email protected]:
502
   *      unrouteable mail domain "b.c"
503
   */
504 2 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...
505 1
    $result['rule_cat'] = 'dns_unknown';
506 1
    $result['rule_no'] = '0247';
507
  }
508
509 3
  if ($result['rule_no'] !== '0000' && $result['email'] === '') {
510 2
    $preBody = substr($body, 0, strpos($body, $match[0]));
511
512 2
    $count = preg_match_all('/(\S+@\S+)/', $preBody, $match);
513 2
    if ($count) {
514 2
      $result['email'] = trim($match[1][$count - 1], "'\"()<>.:; \t\r\n\0\x0B");
515
    }
516
  }
517
518 3
  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...
519 3
  if ($result['rule_no'] == '0000') {
520 2
    if ($debug_mode) {
521
      echo 'Body:' . $bmh_newline . $body . $bmh_newline;
522 2
      echo $bmh_newline;
523
    }
524 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...
525 2
    if ($result['bounce_type'] === false) {
526 2
      $result['bounce_type'] = $rule_categories[$result['rule_cat']]['bounce_type'];
527 2
      $result['remove'] = $rule_categories[$result['rule_cat']]['remove'];
528
    }
529
  }
530
531 3
  return $result;
532
}
533
534
/**
535
 * Defined bounce parsing rules for standard DSN (Delivery Status Notification)
536
 *
537
 * @param string  $dsn_msg    human-readable explanation
538
 * @param string  $dsn_report delivery-status report
539
 * @param boolean $debug_mode show debug info. or not
540
 *
541
 * @return array    $result an array include the following fields: 'email', 'bounce_type','remove','rule_no','rule_cat'
542
 *                      if we could NOT detect the type of bounce, return rule_no = '0000'
543
 */
544
function bmhDSNRules($dsn_msg, $dsn_report, $debug_mode = false)
545
{
546
  // initialize the result array
547
  $result = array(
548 2
      'email'           => '',
549
      'bounce_type'     => false,
550
      'remove'          => 0,
551
      'rule_cat'        => 'unrecognized',
552
      'rule_no'         => '0000',
553
      'status_code'     => '',
554
      'action'          => '',
555
      'diagnostic_code' => '',
556
  );
557 2
  $action = false;
558 2
  $status_code = false;
559 2
  $diag_code = false;
560
561
  // ======= parse $dsn_report ======
562
  // get the recipient email
563 2
  if (preg_match('/Original-Recipient: rfc822;(.*)/i', $dsn_report, $match)) {
564 1
    $email = trim($match[1], "<> \t\r\n\0\x0B");
565
    /** @noinspection PhpUsageOfSilenceOperatorInspection */
566 1
    $email_arr = @imap_rfc822_parse_adrlist($email, 'default.domain.name');
567 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...
568 1
      $result['email'] = $email_arr[0]->mailbox . '@' . $email_arr[0]->host;
569
    }
570 2
  } elseif (preg_match('/Final-Recipient: rfc822;(.*)/i', $dsn_report, $match)) {
571 2
    $email = trim($match[1], "<> \t\r\n\0\x0B");
572
    /** @noinspection PhpUsageOfSilenceOperatorInspection */
573 2
    $email_arr = @imap_rfc822_parse_adrlist($email, 'default.domain.name');
574 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...
575 2
      $result['email'] = $email_arr[0]->mailbox . '@' . $email_arr[0]->host;
576
    }
577
  }
578
579 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...
580 2
    $action = strtolower(trim($match[1]));
581 2
    $result['action'] = $action;
582
  }
583
584 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...
585 2
    $status_code = $match[1];
586 2
    $result['status_code'] = $status_code;
587
  }
588
589
  // Could be multi-line , if the new line is beginning with SPACE or HTAB
590 2
  if (preg_match("/Diagnostic-Code:((?:[^\n]|\n[\t ])+)(?:\n[^\t ]|$)/i", $dsn_report, $match)) {
591 2
    $diag_code = $match[1];
592
  }
593
594
  // No Diagnostic-Code in email, use dsn message
595 2
  if (empty($diag_code)) {
596 2
    $diag_code = $dsn_msg;
597
  }
598
599 2
  $result['diagnostic_code'] = $diag_code;
600
601
  // ======= rules ======
602
603 2
  if (empty($result['email'])) {
604
    /* email address is empty
605
     * rule: full
606
     * sample:   DSN Message only
607
     * User quota exceeded: SMTP <[email protected]>
608
     */
609 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...
610
      $result['rule_cat'] = 'full';
611
      $result['rule_no'] = '0161';
612 1
      $result['email'] = $match[1];
613
    }
614
  } else {
615
    /* action could be one of them as RFC:1894
616
     * "failed" / "delayed" / "delivered" / "relayed" / "expanded"
617
     */
618
    switch ($action) {
619 2
      case 'failed':
620
        /* rule: full
621
         * sample:
622
         *   Diagnostic-Code: X-Postfix; me.domain.com platform: said: 552 5.2.2 Over
623
         *     quota (in reply to RCPT TO command)
624
         */
625 2
        if (preg_match('/over.*quota/is', $diag_code)) {
626 1
          $result['rule_cat'] = 'full';
627 1
          $result['rule_no'] = '0105';
628
        } /* rule: full
629
         * sample:
630
         *   Diagnostic-Code: SMTP; 552 Requested mailbox exceeds quota.
631
         */
632 2
        elseif (preg_match('/exceed.*quota/is', $diag_code)) {
633
          $result['rule_cat'] = 'full';
634
          $result['rule_no'] = '0129';
635
        } /* rule: full
636
         * sample 1:
637
         *   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.
638
         * sample 2:
639
         *   Diagnostic-Code: X-Postfix; host mta5.us4.domain.com.int[111.111.111.111] said:
640
         *     552 recipient storage full, try again later (in reply to RCPT TO command)
641
         * sample 3:
642
         *   Diagnostic-Code: X-HERMES; host 127.0.0.1[127.0.0.1] said: 551 bounce as<the
643
         *     destination mailbox <[email protected]> is full> queue as
644
         *     [email protected] (in reply to end of
645
         *     DATA command)
646
         */
647 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*full/is', $diag_code)) {
648 1
          $result['rule_cat'] = 'full';
649 1
          $result['rule_no'] = '0145';
650
        } /* rule: full
651
         * sample:
652
         *   Diagnostic-Code: SMTP; 452 Insufficient system storage
653
         */
654 2
        elseif (preg_match('/Insufficient system storage/i', $diag_code)) {
655
          $result['rule_cat'] = 'full';
656
          $result['rule_no'] = '0134';
657
        } /* rule: full
658
         * sample:
659
         *   Diagnostic-Code: SMTP; 422 Benutzer hat zuviele Mails auf dem Server
660
         */
661 2
        elseif (preg_match('/Benutzer hat zuviele Mails auf dem Server/i', $diag_code)) {
662
          $result['rule_cat'] = 'full';
663
          $result['rule_no'] = '0998';
664
        } /* rule: full
665
         * sample:
666
         *   Diagnostic-Code: SMTP; 422 exceeded storage allocation
667
         */
668 2
        elseif (preg_match('/exceeded storage allocation/i', $diag_code)) {
669
          $result['rule_cat'] = 'full';
670
          $result['rule_no'] = '0997';
671
        } /* rule: full
672
         * sample:
673
         *   Diagnostic-Code: SMTP; 422 Mailbox quota usage exceeded
674
         */
675 2
        elseif (preg_match('/Mailbox quota usage exceeded/i', $diag_code)) {
676
          $result['rule_cat'] = 'full';
677
          $result['rule_no'] = '0996';
678
        } /* rule: full
679
         * sample:
680
         *   Diagnostic-Code: SMTP; 422 User has exhausted allowed storage space
681
         */
682 2
        elseif (preg_match('/User has exhausted allowed storage space/i', $diag_code)) {
683
          $result['rule_cat'] = 'full';
684
          $result['rule_no'] = '0995';
685
        } /* rule: full
686
         * sample:
687
         *   Diagnostic-Code: SMTP; 422 User mailbox exceeds allowed size
688
         */
689 2
        elseif (preg_match('/User mailbox exceeds allowed size/i', $diag_code)) {
690
          $result['rule_cat'] = 'full';
691
          $result['rule_no'] = '0994';
692
        } /* rule: full
693
         * sample:
694
         *   Diagnostic-Code: smpt; 552 Account(s) <[email protected]> does not have enough space
695
         */
696 2
        elseif (preg_match("/not.*enough\s+space/i", $diag_code)) {
697 1
          $result['rule_cat'] = 'full';
698 1
          $result['rule_no'] = '0246';
699
        } /* rule: full
700
         * sample 1:
701
         *   Diagnostic-Code: X-Postfix; cannot append message to destination file
702
         *     /var/mail/dale.me89g: error writing message: File too large
703
         * sample 2:
704
         *   Diagnostic-Code: X-Postfix; cannot access mailbox /var/spool/mail/b8843022 for
705
         *     user xxxxx. error writing message: File too large
706
         */
707 2
        elseif (preg_match('/File too large/i', $diag_code)) {
708
          $result['rule_cat'] = 'full';
709
          $result['rule_no'] = '0192';
710
        } /* rule: oversize
711
         * sample:
712
         *   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.
713
         */
714 2
        elseif (preg_match('/larger than.*limit/is', $diag_code)) {
715
          $result['rule_cat'] = 'oversize';
716
          $result['rule_no'] = '0146';
717
        } /* rule: unknown
718
         * sample:
719
         *   Diagnostic-Code: X-Notes; User xxxxx ([email protected]) not listed in public Name & Address Book
720
         */
721 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user)(.*)not(.*)list/is', $diag_code)) {
722 1
          $result['rule_cat'] = 'unknown';
723 1
          $result['rule_no'] = '0103';
724
        } /* rule: unknown
725
         * sample:
726
         *   Diagnostic-Code: smtp; 450 user path no exist
727
         */
728 2
        elseif (preg_match('/user path no exist/i', $diag_code)) {
729
          $result['rule_cat'] = 'unknown';
730
          $result['rule_no'] = '0106';
731
        } /* rule: unknown
732
         * sample 1:
733
         *   Diagnostic-Code: SMTP; 550 Relaying denied.
734
         * sample 2:
735
         *   Diagnostic-Code: SMTP; 554 <[email protected]>: Relay access denied
736
         * sample 3:
737
         *   Diagnostic-Code: SMTP; 550 relaying to <[email protected]> prohibited by administrator
738
         */
739 2
        elseif (preg_match('/Relay.*(?:denied|prohibited)/is', $diag_code)) {
740 1
          $result['rule_cat'] = 'unknown';
741 1
          $result['rule_no'] = '0108';
742
        } /* rule: unknown
743
         * sample:
744
         *   Diagnostic-Code: SMTP; 554 qq Sorry, no valid recipients (#5.1.3)
745
         */
746 2
        elseif (preg_match('/no.*valid.*(?:alias|account|recipient|address|email|mailbox|user)/is', $diag_code)) {
747
          $result['rule_cat'] = 'unknown';
748
          $result['rule_no'] = '0185';
749
        } /* rule: unknown
750
         * sample 1:
751
         *   Diagnostic-Code: SMTP; 550 «Dªk¦a§} - invalid address (#5.5.0)
752
         * sample 2:
753
         *   Diagnostic-Code: SMTP; 550 Invalid recipient: <[email protected]>
754
         * sample 3:
755
         *   Diagnostic-Code: SMTP; 550 <[email protected]>: Invalid User
756
         */
757 2
        elseif (preg_match('/Invalid.*(?:alias|account|recipient|address|email|mailbox|user)/is', $diag_code)) {
758 1
          $result['rule_cat'] = 'unknown';
759 1
          $result['rule_no'] = '0111';
760
        } /* rule: unknown
761
         * sample:
762
         *   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
763
         */
764 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*(?:disabled|discontinued)/is', $diag_code)) {
765 1
          $result['rule_cat'] = 'unknown';
766 1
          $result['rule_no'] = '0114';
767
        } /* rule: unknown
768
         * sample:
769
         *   Diagnostic-Code: SMTP; 554 delivery error: dd This user doesn't have a domain.com account ([email protected]) [0] - mta134.mail.tpe.domain.com
770
         */
771 2
        elseif (preg_match("/user doesn't have.*account/is", $diag_code)) {
772 2
          $result['rule_cat'] = 'unknown';
773 2
          $result['rule_no'] = '0127';
774
        } /* rule: unknown
775
         * sample:
776
         *   Diagnostic-Code: SMTP; 550 5.1.1 unknown or illegal alias: [email protected]
777
         */
778 2
        elseif (preg_match('/(?:unknown|illegal).*(?:alias|account|recipient|address|email|mailbox|user)/is', $diag_code)) {
779 2
          $result['rule_cat'] = 'unknown';
780 2
          $result['rule_no'] = '0128';
781
        } /* rule: unknown
782
         * sample 1:
783
         *   Diagnostic-Code: SMTP; 450 mailbox unavailable.
784
         * sample 2:
785
         *   Diagnostic-Code: SMTP; 550 5.7.1 Requested action not taken: mailbox not available
786
         */
787 2
        elseif (preg_match("/(?:alias|account|recipient|address|email|mailbox|user).*(?:un|not\s+)available/is", $diag_code)) {
788 1
          $result['rule_cat'] = 'unknown';
789 1
          $result['rule_no'] = '0122';
790
        } /* rule: unknown
791
         * sample:
792
         *   Diagnostic-Code: SMTP; 553 sorry, no mailbox here by that name (#5.7.1)
793
         */
794 2
        elseif (preg_match('/no (?:alias|account|recipient|address|email|mailbox|user)/i', $diag_code)) {
795 1
          $result['rule_cat'] = 'unknown';
796 1
          $result['rule_no'] = '0123';
797
        } /* rule: unknown
798
         * sample 1:
799
         *   Diagnostic-Code: SMTP; 550 User ([email protected]) unknown.
800
         * sample 2:
801
         *   Diagnostic-Code: SMTP; 553 5.3.0 <[email protected]>... Addressee unknown, relay=[111.111.111.000]
802
         */
803 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*unknown/is', $diag_code)) {
804 1
          $result['rule_cat'] = 'unknown';
805 1
          $result['rule_no'] = '0125';
806
        } /* rule: unknown
807
         * sample 1:
808
         *   Diagnostic-Code: SMTP; 550 user disabled
809
         * sample 2:
810
         *   Diagnostic-Code: SMTP; 452 4.2.1 mailbox temporarily disabled: [email protected]
811
         */
812 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*disabled/is', $diag_code)) {
813
          $result['rule_cat'] = 'unknown';
814
          $result['rule_no'] = '0133';
815
        } /* rule: unknown
816
         * sample:
817
         *   Diagnostic-Code: SMTP; 550 <[email protected]>: Recipient address rejected: No such user ([email protected])
818
         */
819 2
        elseif (preg_match('/No such (?:alias|account|recipient|address|email|mailbox|user)/i', $diag_code)) {
820
          $result['rule_cat'] = 'unknown';
821
          $result['rule_no'] = '0143';
822
        } /* rule: unknown
823
         * sample 1:
824
         *   Diagnostic-Code: SMTP; 550 MAILBOX NOT FOUND
825
         * sample 2:
826
         *   Diagnostic-Code: SMTP; 550 Mailbox ( [email protected] ) not found or inactivated
827
         */
828 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*NOT FOUND/is', $diag_code)) {
829
          $result['rule_cat'] = 'unknown';
830
          $result['rule_no'] = '0136';
831
        } /* rule: unknown
832
         * sample:
833
         *    Diagnostic-Code: X-Postfix; host m2w-in1.domain.com[111.111.111.000] said: 551
834
         *    <[email protected]> is a deactivated mailbox (in reply to RCPT TO
835
         *    command)
836
         */
837 2
        elseif (preg_match('/deactivated (?:alias|account|recipient|address|email|mailbox|user)/i', $diag_code)) {
838
          $result['rule_cat'] = 'unknown';
839
          $result['rule_no'] = '0138';
840
        } /* rule: unknown
841
         * sample:
842
         *   Diagnostic-Code: SMTP; 550 <[email protected]> recipient rejected
843
         *   ...
844
         *   <<< 550 <[email protected]> recipient rejected
845
         *   550 5.1.1 [email protected]... User unknown
846
         */
847 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*reject/is', $diag_code)) {
848 2
          $result['rule_cat'] = 'unknown';
849 2
          $result['rule_no'] = '0148';
850
        } /* rule: unknown
851
         * sample:
852
         *   Diagnostic-Code: smtp; 5.x.0 - Message bounced by administrator  (delivery attempts: 0)
853
         */
854 2
        elseif (preg_match('/bounce.*administrator/is', $diag_code)) {
855
          $result['rule_cat'] = 'unknown';
856
          $result['rule_no'] = '0151';
857
        } /* rule: unknown
858
         * sample:
859
         *   Diagnostic-Code: SMTP; 550 <maxqin> is now disabled with MTA service.
860
         */
861 2
        elseif (preg_match('/<.*>.*disabled/is', $diag_code)) {
862
          $result['rule_cat'] = 'unknown';
863
          $result['rule_no'] = '0152';
864
        } /* rule: unknown
865
         * sample:
866
         *   Diagnostic-Code: SMTP; 551 not our customer
867
         */
868 2
        elseif (preg_match('/not our customer/i', $diag_code)) {
869
          $result['rule_cat'] = 'unknown';
870
          $result['rule_no'] = '0154';
871
        } /* rule: unknown
872
         * sample:
873
         *   Diagnostic-Code: smtp; 5.1.0 - Unknown address error 540-'Error: Wrong recipients' (delivery attempts: 0)
874
         */
875 2
        elseif (preg_match('/Wrong (?:alias|account|recipient|address|email|mailbox|user)/i', $diag_code)) {
876
          $result['rule_cat'] = 'unknown';
877
          $result['rule_no'] = '0159';
878
        } /* rule: unknown
879
         * sample:
880
         *   Diagnostic-Code: smtp; 5.1.0 - Unknown address error 540-'Error: Wrong recipients' (delivery attempts: 0)
881
         * sample 2:
882
         *   Diagnostic-Code: SMTP; 501 #5.1.1 bad address [email protected]
883
         */
884 2
        elseif (preg_match('/(?:unknown|bad).*(?:alias|account|recipient|address|email|mailbox|user)/is', $diag_code)) {
885
          $result['rule_cat'] = 'unknown';
886
          $result['rule_no'] = '0160';
887
        } /* rule: unknown
888
         * sample:
889
         *   Status: 5.1.1 (bad destination mailbox address)
890
         */
891 2
        elseif (preg_match('/(?:unknown|bad).*(?:alias|account|recipient|address|email|mailbox|user)/is', $status_code)) {
892
          $result['rule_cat'] = 'unknown';
893
          $result['rule_no'] = '01601';
894
        } /* rule: unknown
895
         * sample:
896
         *   Diagnostic-Code: SMTP; 550 Command RCPT User <[email protected]> not OK
897
         */
898 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*not OK/is', $diag_code)) {
899
          $result['rule_cat'] = 'unknown';
900
          $result['rule_no'] = '0186';
901
        } /* rule: unknown
902
         * sample:
903
         *   Diagnostic-Code: SMTP; 550 5.7.1 Access-Denied-XM.SSR-001
904
         */
905 2
        elseif (preg_match('/Access.*Denied/is', $diag_code)) {
906
          $result['rule_cat'] = 'unknown';
907
          $result['rule_no'] = '0189';
908
        } /* rule: unknown
909
         * sample:
910
         *   Diagnostic-Code: SMTP; 550 5.1.1 <[email protected]>... email address lookup in domain map failed
911
         */
912 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*lookup.*fail/is', $diag_code)) {
913
          $result['rule_cat'] = 'unknown';
914
          $result['rule_no'] = '0195';
915
        } /* rule: unknown
916
         * sample:
917
         *   Diagnostic-Code: SMTP; 550 User not a member of domain: <[email protected]>
918
         */
919 2
        elseif (preg_match('/(?:recipient|address|email|mailbox|user).*not.*member of domain/is', $diag_code)) {
920
          $result['rule_cat'] = 'unknown';
921
          $result['rule_no'] = '0198';
922
        } /* rule: unknown
923
         * sample:
924
         *   Diagnostic-Code: SMTP; 550-"The recipient cannot be verified.  Please check all recipients of this
925
         */
926 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*cannot be verified/is', $diag_code)) {
927
          $result['rule_cat'] = 'unknown';
928
          $result['rule_no'] = '0202';
929
        } /* rule: unknown
930
         * sample:
931
         *   Diagnostic-Code: SMTP; 550 Unable to relay for [email protected]
932
         */
933 2
        elseif (preg_match('/Unable to relay/i', $diag_code)) {
934
          $result['rule_cat'] = 'unknown';
935
          $result['rule_no'] = '0203';
936
        } /* rule: unknown
937
         * sample 1:
938
         *   Diagnostic-Code: SMTP; 550 [email protected]:user not exist
939
         * sample 2:
940
         *   Diagnostic-Code: SMTP; 550 sorry, that recipient doesn't exist (#5.7.1)
941
         */
942 2
        elseif (preg_match("/(?:alias|account|recipient|address|email|mailbox|user).*(?:n't|not) exist/is", $diag_code)) {
943 2
          $result['rule_cat'] = 'unknown';
944 2
          $result['rule_no'] = '0205';
945
        } /* rule: unknown
946
         * sample:
947
         *   Diagnostic-Code: SMTP; 550-I'm sorry but [email protected] does not have an account here. I will not
948
         */
949 2
        elseif (preg_match('/not have an account/i', $diag_code)) {
950
          $result['rule_cat'] = 'unknown';
951
          $result['rule_no'] = '0207';
952
        } /* rule: unknown
953
         * sample:
954
         *   Diagnostic-Code: SMTP; 550 This account is not [email protected]
955
         */
956 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*is not allowed/is', $diag_code)) {
957
          $result['rule_cat'] = 'unknown';
958
          $result['rule_no'] = '0220';
959
        } /* rule: unknown
960
         * sample:
961
         *   Diagnostic-Code: X-Notes; Recipient user name info ([email protected]) not unique.  Several matches found in Domino Directory.
962
         */
963 2
        elseif (preg_match('/not unique.\s+Several matches found/i', $diag_code)) {
964
          $result['rule_cat'] = 'unknown';
965
          $result['rule_no'] = '0255';
966
        } /* rule: inactive
967
         * sample:
968
         *   Diagnostic-Code: SMTP; 550 <[email protected]>: inactive user
969
         */
970 2
        elseif (preg_match('/inactive.*(?:alias|account|recipient|address|email|mailbox|user)/is', $diag_code)) {
971
          $result['rule_cat'] = 'inactive';
972
          $result['rule_no'] = '0135';
973
        } /* rule: inactive
974
         * sample:
975
         *   Diagnostic-Code: SMTP; 550 [email protected] Account Inactive
976
         */
977 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*Inactive/is', $diag_code)) {
978
          $result['rule_cat'] = 'inactive';
979
          $result['rule_no'] = '0155';
980
        } /* rule: inactive
981
         * sample:
982
         *   Diagnostic-Code: SMTP; 550 <[email protected]>: Recipient address rejected: Account closed due to inactivity. No forwarding information is available.
983
         */
984 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user) closed due to inactivity/i', $diag_code)) {
985
          $result['rule_cat'] = 'inactive';
986
          $result['rule_no'] = '0170';
987
        } /* rule: inactive
988
         * sample:
989
         *   Diagnostic-Code: SMTP; 550 <[email protected]>... User account not activated
990
         */
991 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user) not activated/i', $diag_code)) {
992
          $result['rule_cat'] = 'inactive';
993
          $result['rule_no'] = '0177';
994
        } /* rule: inactive
995
         * sample 1:
996
         *   Diagnostic-Code: SMTP; 550 User suspended
997
         * sample 2:
998
         *   Diagnostic-Code: SMTP; 550 account expired
999
         */
1000 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*(?:suspend|expire)/is', $diag_code)) {
1001
          $result['rule_cat'] = 'inactive';
1002
          $result['rule_no'] = '0183';
1003
        } /* rule: inactive
1004
         * sample:
1005
         *   Diagnostic-Code: SMTP; 553 5.3.0 <[email protected]>... Recipient address no longer exists
1006
         */
1007 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*no longer exist/is', $diag_code)) {
1008
          $result['rule_cat'] = 'inactive';
1009
          $result['rule_no'] = '0184';
1010
        } /* rule: inactive
1011
         * sample:
1012
         *   Diagnostic-Code: SMTP; 553 VS10-RT Possible forgery or deactivated due to abuse (#5.1.1) 111.111.111.211
1013
         */
1014 2
        elseif (preg_match('/(?:forgery|abuse)/i', $diag_code)) {
1015
          $result['rule_cat'] = 'inactive';
1016
          $result['rule_no'] = '0196';
1017
        } /* rule: inactive
1018
         * sample:
1019
         *   Diagnostic-Code: SMTP; 553 mailbox [email protected] is restricted
1020
         */
1021 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*restrict/is', $diag_code)) {
1022
          $result['rule_cat'] = 'inactive';
1023
          $result['rule_no'] = '0209';
1024
        } /* rule: inactive
1025
         * sample:
1026
         *   Diagnostic-Code: SMTP; 550 <[email protected]>: User status is locked.
1027
         */
1028 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*locked/is', $diag_code)) {
1029
          $result['rule_cat'] = 'inactive';
1030
          $result['rule_no'] = '0228';
1031
        } /* rule: user_reject
1032
         * sample:
1033
         *   Diagnostic-Code: SMTP; 553 User refused to receive this mail.
1034
         */
1035 2
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user) refused/i', $diag_code)) {
1036
          $result['rule_cat'] = 'user_reject';
1037
          $result['rule_no'] = '0156';
1038
        } /* rule: user_reject
1039
         * sample:
1040
         *   Diagnostic-Code: SMTP; 501 [email protected] Sender email is not in my domain
1041
         */
1042 2
        elseif (preg_match('/sender.*not/is', $diag_code)) {
1043
          $result['rule_cat'] = 'user_reject';
1044
          $result['rule_no'] = '0206';
1045
        } /* rule: command_reject
1046
         * sample:
1047
         *   Diagnostic-Code: SMTP; 554 Message refused
1048
         */
1049 2
        elseif (preg_match('/Message refused/i', $diag_code)) {
1050
          $result['rule_cat'] = 'command_reject';
1051
          $result['rule_no'] = '0175';
1052
        } /* rule: command_reject
1053
         * sample:
1054
         *   Diagnostic-Code: SMTP; 550 5.0.0 <[email protected]>... No permit
1055
         */
1056 2
        elseif (preg_match('/No permit/i', $diag_code)) {
1057
          $result['rule_cat'] = 'command_reject';
1058
          $result['rule_no'] = '0190';
1059
        } /* rule: command_reject
1060
         * sample:
1061
         *   Diagnostic-Code: SMTP; 553 sorry, that domain isn't in my list of allowed rcpthosts (#5.5.3 - chkuser)
1062
         */
1063 2
        elseif (preg_match("/domain isn't in.*allowed rcpthost/is", $diag_code)) {
1064
          $result['rule_cat'] = 'command_reject';
1065
          $result['rule_no'] = '0191';
1066
        } /* rule: command_reject
1067
         * sample:
1068
         *   Diagnostic-Code: SMTP; 553 AUTH FAILED - [email protected]
1069
         */
1070 2
        elseif (preg_match('/AUTH FAILED/i', $diag_code)) {
1071
          $result['rule_cat'] = 'command_reject';
1072
          $result['rule_no'] = '0197';
1073
        } /* rule: command_reject
1074
         * sample 1:
1075
         *   Diagnostic-Code: SMTP; 550 relay not permitted
1076
         * sample 2:
1077
         *   Diagnostic-Code: SMTP; 530 5.7.1 Relaying not allowed: [email protected]
1078
         */
1079 2
        elseif (preg_match('/relay.*not.*(?:permit|allow)/is', $diag_code)) {
1080
          $result['rule_cat'] = 'command_reject';
1081
          $result['rule_no'] = '0241';
1082
        } /* rule: command_reject
1083
         * sample:
1084
         *   Diagnostic-Code: SMTP; 550 not local host domain.com, not a gateway
1085
         */
1086 2
        elseif (preg_match('/not local host/i', $diag_code)) {
1087
          $result['rule_cat'] = 'command_reject';
1088
          $result['rule_no'] = '0204';
1089
        } /* rule: command_reject
1090
         * sample:
1091
         *   Diagnostic-Code: SMTP; 500 Unauthorized relay msg rejected
1092
         */
1093 2
        elseif (preg_match('/Unauthorized relay/i', $diag_code)) {
1094
          $result['rule_cat'] = 'command_reject';
1095
          $result['rule_no'] = '0215';
1096
        } /* rule: command_reject
1097
         * sample:
1098
         *   Diagnostic-Code: SMTP; 554 Transaction failed
1099
         */
1100 2
        elseif (preg_match('/Transaction.*fail/is', $diag_code)) {
1101
          $result['rule_cat'] = 'command_reject';
1102
          $result['rule_no'] = '0221';
1103
        } /* rule: command_reject
1104
         * sample:
1105
         *   Diagnostic-Code: smtp;554 5.5.2 Invalid data in message
1106
         */
1107 2
        elseif (preg_match('/Invalid data/i', $diag_code)) {
1108
          $result['rule_cat'] = 'command_reject';
1109
          $result['rule_no'] = '0223';
1110
        } /* rule: command_reject
1111
         * sample:
1112
         *   Diagnostic-Code: SMTP; 550 Local user only or Authentication mechanism
1113
         */
1114 2
        elseif (preg_match('/Local user only/i', $diag_code)) {
1115
          $result['rule_cat'] = 'command_reject';
1116
          $result['rule_no'] = '0224';
1117
        } /* rule: command_reject
1118
         * sample:
1119
         *   Diagnostic-Code: SMTP; 550-ds176.domain.com [111.111.111.211] is currently not permitted to
1120
         *   relay through this server. Perhaps you have not logged into the pop/imap
1121
         *   server in the last 30 minutes or do not have SMTP Authentication turned on
1122
         *   in your email client.
1123
         */
1124 2
        elseif (preg_match('/not.*permit.*to/is', $diag_code)) {
1125
          $result['rule_cat'] = 'command_reject';
1126
          $result['rule_no'] = '0225';
1127
        } /* rule: content_reject
1128
         * sample:
1129
         *   Diagnostic-Code: SMTP; 550 Content reject. FAAAANsG60M9BmDT.1
1130
         */
1131 2
        elseif (preg_match('/Content reject/i', $diag_code)) {
1132
          $result['rule_cat'] = 'content_reject';
1133
          $result['rule_no'] = '0165';
1134
        } /* rule: content_reject
1135
         * sample:
1136
         *   Diagnostic-Code: SMTP; 552 MessageWall: MIME/REJECT: Invalid structure
1137
         */
1138 2
        elseif (preg_match("/MIME\/REJECT/i", $diag_code)) {
1139
          $result['rule_cat'] = 'content_reject';
1140
          $result['rule_no'] = '0212';
1141
        } /* rule: content_reject
1142
         * sample:
1143
         *   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
1144
         */
1145 2
        elseif (preg_match('/MIME error/i', $diag_code)) {
1146
          $result['rule_cat'] = 'content_reject';
1147
          $result['rule_no'] = '0217';
1148
        } /* rule: content_reject
1149
         * sample:
1150
         *   Diagnostic-Code: SMTP; 553 Mail data refused by AISP, rule [169648].
1151
         */
1152 2
        elseif (preg_match('/Mail data refused.*AISP/is', $diag_code)) {
1153
          $result['rule_cat'] = 'content_reject';
1154
          $result['rule_no'] = '0218';
1155
        } /* rule: dns_unknown
1156
         * sample:
1157
         *   Diagnostic-Code: SMTP; 550 Host unknown
1158
         */
1159 2
        elseif (preg_match('/Host unknown/i', $diag_code)) {
1160 1
          $result['rule_cat'] = 'dns_unknown';
1161 1
          $result['rule_no'] = '0130';
1162
        } /* rule: dns_unknown
1163
         * sample:
1164
         *   Diagnostic-Code: SMTP; 553 Specified domain is not allowed.
1165
         */
1166 2
        elseif (preg_match('/Specified domain.*not.*allow/is', $diag_code)) {
1167
          $result['rule_cat'] = 'dns_unknown';
1168
          $result['rule_no'] = '0180';
1169
        } /* rule: dns_unknown
1170
         * sample:
1171
         *   Diagnostic-Code: X-Postfix; delivery temporarily suspended: connect to
1172
         *   111.111.11.112[111.111.11.112]: No route to host
1173
         */
1174 2
        elseif (preg_match('/No route to host/i', $diag_code)) {
1175
          $result['rule_cat'] = 'dns_unknown';
1176
          $result['rule_no'] = '0188';
1177
        } /* rule: dns_unknown
1178
         * sample:
1179
         *   Diagnostic-Code: SMTP; 550 unrouteable address
1180
         */
1181 2
        elseif (preg_match('/unrouteable address/i', $diag_code)) {
1182
          $result['rule_cat'] = 'dns_unknown';
1183
          $result['rule_no'] = '0208';
1184
        } /* rule: dns_unknown
1185
         * sample:
1186
         *   Diagnostic-Code: X-Postfix; Host or domain name not found. Name service error
1187
         *     for name=aaaaaaaaaaa type=A: Host not found
1188
         */
1189 2
        elseif (preg_match('/Host or domain name not found/i', $diag_code)) {
1190 1
          $result['rule_cat'] = 'dns_unknown';
1191 1
          $result['rule_no'] = '0238';
1192
        } /* rule: dns_loop
1193
         * sample:
1194
         *   Diagnostic-Code: X-Postfix; mail for mta.example.com loops back to myself
1195
         */
1196 2
        elseif (preg_match('/loops back to myself/i', $diag_code)) {
1197 1
          $result['rule_cat'] = 'dns_loop';
1198 1
          $result['rule_no'] = '0245';
1199
        } /* rule: defer
1200
         * sample:
1201
         *   Diagnostic-Code: SMTP; 451 System(u) busy, try again later.
1202
         */
1203 1
        elseif (preg_match('/System.*busy/is', $diag_code)) {
1204
          $result['rule_cat'] = 'defer';
1205
          $result['rule_no'] = '0112';
1206
        } /* rule: defer
1207
         * sample:
1208
         *   Diagnostic-Code: SMTP; 451 mta172.mail.tpe.domain.com Resources temporarily unavailable. Please try again later.  [#4.16.4:70].
1209
         */
1210 1
        elseif (preg_match('/Resources temporarily unavailable/i', $diag_code)) {
1211
          $result['rule_cat'] = 'defer';
1212
          $result['rule_no'] = '0116';
1213
        } /* rule: antispam, deny ip
1214
         * sample:
1215
         *   Diagnostic-Code: SMTP; 554 sender is rejected: 0,mx20,wKjR5bDrnoM2yNtEZVAkBg==.32467S2
1216
         */
1217 1
        elseif (preg_match('/sender is rejected/i', $diag_code)) {
1218
          $result['rule_cat'] = 'antispam';
1219
          $result['rule_no'] = '0101';
1220
        } /* rule: antispam, deny ip
1221
         * sample:
1222
         *   Diagnostic-Code: SMTP; 554 <unknown[111.111.111.000]>: Client host rejected: Access denied
1223
         */
1224 1
        elseif (preg_match('/Client host rejected/i', $diag_code)) {
1225
          $result['rule_cat'] = 'antispam';
1226
          $result['rule_no'] = '0102';
1227
        } /* rule: antispam, mismatch ip
1228
         * sample:
1229
         *   Diagnostic-Code: SMTP; 554 Connection refused(mx). MAIL FROM [[email protected]] mismatches client IP [111.111.111.000].
1230
         */
1231 1
        elseif (preg_match('/MAIL FROM(.*)mismatches client IP/is', $diag_code)) {
1232
          $result['rule_cat'] = 'antispam';
1233
          $result['rule_no'] = '0104';
1234
        } /* rule: antispam, deny ip
1235
         * sample:
1236
         *   Diagnostic-Code: SMTP; 554 Please visit http:// antispam.domain.com/denyip.php?IP=111.111.111.000 (#5.7.1)
1237
         */
1238 1
        elseif (preg_match('/denyip/i', $diag_code)) {
1239
          $result['rule_cat'] = 'antispam';
1240
          $result['rule_no'] = '0144';
1241
        } /* rule: antispam, deny ip
1242
         * sample:
1243
         *   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
1244
         */
1245 1
        elseif (preg_match('/client host.*blocked/is', $diag_code)) {
1246
          $result['rule_cat'] = 'antispam';
1247
          $result['rule_no'] = '0242';
1248
        } /* rule: antispam, reject
1249
         * sample:
1250
         *   Diagnostic-Code: SMTP; 550 Requested action not taken: mail IsCNAPF76kMDARUY.56621S2 is rejected,mx3,BM
1251
         */
1252 1
        elseif (preg_match('/mail.*reject/is', $diag_code)) {
1253
          $result['rule_cat'] = 'antispam';
1254
          $result['rule_no'] = '0147';
1255
        } /* rule: antispam
1256
         * sample:
1257
         *   Diagnostic-Code: SMTP; 552 sorry, the spam message is detected (#5.6.0)
1258
         */
1259 1
        elseif (preg_match('/spam.*detect/is', $diag_code)) {
1260
          $result['rule_cat'] = 'antispam';
1261
          $result['rule_no'] = '0162';
1262
        } /* rule: antispam
1263
         * sample:
1264
         *   Diagnostic-Code: SMTP; 554 5.7.1 Rejected as Spam see: http:// rejected.domain.com/help/spam/rejected.html
1265
         */
1266 1
        elseif (preg_match('/reject.*spam/is', $diag_code)) {
1267
          $result['rule_cat'] = 'antispam';
1268
          $result['rule_no'] = '0216';
1269
        } /* rule: antispam
1270
         * sample:
1271
         *   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).
1272
         */
1273 1
        elseif (preg_match('/SpamTrap/i', $diag_code)) {
1274
          $result['rule_cat'] = 'antispam';
1275
          $result['rule_no'] = '0200';
1276
        } /* rule: antispam, mailfrom mismatch
1277
         * sample:
1278
         *   Diagnostic-Code: SMTP; 550 Verify mailfrom failed,blocked
1279
         */
1280 1
        elseif (preg_match('/Verify mailfrom failed/i', $diag_code)) {
1281
          $result['rule_cat'] = 'antispam';
1282
          $result['rule_no'] = '0210';
1283
        } /* rule: antispam, mailfrom mismatch
1284
         * sample:
1285
         *   Diagnostic-Code: SMTP; 550 Error: MAIL FROM is mismatched with message header from address!
1286
         */
1287 1
        elseif (preg_match('/MAIL.*FROM.*mismatch/is', $diag_code)) {
1288
          $result['rule_cat'] = 'antispam';
1289
          $result['rule_no'] = '0226';
1290
        } /* rule: antispam
1291
         * sample:
1292
         *   Diagnostic-Code: SMTP; 554 5.7.1 Message scored too high on spam scale.  For help, please quote incident ID 22492290.
1293
         */
1294 1
        elseif (preg_match('/spam scale/i', $diag_code)) {
1295
          $result['rule_cat'] = 'antispam';
1296
          $result['rule_no'] = '0211';
1297
        } /* rule: antispam
1298
         * sample:
1299
         *   Diagnostic-Code: SMTP; 554 5.7.1 reject: Client host bypassing service provider's mail relay: ds176.domain.com
1300
         */
1301 1
        elseif (preg_match('/Client host bypass/i', $diag_code)) {
1302
          $result['rule_cat'] = 'antispam';
1303
          $result['rule_no'] = '0229';
1304
        } /* rule: antispam
1305
         * sample:
1306
         *   Diagnostic-Code: SMTP; 550 sorry, it seems as a junk mail
1307
         */
1308 1
        elseif (preg_match('/junk mail/i', $diag_code)) {
1309
          $result['rule_cat'] = 'antispam';
1310
          $result['rule_no'] = '0230';
1311
        } /* rule: antispam
1312
         * sample:
1313
         *   Diagnostic-Code: SMTP; 553-Message filtered. Please see the FAQs section on spam
1314
         */
1315 1
        elseif (preg_match('/message filtered/i', $diag_code)) {
1316
          $result['rule_cat'] = 'antispam';
1317
          $result['rule_no'] = '0243';
1318
        } /* rule: antispam, subject filter
1319
         * sample:
1320
         *   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.
1321
         */
1322 1
        elseif (preg_match('/subject.*consider.*spam/is', $diag_code)) {
1323
          $result['rule_cat'] = 'antispam';
1324
          $result['rule_no'] = '0222';
1325
        } /* rule: internal_error
1326
         * sample:
1327
         *   Diagnostic-Code: SMTP; 451 Temporary local problem - please try later
1328
         */
1329 1
        elseif (preg_match('/Temporary local problem/i', $diag_code)) {
1330
          $result['rule_cat'] = 'internal_error';
1331
          $result['rule_no'] = '0142';
1332
        } /* rule: internal_error
1333
         * sample:
1334
         *   Diagnostic-Code: SMTP; 553 5.3.5 system config error
1335
         */
1336 1
        elseif (preg_match('/system config error/i', $diag_code)) {
1337
          $result['rule_cat'] = 'internal_error';
1338
          $result['rule_no'] = '0153';
1339
        } /* rule: delayed
1340
         * sample:
1341
         *   Diagnostic-Code: X-Postfix; delivery temporarily suspended: conversation with
1342
         *   111.111.111.11[111.111.111.11] timed out while sending end of data -- message may be
1343
         *   sent more than once
1344
         */
1345 1
        elseif (preg_match('/delivery.*suspend/is', $diag_code)) {
1346
          $result['rule_cat'] = 'delayed';
1347
          $result['rule_no'] = '0213';
1348
        }
1349
1350
        // =========== rules based on the dsn_msg ===============
1351
1352
        /* rule: unknown
1353
         * sample:
1354
         *   ----- The following addresses had permanent fatal errors -----
1355
         *   <[email protected]>
1356
         *   ----- Transcript of session follows -----
1357
         *   ... while talking to mta1.domain.com.:
1358
         *   >>> DATA
1359
         *   <<< 503 All recipients are invalid
1360
         *   554 5.0.0 Service unavailable
1361
         */
1362 1
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user)(?:.*)invalid/i', $dsn_msg)) {
1363
          $result['rule_cat'] = 'unknown';
1364
          $result['rule_no'] = '0107';
1365
        } /* rule: unknown
1366
         * sample:
1367
         *   ----- Transcript of session follows -----
1368
         *   [email protected]... Deferred: No such file or directory
1369
         */
1370 1
        elseif (preg_match('/Deferred.*No such.*(?:file|directory)/i', $dsn_msg)) {
1371
          $result['rule_cat'] = 'unknown';
1372
          $result['rule_no'] = '0141';
1373
        } /* rule: unknown
1374
         * sample:
1375
         *   Failed to deliver to '<[email protected]>'
1376
         *   LOCAL module(account xxxx) reports:
1377
         *   mail receiving disabled
1378
         */
1379 1
        elseif (preg_match('/mail receiving disabled/i', $dsn_msg)) {
1380
          $result['rule_cat'] = 'unknown';
1381
          $result['rule_no'] = '0194';
1382
        } /* rule: unknown
1383
         * sample:
1384
         *   - These recipients of your message have been processed by the mail server:
1385
         *   [email protected]; Failed; 5.1.1 (bad destination mailbox address)
1386
         */
1387 1
        elseif (preg_match('/bad.*(?:alias|account|recipient|address|email|mailbox|user)/i', $status_code)) {
1388
          $result['rule_cat'] = 'unknown';
1389
          $result['rule_no'] = '02441';
1390
        } /* rule: unknown
1391
         * sample:
1392
         *   - These recipients of your message have been processed by the mail server:
1393
         *   [email protected]; Failed; 5.1.1 (bad destination mailbox address)
1394
         */
1395 1
        elseif (preg_match('/bad.*(?:alias|account|recipient|address|email|mailbox|user)/i', $dsn_msg)) {
1396 1
          $result['rule_cat'] = 'unknown';
1397 1
          $result['rule_no'] = '0244';
1398
        } /* rule: full
1399
         * sample 1:
1400
         *   This Message was undeliverable due to the following reason:
1401
         *   The user(s) account is temporarily over quota.
1402
         *   <[email protected]>
1403
         * sample 2:
1404
         *   Recipient address: [email protected]
1405
         *   Reason: Over quota
1406
         */
1407 1
        elseif (preg_match('/over.*quota/i', $dsn_msg)) {
1408
          $result['rule_cat'] = 'full';
1409
          $result['rule_no'] = '0131';
1410
        } /* rule: full
1411
         * sample:
1412
         *   Sorry the recipient quota limit is exceeded.
1413
         *   This message is returned as an error.
1414
         */
1415 1
        elseif (preg_match('/quota.*exceeded/i', $dsn_msg)) {
1416
          $result['rule_cat'] = 'full';
1417
          $result['rule_no'] = '0150';
1418
        } /* rule: full
1419
         * sample:
1420
         *   The user to whom this message was addressed has exceeded the allowed mailbox
1421
         *   quota. Please resend the message at a later time.
1422
         */
1423 1
        elseif (preg_match("/exceed.*\n?.*quota/i", $dsn_msg)) {
1424
          $result['rule_cat'] = 'full';
1425
          $result['rule_no'] = '0187';
1426
        } /* rule: full
1427
         * sample 1:
1428
         *   Failed to deliver to '<[email protected]>'
1429
         *   LOCAL module(account xxxxxx) reports:
1430
         *   account is full (quota exceeded)
1431
         * sample 2:
1432
         *   Error in fabiomod_sql_glob_init: no data source specified - database access disabled
1433
         *   [Fri Feb 17 23:29:38 PST 2006] full error for caltsmy:
1434
         *   that member's mailbox is full
1435
         *   550 5.0.0 <[email protected]>... Can't create output
1436
         */
1437 1
        elseif (preg_match('/(?:alias|account|recipient|address|email|mailbox|user).*full/i', $dsn_msg)) {
1438
          $result['rule_cat'] = 'full';
1439
          $result['rule_no'] = '0132';
1440
        } /* rule: full
1441
         * sample:
1442
         *   gaosong "(0), ErrMsg=Mailbox space not enough (space limit is 10240KB)
1443
         */
1444 1
        elseif (preg_match('/space.*not.*enough/i', $dsn_msg)) {
1445
          $result['rule_cat'] = 'full';
1446
          $result['rule_no'] = '0219';
1447
        } /* rule: defer
1448
         * sample 1:
1449
         *   ----- Transcript of session follows -----
1450
         *   [email protected]... Deferred: Connection refused by nomail.tpe.domain.com.
1451
         *   Message could not be delivered for 5 days
1452
         *   Message will be deleted from queue
1453
         * sample 2:
1454
         *   451 4.4.1 reply: read error from www.domain.com.
1455
         *   [email protected]... Deferred: Connection reset by www.domain.com.
1456
         */
1457 1
        elseif (preg_match('/Deferred.*Connection (?:refused|reset)/i', $dsn_msg)) {
1458
          $result['rule_cat'] = 'defer';
1459
          $result['rule_no'] = '0115';
1460
        } /* rule: dns_unknown
1461
         * sample:
1462
         *   ----- The following addresses had permanent fatal errors -----
1463
         *   Tan XXXX SSSS <[email protected]>
1464
         *   ----- Transcript of session follows -----
1465
         *   553 5.1.2 XXXX SSSS <[email protected]>... Invalid host name
1466
         */
1467 1
        elseif (preg_match('/Invalid host name/i', $dsn_msg)) {
1468
          $result['rule_cat'] = 'dns_unknown';
1469
          $result['rule_no'] = '0239';
1470
        } /* rule: dns_unknown
1471
         * sample:
1472
         *   ----- Transcript of session follows -----
1473
         *   [email protected]... Deferred: mail.domain.com.: No route to host
1474
         */
1475 1
        elseif (preg_match('/Deferred.*No route to host/i', $dsn_msg)) {
1476
          $result['rule_cat'] = 'dns_unknown';
1477
          $result['rule_no'] = '0240';
1478
        } /* rule: dns_unknown
1479
         * sample:
1480
         *   ----- Transcript of session follows -----
1481
         *   550 5.1.2 [email protected]... Host unknown (Name server: .: no data known)
1482
         */
1483 1
        elseif (preg_match('/Host unknown/i', $dsn_msg)) {
1484
          $result['rule_cat'] = 'dns_unknown';
1485
          $result['rule_no'] = '0140';
1486
        } /* rule: dns_unknown
1487
         * sample:
1488
         *   ----- Transcript of session follows -----
1489
         *   451 HOTMAIL.com.tw: Name server timeout
1490
         *   Message could not be delivered for 5 days
1491
         *   Message will be deleted from queue
1492
         */
1493 1
        elseif (preg_match('/Name server timeout/i', $dsn_msg)) {
1494
          $result['rule_cat'] = 'dns_unknown';
1495
          $result['rule_no'] = '0118';
1496
        } /* rule: dns_unknown
1497
         * sample:
1498
         *   ----- Transcript of session follows -----
1499
         *   [email protected]... Deferred: Connection timed out with hkfight.com.
1500
         *   Message could not be delivered for 5 days
1501
         *   Message will be deleted from queue
1502
         */
1503 1
        elseif (preg_match('/Deferred.*Connection.*tim(?:e|ed).*out/i', $dsn_msg)) {
1504
          $result['rule_cat'] = 'dns_unknown';
1505
          $result['rule_no'] = '0119';
1506
        } /* rule: dns_unknown
1507
         * sample:
1508
         *   ----- Transcript of session follows -----
1509
         *   [email protected]... Deferred: Name server: domain.com.: host name lookup failure
1510
         */
1511 1
        elseif (preg_match('/Deferred.*host name lookup failure/i', $dsn_msg)) {
1512
          $result['rule_cat'] = 'dns_unknown';
1513
          $result['rule_no'] = '0121';
1514
        } /* rule: dns_loop
1515
         * sample:
1516
         *   ----- Transcript of session follows -----
1517
         *   554 5.0.0 MX list for znet.ws. points back to mail01.domain.com
1518
         *   554 5.3.5 Local configuration error
1519
         */
1520 1
        elseif (preg_match('/MX list.*point.*back/i', $dsn_msg)) {
1521
          $result['rule_cat'] = 'dns_loop';
1522
          $result['rule_no'] = '0199';
1523
        } /* rule: internal_error
1524
         * sample:
1525
         *   ----- Transcript of session follows -----
1526
         *   451 4.0.0 I/O error
1527
         */
1528 1
        elseif (preg_match("/I\/O error/i", $dsn_msg)) {
1529
          $result['rule_cat'] = 'internal_error';
1530
          $result['rule_no'] = '0120';
1531
        } /* rule: internal_error
1532
         * sample:
1533
         *   Failed to deliver to '[email protected]'
1534
         *   SMTP module(domain domain.com) reports:
1535
         *   connection with mx1.mail.domain.com is broken
1536
         */
1537 1
        elseif (preg_match('/connection.*broken/i', $dsn_msg)) {
1538
          $result['rule_cat'] = 'internal_error';
1539
          $result['rule_no'] = '0231';
1540
        } /* rule: other
1541
         * sample:
1542
         *   Delivery to the following recipients failed.
1543
         *   [email protected]
1544
         */
1545 1
        elseif (preg_match("/Delivery to the following recipients failed.*\n.*\n.*" . $result['email'] . '/i', $dsn_msg)) {
1546
          $result['rule_cat'] = 'other';
1547
          $result['rule_no'] = '0176';
1548
        }
1549
1550
        // Followings are wind-up rule: must be the last one
1551
        //   many other rules msg end up with "550 5.1.1 ... User unknown"
1552
        //   many other rules msg end up with "554 5.0.0 Service unavailable"
1553
1554
        /* rule: unknown
1555
         * sample 1:
1556
         *   ----- The following addresses had permanent fatal errors -----
1557
         *   <[email protected]>
1558
         *   (reason: User unknown)
1559
         * sample 2:
1560
         *   550 5.1.1 [email protected]... User unknown
1561
         */
1562 1
        elseif (preg_match('/(?:User unknown|Unknown user)/i', $dsn_msg)) {
1563
          $result['rule_cat'] = 'unknown';
1564
          $result['rule_no'] = '0193';
1565
        } /* rule: unknown
1566
         * sample:
1567
         *   554 5.0.0 Service unavailable
1568
         */
1569 1
        elseif (preg_match('/Service unavailable/i', $dsn_msg)) {
1570 1
          $result['rule_cat'] = 'unknown';
1571 1
          $result['rule_no'] = '0214';
1572
        }
1573 2
        break;
1574
1575
      case 'delayed':
1576
        $result['rule_cat'] = 'delayed';
1577
        $result['rule_no'] = '0110';
1578
        break;
1579
1580
      case 'delivered':
1581
      case 'relayed':
1582
      case 'expanded': // unhandled cases
1583
        break;
1584
1585
      default:
1586
        break;
1587
    }
1588
  }
1589
1590 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...
1591 2
  if ($result['rule_no'] == '0000') {
1592 1
    if ($debug_mode) {
1593
      echo 'email: ' . $result['email'] . $bmh_newline;
1594
      echo 'Action: ' . $action . $bmh_newline;
1595
      echo 'Status: ' . $status_code . $bmh_newline;
1596
      echo 'Diagnostic-Code: ' . $diag_code . $bmh_newline;
1597
      echo "DSN Message:<br />\n" . $dsn_msg . $bmh_newline;
1598 1
      echo $bmh_newline;
1599
    }
1600 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...
1601 2
    if ($result['bounce_type'] === false) {
1602 2
      $result['bounce_type'] = $rule_categories[$result['rule_cat']]['bounce_type'];
1603 2
      $result['remove'] = $rule_categories[$result['rule_cat']]['remove'];
1604
    }
1605
  }
1606
1607 2
  return $result;
1608
}
1609