example.pl untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 60 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2 #
3 # Copyright (c) 1998 Ugen Antsilevitch (ugen@freebsd.org)
4 # This software can be used anywhere anytime freely.
5 # This copyright has to be attached to any software or product that
6 # uses this code.
7 #
8 # This is a working example program that uses IMAPGet module.
9 # It has a set of rules to either move messages from inbox to other
10 # folders or delete them. The rules are my actual set, you have to write
11 # your own. The username and password are in this file so this
12 # script HAS to have permissions of 500 (no Read/Execute for either
13 # group or other users).
14 #
15 # Add it's own directory to @INC;
16 BEGIN {
17 $0 =~ /(.+)\/.+/;
18 unshift @INC, $1;
19 }
20  
21 use IMAPGet;
22 use NSErr;
23  
24 #
25 #
26 # Rules go here, keep the format - 'IMAP search filter', 'MOV or DEL', 'folder'
27 #
28 @rules = ( 'OR (TO freebsd.org) (CC freebsd.org)' , 'MOV', 'Work/FreeBSD' ,
29 'OR (TO bugtraq@netspace.org) (CC bugtraq@netspace.org)', 'MOV', 'Work/Lists',
30 'FROM bugtraq@netspace.org', 'MOV', 'Work/Lists',
31 'SUBJECT "Netscape Mail Server Message Action Form"', 'MOV', 'Work/Postmaster-ACT',
32 'FROM Error-Handler', 'DEL', 'xxx');
33
34  
35 #
36 # This stuff is important but make sure this file is 700 in permissions
37 #
38 $password = "SECRET";
39 $username = "mr.user";
40 $imaphost = "imap.server.com";
41  
42  
43 $dump = 0;
44 $verbose = 0;
45  
46  
47 NSErr:nserr_setup();
48 my $test = IMAPGet->new(ImapHost => $imaphost , Username => $username,
49 Password => $password, Verbose => $verbose, Dump => $dump);
50  
51 die "Can't connect to $imaphost\n" unless $test->connect();
52 die "Can't logon as $username\n" unless $test->logon();
53 $res = $test->select("inbox");
54 die "Can't select folder inbox\n" unless defined $res;
55  
56 while (($search = shift @rules) and
57 ($action = shift @rules) and
58 ($folder = shift @rules)) {
59 next unless @smsgs = $test->search($search);
60  
61 if ($action eq "MOV") {
62 print "Can't copy\n" unless $res = $test->copy($folder, @smsgs);
63 $action = "DEL" if $res;
64 }
65  
66 if ($action eq "DEL") {
67 print "Can't delete\n" unless $test->del(@smsgs);
68 }
69 }
70