pyproject-metadata currently rolls his own serialization of the metadata. The specification says that the metadata serialization format is what is understood by the email.parser module when using the compat32 policy. I think it would therefore be easier and safer to simply use the email.message module to serialize the metadata.
I started working on this but I was sidetracked by the fact that email.message.Message is now described as "legacy" and email.message.EmailMessage did not work for me when using the compat32 policy. I see that @henryiii is putting some work in this package (thanks!!) thus I just wanted to contribute this thought.