@Override
    public void parse(InputStream stream, ContentHandler handler, Metadata metadata,
                      ParseContext context) throws IOException, TikaException, SAXException {

        EmbeddedDocumentExtractor extractor =
                EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context);

        String charsetName = "windows-1252";

        metadata.set(Metadata.CONTENT_TYPE, MBOX_MIME_TYPE);
        metadata.set(Metadata.CONTENT_ENCODING, charsetName);

        XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
        xhtml.startDocument();

        InputStreamReader isr = new InputStreamReader(stream, charsetName);
        try (BufferedReader reader = new BufferedReader(isr)) {
            String curLine = reader.readLine();
            int mailItem = 0;
            do {
                if (curLine.startsWith(MBOX_RECORD_DIVIDER)) {
                    Metadata mailMetadata = new Metadata();
                    Queue<String> multiline = new LinkedList<>();
                    mailMetadata.add(EMAIL_FROMLINE_METADATA,
                            curLine.substring(MBOX_RECORD_DIVIDER.length()));
                    mailMetadata.set(Metadata.CONTENT_TYPE, "message/rfc822");
                    mailMetadata
                            .set(TikaCoreProperties.CONTENT_TYPE_PARSER_OVERRIDE, "message/rfc822");
                    curLine = reader.readLine();
                    if (curLine == null) {
                        break;
                    }
                    UnsynchronizedByteArrayOutputStream message = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(100000).get();
                    do {
                        if (curLine.startsWith(" ") || curLine.startsWith("\t")) {
                            String latestLine = multiline.poll();
                            latestLine += " " + curLine.trim();
                            multiline.add(latestLine);
                        } else {
                            multiline.add(curLine);
                        }

                        message.write(curLine.getBytes(charsetName));
                        message.write(0x0A);
                        curLine = reader.readLine();
                    } while (curLine != null && !curLine.startsWith(MBOX_RECORD_DIVIDER) &&
                            message.size() < MAIL_MAX_SIZE);

                    for (String item : multiline) {
                        saveHeaderInMetadata(mailMetadata, item);
                    }

                    InputStream messageStream = message.toInputStream();
                    message = null;

                    if (extractor.shouldParseEmbedded(mailMetadata)) {
                        extractor.parseEmbedded(messageStream, xhtml, mailMetadata, true);
                    }

                    if (tracking) {
                        getTrackingMetadata().put(mailItem++, mailMetadata);
                    }
                } else {
                    curLine = reader.readLine();
                }

            } while (curLine != null && !Thread.currentThread().isInterrupted());
        }

        xhtml.endDocument();
    }
@Test
    public void testQuoted() throws Exception {
        ContentHandler handler = new BodyContentHandler();
        Metadata metadata = new Metadata();

        try (InputStream stream = getResourceAsStream("/test-documents/quoted.mbox")) {
            mboxParser.parse(stream, handler, metadata, recursingContext);
        }

        assertContains("Test content", handler.toString());
        assertContains("> quoted stuff", handler.toString());
    }