I understand your situation and that is recommending you MSG files to MBOX. Softaken Convert MSG File to MBOX Formats. I can tell just looking at your code that it's going to work. You do want to use the import function to convert a MSG to MBOX .You should check the tool and work in easily and solve your problem all the time.So,i suggest this tool and use of the tool.
Convert MSG Files to MBOX