/*
* Copyright (c) 2009-2014 Jason Mehrens. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* An error manager used to store mime messages from the <tt>MailHandler</tt>
* to the file system when the email server is unavailable or unreachable. The
* code to manually setup this error manager can be as simple as the following:
* <pre>
* File dir = new File("path to dir");
* FileErrorManager em = new FileErrorManager(dir);
* </pre>
*
* <p>
* <b>Configuration:</b>
* The code to setup this error manager via the logging properties can be as
* simple as the following:
* <pre>
* #Default FileErrorManager settings.
* FileErrorManager.pattern = path to directory
* </pre>
*
* If properties are not defined, or contain invalid values, then the specified
* default values are used.
* <ul>
* <li>FileErrorManager.pattern the absolute file path to the directory which
* will store any failed email messages. (defaults to the value of the system
* property <tt>java.io.tmpdir</tt>)
* </ul>
*
* @author Jason Mehrens
*/
/**
* Stores the LogManager.
*/
/**
* Used to report errors that this error manager fails to report.
*/
/**
* Directory of the email store.
*/
/**
* Creates a new error manager. Files are stored in the users temp
* directory.
*
* @exception SecurityException if unable to access system properties or if
* a security manager is present and unable to read or write to users temp
* directory.
*/
public FileErrorManager() {
this.emailStore = getEmailStore();
init();
}
/**
* Creates a new error manager.
*
* @param dir a directory to store the email files.
* @throws NullPointerException if <tt>dir</tt> is <tt>null</tt>
* @throws IllegalArgumentException if <tt>dir</tt> is a
* <tt>java.io.File</tt> subclass, not a directory, or is not an absolute
* path.
* @throws SecurityException if a security manager is present and unable to
* read or write to a given directory.
*/
this.emailStore = dir;
init();
}
/**
* If the message parameter is a raw email, and passes the store term, then
* this method will store the email to the file system. If the message
* parameter is not a raw email then the message is forwarded to the super
* class. If an email is written to the file system without error, then the
* original reported error is ignored.
*
* @param msg String raw email or plain error message.
* @param ex Exception that occurred in the mail handler.
* @param code int error manager code.
*/
if (isRawEmail(msg)) {
try {
} catch (final IOException IOE) {
} catch (final RuntimeException RE) {
}
} else {
}
}
/**
* Performs the initialization for this object.
*/
private void init() {
}
}
if (!dir.isDirectory()) {
throw new IllegalArgumentException("File must be a directory.");
}
}
//For now, only absolute paths are allowed.
if (!dir.isAbsolute()) {
throw new IllegalArgumentException("Only absolute paths are allowed.");
}
}
}
/**
* Creates a common temp file prefix.
*
* @return the file prefix.
*/
return "FileErrorManager";
}
/**
* Creates a common temp file suffix.
*
* @return the file suffix.
*/
return ".eml";
}
/**
* Determines if the given message is a MIME message or just free text.
*
* @param msg the message to examine.
* @return true if MIME message otherwise false.
*/
}
return false;
}
/**
* Stores the given string in a file.
*
* @param email the message to store.
* @throws IOException if there is a problem.
*/
for (;;) {
try {
break;
} catch (FileNotFoundException FNFE) {
throw FNFE;
}
}
}
try { //Raw email is ASCII.
} finally {
}
}
/**
* Null safe close method.
*
* @param out closes the given stream.
*/
try {
} catch (IOException IOE) {
}
}
}
/**
* Null safe delete method.
*
* @param tmp the file to delete.
*/
try {
try {
try {
tmp.deleteOnExit();
} catch (final LinkageError shutdown) {
throw new RuntimeException(shutdown);
}
} catch (final RuntimeException shutdown) {
}
}
}
} catch (SecurityException SE) {
}
}
}
/**
* Gets the location of the email store.
*
* @return the File location.
*/
}
});
}
}
/**
* Wraps the given stream as a NewLineOutputStream.
*
* @param out the stream to wrap.
* @return the original or wrapped output stream.
*/
Class<?> k;
try {
if (OutputStream.class.isAssignableFrom(k)) {
} else {
super.error("Unable to switch newlines",
new ClassNotFoundException(k.getName()),
}
} catch (RuntimeException re) {
super.error("Unable to switch newlines",
super.error("Unable to switch newlines",
} catch (LinkageError le) {
super.error("Unable to switch newlines",
}
return out;
}
}