I’d recommend starting over and getting the import to do it right to begin with; what @tobiaseigen recommended sounds promising. It’s been a long while since I did a big mbox import and I did a bunch of work up front fixing stuff like you describe. If that’s not an option then you can try something on the rails side where you somehow collect all the posts you think belong together, then sort them by date and create a new topic (or choose the first one) and move all the posts to the new topic.
It’d take me a while to come up with actual code.