-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrfrm.pl
81 lines (57 loc) · 1.64 KB
/
rfrm.pl
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
#!/bin/perl -w
# rfrm - get a list of mail messages waiting on a pop server
use Net::POP3;
use strict;
my ($Pop_host, $Pop_user, $Pop_pass) = read_conf() or usage();
my $pop = Net::POP3->new($Pop_host) or die "Can't connext to $Pop_host: $!\n";
defined ($pop->login($Pop_user, $Pop_pass)) or die "Can't authenticate\n";
my $messages = $pop->list or die "Can't get a list of messages\n";
foreach my $msgid (sort { $a <=> $b } keys %$messages) {
my ($msg, $subject, $sender, $from);
$msg = $pop->top($msgid, 0);
$msg = join "\n", @$msg;
$subject = $sender = '';
if ($msg =~ /Subject: (.*)/m) {
$subject = $1;
}
if ($msg =~ /^From: (.*)/m) {
$sender = $1;
}
($from = $sender) =~ s{<.*>}{};
if ($from =~ m{\(.*\)}) {
$from = $1;
}
$from ||= $sender;
printf("%-20.20s %-58.58s\n", $from, $subject);
}
sub usage {
die <<"EOF" ;
usage: rfrm
Configure with ~/.rfrmrc thus:
SERVER=pop.mydomain.com
USER=myusername
PASS=mypassword
EOF
}
sub read_conf {
my ($server, $user, $pass, @stat);
open(FH, "< $ENV{HOME}/.rfrmrc") or return;
@stat = stat(FH) or die "Can't stat ~/.rfrmrc: $!\n";
if ($stat[2] & 177) {
die "~/.rfrmrc should be mode 600 or tighter\n";
}
while (<FH>) {
if (/SERVER=(.*)/) {
$server = $1;
}
if (/USER=(.*)/) {
$user = $1;
}
if (/PASS=(.*)/) {
$pass = $1;
}
}
close FH;
return unless $server && $user && $pass;
return ($server, $user, $pass);
}