// Path: mbox_parser/src/main/java/org/searchisko/mbox/dto/MailAttachment.java
// public class MailAttachment {
// 
//     private String contentType;
//     private String fileName;
//     private String content;
// 
//     public String getContentType() { return this.contentType; }
//     public void setContentType(String contentType) { this.contentType = contentType; }
// 
//     public String getFileName() { return this.fileName; }
//     public void setFileName(String fileName) { this.fileName = fileName; }
// 
//     public String getContent() { return this.content; }
//     public void setContent(String content) { this.content = content; }
// }


import com.ibm.icu.text.CharsetDetector;
import com.ibm.icu.text.CharsetMatch;
import com.sun.xml.messaging.saaj.packaging.mime.MessagingException;
import com.sun.xml.messaging.saaj.packaging.mime.internet.MimeUtility;
import org.apache.commons.io.IOUtils;
import org.apache.james.mime4j.dom.*;
import org.apache.james.mime4j.message.BodyPart;
import org.apache.tika.Tika;
import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata;
import org.searchisko.mbox.dto.MailAttachment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/*
 * JBoss, Home of Professional Open Source
 * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
 * as indicated by the @authors tag. All rights reserved.
 */

package org.searchisko.mbox.parser;



/**
 * Represents the content of parsed mail body (no headers).
 *
 * @author Lukáš Vlček (lvlcek@redhat.com)
 */
public class MessageBodyParser {

    private static Logger log = LoggerFactory.getLogger(MessageBodyParser.class);

    /**
     * Supported message body subtypes.
     */
    public enum SupportedMultiPartType {
        ALTERNATIVE("alternative"), MIXED("mixed"), RELATED("related"), SIGNED("signed"),
        /*,TODO: APPLEDOUBLE("appledouble")*/
        UNKNOWN("");

        private final String value;

        private SupportedMultiPartType(String value) {
            this.value = value;
        }

        @Override
        public String toString() {
            return this.value;
        }

        public static SupportedMultiPartType getValue(String value) {
            try {
                return valueOf(value.replaceAll("-", "_").toUpperCase());
            } catch (Exception e) {
                return UNKNOWN;
            }
        }
    }


    /**
     * Represents parsed message body content.
     */
    public static class MailBodyContent {

        private String messageId;
        private String firstTextContent;
        private String firstTextContentWithoutQuotes;
        private String firstHtmlContent;
        private List<String> textMessages = new ArrayList<>();
        private List<String> htmlMessages = new ArrayList<>();
// Path: mbox_parser/src/main/java/org/searchisko/mbox/dto/MailAttachment.java
// public class MailAttachment {
// 
//     private String contentType;
//     private String fileName;
//     private String content;
// 
//     public String getContentType() { return this.contentType; }
//     public void setContentType(String contentType) { this.contentType = contentType; }
// 
//     public String getFileName() { return this.fileName; }
//     public void setFileName(String fileName) { this.fileName = fileName; }
// 
//     public String getContent() { return this.content; }
//     public void setContent(String content) { this.content = content; }
// }


// Path: mbox_parser/src/main/java/org/searchisko/mbox/parser/MessageBodyParser.java
import com.ibm.icu.text.CharsetDetector;
import com.ibm.icu.text.CharsetMatch;
import com.sun.xml.messaging.saaj.packaging.mime.MessagingException;
import com.sun.xml.messaging.saaj.packaging.mime.internet.MimeUtility;
import org.apache.commons.io.IOUtils;
import org.apache.james.mime4j.dom.*;
import org.apache.james.mime4j.message.BodyPart;
import org.apache.tika.Tika;
import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata;
import org.searchisko.mbox.dto.MailAttachment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.util.ArrayList;
import java.util.List;

/*
 * JBoss, Home of Professional Open Source
 * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
 * as indicated by the @authors tag. All rights reserved.
 */

package org.searchisko.mbox.parser;



/**
 * Represents the content of parsed mail body (no headers).
 *
 * @author Lukáš Vlček (lvlcek@redhat.com)
 */
public class MessageBodyParser {

    private static Logger log = LoggerFactory.getLogger(MessageBodyParser.class);

    /**
     * Supported message body subtypes.
     */
    public enum SupportedMultiPartType {
        ALTERNATIVE("alternative"), MIXED("mixed"), RELATED("related"), SIGNED("signed"),
        /*,TODO: APPLEDOUBLE("appledouble")*/
        UNKNOWN("");

        private final String value;

        private SupportedMultiPartType(String value) {
            this.value = value;
        }

        @Override
        public String toString() {
            return this.value;
        }

        public static SupportedMultiPartType getValue(String value) {
            try {
                return valueOf(value.replaceAll("-", "_").toUpperCase());
            } catch (Exception e) {
                return UNKNOWN;
            }
        }
    }


    /**
     * Represents parsed message body content.
     */
    public static class MailBodyContent {

        private String messageId;
        private String firstTextContent;
        private String firstTextContentWithoutQuotes;
        private String firstHtmlContent;
        private List<String> textMessages = new ArrayList<>();
        private List<String> htmlMessages = new ArrayList<>();
        private List<MailAttachment> attachments = new ArrayList<>();