The next step is e-mail filtering. Following https://help.ubuntu.com/lts/serverguide/mail-filtering.html.en worked out nicely. Spamassassin is blocking all spam. But acutally I do not want to block it, I just want that spamassassin marks it as spam and that the spam gets redirected into my spam-folder. This is just in case something gets filtered out that was not a spam.

and there the part "Sending spam to the Junk folder". But it doesn't work. I have seen that sieve is not working for imap. But I cannot find any tutorial or manual on imap_sieve, that would solve my problem. Does anyone of you has an idea? I also do not find any log entry where I could see that sieve is working (or not)?

The waiting time is needed, because dovecot moves the mail in the meanwhile from new to cur. The code is not fast enough to do ot while it is all in new.

the rest my code checks if the e-mail has a spam flag and if so, it moves it to the Junk folder of the user. The way to read in the e-mail is a bit unusual, but due to the "/" in the name of the mail I struggled a lot to read it in directly.
I add "S" at the end of the name of the file, when I move it to the Junk so that it is marked as read. Then thunderbird does not bother me with a new mail there.

Then your messages will be proceeded by default.sieve and stopped before normal delivery if *SPAM* pattern is present in the subject.

My strong advise is to use name like before1.sieve instead of default.sieve for sieve_before because default.sieve has a special meaning. Also it would be much better to add some special header to the message like X-SPAM-DETECTED instead of subject manipulations.

UPDATE

Here is my complete solution. I've used exim for MTA and dovecot for delivery/sieving

exim have an ACL that invoke the spamassassin to calculate the score for message.
Two custom headers are added if score above the threshold:

Thank you very much for your code! I tested it but my problem remains. Only when I click at the spam mail, the mail gets moved to Junk. But my solution with incrontab works. Since it is my private server and not a professional system, I can live with my incrontab solution. But thanks again! :-)
– MarcOct 9 '18 at 9:05