Interface MessageHandler

All Superinterfaces:
MIMEHandler
All Known Implementing Classes:
DMARCMessageHandler

public interface MessageHandler extends MIMEHandler
Receive notification of the logical content of an RFC 5322 email message. This interface extends MIMEHandler to add email-specific callbacks for structured headers defined in RFC 5322.

In addition to the MIME-level events from MIMEHandler, this interface provides callbacks for:

  • Unstructured headers (Subject, Comments, etc.)
  • Date headers (Date, Resent-Date)
  • Address headers (From, To, Cc, Bcc, etc.)
  • Message-ID headers (Message-ID, References, In-Reply-To)
  • Obsolete syntax detection

Author:
Chris Burdess
See Also:
  • Method Details

    • header

      void header(String name, String value) throws MIMEParseException
      Receive notification of an unstructured header in the message. Headers are fields that occur at the beginning of a message or body part. They contain a name and an optional value.

      Header values may be continued over multiple lines in the underlying message data. The value supplied here is the logical value of the header after any line unfolding and decoding of non-ASCII characters performed according to RFC 2047.

      Parameters:
      name - the name of the header (field-name, cannot be null)
      value - the header value (field-body, may be null)
      Throws:
      MIMEParseException - if the processor encountered a fatal condition during parsing and wishes to cancel the parse process
    • unexpectedHeader

      void unexpectedHeader(String name, String value) throws MIMEParseException
      Receive notification of a structured header field for which the value was unparseable. This indicates a malformed message, but handlers may choose to log or ignore these events instead of throwing an exception.
      Parameters:
      name - the name of the header (field-name, cannot be null)
      value - the header value (field-body, may be null)
      Throws:
      MIMEParseException - if the processor encountered a fatal condition during parsing and wishes to cancel the parse process
    • dateHeader

      void dateHeader(String name, OffsetDateTime date) throws MIMEParseException
      Receive notification of a date header in the message.
      Parameters:
      name - the name of the header field, e.g. "Date"
      date - the parsed date value of the header with timezone preserved
      Throws:
      MIMEParseException - if the processor encountered a fatal condition during parsing and wishes to cancel the parse process
    • addressHeader

      void addressHeader(String name, List<EmailAddress> addresses) throws MIMEParseException
      Receive notification of an address header in the message. Some header fields (e.g. From, Sender) will only have one address. Others (To, Cc, Bcc) may have multiple addresses. The addresses list will never be empty. If the value in the underlying message did not contain valid addresses it will be reported via unexpectedHeader.
      Parameters:
      name - the name of the header field, e.g. "From", "To"
      addresses - a non-empty list of parsed email addresses
      Throws:
      MIMEParseException - if the processor encountered a fatal condition during parsing and wishes to cancel the parse process
    • messageIDHeader

      void messageIDHeader(String name, List<ContentID> contentIDs) throws MIMEParseException
      Receive notification of a message-id header in the message. Some header fields (e.g. Message-ID) will only have one ID. Others (References, In-Reply-To) may have multiple IDs. The contentIDs list will never be empty. If the value in the underlying message did not contain valid message-ids it will be reported via unexpectedHeader.
      Parameters:
      name - the name of the header field, e.g. "Message-ID", "References"
      contentIDs - the parsed message-id values (same structure as Content-ID)
      Throws:
      MIMEParseException - if the processor encountered a fatal condition during parsing and wishes to cancel the parse process
    • obsoleteStructure

      void obsoleteStructure(ObsoleteStructureType type) throws MIMEParseException
      Receive notification of an obsolete but recoverable message structure. This method will be called before the corresponding normal parsing event to allow handlers to gather statistics on obsolete structures while still processing the message content normally.
      Parameters:
      type - the type of obsolete structure detected
      Throws:
      MIMEParseException - if the processor encountered a fatal condition during parsing and wishes to cancel the parse process