Results 1 to 4 of 4
  1. #1

    Shell Scripting sa-learn

    I don't know much about shell scripting so I'm asking for a bit of help. Right now I use the bash shell, since I don't use any advanced features or anything. I'd like to automate the learning of sa-learn on my server. I use IMAP folders, and SpamAssassin assisted by procmail to manage my mail. I'd like mail that I move to the Junk folder (stuff not automatically moved there when tagged as spam by SA and directly delivered there by procmail) to be learned as Spam by spam assassin, that means invoking the sa-learn script. I would like to automate this process, but with one special addition, I would like the folder list to be dynamic (i.e. everytime the script runs it recognizes new folder, instead of hard coding them in.).

    Here is the directory structure:
    /home/username/Maildir
    -.Junk
    -.Trash
    -.Sent
    -.Drafts
    -.NEISA
    etc.

    I'd like it to run the command sa-learn --spam --no-sync .Junk/cur/ for the Junk folder, and then sa-learn --ham --no-sync for every other folder (folders all start with a ., there are some extra folders and files but those are not the mail files). After these commands are completed a single sa-learn --sync should update the tokens. I have experimented with the sa-learn --folders command, but it doesn't seem to work, mus be something with the leading '.'? Once I've got this script I'll set it to run at about 4am every morning, which is when I've typically gone through and sorted all my mail for the day.

    Any help with this would be really appreciated! I've read the sa-learn documentation but its not very helpful.
    --Andrew
    http://andrewloe.com/

  2. #2
    Join Date
    May 2004
    Location
    Lansing, MI, USA
    Posts
    1,548
    how about something like...

    Code:
    #!/bin/sh
    
    for DIR in /home/user/Maildir/.*
    do
      if [ "$DIR" != "." ] && [ "$DIR" != ".." ]
      then
        if [ -d $DIR ] && [ -d $DIR/cur ]
        then
          if [ "$DIR" = ".Junk" ]
          then
            thecommandhere
          else
            theothercommandhere
          fi
        fi
      fi
    done
    first if eliminates the current and parent directories

    second makes sure it's a directory and has a /cur directory

    third looks to see if it's the spam folder.

    Jacob - WebOnce Technologies - 30 Day 100% Satisfaction Guarantee - Over 5 Years Going Strong!
    Website Hosting, PHP4&5, RoR, MySQL 5.0, Reseller Hosting, Development, and Designs
    Powered By JAM - Professional Website Development - PHP, MySQL, JavaScript, AJAX - Projects Small & Large

  3. #3
    Originally posted by WebOnce
    how about something like...

    Code:
    #!/bin/sh
    
    for DIR in /home/user/Maildir/.*
    do
      if [ "$DIR" != "." ] && [ "$DIR" != ".." ]
      then
        if [ -d $DIR ] && [ -d $DIR/cur ]
        then
          if [ "$DIR" = ".Junk" ]
          then
            thecommandhere
          else
            theothercommandhere
          fi
        fi
      fi
    done
    first if eliminates the current and parent directories

    second makes sure it's a directory and has a /cur directory

    third looks to see if it's the spam folder.

    Sweet! so my commands would be sa-learn --spam --no-sync $DIR/cur/ for the Junk and with --ham for the non junk folders, and after the done on a new line I can put sa-learn --sync right?
    --Andrew
    http://andrewloe.com/

  4. #4
    Join Date
    May 2004
    Location
    Lansing, MI, USA
    Posts
    1,548
    That sounds about right, though i'm not sure of the particulars with spam-assassin so I couldn't say for sure
    Jacob - WebOnce Technologies - 30 Day 100% Satisfaction Guarantee - Over 5 Years Going Strong!
    Website Hosting, PHP4&5, RoR, MySQL 5.0, Reseller Hosting, Development, and Designs
    Powered By JAM - Professional Website Development - PHP, MySQL, JavaScript, AJAX - Projects Small & Large

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •