hooks: check if a method has been defined and remove it before redefining it

Avoid warnings of redefined methods (particularly the
num_inbox_total_unread lambda in maildir-sync) in hooks.