Debian Codegraph @

lib/Qpsmtpd/DSN.pm

raw
1 #
2 # Enhanced Mail System Status Codes - RFC 1893
3 #
4 package Qpsmtpd::DSN;
5 use strict;
6 use Qpsmtpd::Constants;
7
8 =head1 NAME
9
10 Qpsmtpd::DSN - Enhanced Mail System Status Codes - RFC 1893
11
12 =head1 DESCRIPTION
13
14 The B<Qpsmtpd::DSN> implements the I<Enhanced Mail System Status Codes> from
15 RFC 1893.
16
17 =head1 USAGE
18
19 Any B<qpsmtpd> plugin can access these status codes. All sub routines are used
20 the same way:
21 use Qpsmtpd::DSN;
22 ...;
23 return Qpsmtpd::DSN->relaying_denied();
24
25 or
26
27 return Qpsmtpd::DSN->relaying_denied("Relaying from $ip denied");
28
29 or
30
31 return Qpsmtpd::DSN->relaying_denied(DENY,"Relaying from $ip denied");
32
33 If no status message was given, it will use the predefined one from the
34 RFC. If the first argument is numeric, it will use this as a return code,
35 else the default return code is used. See below which default return code
36 is used in the different functions.
37
38 The first example will return
39 I<(DENY, "Relaying denied");>
40 the others
41 I<(DENY, "Relaying from $ip denied");>
42 which will be returned to qpsmtpd.
43
44 In those sub routines which don't start with I<addr_, sys_, net_, proto_,
45 media_, sec_> I've added a default message which describes the status better
46 than the RFC message.
47
48 =cut
49
50 my @rfc1893 = (
51 [
52 "Other or Undefined Status", # x.0.x
53 ],
54 [
55 "Other address status.", # x.1.0
56 "Bad destination mailbox address.", # x.1.1
57 "Bad destination system address.", # x.1.2
58 "Bad destination mailbox address syntax.", # x.1.3
59 "Destination mailbox address ambiguous.", # x.1.4
60 "Destination address valid.", # x.1.5
61 "Destination mailbox has moved, No forwarding address.", # x.1.6
62 "Bad sender's mailbox address syntax.", # x.1.7
63 "Bad sender's system address.", # x.1.8
64 ],
65 [
66 "Other or undefined mailbox status.", # x.2.0
67 "Mailbox disabled, not accepting messages.", # x.2.1
68 "Mailbox full.", # x.2.2
69 "Message length exceeds administrative limit.", # x.2.3
70 "Mailing list expansion problem.", # x.2.4
71 ],
72 [
73 "Other or undefined mail system status.", # x.3.0
74 "Mail system full.", # x.3.1
75 "System not accepting network messages.", # x.3.2
76 "System not capable of selected features.", # x.3.3
77 "Message too big for system.", # x.3.4
78 "System incorrectly configured.", # x.3.5
79 ],
80 [
81 "Other or undefined network or routing status.", # x.4.0
82 "No answer from host.", # x.4.1
83 "Bad connection.", # x.4.2
84 "Directory server failure.", # x.4.3
85 "Unable to route.", # x.4.4
86 "Mail system congestion.", # x.4.5
87 "Routing loop detected.", # x.4.6
88 "Delivery time expired.", # x.4.7
89 ],
90 [
91 "Other or undefined protocol status.", # x.5.0
92 "Invalid command.", # x.5.1
93 "Syntax error.", # x.5.2
94 "Too many recipients.", # x.5.3
95 "Invalid command arguments.", # x.5.4
96 "Wrong protocol version.", # x.5.5
97 ],
98 [
99 "Other or undefined media error.", # x.6.0
100 "Media not supported.", # x.6.1
101 "Conversion required and prohibited.", # x.6.2
102 "Conversion required but not supported.", # x.6.3
103 "Conversion with loss performed.", # x.6.4
104 "Conversion Failed.", # x.6.5
105 ],
106 [
107 "Other or undefined security status.", # x.7.0
108 "Delivery not authorized, message refused.", # x.7.1
109 "Mailing list expansion prohibited.", # x.7.2
110 "Security conversion required but not possible.", # x.7.3
111 "Security features not supported.", # x.7.4
112 "Cryptographic failure.", # x.7.5
113 "Cryptographic algorithm not supported.", # x.7.6
114 "Message integrity failure.", # x.7.7
115 ],
116 );
117
118 sub _status {
119 my $return = shift;
120 my $const = Qpsmtpd::Constants::return_code($return);
121 if ($const =~ /^DENYSOFT/) {
122 return 4;
123 }
124 elsif ($const =~ /^DENY/) {
125 return 5;
126 }
127 elsif ($const eq 'OK' or $const eq 'DONE') {
128 return 2;
129 }
130 else { # err .... no :)
131 return 4; # just 2,4,5 are allowed.. temp error by default
132 }
133 }
134
135 sub _dsn {
136 my ($self, $return, $reason, $default, $subject, $detail) = @_;
137 if (!defined $return) {
138 $return = $default;
139 }
140 elsif ($return !~ /^\d+$/) {
141 $reason = $return;
142 $return = $default;
143 }
144 my $msg = $rfc1893[$subject][$detail];
145 unless (defined $msg) {
146 $detail = 0;
147 $msg = $rfc1893[$subject][$detail];
148 unless (defined $msg) {
149 $subject = 0;
150 $msg = $rfc1893[$subject][$detail];
151 }
152 }
153 my $class = &_status($return);
154 if (defined $reason) {
155 $msg = $reason;
156 }
157 return ($return, "$msg (#$class.$subject.$detail)");
158 }
159
160 sub unspecified { shift->_dsn(shift, shift, DENYSOFT, 0, 0); }
161
162 =head1 ADDRESS STATUS
163
164 =over 9
165
166 =item addr_unspecified
167
168 X.1.0
169 default: DENYSOFT
170
171 =cut
172
173 sub addr_unspecified { shift->_dsn(shift, shift, DENYSOFT, 1, 0); }
174
175 =item no_such_user, addr_bad_dest_mbox
176
177 X.1.1
178 default: DENY
179
180 =cut
181
182 sub no_such_user { shift->_dsn(shift, (shift || "No such user"), DENY, 1, 1); }
183 sub addr_bad_dest_mbox { shift->_dsn(shift, shift, DENY, 1, 1); }
184
185 =item addr_bad_dest_system
186
187 X.1.2
188 default: DENY
189
190 =cut
191
192 sub addr_bad_dest_system { shift->_dsn(shift, shift, DENY, 1, 2); }
193
194 =item addr_bad_dest_syntax
195
196 X.1.3
197 default: DENY
198
199 =cut
200
201 sub addr_bad_dest_syntax { shift->_dsn(shift, shift, DENY, 1, 3); }
202
203 =item addr_dest_ambigous
204
205 X.1.4
206 default: DENYSOFT
207
208 =cut
209
210 sub addr_dest_ambigous { shift->_dsn(shift, shift, DENYSOFT, 1, 4); }
211
212 =item addr_rcpt_ok
213
214 X.1.5
215 default: OK
216
217 =cut
218
219 # XXX: do we need this? Maybe in all address verifying plugins?
220 sub addr_rcpt_ok { shift->_dsn(shift, shift, OK, 1, 5); }
221
222 =item addr_mbox_moved
223
224 X.1.6
225 default: DENY
226
227 =cut
228
229 sub addr_mbox_moved { shift->_dsn(shift, shift, DENY, 1, 6); }
230
231 =item addr_bad_from_syntax
232
233 X.1.7
234 default: DENY
235
236 =cut
237
238 sub addr_bad_from_syntax { shift->_dsn(shift, shift, DENY, 1, 7); }
239
240 =item addr_bad_from_system
241
242 X.1.8
243 default: DENY
244
245 =back
246
247 =cut
248
249 sub addr_bad_from_system { shift->_dsn(shift, shift, DENY, 1, 8); }
250
251 =head1 MAILBOX STATUS
252
253 =over 5
254
255 =item mbox_unspecified
256
257 X.2.0
258 default: DENYSOFT
259
260 =cut
261
262 sub mbox_unspecified { shift->_dsn(shift, shift, DENYSOFT, 2, 0); }
263
264 =item mbox_disabled
265
266 X.2.1
267 default: DENY ...but RFC says:
268 The mailbox exists, but is not accepting messages. This may
269 be a permanent error if the mailbox will never be re-enabled
270 or a transient error if the mailbox is only temporarily
271 disabled.
272
273 =cut
274
275 sub mbox_disabled { shift->_dsn(shift, shift, DENY, 2, 1); }
276
277 =item mbox_full
278
279 X.2.2
280 default: DENYSOFT
281
282 =cut
283
284 sub mbox_full { shift->_dsn(shift, shift, DENYSOFT, 2, 2); }
285
286 =item mbox_msg_too_long
287
288 X.2.3
289 default: DENY
290
291 =cut
292
293 sub mbox_msg_too_long { shift->_dsn(shift, shift, DENY, 2, 3); }
294
295 =item mbox_list_expansion_problem
296
297 X.2.4
298 default: DENYSOFT
299
300 =back
301
302 =cut
303
304 sub mbox_list_expansion_problem { shift->_dsn(shift, shift, DENYSOFT, 2, 4); }
305
306 =head1 MAIL SYSTEM STATUS
307
308 =over 4
309
310 =item sys_unspecified
311
312 X.3.0
313 default: DENYSOFT
314
315 =cut
316
317 sub sys_unspecified { shift->_dsn(shift, shift, DENYSOFT, 3, 0); }
318
319 =item sys_disk_full
320
321 X.3.1
322 default: DENYSOFT
323
324 =cut
325
326 sub sys_disk_full { shift->_dsn(shift, shift, DENYSOFT, 3, 1); }
327
328 =item sys_not_accepting_mail
329
330 X.3.2
331 default: DENYSOFT
332
333 =cut
334
335 sub sys_not_accepting_mail { shift->_dsn(shift, shift, DENYSOFT, 3, 2); }
336
337 =item sys_not_supported
338
339 X.3.3
340 default: DENYSOFT
341 Selected features specified for the message are not
342 supported by the destination system. This can occur in
343 gateways when features from one domain cannot be mapped onto
344 the supported feature in another.
345
346 =cut
347
348 sub sys_not_supported { shift->_dsn(shift, shift, DENYSOFT, 3, 3); }
349
350 =item sys_msg_too_big
351
352 X.3.4
353 default DENY
354
355 =back
356
357 =cut
358
359 sub sys_msg_too_big { shift->_dsn(shift, shift, DENY, 3, 4); }
360
361 =head1 NETWORK AND ROUTING STATUS
362
363 =cut
364
365 =over 4
366
367 =item net_unspecified
368
369 X.4.0
370 default: DENYSOFT
371
372 =cut
373
374 sub net_unspecified { shift->_dsn(shift, shift, DENYSOFT, 4, 0); }
375
376 # not useful # sub net_no_answer { shift->_dsn(shift,shift,4,1); }
377 # not useful # sub net_bad_connection { shift->_dsn(shift,shift,4,2); }
378
379 =item net_directory_server_failed, temp_resolver_failed
380
381 X.4.3
382 default: DENYSOFT
383
384 =cut
385
386 sub temp_resolver_failed {
387 shift->_dsn(shift, (shift || "Temporary address resolution failure"),
388 DENYSOFT, 4, 3);
389 }
390 sub net_directory_server_failed { shift->_dsn(shift, shift, DENYSOFT, 4, 3); }
391
392 # not useful # sub net_unable_to_route { shift->_dsn(shift,shift,4,4); }
393
394 =item net_system_congested
395
396 X.4.5
397 default: DENYSOFT
398
399 =cut
400
401 sub net_system_congested { shift->_dsn(shift, shift, DENYSOFT, 4, 5); }
402
403 =item net_routing_loop, too_many_hops
404
405 X.4.6
406 default: DENY, but RFC says:
407 A routing loop caused the message to be forwarded too many
408 times, either because of incorrect routing tables or a user
409 forwarding loop. This is useful only as a persistent
410 transient error.
411
412 Why do we want to DENYSOFT something like this?
413
414 =back
415
416 =cut
417
418 sub net_routing_loop { shift->_dsn(shift, shift, DENY, 4, 6); }
419 sub too_many_hops {
420 shift->_dsn(shift, (shift || "Too many hops"), DENY, 4, 6,);
421 }
422
423 # not useful # sub delivery_time_expired { shift->_dsn(shift,shift,4,7); }
424
425 =head1 MAIL DELIVERY PROTOCOL STATUS
426
427 =over 6
428
429 =item proto_unspecified
430
431 X.5.0
432 default: DENYSOFT
433
434 =cut
435
436 sub proto_unspecified { shift->_dsn(shift, shift, DENYSOFT, 5, 0); }
437
438 =item proto_invalid_command
439
440 X.5.1
441 default: DENY
442
443 =cut
444
445 sub proto_invalid_command { shift->_dsn(shift, shift, DENY, 5, 1); }
446
447 =item proto_syntax_error
448
449 X.5.2
450 default: DENY
451
452 =cut
453
454 sub proto_syntax_error { shift->_dsn(shift, shift, DENY, 5, 2); }
455
456 =item proto_rcpt_list_too_long, too_many_rcpts
457
458 X.5.3
459 default: DENYSOFT
460
461 =cut
462
463 sub proto_rcpt_list_too_long { shift->_dsn(shift, shift, DENYSOFT, 5, 3); }
464 sub too_many_rcpts { shift->_dsn(shift, shift, DENYSOFT, 5, 3); }
465
466 =item proto_invalid_cmd_args
467
468 X.5.4
469 default: DENY
470
471 =cut
472
473 sub proto_invalid_cmd_args { shift->_dsn(shift, shift, DENY, 5, 4); }
474
475 =item proto_wrong_version
476
477 X.5.5
478 default: DENYSOFT
479
480 =back
481
482 =cut
483
484 sub proto_wrong_version { shift->_dsn(shift, shift, DENYSOFT, 5, 5); }
485
486 =head1 MESSAGE CONTENT OR MESSAGE MEDIA STATUS
487
488 =over 5
489
490 =item media_unspecified
491
492 X.6.0
493 default: DENYSOFT
494
495 =cut
496
497 sub media_unspecified { shift->_dsn(shift, shift, DENYSOFT, 6, 0); }
498
499 =item media_unsupported
500
501 X.6.1
502 default: DENY
503
504 =cut
505
506 sub media_unsupported { shift->_dsn(shift, shift, DENY, 6, 1); }
507
508 =item media_conv_prohibited
509
510 X.6.2
511 default: DENY
512
513 =cut
514
515 sub media_conv_prohibited { shift->_dsn(shift, shift, DENY, 6, 2); }
516
517 =item media_conv_unsupported
518
519 X.6.3
520 default: DENYSOFT
521
522 =cut
523
524 sub media_conv_unsupported { shift->_dsn(shift, shift, DENYSOFT, 6, 3); }
525
526 =item media_conv_lossy
527
528 X.6.4
529 default: DENYSOFT
530
531 =back
532
533 =cut
534
535 sub media_conv_lossy { shift->_dsn(shift, shift, DENYSOFT, 6, 4); }
536
537 =head1 SECURITY OR POLICY STATUS
538
539 =over 8
540
541 =item sec_unspecified
542
543 X.7.0
544 default: DENYSOFT
545
546 =cut
547
548 sub sec_unspecified { shift->_dsn(shift, shift, DENYSOFT, 7, 0); }
549
550 =item sec_sender_unauthorized, bad_sender_ip, relaying_denied
551
552 X.7.1
553 default: DENY
554
555 =cut
556
557 sub sec_sender_unauthorized { shift->_dsn(shift, shift, DENY, 7, 1); }
558
559 sub bad_sender_ip {
560 shift->_dsn(shift, (shift || "Bad sender's IP"), DENY, 7, 1,);
561 }
562
563 sub relaying_denied {
564 shift->_dsn(shift, (shift || "Relaying denied"), DENY, 7, 1);
565 }
566
567 =item sec_list_dest_prohibited
568
569 X.7.2
570 default: DENY
571
572 =cut
573
574 sub sec_list_dest_prohibited { shift->_dsn(shift, shift, DENY, 7, 2); }
575
576 =item sec_conv_failed
577
578 X.7.3
579 default: DENY
580
581 =cut
582
583 sub sec_conv_failed { shift->_dsn(shift, shift, DENY, 7, 3); }
584
585 =item sec_feature_unsupported
586
587 X.7.4
588 default: DENY
589
590 =cut
591
592 sub sec_feature_unsupported { shift->_dsn(shift, shift, DENY, 7, 4); }
593
594 =item sec_crypto_failure
595
596 X.7.5
597 default: DENY
598
599 =cut
600
601 sub sec_crypto_failure { shift->_dsn(shift, shift, DENY, 7, 5); }
602
603 =item sec_crypto_algorithm_unsupported
604
605 X.7.6
606 default: DENYSOFT
607
608 =cut
609
610 sub sec_crypto_algorithm_unsupported {
611 shift->_dsn(shift, shift, DENYSOFT, 7, 6);
612 }
613
614 =item sec_msg_integrity_failure
615
616 X.7.7
617 default: DENY
618
619 =back
620
621 =cut
622
623 sub sec_msg_integrity_failure { shift->_dsn(shift, shift, DENY, 7, 7); }
624
625 1;
626
627 # vim: st=4 sw=4 expandtab