-1

I am setting up a script to learn spam from a maildir folder ".LearnAsSpam"

After the spam is learnt, I'd like to move all spam to the ".Junk" folder for all users:

ie:

  • /home/vmail/domain1/user1/Maildir/.LearnAsSpam/cur/* -> /home/vmail/domain1/user1/Maildir/.Junk/cur/

  • /home/vmail/domain1/user2/Maildir/.LearnAsSpam/cur/* -> /home/vmail/domain1/user2/Maildir/.Junk/cur/

Is there a simple way to write a bash script that will properly match and move the files for each user?

FGiorlando
  • 1,121
  • 2
  • 12
  • 22

1 Answers1

0

OK, think this will work:

find /home/vmail/ -type d -path "*/*/Maildir/.LearnAsSpam/cur" -exec sh -c '(cd {} && mv ./* ../../.Junk/cur)' ';'

Just in case anyone is interested, the whole script for spam learning and moving spam looks like this:

# do a spam check in LearnAsSpam and LearnAsHam folders
# find spam
sa-learn -p ~/.spamassassin/user_prefs --spam /home/vmail/*/*/Maildir/.LearnAsSpam/{cur,new}
# find ham
sa-learn -p ~/.spamassassin/user_prefs --ham /home/vmail/*/*/Maildir/.LearnAsHam/{cur,new}
# move spam
find /home/vmail/ -type d -path "*/*/Maildir/.LearnAsSpam/cur" -exec sh -c '(cd {} && mv ./* ../../.Junk/cur)' ';'
find /home/vmail/ -type d -path "*/*/Maildir/.LearnAsSpam/new" -exec sh -c '(cd {} && mv ./* ../../.Junk/new)' ';'
# move ham
find /home/vmail/ -type d -path "*/*/Maildir/.LearnAsHam/cur" -exec sh -c '(cd {} && mv ./* ../../.Inbox/cur)' ';'
find /home/vmail/ -type d -path "*/*/Maildir/.LearnAsHam/new" -exec sh -c '(cd {} && mv ./* ../../.Inbox/new)' ';' 

this was added to the /etc/cron.daily/spamassassin script

FGiorlando
  • 1,121
  • 2
  • 12
  • 22