]> Pileus Git - ~andy/fetchmail/blob - contrib/delete-later
Update website for 6.3.24.
[~andy/fetchmail] / contrib / delete-later
1 #!/usr/bin/expect -f
2
3 # MySQL database connection settings
4 set CRDB_host     localhost
5 set CRDB_DB       test
6 set CRDB_username root
7 set CRDB_password root
8
9 # set eiter one to 1 for verbose output
10 log_user 0
11 set comments 0
12
13 package require mysqltcl
14
15 # connect to MySQL database
16 set handle [::mysql::connect -host $CRDB_host -user $CRDB_username -password $CRDB_password]
17
18 # get server/usernames to clean up
19 set userlist [::mysql::sel $handle "SELECT UserID, server, username, password, retaindays from $CRDB_DB.fetchmail_user" -flatlist]
20
21 # loop through all users in database
22 foreach {userid server username password days} $userlist {
23   if {$comments==1} { send_user "\r\nWorking on accound #$userid\r\n*******************************\r\n" }
24   eval spawn telnet -l fetchmail_cleanup $server 110
25   expect "ready"
26   send "USER $username\r"
27   expect "password"
28   send "PASS $password\r"
29   expect "OK"
30   send "STAT\r"
31   expect "+OK "
32   expect -re "\[0-9]* "
33   set anz $expect_out(0,string)
34   if {$comments==1} { send_user "message count: $anz \r\n" }
35   set i 0
36   while { $i < $anz } {
37     incr i
38     send "UIDL $i\r"
39     expect -re "\\\+OK $i \(.*\)\r"
40     set uid $expect_out(1,string)
41     ::mysql::exec $handle "insert ignore into $CRDB_DB.fetchmail values ($userid,'$uid',now());"
42     set age [::mysql::sel $handle "SELECT DATEDIFF(now(),Fetchdate) from $CRDB_DB.fetchmail where UserID=$userid and UID='$uid'" -list]
43     if {$comments==1} { send_user "Message #$i: UID: $uid , age: $age \r\n" }
44     if {$age > $days} {
45       send "DELE $i\r"
46       expect "deleted"
47       if {$comments==1} { send_user "Message $i deleted.\r\n" }
48     }
49   }
50   send "quit\r"
51   expect "signing off"
52   ::mysql::exec $handle "delete from $CRDB_DB.fetchmail where DATEDIFF(now(),Fetchdate)>($days*2) and UserID=$userid;"
53 }
54 ::mysql::close $handle
55 exit
56