procmail
[Top] [All Lists]

Re: Scanning IMAP mail (first solution)

2009-11-16 12:46:48
On Mon, 2009-11-16 at 02:13 -0700, LuKreme wrote:

OK, I have a working solution now. It's kludgy, and slow, and I wouldn't 
recommend using it, but it is working for me (for certain values of working). 
The heart of it is this bit of procmail that is embedded in the portion of my 
recipes where list mail gets delivered to the IMAP store.

...

   USER = `/usr/bin/id -un`

This value should already be in the variable LOGNAME.
You can see all of the preset variables by temporarily adding
"ENVFILE=`/bin/sh -c set >> /tmp/env.log`" to your rc.

   UNREAD = `/usr/bin/tail -1 <<< "$NEWMAIL"`

It *might* be faster to use `/bin/sed -ne '$p' <<< "$NEWMAIL"`

   :0c

You should use an i flag on your : line. ( w/thx2
http://mailman.rwth-aachen.de/pipermail/procmail/2009-November/028169.html )

   |(echo "Subject: $UNREAD unread mail(s)"; echo; echo "$NEWMAIL")| 
$SENDMAIL $MYAD

Use the -e flag with echo, so that you can avoid multiple calls to echo.
Also, Avoid using the ()'s, as they invoke a subshell.
If you are using /bin/echo, you should specify the path.  That decreases
the load time for the external echo command.

        | /bin/echo -e "Subject: $UNREAD unread mail(s)\n\n$NEWMAIL" |
        $SENDMAIL $MYAD



UNAME=`id -un`

Again, this is already set as LOGNAME.  You can use "set
/tmp/env.log" to see what's already available.


rm /tmp/$UNAME.* 2>/dev/null

Use -f flag for rm to suppress output.  Then you don't have to use the
redirection.


for i in `ls -A $HOME/Maildir/ | grep '[0-9]-*'`;

You don't need the call to grep.

        for i in `ls -A $HOME/Maildir/[0-9]-*`;
        
 do ls −1 $HOME/Maildir/$i/{cur,new}/*, 2>/dev/null >>/tmp/$UNAME.$DATE.$i;

Don't use a tmp file.

        TMP=`ls −1 $HOME/Maildir/$i/{cur,new}/*, 2>/dev/null`

You should stop there.  The rest can be handled by procmail "scoring".
Come to think of it... I think you can probably do the whole process
without the script.

 if [ -s /tmp/$UNAME.$DATE.$i ]; then
   echo -n;

Use a : instead of echo.  (And your semicolon's are optional.)


Also, it's just too slow.

The only reason I'm nitpicking ... is because you included that
statement.  :-D

-- 
JW Simpson <john(_at_)swajime(_dot_)com>
SwaJime's Cove℠
____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)de
http://mailman.rwth-aachen.de/mailman/listinfo/procmail