procmail
[Top] [All Lists]

Re: Scanning imap mail

2009-11-16 03:10:54
On Sun, 2009-11-15 at 17:23 -0700, LuKreme wrote:

On 15-Nov-2009, at 16:32, LuKreme wrote:
for i in `ls -a Maildir/ | grep -v '\.\.'` 
 do ls -1a Maildir/$i/{cur,new}/* 2>/dev/null | grep ",$"
done


Came up with this:

<<EOF
#!/bin/bash

UNAME=`id -un`
DATE=`date +'%F.%T'`

for i in `ls -a $HOME/Maildir/ | grep -v '\.\.' | grep -v '\.$'`;
  do ls -1a $HOME/Maildir/$i/{cur,new}/* 2>/dev/null | grep ",$" 
/tmp/$UNAME.$DATE.$i;
  if [ -s /tmp/$UNAME.$DATE.$i ]; then
    echo -n ''
  else
    rm /tmp/$UNAME.$DATE.$i;
  fi
done

wc -l /tmp/$UNAME.$DATE.* | sed "s/\/tmp\/$UNAME.$DATE\.//" ;
rm /tmp/$UNAME.$DATE.*
EOF

takes about 2 seconds to run… 

That's a very long time.

1. Always use a full path when running id,date,grep,echo,rm,wc,sed, and
any other non-procmail utilities that you use.  Not doing so causes a
PATH search to be launched for every single call.
2. Use -I option for ls instead of calling grep to filter out the ",$"
files.
3. Use egrep instead of grep so that you can use egrep -v '(\.\.|\.)$'.
That way, you don't have to load egrep twice.
4. Better yet, don't use the "ls -a"; use "ls -A" instead, then you
don't have to make the call to grep in the first place.
5. Don't use file I/O for temporary storage.  It is extremely costly.
Use a Variable instead, and set LINEBUF beforehand to be large enough.
6. Why are you using echo for a null string ???
7. You don't even need the if statement.  You can use "rm
-f /tmp/$UNAME.$DATE.$i", and eliminate 4 lines of code altogether.




-- 
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
<Prev in Thread] Current Thread [Next in Thread>