// Path: src/main/java/xpertss/mime/Header.java
// public interface Header {
// 
//    /**
//     * Http defines four types of headers. All headers not specifically
//     * defined to be general, request, or response are treated as entity
//     * headers.
//     */
//    public enum Type {
//       /**
//        * A general header is one that may be included in either the request or
//        * response and is applied to the overall message itself.
//        */
//       General,
// 
//       /**
//        * A request header is applied only to impl requests and applies to the
//        * message overall.
//        */
//       Request,
// 
//       /**
//        * A response header is applied only to impl responses and applies to the
//        * message overall.
//        */
//       Response,
// 
//       /**
//        * An entity header defines the entity contained within the message.
//        */
//       Entity,
// 
//       /**
//        * A raw header is any header for which a defined parser was not found.
//        * These are typically non-standard headers and will always return an
//        * unparsed raw string when getValue is called.
//        */
//       Raw
//    }
// 
// 
//    /**
//     * Returns the header name as a String.
//     */
//    public String getName();
// 
//    /**
//     * Returns a fully formatted value line including all values and their
//     * associated parameters. This method  provides an easier means of access
//     * to simple values.
//     */
//    public String getValue();
// 
//    /**
//     * Returns the header type this header represents.
//     */
//    public Type getType();
// 
// 
//    /**
//     * Returns the number of values this header contains.
//     */
//    public int size();
// 
//    /**
//     * Returns the header value at the specified index.
//     */
//    public HeaderValue getValue(int index);
// 
//    /**
//     * Returns the specified named header value if it exists.
//     */
//    public HeaderValue getValue(String name);
// 
// 
//    /**
//     * Return a formatted string representation of this header and its values
//     * and parameters.
//     */
//    public String toString();
// 
// 
// }
// 
// Path: src/main/java/xpertss/mime/HeaderParser.java
// public abstract class HeaderParser {
// 
//    private static ServiceLoader<HeaderParserProvider> loader =
//          ServiceLoader.load(HeaderParserProvider.class, HeaderParserProvider.class.getClassLoader());
// 
// 
//    /**
//     * Parse a raw header and return an appropriate Header object representation.
//     *
//     * @param raw The raw header string from a request or response
//     * @return A header object instance
//     * @throws MalformedException If the header was malformed or incomplete
//     * @throws NullPointerException If the raw header is {@code null}
//     */
//    public static Header parse(CharSequence raw) throws MalformedException
//    {
//       if(raw == null) throw new NullPointerException("raw can not be null");
//       HeaderTokenizer h = new HeaderTokenizer(raw, HeaderTokenizer.MIME);
//       HeaderTokenizer.Token token = h.next();
//       if(token.getType() != HeaderTokenizer.Token.ATOM) throw new MalformedException("expected header name");
//       String name = token.getValue();
//       if((token = h.next()).getType() != ':') throw new MalformedException("expected header delimiter");
//       if((token = h.next()).getType() != HeaderTokenizer.Token.LWS) throw new MalformedException("expected header separator");
//       return parse(name, h.getRemainder());
//    }
// 
//    /**
//     * Parse the given header value for the specified header name and return an
//     * appropriate Header objects representation.
//     *
//     * @param name The name of the header
//     * @param rawValue A string representing the raw value to be parsed
//     * @return A header object instance
//     * @throws MalformedException If the header value was malformed or incomplete
//     * @throws NullPointerException If either the header or rawValue values are {@code null}
//     */
//    public static Header parse(String name, CharSequence rawValue) throws MalformedException
//    {
//       if(name == null) throw new NullPointerException("name can not be null");
//       if(rawValue == null) throw new NullPointerException("rawValue can not be null");
//       // revert to the service providers.
//       for(HeaderParserProvider provider: loader) {
//          HeaderParser parser = provider.create(name);
//          if(parser != null) return parser.doParse(rawValue);
//       }
//       return new RawHeader(name, rawValue); // default to a RawHeader as nothing knows how to parse it
//    }
// 
// 
//    /**
//     * Service provider implementations should implement this method to parse a
//     * raw header value into a Header object.
//     *
//     * @param raw The raw header value to parse.
//     * @return A header object representing the parsed header value
//     * @throws MalformedException If the header value was malformed or incomplete
//     */
//    protected abstract Header doParse(CharSequence raw) throws MalformedException;
// 
//    private static class RawHeader implements Header {
// 
//       private String name;
//       private String value;
// 
//       private RawHeader(String name, CharSequence value)
//       {
//          this.name = name;
//          this.value = value.toString();
//       }
// 
//       public String getName()
//       {
//          return name;
//       }
// 
//       public String getValue()
//       {
//          return value;
//       }
// 
//       public Type getType()
//       {
//          return Type.Raw;
//       }
// 
//       public int size()
//       {
//          return 0;
//       }
// 
//       public HeaderValue getValue(int index)
//       {
//          return null;
//       }
// 
//       public HeaderValue getValue(String name)
//       {
//          return null;
//       }
// 
//       public String toString()
//       {
//          return name + ": " + value;
//       }
//    }
// }
// 
// Path: src/main/java/xpertss/mime/spi/HeaderParserProvider.java
// public interface HeaderParserProvider {
// 
//    /**
//     * Return a HeaderParser implementation for the named header or {@code null}
//     * if this provider does not support the given header.
//     *
//     * @param name The header name for which a parser is desired
//     * @return A parser capable of parsing the named header or {@code null}
//     */
//    public HeaderParser create(String name);
// 
// }


import xpertss.mime.Header;
import xpertss.mime.HeaderParser;
import xpertss.mime.spi.HeaderParserProvider;
import java.util.HashMap;
import java.util.Map;
package xpertss.mime.impl;



/**
 *
 */
public class MailHeaderParserProvider implements HeaderParserProvider {

   private Map<String,HeaderParser> parsers = new HashMap<>();

// Path: src/main/java/xpertss/mime/Header.java
// public interface Header {
// 
//    /**
//     * Http defines four types of headers. All headers not specifically
//     * defined to be general, request, or response are treated as entity
//     * headers.
//     */
//    public enum Type {
//       /**
//        * A general header is one that may be included in either the request or
//        * response and is applied to the overall message itself.
//        */
//       General,
// 
//       /**
//        * A request header is applied only to impl requests and applies to the
//        * message overall.
//        */
//       Request,
// 
//       /**
//        * A response header is applied only to impl responses and applies to the
//        * message overall.
//        */
//       Response,
// 
//       /**
//        * An entity header defines the entity contained within the message.
//        */
//       Entity,
// 
//       /**
//        * A raw header is any header for which a defined parser was not found.
//        * These are typically non-standard headers and will always return an
//        * unparsed raw string when getValue is called.
//        */
//       Raw
//    }
// 
// 
//    /**
//     * Returns the header name as a String.
//     */
//    public String getName();
// 
//    /**
//     * Returns a fully formatted value line including all values and their
//     * associated parameters. This method  provides an easier means of access
//     * to simple values.
//     */
//    public String getValue();
// 
//    /**
//     * Returns the header type this header represents.
//     */
//    public Type getType();
// 
// 
//    /**
//     * Returns the number of values this header contains.
//     */
//    public int size();
// 
//    /**
//     * Returns the header value at the specified index.
//     */
//    public HeaderValue getValue(int index);
// 
//    /**
//     * Returns the specified named header value if it exists.
//     */
//    public HeaderValue getValue(String name);
// 
// 
//    /**
//     * Return a formatted string representation of this header and its values
//     * and parameters.
//     */
//    public String toString();
// 
// 
// }
// 
// Path: src/main/java/xpertss/mime/HeaderParser.java
// public abstract class HeaderParser {
// 
//    private static ServiceLoader<HeaderParserProvider> loader =
//          ServiceLoader.load(HeaderParserProvider.class, HeaderParserProvider.class.getClassLoader());
// 
// 
//    /**
//     * Parse a raw header and return an appropriate Header object representation.
//     *
//     * @param raw The raw header string from a request or response
//     * @return A header object instance
//     * @throws MalformedException If the header was malformed or incomplete
//     * @throws NullPointerException If the raw header is {@code null}
//     */
//    public static Header parse(CharSequence raw) throws MalformedException
//    {
//       if(raw == null) throw new NullPointerException("raw can not be null");
//       HeaderTokenizer h = new HeaderTokenizer(raw, HeaderTokenizer.MIME);
//       HeaderTokenizer.Token token = h.next();
//       if(token.getType() != HeaderTokenizer.Token.ATOM) throw new MalformedException("expected header name");
//       String name = token.getValue();
//       if((token = h.next()).getType() != ':') throw new MalformedException("expected header delimiter");
//       if((token = h.next()).getType() != HeaderTokenizer.Token.LWS) throw new MalformedException("expected header separator");
//       return parse(name, h.getRemainder());
//    }
// 
//    /**
//     * Parse the given header value for the specified header name and return an
//     * appropriate Header objects representation.
//     *
//     * @param name The name of the header
//     * @param rawValue A string representing the raw value to be parsed
//     * @return A header object instance
//     * @throws MalformedException If the header value was malformed or incomplete
//     * @throws NullPointerException If either the header or rawValue values are {@code null}
//     */
//    public static Header parse(String name, CharSequence rawValue) throws MalformedException
//    {
//       if(name == null) throw new NullPointerException("name can not be null");
//       if(rawValue == null) throw new NullPointerException("rawValue can not be null");
//       // revert to the service providers.
//       for(HeaderParserProvider provider: loader) {
//          HeaderParser parser = provider.create(name);
//          if(parser != null) return parser.doParse(rawValue);
//       }
//       return new RawHeader(name, rawValue); // default to a RawHeader as nothing knows how to parse it
//    }
// 
// 
//    /**
//     * Service provider implementations should implement this method to parse a
//     * raw header value into a Header object.
//     *
//     * @param raw The raw header value to parse.
//     * @return A header object representing the parsed header value
//     * @throws MalformedException If the header value was malformed or incomplete
//     */
//    protected abstract Header doParse(CharSequence raw) throws MalformedException;
// 
//    private static class RawHeader implements Header {
// 
//       private String name;
//       private String value;
// 
//       private RawHeader(String name, CharSequence value)
//       {
//          this.name = name;
//          this.value = value.toString();
//       }
// 
//       public String getName()
//       {
//          return name;
//       }
// 
//       public String getValue()
//       {
//          return value;
//       }
// 
//       public Type getType()
//       {
//          return Type.Raw;
//       }
// 
//       public int size()
//       {
//          return 0;
//       }
// 
//       public HeaderValue getValue(int index)
//       {
//          return null;
//       }
// 
//       public HeaderValue getValue(String name)
//       {
//          return null;
//       }
// 
//       public String toString()
//       {
//          return name + ": " + value;
//       }
//    }
// }
// 
// Path: src/main/java/xpertss/mime/spi/HeaderParserProvider.java
// public interface HeaderParserProvider {
// 
//    /**
//     * Return a HeaderParser implementation for the named header or {@code null}
//     * if this provider does not support the given header.
//     *
//     * @param name The header name for which a parser is desired
//     * @return A parser capable of parsing the named header or {@code null}
//     */
//    public HeaderParser create(String name);
// 
// }


// Path: src/main/java/xpertss/mime/impl/MailHeaderParserProvider.java
import xpertss.mime.Header;
import xpertss.mime.HeaderParser;
import xpertss.mime.spi.HeaderParserProvider;
import java.util.HashMap;
import java.util.Map;

package xpertss.mime.impl;



/**
 *
 */
public class MailHeaderParserProvider implements HeaderParserProvider {

   private Map<String,HeaderParser> parsers = new HashMap<>();

   public MailHeaderParserProvider()