aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/fetchmaildistrib
blob: 00cc19107230abc10071c94d5c23cf42aa140d0a (plain)
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
#/bin/bash
#
# fetchmaildistrib --- Distribute central fetchmail knowledge.
#
# The central fetchmail database, /etc/fetchmail, contains all accounts that
# are to be fetched by the root's daemon. Often, a user desires quicker
# access (e.g., when testing some email path). In such cases, the destination
# user (marked as is USER here in the poll lines) should set up a ~/.fetchmailrc
# for himself. This scripts generates such lines from the central file.
#
# By Rick van Rein.

# From stdin, select poll lines for user $1
function selectuser () {
	grep ^poll | grep "is $1 here"
}


for i in `cut -d: -f1 </etc/passwd`
do	homedir=`grep ^$i: /etc/passwd | cut -d: -f6`
	fetchfile=`selectuser $i </etc/fetchmailrc`
	if [ -z "$fetchfile" ]
	then	rm -f $homedir/.fetchmailrc
	else	cp /dev/null $homedir/.fetchmailrc
		chmod go-rwx $homedir/.fetchmailrc
		grep ^defaults /etc/fetchmailrc >>$homedir/.fetchmailrc
		selectuser $i </etc/fetchmailrc >>$homedir/.fetchmailrc
	fi
done
* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#!/usr/bin/perl
# Copyright 2000 john Summerfield ,summer@os2.ami.com.au>
# Your choice of licence: GPL 2 or later, or same licence as Perl.
#
# Warranty? 					None
# If it breaks? 				The pieces are yours
# If it breaks something?	You drove it.
# Bugs?							At least one.

# now we've cleared the air;
#	This supposed to allow one to talk pop-3 to a mail server. If you're lucky (and know how)
#		you might also be able to talk a few other Internet protocols with it.
#	Typically, it's run thus:
#		pop2test.1 <mailserver> [<mailport>]
#	mailport's optional; default is 110 (pop-3).
#	
#	Having started, you type away much as you would with telnet.
#	
#	
#	
#	It has this great advantage over telnet: it reads its input from stdin and writes to stdout;
#		you can prepare the entire sequence in a file, then run it this:
#			pop2test.1 <thefileyoujustcreated >theresultsyouwanttoperuse host port
#	
#	
#	uses:
#		1	Debugging POP3 (and maybe imap does anyone know?) mail problems
#		2	Deleting the occasional piece of mail that's too big or stuffs fetchmail.
#		3	Talking to sendmail
#	
use Socket;
sub hx;
sub getreply;
$timeout=1;
$RemoteHost = $ARGV[0];shift;
$RemotePort = $ARGV[0] || 110;shift;
($PRname,$PRaliases,$PRport,$PRproto) = getservbyname($RemotePort,'tcp');
$PRport=$RemotePort unless $PRport;
$proto=getprotobyname($PRproto);  
$RemoteIP = inet_aton $RemoteHost or die "Can't resolve $RemoteHost";
$that = pack 'Sna4x8',AF_INET, $PRport, $RemoteIP;
socket(REMOTESITE,AF_INET,SOCK_STREAM,$proto)
        or die "Can't create socket to $RemoteHost: $!\n";;
connect(REMOTESITE, $that) or die "Can't connect: $!\n";
select(REMOTESITE);$|=1;select STDOUT;
$rin = $win = $ein = '';
vec($rin,fileno(REMOTESITE),1) = 1;
#vec($win,fileno(REMOTESITE),1) = 1;
$ein = $rin | $win;
getreply;
while ($L=<STDIN>)
{
	chomp $L;
	print REMOTESITE $L . "\r\n";
	print "send: " . $L . "\n";
	getreply;
}
print REMOTESITE "Quit\r\n";
getreply;
#print <REMOTESITE>;
close REMOTESITE;
exit;
# P
sub hx
{
	$N=$_[0];shift;
	$S=$_[0];shift;
	return "$N(" . unpack("h", $S) . ") "; 
}
sub getreply
{
	while ('x')
	{
		($nfound,$timeleft) = select($rout=$rin, undef, $eout=$ein, $timeout);
		last if $nfound == 0;
#		print "nf($nfound) tl($timeleft) " . hx("rin",$rin) . hx("rout", $rout) . hx("ein",$ein) . hx("eout",$eout) . "\n";
		$Reply= <REMOTESITE>;
		print "recv: " . $Reply;
		last if $Reply eq '';
		$Reply =~ s/[\r\n]*//;
		last if $Reply eq '.';
	}
}