Class MailExtension

java.lang.Object
org.faceless.publisher.ext.MailExtension
All Implemented Interfaces:
ReportFactoryExtension, ResourceLoader

public class MailExtension extends Object implements ReportFactoryExtension, ResourceLoader

Allow the loading of javax.mail.internet.WrapMimeMessage Mail messages into the Report. They can be loaded by either passing an instance of that class into the Report.load(java.lang.Object) method, or by parsing an object of media type "message/rfc822".

Email is converted into HTML in several steps:

  1. The Email is parsed and a JSON structure created which has details on all the metadata (headers etc) as well as the URLs for the various parts of the messages.
  2. The JSON structure is converted to HTML using a template - the API ships with two pre-defined ZTemplate templates for a default conversion and one complying with EA-PDF 1.0

The conversion to JSON is not configurable, but the conversion from JSON to HTML is entirely under user control and can be configured with the following environment properties

bfo-ext-mail
Either the name of a predefined template, or the URL of the template to apply
bfo-ext-mail-template-type
The template format, which may be "freemarker" or "ztemplate". If not specified, the API will attempt to guess this based on the template URL, defaulting to "ztemplate"
bfo-ext-mail-template-output-type
Set to "text/xml" if the template generates XML rather than HTML
bfo-ext-mail-template-NNN
Any additional parameters will be set on the template processing instruction
bfo-ext-mail-NNN
Any additional parameters will be set in the "env" map of the JSON
Since:
1.4
See Also:
  • Constructor Details

    • MailExtension

      public MailExtension()
  • Method Details

    • register

      public void register(ReportFactory factory)
      Description copied from interface: ReportFactoryExtension
      Notify this object it has beem added to a ReportFactory. Will be called when this object is added to the list returned by ReportFactory.getReportFactoryExtensions(). The default implementation is a no-op.
      Specified by:
      register in interface ReportFactoryExtension
    • unregister

      public void unregister(ReportFactory factory)
      Description copied from interface: ReportFactoryExtension
      Notify this object it has been removed from a ReportFactory. Will be called when this object is removed from the list returned by ReportFactory.getReportFactoryExtensions(). The default implementation is a no-op.
      Specified by:
      unregister in interface ReportFactoryExtension
    • configure

      public void configure(Json json)
      Description copied from interface: ReportFactoryExtension
      Configure the extension. This method will be called by the web-service immediately after the extension is added, to pass in any parameters set by the user. The default implementation does nothing
      Specified by:
      configure in interface ReportFactoryExtension
    • loadMessage

      public MailExtension.Message loadMessage(Object o) throws IOException
      Given a Message (as an InputStream, javax.mail.internet.MimeMessage or jakarta.mail.internet.MimeMessage) return a MailExtension.Message that wraps it.
      Throws:
      IOException
    • load

      public boolean load(Object o, Report report) throws IOException
      Description copied from interface: ReportFactoryExtension
      Attempt to load the specified object into the specified Report. If this extension can load the specified type of object, it should configure the report however it needs to, eventually call ReportFactoryExtension.load(java.lang.Object, org.faceless.publisher.Report) with an InputSource, Reader or similar, and return true. If this extension cannot load the specified type of object, return false. This is the default.
      Specified by:
      load in interface ReportFactoryExtension
      Throws:
      IOException
    • apply

      public void apply(MailExtension.Message message, Report report) throws IOException
      Given a MailExtension.Message, convert it to an object and call Report.load(java.lang.Object) with the result. The default implementation converts the message to Json and makes use of the bfo-ext-mail and other environment properties to convert that JSON to HTML by processing it with a ProcessingInstruction that loads a template. Custom conversion is possible by overriding this method.
      Parameters:
      message - the message
      report - the report
      Throws:
      IOException
    • supports

      public boolean supports(ResourceDescriptor descriptor)
      Description copied from interface: ResourceLoader
      Return true if this ResourceLoader could load a descriptor of the specified type. The resourceClass, outputClass and mediaType of the descriptor should be checked as appropriate. The MediaType in particular will not be a wildcard for normal use; it may be a wildcard if we're being called from ResourceManager.getResourceLoader(org.faceless.publisher.type.MediaType, java.lang.Class<?>).
      Specified by:
      supports in interface ResourceLoader
    • load

      public ResourceFlavor load(ResourceDescriptor descriptor, Resource resource, URL2Connection con) throws Exception
      Description copied from interface: ResourceLoader
      Attempt to load a Resource from the specified URL2Connection. If the ResourceLoader applies (it should test the resource mediatype and class) then it should load the resource from the URL. If the URI has a fragment and the loaded resource to ALL fragments, it should change the URI to have no fragment. Likewise if any aspect of the MediaType does not apply (i.e. the encoding) then it should remove it, so the Resource describes the widest possible URI and MediaType that would match this object. Finally, on success this method should set the Object on the resource, or throw an exception on failure. The supplied "con" will have an InputStream that is mark-capable already. If the stream is a gzip or brotli compresed stream, decompression will already be applied. The mediatype wil be set on "d". Returning null from this object is considered an error condition - if that happens we shouldn't have got here, and the only reason we did was because "supports" for the same descriptor returned true.
      Specified by:
      load in interface ResourceLoader
      Parameters:
      descriptor - the descriptor of what type of flavor we want.
      resource - the Resource we're populating
      con - the URLConnection to load the resource from
      Returns:
      the new Flavor, or null if it doesn't apply.
      Throws:
      Exception