Where a person lawfully does anything for another person, or delivers anything to him, not intending to do so gratuitously, and such another person enjoys the benefit thereof, the letter is bound to make compensation to the former in respect of, or to restore, the thing so done or delivered.
(a) A, a tradesman, leaves goods at B’s house by mistake. B treats the goods as his own. He is bound to pay A for them.
(b) A saves B’s property from fire. A is not entitled to compensation from B, if the circumstances show that he intended to act gratuitously.