Export and import SOGo user mail filters

Inspect mail filters for specific user that was not using mail filters.

$ docker-compose exec -u sogo sogo-mailcow /usr/sbin/sogo-tool user-preferences get defaults milosz@example.com SOGoSieveFilters
<0x0x55c076a7aff0[SOGoCache]> Cache cleanup interval set every 900.000000 seconds
<0x0x55c076a7aff0[SOGoCache]> Using host(s) 'memcached' as server(s)
2023-05-07 10:26:19.239 sogo-tool[326427:326427] Value for key "SOGoSieveFilters" not found in defaults

Inspect mail filters for specific user that was using mail filters.

$ docker-compose exec -u sogo sogo-mailcow /usr/sbin/sogo-tool user-preferences get defaults milosz@example.org SOGoSieveFilters
<0x0x55c076a7aff0[SOGoCache]> Cache cleanup interval set every 900.000000 seconds
<0x0x55c076a7aff0[SOGoCache]> Using host(s) 'memcached' as server(s)
SOGoSieveFilters: []

Inspect mail filters for specific user that is using mail filters.

$ docker-compose exec -u sogo sogo-mailcow /usr/sbin/sogo-tool user-preferences get defaults milosz@example.eu SOGoSieveFilters
<0x0x55c076a7aff0[SOGoCache]> Cache cleanup interval set every 900.000000 seconds
<0x0x55c076a7aff0[SOGoCache]> Using host(s) 'memcached' as server(s)
SOGoSieveFilters: [{"actions":[{"argument":"News","method":"fileinto"}],"name":"News","rules":[{"field":"from","operator":"contains","value":"news@example.com"}],"match":"all","active":1}]

Set mail filters for specific user.

$ docker-compose exec -u sogo sogo-mailcow /usr/sbin/sogo-tool user-preferences -p /etc/sogo/sieve.creds set defaults milosz@example.eu SOGoSieveFilters \
'{"SOGoSieveFilters": 
  [
    { 
      "name":"News",
      "actions": [{"argument":"News","method":"fileinto"}],
      "rules":[{"field":"from","operator":"contains","value":"news@example.org"}],"match":"all","active":1
    },
    { 
      "name":"Alerts",
      "actions": [{"argument":"Alerts","method":"fileinto"}],
      "rules":[{"field":"body","operator":"contains","value":"ALERT"}],"match":"all","active":1
    },
    { 
      "name":"Events",
      "actions": [{"argument":"Events","method":"fileinto"}],
      "rules":[{"field":"subject","operator":"contains","value":"CRON"}],"match":"all","active":1
    },
    { 
      "name":"Internal logs",
      "actions": [{"argument":"Logs","method":"fileinto"}],
      "rules":[{"field":"header","operator":"contains","custom_header":"X-LOGS","value":"news@example.org"}],"match":"all","active":1
    }
  ] 
}'
<0x0x55c076a7aff0[SOGoCache]> Cache cleanup interval set every 900.000000 seconds
<0x0x55c076a7aff0[SOGoCache]> Using host(s) 'memcached' as server(s)

Verify defined mail filters.

$ docker-compose exec -u sogo sogo-mailcow /usr/sbin/sogo-tool user-preferences get defaults milosz@example.eu SOGoSieveFilters
<0x0x55c076a7aff0[SOGoCache]> Cache cleanup interval set every 900.000000 seconds
<0x0x55c076a7aff0[SOGoCache]> Using host(s) 'memcached' as server(s)
SOGoSieveFilters: [{"actions":[{"argument":"News","method":"fileinto"}],"name":"News","rules":[{"field":"from","operator":"contains","value":"news@example.org"}],"match":"all","active":1}, {"actions":[{"argument":"Alerts","method":"fileinto"}],"name":"Alerts","rules":[{"field":"body","operator":"contains","value":"ALERT"}],"match":"all","active":1}, {"actions":[{"argument":"Events","method":"fileinto"}],"name":"Events","rules":[{"field":"subject","operator":"contains","value":"CRON"}],"match":"all","active":1}, {"actions":[{"argument":"Logs","method":"fileinto"}],"name":"Internal logs","rules":[{"field":"header","operator":"contains","custom_header":"X-LOGS","value":"news@example.org"}],"match":"all","active":1}]

Clear mail filters for specific user.

$ docker-compose exec -u sogo sogo-mailcow /usr/sbin/sogo-tool user-preferences -p /etc/sogo/sieve.creds set defaults milosz@example.eu SOGoSieveFilters \
'{"SOGoSieveFilters": [] }'
<0x0x55c076a7aff0[SOGoCache]> Cache cleanup interval set every 900.000000 seconds
<0x0x55c076a7aff0[SOGoCache]> Using host(s) 'memcached' as server(s)

Simple as that.

ko-fi