Class MailboxExtension
- All Implemented Interfaces:
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:
-
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. - Once every email in the mailbox has been converted, an index PDF will be created listing every message.
- 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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconfigure(Json json) Configure the extension.booleanAttempt to load the specified object into the specified Report.load(ResourceDescriptor descriptor, Resource resource, URL2Connection con) Attempt to load a Resource from the specified URL2Connection.JsonloadMailbox(InputStream in, String mboxid, Report report, Map<String, Object> env) Given a Message in a suitable format, return aMessagethat wraps it, or null if the input is EOF.voidregister(ReportFactory factory) Notify this object it has beem added to a ReportFactory.booleansupports(ResourceDescriptor descriptor) Return true if this ResourceLoader could load a descriptor of the specified type.voidunregister(ReportFactory factory) Notify this object it has been removed from a ReportFactory.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.faceless.publisher.ext.ReportFactoryExtension
register, unregisterMethods inherited from interface org.faceless.publisher.resource.ResourceLoader
isTrustRequired
-
Constructor Details
-
MailboxExtension
public MailboxExtension()
-
-
Method Details
-
register
Description copied from interface:ReportFactoryExtensionNotify this object it has beem added to a ReportFactory. Will be called when this object is added to the list returned byReportFactory.getReportFactoryExtensions(). The default implementation is a no-op.- Specified by:
registerin interfaceReportFactoryExtension
-
unregister
Description copied from interface:ReportFactoryExtensionNotify this object it has been removed from a ReportFactory. Will be called when this object is removed from the list returned byReportFactory.getReportFactoryExtensions(). The default implementation is a no-op.- Specified by:
unregisterin interfaceReportFactoryExtension
-
configure
public void configure(Json json) Description copied from interface:ReportFactoryExtensionConfigure 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:
configurein interfaceReportFactoryExtension
-
loadNextMessageFromMbox
Given a Message in a suitable format, return aMessagethat wraps it, or null if the input is EOF.- Returns:
- a
Message, ornullif the input is a stream that is EOF. a @param o the input, as aPath, {@link @File}InputStream,javax.mail.internet.MimeMessageorjakarta.mail.internet.MimeMessage - Throws:
IOException
-
load
Description copied from interface:ReportFactoryExtensionAttempt 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 callReportFactoryExtension.load(java.lang.Object, org.faceless.publisher.Report)with anInputSource,Readeror similar, and return true. If this extension cannot load the specified type of object, return false. This is the default.- Specified by:
loadin interfaceReportFactoryExtension- Throws:
IOException
-
supports
Description copied from interface:ResourceLoaderReturn 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 fromResourceManager.getResourceLoader(org.faceless.publisher.type.MediaType, java.lang.Class<?>).- Specified by:
supportsin interfaceResourceLoader
-
load
public ResourceFlavor load(ResourceDescriptor descriptor, Resource resource, URL2Connection con) throws Exception Description copied from interface:ResourceLoaderAttempt 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:
loadin interfaceResourceLoader- Parameters:
descriptor- the descriptor of what type of flavor we want.resource- the Resource we're populatingcon- 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
-