mail-mime-parser
mail-mime-parser copied to clipboard
ParsingErrorBag
Follow-up of https://github.com/zbateson/mail-mime-parser/issues/119#issuecomment-668740788 about this idea:
Whenever the parser does some error correction, drop something like $this->addParsingError('Invalid timezone') into it; then the user could retrieve all those errors with something like $message->getParserErrors().
Let's collect the occurrences of such parsing errors first, to see if it's worth it. I found:
- https://github.com/zbateson/mail-mime-parser/blob/master/src/Header/Part/DatePart.php#L43
- https://github.com/zbateson/mail-mime-parser/blob/master/src/Header/Part/DatePart.php#L47
Ooh, I quite like this. I'd like to spend some time and see if there are good implementations of what you're proposing and maybe other good ideas/caveats, etc...
The error handling could be an interface applied to all objects, so you could call $dateHeader->hasErrors() directly potentially or $message->hasErrors(), etc... and you could maybe $message->getParserErrors() or $message->getAllParserErrors (including its children?) or something.
If you (or anyone reading) has a good example(s) of this being done elsewhere or more ideas/warnings/comments, very much welcome.
The only idea I'm having is:
- Add
public array $parsingErrorstoDatePart(and all other parts) - In
AbstractHeader, where all header parts are collected (probably insetParseHeaderValue()), add each part'sparsingErrorsto$this->parsingErrors - In
ParentHeaderPart, addfunction getParsingErrors():foreach($this->headerContainer->getHeaderObjects() as $header) { $parsingErrors[] = $header->getParsingErrors(); }
Added in 3.0