I applied your fix and now regular emails are sent correctly, but not the PEC ones. For these to work I need the originator set to $from_addr and so, for the moment, I'll stick with my customized proc.
All the best,
Claudio