Correcly handle message headers when gatewaying. Closes #4322 and #4447.
Merge remote-tracking branch 'drebs/feature/4447_fix-headers-when-gatewaying-messages' into develop