manual backport of changes related to #3459
Merge pull request #4222 from owncloud/backport-3459-stable5

Backport 3459 stable5