{
    use esmith::ConfigDB;
    my $cdb = esmith::ConfigDB->open() || die "Couldn't open ConfigDB\n";
    ##Added for version smeserver-roundcube-1.1-4
    my $plugins = $cdb->get_prop('roundcube','PluginsList') || 'globaladdressbook,contextmenu,markasjunk,vcard_attachments,newmail_notifier,emoticons,managesieve,nextcloud_attachments,html5_notifier,fail2ban,message_highlight,thunderbird_labels,sievefilter_apply';

    # workaround for SME10.0 wrong default
    $plugins = 'globaladdressbook,contextmenu,markasjunk,vcard_attachments,newmail_notifier,emoticons,managesieve,nextcloud_attachments,html5_notifier,fail2ban,message_highlight,thunderbird_labels,sievefilter_apply' if ( $plugins == "nextcloud_attachments,html5_notifier,fail2ban,message_highlight,thunderbird_labels,sievefilter_apply,managesieve" );

    my @plugin_list = grep { length $_ } split(/\s*,\s*/, $plugins);

    # Remove outdated, deprecated, or dangerous plugins
    my %remove = map { $_ => 1 } qw(sieverule tasklist);
    @plugin_list = grep { !$remove{$_} } @plugin_list;

    # Migrate renamed plugins (markasjunk2 -> markasjunk)
    @plugin_list = map { $_ eq 'markasjunk2' ? 'markasjunk' : $_ } @plugin_list;

    # Force-add required plugins (preserving order, avoiding duplicates)
    my %seen;
    @plugin_list = grep { !$seen{$_}++ } @plugin_list;

    # force add plugin we use
    for my $plug (qw(nextcloud_attachments html5_notifier fail2ban managesieve message_highlight thunderbird_labels sievefilter_apply) ) 
            {
            unless ($seen{$plug}++) {
               push @plugin_list, $plug;
               }
            }
    # update ConfigDB only if changed
    my $updated_plugins = join(',', @plugin_list);
    if ($updated_plugins ne $plugins) {
        $cdb->set_prop('roundcube', 'PluginsList', $updated_plugins);
    }
}
