3 # Run fetchmail, and send the output somewhere
6 $ENV{'REMOTE_USER'} = getpwuid($<);
7 require './fetchmail-lib.pl';
9 # Parse command-line args
11 local $a = shift(@ARGV);
15 elsif ($a eq "--file") {
18 elsif ($a eq "--output") {
21 elsif ($a eq "--user") {
24 elsif ($a eq "--errors") {
27 elsif ($a eq "--owner") {
32 if ($fetchmail_config) {
33 # Just run once for a single config file
34 &run_fetchmail($fetchmail_config, $user);
39 while(@uinfo = getpwent()) {
40 next if ($donehome{$uinfo[7]}++);
41 @conf = &parse_config_file("$uinfo[7]/.fetchmailrc");
42 @conf = grep { $_->{'poll'} } @conf;
44 &run_fetchmail("$uinfo[7]/.fetchmailrc", $uinfo[0]);
50 # run_fetchmail(config, user)
53 local ($config, $user) = @_;
55 # Check if we have anything to do
56 local @conf = &parse_config_file($config);
57 @conf = grep { $_->{'poll'} } @conf;
61 local $cmd = "$config{'fetchmail_path'} -v -f ".quotemeta($config);
62 if ($config{'mda_command'}) {
63 $cmd .= " -m ".quotemeta($config{'mda_command'});
65 if ($user && $user ne "root") {
66 $cmd = &command_as_user($user, 0, $cmd);
70 local $out = &backquote_command("($cmd) 2>&1 </dev/null");
75 # Force mailing to user
76 $mail = $user."\@".&get_system_hostname();
78 if ($errors && $ex <= 1) {
79 # No error occurred, so do nothing
82 # Just write to a file
88 # Capture output and email
89 $mm = $module_info{'usermin'} ? "mailbox" : "mailboxes";
90 if (&foreign_check($mm)) {
91 &foreign_require($mm, "$mm-lib.pl");
92 &foreign_require($mm, "boxes-lib.pl");
93 if ($module_info{'usermin'}) {
95 &foreign_call($mm, "list_from_addresses");
99 $fr = &foreign_call($mm, "get_from_address");
101 &foreign_call($mm, "send_text_mail", $fr, $mail, undef,
102 $ex <= 1 ? $text{'email_ok'}
103 : $text{'email_failed'},
107 print "$mm module not installed - could not email the following output :\n";
112 # Output goes to cron
116 # Just throw away output