Class MailboxExtension

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

public class MailboxExtension extends Object implements ReportFactoryExtension, ResourceLoader

Allow the loading of mbox mailbox files containing one or more email messages, which are converted using MailExtension before being bundled together in a PDF Portfolio.

Conversion of a mailbox runs in several steps:

  1. Each email is converted individually using the MailExtension, with the resulting PDF saved to a temporary directory. These files are not removed on completion for reasons explained below, so will not be reconverted if they already exist. This allows conversion of large mailboxes to be interrupted if necessary; restarting will not repeat.
  2. Once every email in the mailbox has been converted, an index PDF will be created listing every message.
  3. The individual messages are attached to the index PDF to form a PDF Portfolio. Although technically nothing more than a PDF with a number of attachments, many PDF viewers will present these files in a particular way when opened.

After these steps the conversion is technically complete, but it's important to note the individual message PDFs are not held in memory at this point, but kept on disk. Saving the PDF will assemble all of them into a single PDF file; only after that is done is it safe to delete the message files.

As with MailExtension the exact format of the PDF is based on a JSON file created from the index of all the messages. The configuration for this is expected to change so is not currently documented, but the format is derived from the format used for the individual messages; if they are created as PDF/mail-1s files based on PDF 2.0, then the index PDF will be PDf/mail-1c based on PDF 2.0.

Since:
1.5
  • Constructor Details

    • MailboxExtension

      public MailboxExtension()
  • 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
    • loadNextMessageFromMbox

      public MailExtension.Message loadNextMessageFromMbox(InputStream in) throws IOException
      Given a Message in a suitable format, return a Message that wraps it, or null if the input is EOF.
      Returns:
      a Message, or null if the input is a stream that is EOF. a @param o the input, as a Path, {@link @File} InputStream, javax.mail.internet.MimeMessage or jakarta.mail.internet.MimeMessage
      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
    • 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
    • loadMailbox

      public Json loadMailbox(InputStream in, String mboxid, Report report, Map<String,Object> env) throws IOException, SAXException, ParserConfigurationException
      Throws:
      IOException
      SAXException
      ParserConfigurationException