3 # MySQL database connection settings
4 set CRDB_host localhost
9 # set eiter one to 1 for verbose output
13 package require mysqltcl
15 # connect to MySQL database
16 set handle [::mysql::connect -host $CRDB_host -user $CRDB_username -password $CRDB_password]
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]
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
26 send "USER $username\r"
28 send "PASS $password\r"
33 set anz $expect_out(0,string)
34 if {$comments==1} { send_user "message count: $anz \r\n" }
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" }
47 if {$comments==1} { send_user "Message $i deleted.\r\n" }
52 ::mysql::exec $handle "delete from $CRDB_DB.fetchmail where DATEDIFF(now(),Fetchdate)>($days*2) and UserID=$userid;"
54 ::mysql::close $handle