document and check refund reasons
[freeside.git] / bin / create-fetchmailrc
1 #!/usr/bin/perl -w
2 # this quick hack helps you generate/maintain .fetchmailrc files from
3 # FS::acct_snarf data.  it is run from a shellcommands export as:
4 # create-fetchmailrc $username $dir $snarf_machine1 $snarf_username1 $snarf__password1 $snarf_machine2 $snarf_username2 $snarf__password2 ...
5
6 use strict;
7 use POSIX qw( setuid setgid );
8
9 my $header = <<END;
10 # Configuration created by create-fetchmailrc
11 set postmaster "postmaster"
12 set bouncemail
13 set no spambounce
14 set properties ""
15 set daemon 240
16 END
17
18 my $username = shift @ARGV or die "no username specified\n";
19 my $homedir  = shift @ARGV or die "no homedir specified\n";
20 my $filename = "$homedir/.fetchmailrc";
21
22 my $gid = scalar(getgrnam($username)) or die "can't find $username's gid\n";
23 my $uid = scalar(getpwnam($username)) or die "can't find $username's uid\n";
24
25 exit unless $ARGV[0];
26
27 open(FETCHMAILRC, ">$filename") or die "can't open $filename: $!\n";
28 chown $uid, $gid, $filename     or die "can't chown $uid.$gid $filename: $!\n";
29 chmod 0600, $filename           or die "can't chmod 600 $filename: $!\n";
30 print FETCHMAILRC $header;
31
32 while ($ARGV[0]) {
33   my( $s_machine, $s_username, $s_password ) = splice( @ARGV, 0, 3 );
34   print FETCHMAILRC <<END;
35 poll $s_machine
36         user '$s_username' there with password '$s_password' is '$username' here
37 END
38 }
39
40 close FETCHMAILRC;
41
42 setgid($gid) or die "can't setgid $gid\n";
43 setuid($uid) or die "can't setuid $uid\n";
44 $ENV{HOME} = $homedir;
45
46 system(qq(fetchmail -a -K --antispam "550,451" -d 180 -f $filename));
47