SpamAssassin spam analyzer script in PHP based on sa-learn command
Here's an untested Bash version:

#!/usr/bin/env bash
set -o errexit -o noclobber -o nounset

while IFS= read -r -u 9 path
do
    /usr/bin/sa-learn --spam "$path" \
        &gt; "/home/domainexample.ru/.spamassassin/logs/$(date +%d.%m.%Y-%G:%S)_analyzer.log" \
        2&gt;&amp;1 &amp;
    sed -i -e 's/^Subject:/Subject: [SPAM] /' "$path"
    rm "$path"
done 9&lt; &lt;(grep -FL '[SPAM]' /home/domainexample.ru/Maildir/.Junk/cur/* 2&gt; /dev/null)


Some changes from the original:


Uses grep's -F option to speed up search.
Runs sa-learn repeatedly instead of once to avoid having to accumulate the data. Shouldn't slow down the execution since the processes are backgrounded.
Deletes files as soon as they are processed, to avoid reprocessing if the previous run failed.