File: sendmail.diff

package info (click to toggle)
debarchiver 0.11.7
  • links: PTS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 724 kB
  • sloc: perl: 1,599; sh: 109; makefile: 92
file content (629 lines) | stat: -rw-r--r-- 26,647 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
diff --git a/src/debarchiver.pl b/src/debarchiver.pl
index 2eaa9bd..73bf596 100755
--- a/src/debarchiver.pl
+++ b/src/debarchiver.pl
@@ -34,7 +34,7 @@
 ###############################################################################
 ############################# USES ############################################
 ###############################################################################
-
+use File::Spec;
 use Digest::MD5;
 use File::Path qw(mkpath);
 use OpaL::action qw(pdebug action cmdaction
@@ -72,9 +72,16 @@ use OpaL::read qw(readfile readcommand);
 #  2007-10-09 Ola Lundqvist <ola@inguza.com>
 #       Changed force option to ignoredestcheck option.
 
+$mailformat    = "sendmail";
+@mailsearch    = ();
+$usermailcmd   = '';
+
+%cmds = ();
+$cmds{'sendmail'} = "sendmail";
+$cmds{'mail'}     = "mail";
+
 $copycmd = "cp -af";
 $rmcmd = "rm -f";
-$mailcmd = "mail";
 $movecmd = "mv";
 $vrfycmd = "dscverify";
 $cachedir = "/var/cache/debarchiver";
@@ -304,107 +311,124 @@ $help =
     "Usage: debarchiver [option(s)]
 
 options:
- -a | --autoscan       	Does both --autoscanpackages and --autoscansources.
-                         Use this *or* --index, not both.
- --autoscanall		Same as --scanall --autoscan.
- --autoscanpackages	Automaticly run dpkg-scanpackages after all new
-			 packages are installed.
- --autoscansources	Automaticly run dpkg-scansources after all new
-			 packages are installed.
- -b | --bzip            Create bzip2 compressed Packages.bz2 and Sources.bz2
-			 files. 
- --cachedir dir         The apt-ftparchive package cache directory, if --index
-                         is used.  Default $cachedir.
- --cinstall dir		Where the .changes file will be installed to,
-			 empty string to remove it instead, default $cinstall.
- --configfile file      Specify an extra configuration file to read. Will be read
-                         after etc config and user config file.
- --copycmd		The install command to use, default $copycmd.
-			 Both packages and .changes files are installed using
-			 this command.
- -d | --dest dir       	Destination directory. The base directory where all
-  --destdir dir		 the distribution packages reside. Here the
-			 \$distrib/\$major/\$arch/\$section directory structure
-			 will be created.
-                         Default $destdir,
-                         relative to the input directory.
- --debug-level level	What information that should be printed.
-  --dl level		 1 = critical, 2 = error, 3 = normal,
-			 4 = message, 5 = debug, 6 = verbose debug (modules).
- --distinputcriteria     The criteria for which binary packages that should be
-			 installed even if it does not have a .changes file,
-			 default $distinputcriteria.
- --gpgkey               GnuPG key to use to sign the archive.
- --gpgpassfile          File to provide password to GnuPG.
- --help			Prints this information.
- -i | --input dir      	This is the directory where debarchiver is looking for
-  --indir dir		 new packages corresponding *.changes files that
-  --inputdir dir	 should be installed to the --dest directory.
-			 The default directory is
-			 /var/lib/debarchiver/incoming.
- --index | -x           Automatically run apt-ftparchive after all new packages
-                         are installed.  Use this *or* --autoscan, not both.
- --instcmd		DEPRICATED!
- --lockfile file	The lockfile to use, default $lockfile.
- --incompletetime       The time to allow .changes file to be incomplete in
-                         seconds. Defaults to 24 hours.
- --mailcmd		The mail command to use, default $mail.
- --mailfrom             Specify mail sender.
- --majordefault section Default major section to use if undefined
-                        (default: main)
- --movecmd		Command to move files (currently not used at all).
- --nosort		Do not sort packages.
- --nostructurefix	Do not create directories and touch Package files.
- -o | --addoverride    	Automaticly add new packages to the override file.
- --rmcmd		The remove command to use, default $rmcmd.
-			 This can be used to move away the old packages to
-			 some other place.
- --quit-level level	On what level to quit the application, see debug level.
- --scanall		Scan all distributions, sections, etc.
- --scandetect | -s      Scan using apt-ftparchive or dpkg-scan* depending on
-                         what is installed on the system. This is the
-                         recommended way. Only use --index or --autoscan if
-                         you know what you are doing.
- --scanonly             Same as --nosort --nostructurefix.
- -v | --version		Prints the version string.
- --ignoredestcheck	Force install of changes files even if some files
-                        already exists with wrong size or md5 hash.
+ -a | --autoscan        - Does both --autoscanpackages and --autoscansources.
+                          Use this *or* --index, not both.
+ --autoscanall          - Same as --scanall --autoscan.
+ --autoscanpackages     - Automaticly run dpkg-scanpackages after all new
+                          packages are installed.
+ --autoscansources      - Automaticly run dpkg-scansources after all new
+                          packages are installed.
+ -b | --bzip            - Create bzip2 compressed Packages.bz2 and Sources.bz2
+                          files.
+ --cachedir dir         - The apt-ftparchive package cache directory, if --index
+                          is used.  Default $cachedir.
+ --cinstall dir         - Where the .changes file will be installed to,
+                          empty string to remove it instead, default $cinstall.
+ --configfile file      - Specify an extra configuration file to read. Will be
+                          read after etc config and user config file.
+ --copycmd              - The install command to use, default $copycmd.
+                          Both packages and .changes files are installed using
+                          this command.
+ -d | --dest dir        - Destination directory. The base directory where all
+ --destdir dir            the distribution packages reside. Here the
+                          \$distrib/\$major/\$arch/\$section directory structure
+                          will be created.
+                          Default $destdir, relative to the input directory.
+ --debug-level level    - What information that should be printed.
+ --dl level                 1 = critical, 2 = error, 3 = normal,
+                            4 = message, 5 = debug, 6 = verbose debug (modules).
+ --distinputcriteria    - The criteria for which binary packages that should be
+                          installed even if it does not have a .changes file,
+                          default $distinputcriteria.
+ --gpgkey               - GnuPG key to use to sign the archive.
+ --gpgpassfile          - File to provide password to GnuPG.
+ --help                 - Prints this information.
+ -i | --input dir       - This is the directory where debarchiver is looking for
+  --indir dir             new packages corresponding *.changes files that
+  --inputdir dir          should be installed to the --dest directory.
+                          The default directory is
+                          /var/lib/debarchiver/incoming.
+ --index | -x           - Automatically run apt-ftparchive after all new
+                          packages are installed.  Use this *or* --autoscan,
+                          not both.
+ --instcmd              - DEPRICATED!
+ --lockfile file        - The lockfile to use, default $lockfile.
+ --incompletetime       - The time to allow .changes file to be incomplete in
+                          seconds. Defaults to 24 hours.
+ --mailcmd              - The mail command to use, default $mailformat.
+ --mailfrom             - Specify mail sender.
+ --mailformat format    - Define which format has to be used to send emails with
+                          the user command specify by --mailfrom. Only sendmail
+                          and mail formats are supported. By default, if this
+                          option is not given, debarchiver assumes the sendmail
+                          format. The format argument can be one of the
+                          followings:
+                            sendmail = use of the sendmail format
+                            mail     = use of the mail format
+ --majordefault section - Default major section to use if undefined
+                          (default: main)
+ --movecmd              - Command to move files (currently not used at all).
+ --nosort               - Do not sort packages.
+ --nostructurefix       - Do not create directories and touch Package files.
+ -o | --addoverride     - Automaticly add new packages to the override file.
+ --rmcmd                - The remove command to use, default $rmcmd.
+                          This can be used to move away the old packages to
+                          some other place.
+ --quit-level level     - On what level to quit the application, see debug
+                          level.
+ --scanall              - Scan all distributions, sections, etc.
+ --scandetect | -s      - Scan using apt-ftparchive or dpkg-scan* depending on
+                          what is installed on the system. This is the
+                          recommended way. Only use --index or --autoscan if
+                          you know what you are doing.
+ --scanonly             - Same as --nosort --nostructurefix.
+ -v | --version         - Prints the version string.
+ --ignoredestcheck      - Force install of changes files even if some files
+                          already exists with wrong size or md5 hash.
 
 You can also place config files with the following names (in following order)
 $etcconfigfile, $userconfigfile and $inputconfigfile
 (relative to input dir), that will be read before the arguments to this program
 will be parsed. Here you can change the following variables
-        \$cachedir	The cache directory for apt-ftparchive, used if
-			--index is used.
-	\$cinstall	Where the .changes files are installed
-			 (see --cinstall above).
-	\$copycmd	The install command (see --copycmd).
-	\$destdir      	The destination directory (see --destdir above).
-        \$distinputcriteria The criteria for which packages that should be
-			 installed even if it does not have a .changes file,
-			 default $distinputcriteria.
-        \%distinputdirs The directories (distribution => dir) that should be
-			 searched for extra binary packages that does not need
-			 a .changes file to be installed.
-	\$gpgkey	GnuPG key to use to sign the archive.
-        \$gpgpassfile   File to provide password to GnuPG.
-	\$inputdir	The input directory (no effect in $inputconfigfile).
-	\$lockfile	The lockfile to use, default $lockfile.
-        \$ignoredestcheck Force install of changes files even if some files
-                         already exists with wrong size or md5 hash.
-                         Default to 0.
-        \$incompletetime The time to allow .changes file to be incomplete in
-                         seconds. Defaults to 24 hours.
-	\@mailtos	The fields in .changes file that should be used for
-			 mailing SUCCESS and REJECT messages. If there is an
-			 @ char in the arrach it will be used directly.
-        \$mailfrom      Specify mail sender.
-	\$majordefault  Default major section (see --majordefault above).
-	\$movecmd	The move command (see --movecmd).
-        \%release	Additional information to add to generated Release
-			 files.  Supported keys are origin, label, and
-			 description.
-	\$rmcmd		The remove command (see --rmcmd above).
+     \$cachedir          - The cache directory for apt-ftparchive, used if
+                          --index is used.
+     \$cinstall          - Where the .changes files are installed
+                          (see --cinstall above).
+     \$copycmd           - The install command (see --copycmd).
+     \$destdir           - The destination directory (see --destdir above).
+     \$distinputcriteria - The criteria for which packages that should be
+                          installed even if it does not have a .changes file,
+                          default $distinputcriteria.
+     \%distinputdirs     - The directories (distribution => dir) that should be
+                          searched for extra binary packages that does not need
+                          a changes file to be installed.
+     \$gpgkey            - GnuPG key to use to sign the archive.
+     \$gpgpassfile       - File to provide password to GnuPG.
+     \$inputdir          - The input directory (no effect in $inputconfigfile).
+     \$ignoredestcheck   - Force install of changes files even if some files
+                          already exists with wrong size or md5 hash.
+                          Default to 0.
+     \$incompletetime    - The time to allow .changes file to be incomplete in
+                          seconds. Defaults to 24 hours.
+     \$lockfile          - The lockfile to use, default $lockfile.
+     \$mailformat        - The format to use to send emails (see --mailformat
+                          above).
+     \$mailfrom          - Specify mail sender.
+     \@mailtos           - The fields in .changes file that should be used for
+                          mailing SUCCESS and REJECT messages. If there is an
+                          @ char in the arrach it will be used directly.
+     \$majordefault      - Default major section (see --majordefault above).
+     \$movecmd           - The move command (see --movecmd).
+     \%release           - Additional information to add to generated Release
+                          files. Supported keys are origin, label, and
+                          description.
+     \$rmcmd             - The remove command (see --rmcmd above).
+     \$usermailcmd       - It allows the user to tell debarchiver to use a
+                          specific command to send emails. You may also want to
+                          specify which mailformat your mail command handles
+                          by setting the value of the $mailformat variable.
+                          Using the --mailcmd option on the command line will
+                          superseed this variable.
 ";
 
 ###############################################################################
@@ -456,9 +480,12 @@ while ($_ = shift @ARGS2) {
 	elsif (/^--movecmd$/) {
 	    $movecmd = shift @ARGS2;
 	}
-	elsif (/^--mailcmd$/) {
-	    $mailcmd = shift @ARGS2;
-	}
+        elsif (/^--mailcmd$/) {
+            $usermailcmd = shift @ARGS2;
+        }
+        elsif (/^--mailformat$/) {
+            $mailformat = shift @ARGS2;
+        }
 	elsif (/^--mailfrom$/) {
 	    $mailfrom = shift @ARGS2;
 	}
@@ -553,10 +580,13 @@ while ($_ = shift @ARGS2) {
 	}
     }
     else {
-	pdebug(2, "Unknown option $_\n");
+        pdebug(2, "Unknown option $_\n");
     }
 }
 
+&check_mailconfig();
+&check_commands({}, {});
+
 ###############################################################################
 ############################# START ###########################################
 ###############################################################################
@@ -742,37 +772,59 @@ sub determineMailTo() {
 #  2007-10-08 Ola Lundqvist <ola@inguza.com>
 #       Make it possible to specify mail sender.
 ###############################################################################
+sub email($$$) {
+    my ($toAddress, $subject, $msg) = @_;
 
-sub email($$$$) {
-    my ($to, $package, $key, $message) = @_;
-    if (length($to) > 0) {
-	pdebug(5, "Executing mail command, $mailcmd -s '$package $key' $to.");
-	if ($mailfrom ne "") {
-	    if (open(M, "|$mailcmd -s '$package $key' '$to' -- -f '$mailfrom'")) {
-		print M $message;
-		close(M);
-	    }
-	    else {
-		pdebug(2,
-		       "Error executing mail command, $mailcmd -s '$package $key' '$to' -- -f '$mailfrom'.");
-	    }
-	    pdebug(5, "Mail exec done.");
-	}
-	else {
-	    if (open(M, "|$mailcmd -s '$package $key' '$to'")) {
-		print M $message;
-		close(M);
-	    }
-	    else {
-		pdebug(2,
-		       "Error executing mail command, $mailcmd -s '$package $key' '$to'.");
-	    }
-	    pdebug(5, "Mail exec done.");
-	}
+    pdebug(5, "Sending mail ...");
+
+    if ( $use_sendmail && ($mailfrom eq "") ) {
+        pdebug(5, "No sender mail address found, use of the debarchiver user instead.");
     }
-    else {
-	pdebug(3, "No one to send mail to.");
+
+    my $err=1;
+    if ($toAddress eq "") {
+        pdebug(3, "No recipient to send mail to.");
+
+    } elsif ($subject eq "") {
+        pdebug(3, "Empty subject");
+
+    } elsif ($msg eq "") {
+        pdebug(3, "Empty message")
+
+    } else {
+        $err = 0;
+    }
+
+    if ($err) {
+        pdebug(2, "No mail sent due to missing parameters");
+
+    } elsif (defined $cmds{'sendmail'}) {
+
+        pdebug(4, "Use of the sendmail command: $cmds{'sendmail'}");
+        if (open(M, "| $cmds{'sendmail'} -t")) {
+            print M "From: $mailfrom\n" unless ($mailfrom eq "");
+            print M "To: $toAddress\n",
+                    "Subject: $subject\n\n",
+                    $msg . "\n";
+            close(M);
+
+        } else {
+            pdebug(2, "Could not execute $cmds{'sendmail'} $!");
+        }
+
+    } else {
+        pdebug(4, "Use of the mail command: $cmds{'mail'}");
+        if (open(M, "| $cmds{'mail'} -s '$subject' '$toAddress'")) {
+            print M $msg . "\n";
+            close(M);
+
+        } else {
+            pdebug(2, "Could not execute $cmds{'mail'} $!");
+        }
+
     }
+
+    pdebug(5, "Mail exec done.");
 }
 
 ###############################################################################
@@ -790,12 +842,11 @@ sub email($$$$) {
 
 sub mailSuccess() {
     # OOPS! We can not read that file after it has been moved!
-    my $message = $CMeta{ChangesContent};
+    my $message   = $CMeta{ChangesContent};
+    my $subject   = "$CConf{'Source'} ACCEPTED";
+    my $recipient = determineMailTo();
     pdebug(5, "Mail Success.");
-    email(determineMailTo(),
-	  $CConf{'Source'},
-	  "ACCEPTED",
-	  $message);
+    email($recipient, $subject, $message);
 }
 
 ###############################################################################
@@ -816,15 +867,13 @@ sub mailReject() {
     # OOPS! We can not read that file after it has been moved!
     my $message;
     if (length($CConf{ERROR}) > 0) {
-	$message = "ERROR:\n$CConf{ERROR}\n";
+        $message = "ERROR:\n$CConf{ERROR}\n";
     }
-    $message .= $CMeta{ChangesContent};
-
+    $message     .= $CMeta{ChangesContent};
+    my $subject   = "$CConf{'Source'} REJECTED";
+    my $recipient = determineMailTo();
     pdebug(5, "Mail Reject.");
-    email(determineMailTo(),
-	  $CConf{'Source'},
-	  "REJECTED",
-          $message);
+    email($recipient, $subject, $message);
 }
 
 ###############################################################################
@@ -2246,7 +2295,7 @@ sub parseDebOnlyFile($$) {
 #	Switched to using CMeta for ChangeLog meta information.
 #  2005-05-01 Ola Lundqvist <ola@inguza.com>
 #	Renamed to parseChangesFile.
-#  2006-03-25 Jrmy Bobbio <jeremy.bobbio@etu.upmc.fr>
+#  2006-03-25 J�r�my Bobbio <jeremy.bobbio@etu.upmc.fr>
 #       One line fix for udeb support.
 ###############################################################################
 
@@ -2403,8 +2452,146 @@ sub secondIfNotEmpty ($$) {
     return $p1;
 }
 
+###############################################################################
+# Name:         check_commands
+# Description:  Check command available through the hash %cmds
+# Arguments:    %include_hr: set of commands to check
+#                            they must be available into the hash %cmds
+#               %exclude_hr: set of commands to exclude from the check
+#                            they must be available into the hash %cmds
+# Uses:         %cmds
+# Changelog:
+#  2009-03-15 Franck Joncourt <franck.mail@dthconnex.com>
+#   Taken from fwknop (cipherdyne.com)
+###############################################################################
+sub check_commands() {
+    my ($include_hr, $exclude_hr) = @_;
+
+    my @path = qw(
+        /bin
+        /sbin
+        /usr/bin
+        /usr/sbin
+        /usr/local/bin
+        /usr/local/sbin
+    );
+
+    for my $cmd (keys %cmds) {
+
+        if (keys %$include_hr) {
+            next unless defined $include_hr->{$cmd};
+        }
+        if (keys %$exclude_hr) {
+            next if defined $exclude_hr->{$cmd};
+        }
+
+        unless (-x $cmds{$cmd}) {
+
+            my $found = 0;
+            pdebug(4, "$cmd not located/executable at $cmds{$cmd}\n");
+
+            PATH: for my $dir (@path) {
+                if (-x "${dir}/${cmd}") {
+                    $cmds{$cmd} = "${dir}/${cmd}";
+                    $found = 1;
+                    last PATH;
+                }
+            }
+
+            if ($found) {
+                pdebug(4,"Found $cmd at $cmds{$cmd}\n");
+
+            } else {
+                $err = 1;
+                pdebug(4,  "Could not find $cmd anywhere.");
+                return 1;
+            }
+
+        }
+
+        unless (-x $cmds{$cmd}) {
+            pdebug(4,  "Command $cmd is located at $cmds{$cmd}, but is not executable by uid: $<");
+            return 1;
+        }
+    }
+
+    return 0;
+ }
+
+###############################################################################
+# Name:         check_mailconfig
+# Description:  Check the mail settings
+# Arguments:    none
+# Uses:         @mailsearch, %cmds, $usermailcmd, $mailformat
+# Changelog:
+#  2009-03-15 Franck Joncourt <franck.mail@dthconnex.com>
+#   Written
+###############################################################################
+sub  check_mailconfig()
+{
+    # If the user defines his own mail command through the --mailcmd option,
+    # we check which mail format has to be used according to the --mailformat
+    # option. Sendmail is the default behavior.
+    if ( ($mailformat ne "") && ($usermailcmd eq "") ) {
+        pdebug(2, "The mailformat option must be used in conjunction to the mailcmd option.");
+
+    } elsif ($mailformat eq "sendmail") {
+        @mailsearch = ("sendmail", "mail");
+
+    } elsif ($mailformat eq "mail") {
+        @mailsearch = ("mail", "sendmail");
+
+    } else {
+        pdebug(2, "The mailformat option only supports either sendmail or mail format.");
+    }
+
+    # Check whether the user has specified its own mail command or not.
+    # The full path to this one is stored in the cmd specify by first
+    # value in the  array $mailformat.
+    if ($usermailcmd ne "") {
+
+        if (!File::Spec->file_name_is_absolute($usermailcmd)) {
+            $usermailcmd = File::Spec->rel2abs($usermailcmd);
+        }
+
+        $usermailcmd !~ m|^(.*\/)+(.*)|;
+        $cmds{$2} = $usermailcmd;
+        $usermailcmd = $2;
+
+        my $err = &check_commands({$usermailcmd => ''}, {});
+        if ($err) {
+            pdebug(2, "Unable to find $usermailcmd");
+        }
+
+        $cmds{$mailsearch[0]} = $cmds{$usermailcmd};
+    }
+
+    # Go through all of the mail commands, find one available and remove
+    # the others from the hash.
+    my $nberr = 0;
+    my $found = 0;
+    foreach $cmd (@mailsearch) {
+
+        my $err = &check_commands({$cmd => ''}, {});
+        if ($err) {
+            delete $cmds{$cmd};
+            $nberr++;
+
+        } elsif ($found == 0) {
+            $found = 1;
+
+        } else {
+            delete $cmds{$cmd};
+        }
+    }
+    if ($nberr >= @mailsearch) {
+        pdebug(2, "No mail command has been found.");
+    }
+}
+
 __END__
 
+
 ###############################################################################
 ############################# DOCUMENTATION ###################################
 ###############################################################################
@@ -2516,6 +2703,20 @@ Command to move files (currently not used at all).
 The time to allow .changes file to be incomplete in seconds.
 Defaults to 24 hours.
 
+=item B<--mailcmd>
+
+The command to use to send emails. The default behavior is to use the
+sendmail command.
+
+=item B<--mailformat>
+
+Define which format has to be used to send emails with the user command
+specify by --mailfrom. Only sendmail and mail formats are supported. By
+default, if this  option is not given, debarchiver assumes the sendmail
+format. The argument can be one of the followings:
+  sendmail = use of the sendmail format
+  mail     = use of the mail format
+
 =item B<--mailfrom>
 
 Specify mail sender.
@@ -2560,12 +2761,16 @@ Prints the version string.
 
 Force install of changes files even if some files already exists with wrong size or md5 hash.
 
+=back
+
 =head1 CONFIG FILE
 
 You can also place config files with the following names (in following order) /etc/debarchiver.conf, ~/.debarchiver.conf and input.conf (relative to input directory) that will be read before, the arguments to this program will be parsed. Here you can change the following variables:
 
 The configuration files are read as perl modules they should end with a true value. Therefore they should always end with 1;
 
+=over 4
+
 =item B<$bzip>
 
 If set to 0 no bzip2 files will be generated. If set to 1 bzip2 files will
@@ -2621,6 +2826,10 @@ The lockfile to use, default $lockfile.
 
 An array of strings that should be mailed to. If the string contains an email address that one is used. If it contains an incomplete email address, i.e. @hostname, the username owning the file is used @ the hostname specified. If no @ character is found in the string, it is considered as a field in the .changes file. Such a field can for example be Maintainer or Uploaders.
 
+=item B<$mailformat>
+
+The format to use to send emails (see --mailformat above).
+
 =item B<$mailfrom>
 
 Specify the sender of emails.
@@ -2654,6 +2863,14 @@ Force install of changes files even if some files already exists with wrong size
 
 Choose to enable (1) or disable (2) signature verification for packages uploaded into %distinputdirs. This works independently from $verifysignatures.
 
+=item B<$usermailcmd>
+
+It allows the user to tell debarchiver to use a specific command to send emails.
+You may also want to specify which mailformat your mail command handles by
+setting the value of the $mailformat variable. Using the --mailcmd option on the
+command line will superseed this
+variable.
+
 =back
 
 =head1 PACKAGE INDEXING