In that case there is a limited number of approaches which you could take to this. I can immediately think of these three.
- Use your current strategy to parse the pflogsumm output. This means that you can leverage the options to pflogsumm to help you structure the data in the most useful way to you. Be aware that it is prone to breakage if the output format ever changes.
- Modify (a copy of) pflogsumm so that it either outputs precisely what you want or even performs the whole task for you including the database insertion. pflogsumm is written in Perl which makes this option less daunting that it would otherwise be.
- Ignore pflogsumm and read the mail log directly. There is Mail::Log::Parse::Postfix which might help with this (I've not used it so YMMV).
Good luck with your project.