zbateson / mail-mime-parser

An email parser written in PHP
https://mail-mime-parser.org/
BSD 2-Clause "Simplified" License
458 stars 58 forks source link

Custom Message class #71

Closed mvnaz closed 6 years ago

mvnaz commented 6 years ago

Hi, when I parse email I get big and complicated Message object. But can I use my own class for Message object ? For now I parse email, get big Message object, then create my object and get necessary data from big Message object. As I see in the method where Message is coming, the dependency there set strictly on Message class, not with interface. But may be exists some another way ?

zbateson commented 6 years ago

@mvnaz --

You could extend ZBateson\MailMimeParser\Message\MessageParser, and provide your own Message in the constructor, simply calling parent::__construct with your Message. You could then call $messageParser->parse() directly.

I wouldn't recommend doing that for one reason though. In the next version of MMP the dependencies in MessageParser are different, so I think your current approach will probably be more backwards-compatible.