Version 6 of procmail sux

Updated 2003-07-06 09:21:37

Luciano ES, July 6, 2003. Many people use procmail to filter their mail and do other funny stuff with it. Also, many people TRY to use procmail to filter their mail and do other funny stuff with it, and succumb to frustration. Too many complex rules and settings to make the damn thing work and maybe you're not that interested in becoming a procmail expert. There are so many other interesting things in life!

If you know Tcl, your headaches are over. Tcl can do procmail's job, probably much better than procmail itself.

The idea is not mine. I really would like to credit the actual author, but I can no longer remember where I saw it. I just rewrote it with better variable names and added sound notification. All I know is that it was posted at some very enthusiastic Tcl fan's Web page, with plenty of encouragement for anyone to reuse the code.

 #!/bin/sh
 # \
 exec tclsh "$0" "$@"

 package require sound
 proc        playwav {myWavFile}        { snack::sound s -file $myWavFile; s play -block 1 }

 # The two lines above are optional. If you don't want any sound notifications,
 # remove them and also all lines below that contain "playwav"


 package require pop3
 proc func_GetPop {argBoxFile argPopHost argLogin argPassword}        {
         set myPop [ pop3::open $argPopHost $argLogin $argPassword ]
         set myFP [ open $argBoxFile a+ ]
         set myStatus [ pop3::status $myPop ]
                 playwav /path/to/sounds/accessing.wav
         set myMessageCount [ lindex $myStatus 0 ] 
         puts "\nmyMessageCount is $myMessageCount\n"
         puts "status: $myStatus"
         for        {set i 1} {$i <= $myMessageCount} {incr i}        {
                 playwav /path/to/sounds/baqueta.wav
                     puts "retrieving msg $i"
                     set body [ lindex [ pop3::retrieve $myPop $i ] 0 ]
                     set timestamp [ clock format [ clock seconds ] -gmt 1 ]

 # now $body has the message's header and body, ready to be appended to your
 # mailbox file. If you want to filter it, filter it now.
 # ...
 # once you're done with your filtering, save the message to the mailbox file

                     puts $myFP "From pop3-tclmail $timestamp\n$body"
         }
 #        pop3::delete $myPop 1 end
 # uncomment line above to delete downloaded messages from the server
         pop3::close $myPop
         close $myFP
         puts "--------------"
         if        {$myMessageCount > 0}        {
                 playwav /path/to/sounds/blimp2.wav
         } else        { playwav /path/to/sounds/beep5.wav }
 }

 # WARNING - edit options below according to your own settings
 set myBoxFile {~/Mail/Mailbox.txt}
 set myPopHost {pop3.myhost.com}
 set myLogin {your login here}
 set myPassword {your password here}

 # finally, run the function
 func_GetPop $myBoxFile $myPopHost $myLogin $myPassword