Move Incoming Mails Flagged as "Spam" to Spam Folder Using Dovecot-Pigeonhole

Hi There!

I configured my server with Postfix and Spamassassin to flag incoming mails as spam an it works perfectly, Now, I need to move all the new and existing incoming Spam flagged mails to a new directory called Spam, Not the Junk, So I made these steps:

Dovecot Pigeonhole

dnf install dovecot-pigeonhole

Spamassassin – [/etc/mail/spamassassin/local.cf]

required_hits 5
report_safe 0
required_score 5
rewrite_header Subject [SPAM]

Postfix

# ------------- main.cf -------------
spamassassin_destination_recipient_limit = 1
# ------------- master.cf -------------
smtp	inet	n	-	n	-	-	smtpd -o smtpd_sasl_auth_enable=yes -o content_filter=spamassassin

spamassassin unix - n n - - pipe flags=R user=MY_USER_ID argv=/usr/bin/spamc -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}

Dovecot

# ------------- 20-lmtp.conf -------------
protocol lmtp {
  # Space separated list of plugins to load (default is global mail_plugins).
  mail_plugins = $mail_plugins sieve
}
#------------- 90-sieve.conf -------------
sieve_default = /etc/dovecot/sieve/default.sieve
#------------- Create new file: /etc/dovecot/sieve/default.sieve -------------
require ["envelope", "fileinto", "mailbox"];
if header :contains "X-Spam-Flag" "YES"
{
	fileinto :create "Spam";
	stop;
}

I tried to create a new Spam mailbox in 15-mailboxes.conf, But it the Dovecot didn’t start.

#------------- 15-mailboxes.conf -------------
namespace inbox {
  # These mailboxes are widely used and could perhaps be created automatically:
  mailbox Drafts {
    special_use = \Drafts
  }
  mailbox Junk {
    special_use = \Junk
  }
  mailbox Trash {
    special_use = \Trash
  }

  # This is WRONG -- Dovecot Won't Start
  mailbox Spam {
    special_use = \Spam
  }

What I missed!?
Thank You

you did not give the actual startup error, that would have been helpful or the “journalctl -xe|grep -i dovecot” output which would also help, and should if im right give you a clue about the reason.
but check that your are not duplicating something that is already in 10-mail.conf.
I run dovecot for my imap mail, but I use proxmox mail for my spam filtering/mailrelay and only use dovecote for the internal mail store. I also have mail delivered using lmtp.
I use mysql for authentication/configuration of dovecot, as its cleaner to use than ldap.
regards peter

After some search, I have succeeded to enable filters on RoundCube but still not working even though RoundCube had a filter to move the flagged emails to the Spam folder.

P.S. Port 4190 added to Inbound Rules and Blocked by Firewalld

— Dovecot —

# ------------- 15-lda.conf -------------
# Should saving a mail to a nonexistent mailbox automatically create it?
lda_mailbox_autocreate = yes

# Should automatically created mailboxes be also automatically subscribed?
lda_mailbox_autosubscribe = yes

protocol lda {
  # Space separated list of plugins to load (default is global mail_plugins).
  mail_plugins = $mail_plugins autocreate sieve quota
}
# ------------- 20-lmtp.conf -------------
protocol lmtp {
  # Space separated list of plugins to load (default is global mail_plugins).
  mail_plugins = $mail_plugins autocreate sieve quota
}
# ------------- 20-managesieve.conf -------------
# Uncomment to enable managesieve protocol:
protocols = $protocols sieve

# Service definitions
service managesieve-login {
  inet_listener sieve {
    port = 4190
  }
}

# Service configuration
protocol sieve {
  managesieve_max_line_length = 65536
  managesieve_implementation_string = Dovecot Pigeonhole
}
# ------------- 90-sieve.conf -------------
plugin {

  # Default line after install Dovecot-Pigeonhole
  sieve = file:~/sieve;active=~/.dovecot.sieve

  # This is Mine
  sieve_default = /etc/dovecot/sieve/default.sieve
}

Now, I have created /etc/dovecot/sieve directory and /etc/dovecot/sieve/default.sieve file inside with the following code:

require ["envelope", "fileinto", "mailbox"];
# rule:[Filtering Spam]
if header :contains "X-Spam-Flag" "YES"
{
	fileinto "Spam";
	stop;
}

I have installed RoundCube on a subdomain because I didn’t find /etc/roundcube/ directory on my system, So actually I don’t know how to create a configuration file that does not delete after every RoundCube upgrade (My Bad), So I modified the SUBDOMAIN/public_html/config/config.inc.php temporarily until I find out how to read config from custom file in etc

$config['plugins'] = [
    'archive',
    'zipdownload',

    // This is mine
    'managesieve'
];


$config['managesieve_host'] = 'localhost';
$config['managesieve_default'] = '/etc/dovecot/sieve/default.sieve';

Now, I got Filters tab on my RoundCube, But unfortunately, RoundCube is unable to create a Spam folder automatically, and even if I create it manually, The Flagged emails don’t move into it.