Backport #1234

Backport of #1234 by @MTGap 
Fixes among others https://github.com/owncloud/apps/issues/463 and https://github.com/owncloud/apps/issues/192
If #1248 is merged first the change is only one line.
This would be great to have before 4.5.6.

@MTGap @butonic @karlitschek