####[ How-Do-I Documents ]###################################### Sub : Clearing blocked mails from POP3 servers How-Do-I retreive and clear blocked mails from POP3 servers ? ################################################################ 1 Introduction 1.1 Ever been stuck up in a situation where there are some mails stuck up in your POP3 server, which cannot be re- trieved or deleted from the server after download with software like fetchmail, and does not auto-delete (even if set) on its own ? 1.2 How do you know that mail is stuck up ? A normal fetch- mail session configured for deletion after retreival may turn up something like this: bish@aedes:~$fetchmail nde.vsnl.net.in 25 messages (12 seen) for bish at nde.vsnl.net.in (236487 octets). skipping message 1 not flushed skipping message 2 not flushed skipping message 3 not flushed <...snipped...> skipping message 10 not flushed skipping message 11 not flushed skipping message 12 not flushed reading message 13 of 25 (3512 octets) ... flushed reading message 14 of 25 (5483 octets) ..... flushed reading message 15 of 25 (1474 octets) . flushed <...rest snipped...> 1.3 Note, messages 1 - 12 ( of which only three has been shown above) have been "skipped" and therefore not down loaded at all. This is because of some problem at the POP3 server level, and you need to force retreival and deletion. At times such problems arise if the mail is really large. 2 Retreiving blocked mails 2.1 Once you get the "seen" message, notmal POP3 retreival methods through fetchmail or MUAs like netscape do not work. You can however, telnet into the server and view the message. Since you cannot save to local medium once the telnet session is on, you may like to capture the full screen output locally with "script" running in the background. 2.2 First set of capture of screen output with script, and take the output to a file: $script filename 2.3 Then telnet into the server. $telnet pop.server.id 110 POP3 servers are usually on port 110. May have to change value if your ser- ver uses something else $userEnter the username that you use to retrieve mail $pass ... and the password $stat This resets the current status $list gives chronological list- ing of mails pending on the server, along with sizes. $retr Retreive the mail by #no 2.4 You need to repeat the retr command for all the blocked mails (in the case shown above from 1 to 12). Once this is done, you need to delete them. 3 Deleting blocked mails 3.1 Deleting such mails from POP3 servers can be achieved by telneting directly into the server and manually del- eting it. Since you have already logged on to the POP3 server, you can start deleting from where you left off. $list gives chronological list- ing of mails pending on the server, along with sizes. $dele Delete the mail by number ...... repeat above processes $list Catalog again to check if things worked. $quit Terminate telnet session when done 4 Finishing touches 4.1 Now you need to terminate the 'script' session which you started with. Just type in "exit" once out of the telnet session. The check the text file "filename" in any text procerssor. 5 Automating the above (netcat) 5.1 Unfortunately, telnet itself is not a very friendly tool, and does not lend itself to automation and scrip- ting. Under such conditions, you may like to try out a program called netcat. #!/bin/sh # Netcat source wget -c -v http://www.l0pht.com/~weld/netcat/nc110.tgz 5.2 Netcat is a network debugging and exploration tool. Has just one binary nc. The following script under nc would work in the situation like shown above, where 12 mails need to be brought from the POP3 server to the local hard disk, and then deleted. #! /bin/sh ( echo user my_login echo pass my_password echo stat echo list for i in 1 2 3 4 5 6 7 8 9 10 11 12; do echo retr $i done echo quit ) | nc -v -v pop.server.id > my_file.in 5.3 Deleting through a nc script is just as easy. Since no file output is necessary, we can omit the last bit. #! /bin/sh ( echo user my_login echo pass my_password echo stat for i in 1 2 3 4 5 6 7 8 9 10 11 12; do echo dele $i done echo quit ) | nc -v -v pop.server.id 6 Tailpiece. 6.1 Life is really not that difficult, only if you knew how You don't have to send mails to your ISP ever again for blocked mails on their server ! 6.2 Enjoy. ################################################################# 7 Kudos and Brickbats 7.1 This document is released under GFDL license. You are free to use and distribute under freedom of the said license 7.2 Any kudos and brickbats should be directed at: USM Bish 28 Dec 2001