This is a left over from the Latin. In Latin the declension of the noun for me had different ending depending on the use so “mi” represents the dative or genetive cases and even the ablative. So by, with, from, to + me can be expressed as mi. If you use me as the accusative, the objective as we know it, it would be “me” eg. il regalo è per me. Hope that helps a little.