I wrote another code initially that reads each header and line and then creates the mbox (similiar to nnptlist), but I didn't like it at all because it introduced many other problems. So the above code is IMHO the best way to go about it, even though there are some problems.