Share code for mailbox handling

Signed-off-by: Michal Čihař <michal@cihar.com>