Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!news.rmit.EDU.AU!news.unimelb.EDU.AU!munnari.OZ.AU!news.Hawaii.Edu!news.uoregon.edu!hunter.premier.net!www.nntp.primenet.com!nntp.primenet.com!news.primenet.com!bkogawa From: bkogawa@primenet.com (Bryan Ogawa) Newsgroups: comp.unix.bsd.freebsd.misc Subject: Re: .forward file format Date: 31 Oct 1996 23:54:02 -0700 Organization: Primenet Services for the Internet Lines: 121 Message-ID: <55c6qa$5m5@nnrp1.news.primenet.com> References: <54olal$h5u@uuneo.neosoft.com> <54orfi$jte@uuneo.neosoft.com> <54rg7t$9cj@nntp.Stanford.EDU> <54rote$bsc@nntp.Stanford.EDU> <54s8l5$bqs@uuneo.neosoft.com> X-Posted-By: bkogawa@206.165.5.111 (bkogawa) conrads@neosoft.com (Conrad Sabatier) writes: >In article <54rote$bsc@nntp.Stanford.EDU>, >Annelise Anderson <andrsn@andrsn.stanford.edu> wrote: >>Annelise Anderson (andrsn@andrsn.stanford.edu) wrote: >>: Conrad Sabatier (conrads@neosoft.com) wrote: >> >>: : Could it be because I'm using popclient to retrieve my mail from my ISP's >>: : POP3 server? >> >>: Yes, I think so. I get some mail from a POP3 server and it goes >>: directly into a mail box and never gets processed by procmail. [...] >>This won't work--but the man page for procmail says that it will process >>an already filled (the key word to search for) mailbox. There's a >>script for doing so that assumes the mail is put in /var/mail/username. >>So if you run popclient and then the script (extract it from the man >>page) it will process the mail in accordance with your .procmailrc. >Yes...but...*how*??? >My shell programming skills leave much to be desired. As I said, running >procmail manually (the script from man procmail mentioned above) on an >already-loaded /var/mail/$LOGNAME mailbox works beautifully. >OK, so popclient stuffs everything into the /var/mail/$LOGNAME inbox, and >then I need to run procmail (the script) on it. >So how can I automate this process? The most trivial way: ---- CUT HERE ---- #!/bin/sh /usr/local/bin/popclient /usr/local/bin/formail -s procmail < /var/mail/username ---- CUT HERE ---- This has some fatal problems, but is a start (you need to have popclient set up right, and you will keep getting old messages). Here's what I use. It uses perl (comes with freebsd), and it expects that you have a directory called inbox in your home directory. $inbox is the path to the inbox directory (in this case, $HOME/inbox). $mail is the temporary filename which stores the incoming mail (called waiting in $inbox). $host is the POP3 host you're getting mail from. $num_backups is the number of backups stored (e.g. this one will store the mail downloaded during the 7 previous sessions or so). I've made some cosmetic changes when uploading this script--hopefully they won't cause you any problems. ---- CUT HERE ---- #!/usr/bin/perl $inbox = "$ENV{HOME}/inbox"; $mail = "$inbox/waiting"; $host = "mailhost.primenet.com"; $num_backups = 7; $popclient = "popclient -a -3 -o $mail $host"; &rotate($mail, $num_backups) if(-e $mail); system($popclient); if(system("echo \"unlimit; formail -s procmail < $mail\" | csh -s")) { print "Error: procmail failed for some reason!\n"; } sub rotate { local($filename, $number) = @_; if(-e "$filename.$number") { unlink("$filename.$number") || die "couldn't unlink"; } $number--; while($number >= 0) { if(-e "$filename.$number") { rename("$filename.$number", "$filename." . ($number+1)); } $number--; } if(-e $filename) { rename($filename, "$filename.0"); } } __END__ --- END END END --- >Or can I pipe popclient's output to sendmail/procmail? You can. I don't recommend it, because if procmail/formail ever blow up, you'll lose mail. The way the above script works, it keeps a number of backups of the file, which you can read manually or repipe through the formail should something happen (this has happened to me, most often when I'm hacking on my procmail scripts). It also rotates these backups, keeping them from consuming all of your disk space. >Help? Please? >I *really* need to get this thing working! The junk mail these days is >driving me nuts! I hope this helps. Email me if you've got further questions. >Many thanks! >-- >Conrad Sabatier | >conrads@neosoft.com | Eschew obfuscation. >http://www.neosoft.com/~conrads | -- bryan k. ogawa <bkogawa@primenet.com> <bkogawa@netvoyage.net>