+* This class is used to encode and decode data in Base64 format as described in RFC 1521.
+*
+*
+* Home page: www.source-code.biz
+* Author: Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland
+* Multi-licensed: EPL/LGPL/AL/BSD.
+*
+*
+* Version history:
+* 2003-07-22 Christian d'Heureuse (chdh): Module created.
+* 2005-08-11 chdh: Lincense changed from GPL to LGPL.
+* 2006-11-21 chdh:
+* Method encode(String) renamed to encodeString(String).
+* Method decode(String) renamed to decodeString(String).
+* New method encode(byte[],int) added.
+* New method decode(String) added.
+* 2009-07-16: Additional licenses (EPL/AL) added.
+* 2009-09-16: Additional license (BSD) added.
+* 2009-09-16: Additional license (BSD) added.
+* 2010-01-27: Package name added.
+*/
+
+public class Base64Coder {
+
+// Mapping table from 6-bit nibbles to Base64 characters.
+private static char[] map1 = new char[64];
+ static {
+ int i=0;
+ for (char c='A'; c<='Z'; c++) map1[i++] = c;
+ for (char c='a'; c<='z'; c++) map1[i++] = c;
+ for (char c='0'; c<='9'; c++) map1[i++] = c;
+ map1[i++] = '+'; map1[i++] = '/'; }
+
+// Mapping table from Base64 characters to 6-bit nibbles.
+private static byte[] map2 = new byte[128];
+ static {
+ for (int i=0; iin.
+* @return A character array with the Base64 encoded data.
+*/
+public static char[] encode (byte[] in, int iLen) {
+ int oDataLen = (iLen*4+2)/3; // output length without padding
+ int oLen = ((iLen+2)/3)*4; // output length including padding
+ char[] out = new char[oLen];
+ int ip = 0;
+ int op = 0;
+ while (ip < iLen) {
+ int i0 = in[ip++] & 0xff;
+ int i1 = ip < iLen ? in[ip++] & 0xff : 0;
+ int i2 = ip < iLen ? in[ip++] & 0xff : 0;
+ int o0 = i0 >>> 2;
+ int o1 = ((i0 & 3) << 4) | (i1 >>> 4);
+ int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6);
+ int o3 = i2 & 0x3F;
+ out[op++] = map1[o0];
+ out[op++] = map1[o1];
+ out[op] = op < oDataLen ? map1[o2] : '='; op++;
+ out[op] = op < oDataLen ? map1[o3] : '='; op++; }
+ return out; }
+
+/**
+* Decodes a string from Base64 format.
+* @param s a Base64 String to be decoded.
+* @return A String containing the decoded data.
+* @throws IllegalArgumentException if the input is not valid Base64 encoded data.
+*/
+public static String decodeString (String s) {
+ return new String(decode(s)); }
+
+/**
+* Decodes a byte array from Base64 format.
+* @param s a Base64 String to be decoded.
+* @return An array containing the decoded data bytes.
+* @throws IllegalArgumentException if the input is not valid Base64 encoded data.
+*/
+public static byte[] decode (String s) {
+ return decode(s.toCharArray()); }
+
+/**
+* Decodes a byte array from Base64 format.
+* No blanks or line breaks are allowed within the Base64 encoded data.
+* @param in a character array containing the Base64 encoded data.
+* @return An array containing the decoded data bytes.
+* @throws IllegalArgumentException if the input is not valid Base64 encoded data.
+*/
+public static byte[] decode (char[] in) {
+ int iLen = in.length;
+ if (iLen%4 != 0) throw new IllegalArgumentException ("Length of Base64 encoded input string is not a multiple of 4.");
+ while (iLen > 0 && in[iLen-1] == '=') iLen--;
+ int oLen = (iLen*3) / 4;
+ byte[] out = new byte[oLen];
+ int ip = 0;
+ int op = 0;
+ while (ip < iLen) {
+ int i0 = in[ip++];
+ int i1 = in[ip++];
+ int i2 = ip < iLen ? in[ip++] : 'A';
+ int i3 = ip < iLen ? in[ip++] : 'A';
+ if (i0 > 127 || i1 > 127 || i2 > 127 || i3 > 127)
+ throw new IllegalArgumentException ("Illegal character in Base64 encoded data.");
+ int b0 = map2[i0];
+ int b1 = map2[i1];
+ int b2 = map2[i2];
+ int b3 = map2[i3];
+ if (b0 < 0 || b1 < 0 || b2 < 0 || b3 < 0)
+ throw new IllegalArgumentException ("Illegal character in Base64 encoded data.");
+ int o0 = ( b0 <<2) | (b1>>>4);
+ int o1 = ((b1 & 0xf)<<4) | (b2>>>2);
+ int o2 = ((b2 & 3)<<6) | b3;
+ out[op++] = (byte)o0;
+ if (op
+ *
+ * This stream can be used with the Part.writeTo and Message.writeTo
+ * methods to generate the canonical MIME format of the data for the
+ * purpose of (e.g.) sending it via SMTP or computing a digital
+ * signature.
+ */
+public class CRLFOutputStream extends FilterOutputStream {
+ protected int lastb = -1;
+ protected static byte[] newline;
+ static {
+ newline = new byte[2];
+ newline[0] = (byte)'\r';
+ newline[1] = (byte)'\n';
+ }
+
+ public CRLFOutputStream(OutputStream os) {
+ super(os);
+ }
+
+ public void write(int b) throws IOException {
+ if (b == '\r') {
+ out.write(newline);
+ } else if (b == '\n') {
+ if (lastb != '\r')
+ out.write(newline);
+ } else {
+ out.write(b);
+ }
+ lastb = b;
+ }
+
+ public void write(byte b[]) throws IOException {
+ write(b, 0, b.length);
+ }
+
+ public void write(byte b[], int off, int len) throws IOException {
+ int start = off;
+
+ len += off;
+ for (int i = start; i < len ; i++) {
+ if (b[i] == '\r') {
+ out.write(b, start, i - start);
+ out.write(newline);
+ start = i + 1;
+ } else if (b[i] == '\n') {
+ if (lastb != '\r') {
+ out.write(b, start, i - start);
+ out.write(newline);
+ }
+ start = i + 1;
+ }
+ lastb = b[i];
+ }
+ if ((len - start) > 0)
+ out.write(b, start, len - start);
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/NewlineOutputStream.java b/src/Java/Jars/javamail-samples/javamail-samples/NewlineOutputStream.java
new file mode 100644
index 0000000..0b17d10
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/NewlineOutputStream.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 1997-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.io.*;
+
+/**
+ * Convert the various newline conventions to the local platform's
+ * newline convention.
+ *
+ * This stream can be used with the Message.writeTo method to
+ * generate a message that uses the local plaform's line terminator
+ * for the purpose of (e.g.) saving the message to a local file.
+ */
+public class NewlineOutputStream extends FilterOutputStream {
+ private int lastb = -1;
+ private static byte[] newline;
+
+ public NewlineOutputStream(OutputStream os) {
+ super(os);
+ if (newline == null) {
+ String s = System.getProperty("line.separator");
+ if (s == null || s.length() <= 0)
+ s = "\n";
+ try {
+ newline = s.getBytes("iso-8859-1"); // really us-ascii
+ } catch (UnsupportedEncodingException ex) {
+ // should never happen
+ newline = new byte[] { (byte)'\n' };
+ }
+ }
+ }
+
+ public void write(int b) throws IOException {
+ if (b == '\r') {
+ out.write(newline);
+ } else if (b == '\n') {
+ if (lastb != '\r')
+ out.write(newline);
+ } else {
+ out.write(b);
+ }
+ lastb = b;
+ }
+
+ public void write(byte b[]) throws IOException {
+ write(b, 0, b.length);
+ }
+
+ public void write(byte b[], int off, int len) throws IOException {
+ for (int i = 0 ; i < len ; i++) {
+ write(b[off + i]);
+ }
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/README.txt b/src/Java/Jars/javamail-samples/javamail-samples/README.txt
new file mode 100644
index 0000000..781d064
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/README.txt
@@ -0,0 +1,384 @@
+ README for the demo programs in this directory
+ ==============================================
+
+These demo programs illustrate how to use the JavaMail API to
+perform a number of common email functions. Note these these
+programs are not intended to be examples of good user interfaces,
+or good command line interfaces. No one is expected to actually
+*use* these programs for anything real. Rather, their value is
+in the source code. Don't look at their command line arguments
+or user interface to figure out what JavaMail can do, look at
+their source code. We strongly recommend that you read the
+source code and understand what these programs are doing before
+running them.
+
+All of these programs are simple command line tools with a UNIX
+style interface. On Windows you'll need to run them in an MS-DOS
+window. We apologize in advance for the inconsistency in how these
+programs accept options. There are generally two styles. The very
+simple style (e.g., as used by copier.java) requires a fixed number
+of arguments in a fixed order. Others (e.g., folderlist.java) take
+UNIX-style options, many of which are optional, and which may appear
+in any order. The following notes should help you figure it out,
+but if in doubt, read the source code.
+
+
+
+- copier.java
+
+ This program copies the specified messages from one folder to
+ another. Both folders must belong to the same store.
+
+ Usage:
+ java copier
+
+ Arguments (in order):
+
+ : URL of the Store. The URL should include
+ the password as well (if needed).
+ Example: "imap://john:password@mailstore.com"
+
+ : source folder
+ : destination folder
+ : start message number
+ : end message number
+
+
+- folderlist.java
+
+ This program lists information about the folders in a Store.
+
+ Usage:
+ java folderlist -L -T -H -U -P
+ [-R ] [-r] [-v] [-D]
+
+ Options:
+
+ -L : URL of the Store. The URL should include
+ the password as well (if needed).
+ Example: "imap://john:password@mailstore.com"
+ -T : store protocol (Ex: "imap")
+ -H : hostname of store.
+ -U : username (if needed)
+ -P : password (if needed)
+ -R : root of the folder hierarchy. This is optional. If
+ not present, listing starts from the default folder.
+ -r : list recursively - folder and all subfolders.
+ -v : verbose - show more info about each folder.
+ -D : Turn on session debugging
+ : folders that match this pattern are listed. Use "*"
+ as wildcard to match everything.
+
+
+- monitor.java
+
+ Illustrates how to monitor a folder for interesting events,
+ like new mail arrival.
+
+ Usage:
+ java monitor
+
+ Arguments (in order):
+
+ : hostname of store.
+ : username (if needed)
+ : password (if needed)
+ : folder to monitor
+ : frequency of monitoring
+
+
+- mover.java
+
+ Moves messages between folders. The folders must belong to the
+ same store.
+
+ Usage:
+ java mover -T -H -U -P [-v]
+ -s -d [-x]
+
+ Options:
+
+ -T : store protocol (Ex: "imap")
+ -H : hostname of store.
+ -U : username (if needed)
+ -P : password (if needed)
+ -s : source folder
+ -d : destination folder
+ -v : Optional verbose option
+ -x : Optional expunge option, to expunge the deleted
+ messages from src
+
+ Arguments (in order):
+
+ : start message number
+ : end message number
+
+
+- msgmultisendsample.java
+
+ Demonstrates how to construct and send a multipart message.
+
+ Usage:
+ java msgmultisendsample true|false
+
+ Arguments (in order):
+
+ : Recipient address
+ : Sender address
+ : name of SMTP server
+ true|false : "true" to turn on session debugging, "false" otherwise
+
+
+- msgsend.java
+
+ Send a simple text message. Optionally saves a copy
+ of the outgoing message in a folder (record-folder).
+
+ Most parameters to this program are optional. When
+ the program is run, it interactively asks for
+ the "To" and "Subject" fields if not already available.
+ Then the program expects the body of the message.
+ After you type in the body, hit Ctrl-D on Unix
+ systems or Ctrl-Z on Windows systems to send
+ the message.
+
+ Usage:
+ java msgsend -L -T -H -U
+ -P -s -o -c -b
+ -f -M [-d]
+
+ Options:
+
+ -L : URL of the store for the record-folder
+ -T : If is not present, this indicates
+ the store protocol for the record-folder.
+ -H : If is not present, this indicates
+ the hostname for the record-folder.
+ -U : If is not present, this indicates
+ the username for the record-folder.
+ -P : If is not present, this indicates
+ the password for the record-folder.
+ -f : name of record-folder.
+ -M : Host name of SMTP server. Defaults to "localhost"
+ which often works on UNIX but rarely on Windows.
+ -s : Subject of message to be sent
+ -o : From address of message to be sent
+ -c : Cc address of message to be sent
+ -b : Bcc address of message to be sent
+ -d : Turn on session debugging.
+ -a : Include file as an attachment with the message
+
+ Argument:
+
+ : To address of message to be sent
+
+
+- msgsendsample.java
+
+ Demonstrates how to construct and send a simple text message.
+
+ Usage:
+ java msgsendsample true|false
+
+ Arguments (in order):
+
+ : Recipient address
+ : Sender address
+ : name of SMTP server
+ true|false : "true" to turn on session debugging, "false" otherwise
+
+
+- msgshow.java
+
+ Displays message(s) from a folder or from stdin.
+
+ Usage:
+ java msgshow -L -T -H -p
+ -U -P -f
+ [-D] [-s] [-S] [-a] [-v] [msgnum]
+ java msgshow -m [-D] [-s] [-S] [-v]
+
+ Options:
+
+ -L : URL of the Store. The URL should include
+ the password as well (if needed).
+ Example: "imap://john:password@mailstore.com"
+ -T : If is not present, this indicates
+ the store protocol
+ -H : If is not present, this indicates
+ the hostname
+ -p : If is not present, this indicates
+ the port number (usually not needed)
+ -U : If is not present, this indicates
+ the username
+ -P : If is not present, this indicates
+ the password
+ -f : Folder to open
+ -m : Read message from standard input
+ -D : Turn on session debugging
+ -s : Show the structure of the message, but not the contents
+ -S : Save attachments to appropriately named files
+ -a : Show ALERTS and NOTIFICATIONS from the Store
+ -v : Verbose mode - show total messages and number of new messages
+
+ Argument:
+
+ : the message to be displayed. If this
+ parameter is not present, all messages in the
+ folder are displayed.
+
+
+- namespace.java
+
+ Displays the namespaces supported by a store.
+
+ Usage:
+ java namespace -L -T -H -p
+ -U -P [-D]
+
+ Options:
+
+ -L : URL of the Store. The URL should include
+ the password as well (if needed).
+ Example: "imap://john:password@mailstore.com"
+ -T : If is not present, this indicates
+ the store protocol
+ -H : If is not present, this indicates
+ the hostname
+ -p : If is not present, this indicates
+ the port number (usually not needed)
+ -U : If is not present, this indicates
+ the username
+ -P : If is not present, this indicates
+ the password
+ -D : Turn on session debugging
+
+
+- populate.java
+
+ Copies an entire folder hierarchy from one message store to
+ another.
+
+ Usage:
+ java populate -s -d -D -f
+
+ Options:
+
+ -s : URL of source folder
+ -d : URL of destination folder
+ -D : Turn on session debugging
+ -f : force the copy to occur even if the destination
+ folder already exists
+ -S : skip special folders named "SCCS", "Drafts", "Trash", and
+ "Shared Folders"
+ -c : clear out old folders before copying messages
+ -P : don't preserve flags when copying messages
+
+
+- registry.java
+
+ Demonstrates how to query the JavaMail "registry" for providers,
+ set default providers, etc.
+
+ Usage:
+ java registry
+
+
+- search.java
+
+ Search the given folder for messages matching the
+ given criteria. Illustrates the use of the
+ javax.mail.search package.
+
+ Usage:
+ java search -L -T -H -U -P
+ -f -subject -from
+ -today -or
+
+ Options:
+
+ -L : URL of the store
+ -T : If is not present, this indicates
+ the store protocol
+ -H : If is not present, this indicates
+ the hostname
+ -U : If is not present, this indicates
+ the username
+ -P : If is not present, this indicates
+ the password
+ -f : folder to search
+
+ -or : If this flag is present, the search will
+ return messages that match any one of the
+ below criteria. Else the search will only
+ return messages that match all the criteria
+
+ -subject : search for messages containing this string
+ as the Subject
+ -from : search for messages containing this string
+ as the From address
+ -today : search for messages received today
+
+
+- sendfile.java
+
+ Send the specified file to the given address. The file
+ is sent as an attachment. An SMTP server must be available.
+
+ Usage:
+ java sendfile true|false
+
+ Arguments (in order):
+
+ : Recipient address
+ : Sender address
+ : name of SMTP server
+ : name of file to be sent
+ true|false : "true" to turn on session debugging, "false" otherwise
+
+
+- sendhtml.java
+
+ The sendhtml program works like the msgsend program, taking
+ the same options and input, but the text collected from the
+ user is sent as type "text/html" instead of "text/plain".
+
+ This program is a good example of how to send arbitrary
+ string data as any arbitrary MIME type.
+
+
+- smtpsend.java
+
+ Takes the same options as the msgsend program, but illustrates
+ how to handle SMTP-specific error codes. Also accepts the
+ following options:
+
+ Option:
+
+ -v : verbose output
+ -A : use SMTP authentication
+ -S : use SSL
+
+- transport.java
+
+ Illustrates how to use an explicit Transport object, how to
+ handle transport exceptions, and how to handle transport events.
+
+ Usage:
+ java transport true|false
+
+ Arguments (in order):
+
+ : Recipient address
+ : Sender address
+ : name of SMTP server
+ : name of file to be sent
+ true|false : "true" to turn on session debugging, "false" otherwise
+
+
+- uidmsgshow.java
+
+ The uidmsgshow program works like the msgshow program, taking
+ the same options, except instead of using message numbers, it
+ uses message UID's. This will typically only work with IMAP
+ message stores.
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/client/ComponentFrame.java b/src/Java/Jars/javamail-samples/javamail-samples/client/ComponentFrame.java
new file mode 100644
index 0000000..70b7636
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/client/ComponentFrame.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 1997-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.JFrame;
+import javax.swing.WindowConstants;
+
+
+/**
+ * this Frame provides a utility class for displaying a single
+ * Component in a Frame.
+ *
+ * @author Christopher Cotton
+ */
+
+public class ComponentFrame extends JFrame {
+
+ /**
+ * creates the frame
+ * @param what the component to display
+ */
+ public ComponentFrame(Component what) {
+ this(what, "Component Frame");
+ }
+
+ /**
+ * creates the frame with the given name
+ * @param what the component to display
+ * @param name the name of the Frame
+ */
+ public ComponentFrame(Component what, String name) {
+ super(name);
+
+ // make sure that we close and dispose ourselves when needed
+ setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
+
+ // default size of the frame
+ setSize(700,600);
+
+ // we want to display just the component in the entire frame
+ if (what != null) {
+ getContentPane().add("Center", what);
+ }
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/client/FolderModel.java b/src/Java/Jars/javamail-samples/javamail-samples/client/FolderModel.java
new file mode 100644
index 0000000..6f7ccf0
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/client/FolderModel.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 1997-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import javax.mail.*;
+import java.util.Date;
+import javax.swing.table.AbstractTableModel;
+
+/**
+ * Maps the messages in a Folder to the Swing's Table Model
+ *
+ * @author Christopher Cotton
+ * @author Bill Shannon
+ */
+
+public class FolderModel extends AbstractTableModel {
+
+ Folder folder;
+ Message[] messages;
+
+ String[] columnNames = { "Date", "From", "Subject"};
+ Class[] columnTypes = { String.class, String.class, String.class };
+
+ public void setFolder(Folder what) throws MessagingException {
+ if (what != null) {
+
+ // opened if needed
+ if (!what.isOpen()) {
+ what.open(Folder.READ_WRITE);
+ }
+
+ // get the messages
+ messages = what.getMessages();
+ cached = new String[messages.length][];
+ } else {
+ messages = null;
+ cached = null;
+ }
+ // close previous folder and switch to new folder
+ if (folder != null)
+ folder.close(true);
+ folder = what;
+ fireTableDataChanged();
+ }
+
+ public Message getMessage(int which) {
+ return messages[which];
+ }
+
+ //---------------------
+ // Implementation of the TableModel methods
+ //---------------------
+
+ public String getColumnName(int column) {
+ return columnNames[column];
+ }
+
+ public Class getColumnClass(int column) {
+ return columnTypes[column];
+ }
+
+
+ public int getColumnCount() {
+ return columnNames.length;
+ }
+
+ public int getRowCount() {
+ if (messages == null)
+ return 0;
+
+ return messages.length;
+ }
+
+ public Object getValueAt(int aRow, int aColumn) {
+ switch(aColumn) {
+ case 0: // date
+ case 1: // From String[] what = getCachedData(aRow);
+ case 2: // Subject
+ String[] what = getCachedData(aRow);
+ if (what != null) {
+ return what[aColumn];
+ } else {
+ return "";
+ }
+
+ default:
+ return "";
+ }
+ }
+
+ protected static String[][] cached;
+
+ protected String[] getCachedData(int row) {
+ if (cached[row] == null) {
+ try{
+ Message m = messages[row];
+
+ String[] theData = new String[4];
+
+ // Date
+ Date date = m.getSentDate();
+ if (date == null) {
+ theData[0] = "Unknown";
+ } else {
+ theData[0] = date.toString();
+ }
+
+ // From
+ Address[] adds = m.getFrom();
+ if (adds != null && adds.length != 0) {
+ theData[1] = adds[0].toString();
+ } else {
+ theData[1] = "";
+ }
+
+ // Subject
+ String subject = m.getSubject();
+ if (subject != null) {
+ theData[2] = subject;
+ } else {
+ theData[2] = "(No Subject)";
+ }
+
+ cached[row] = theData;
+ }
+ catch (MessagingException e) {
+ e.printStackTrace();
+ }
+ }
+
+ return cached[row];
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/client/FolderTreeNode.java b/src/Java/Jars/javamail-samples/javamail-samples/client/FolderTreeNode.java
new file mode 100644
index 0000000..f02f833
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/client/FolderTreeNode.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 1997-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.mail.Store;
+import javax.mail.Folder;
+import javax.mail.MessagingException;
+
+/**
+ * Node which represents a Folder in the javax.mail apis.
+ *
+ * @author Christopher Cotton
+ */
+public class FolderTreeNode extends DefaultMutableTreeNode {
+
+ protected Folder folder = null;
+ protected boolean hasLoaded = false;
+
+ /**
+ * creates a tree node that points to the particular Store.
+ *
+ * @param what the store for this node
+ */
+ public FolderTreeNode(Folder what) {
+ super(what);
+ folder = what;
+ }
+
+
+ /**
+ * a Folder is a leaf if it cannot contain sub folders
+ */
+ public boolean isLeaf() {
+ try {
+ if ((folder.getType() & Folder.HOLDS_FOLDERS) == 0)
+ return true;
+ } catch (MessagingException me) { }
+
+ // otherwise it does hold folders, and therefore not
+ // a leaf
+ return false;
+ }
+
+ /**
+ * returns the folder for this node
+ */
+ public Folder getFolder() {
+ return folder;
+ }
+
+
+
+ /**
+ * return the number of children for this folder node. The first
+ * time this method is called we load up all of the folders
+ * under the store's defaultFolder
+ */
+
+ public int getChildCount() {
+ if (!hasLoaded) {
+ loadChildren();
+ }
+ return super.getChildCount();
+ }
+
+ protected void loadChildren() {
+ // if it is a leaf, just say we have loaded them
+ if (isLeaf()) {
+ hasLoaded = true;
+ return;
+ }
+
+ try {
+ // Folder[] sub = folder.listSubscribed();
+ Folder[] sub = folder.list();
+
+ // add a FolderTreeNode for each Folder
+ int num = sub.length;
+ for(int i = 0; i < num; i++) {
+ FolderTreeNode node = new FolderTreeNode(sub[i]);
+ // we used insert here, since add() would make
+ // another recursive call to getChildCount();
+ insert(node, i);
+ }
+
+ } catch (MessagingException me) {
+ me.printStackTrace();
+ }
+ }
+
+
+ /**
+ * override toString() since we only want to display a folder's
+ * name, and not the full path of the folder
+ */
+ public String toString() {
+ return folder.getName();
+ }
+
+}
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/client/FolderViewer.java b/src/Java/Jars/javamail-samples/javamail-samples/client/FolderViewer.java
new file mode 100644
index 0000000..d313d9a
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/client/FolderViewer.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 1997-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.awt.*;
+import javax.mail.*;
+import javax.swing.*;
+import javax.swing.event.*;
+import javax.swing.table.*;
+
+/**
+ * @author Christopher Cotton
+ * @author Bill Shannon
+ */
+
+public class FolderViewer extends JPanel {
+
+ FolderModel model = new FolderModel();
+ JScrollPane scrollpane;
+ JTable table;
+
+ public FolderViewer() {
+ this(null);
+ }
+
+ public FolderViewer(Folder what) {
+ super(new GridLayout(1,1));
+
+ table = new JTable(model);
+ table.setShowGrid(false);
+
+ scrollpane = new JScrollPane(table);
+
+ // setup the folder we were given
+ setFolder(what);
+
+ // find out what is pressed
+ table.getSelectionModel().addListSelectionListener(
+ new FolderPressed());
+ scrollpane.setPreferredSize(new Dimension(700, 300));
+ add(scrollpane);
+ }
+
+ /**
+ * Change the current Folder for the Viewer
+ *
+ * @param what the folder to be viewed
+ */
+ public void setFolder(Folder what) {
+ try {
+ table.getSelectionModel().clearSelection();
+ if (SimpleClient.mv != null)
+ SimpleClient.mv.setMessage(null);
+ model.setFolder(what);
+ scrollpane.invalidate();
+ scrollpane.validate();
+ } catch (MessagingException me) {
+ me.printStackTrace();
+ }
+ }
+
+ class FolderPressed implements ListSelectionListener {
+
+ public void valueChanged(ListSelectionEvent e) {
+ if (model != null && !e.getValueIsAdjusting()) {
+ ListSelectionModel lm = (ListSelectionModel) e.getSource();
+ int which = lm.getMaxSelectionIndex();
+ if (which != -1) {
+ // get the message and display it
+ Message msg = model.getMessage(which);
+ SimpleClient.mv.setMessage(msg);
+ }
+ }
+ }
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/client/MessageViewer.java b/src/Java/Jars/javamail-samples/javamail-samples/client/MessageViewer.java
new file mode 100644
index 0000000..31da320
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/client/MessageViewer.java
@@ -0,0 +1,255 @@
+/*
+ * Copyright (c) 1997-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.mail.*;
+import javax.activation.*;
+import java.util.Date;
+import java.io.IOException;
+import javax.swing.JPanel;
+
+/**
+ * @author Christopher Cotton
+ * @author Bill Shannon
+ */
+
+public class MessageViewer extends JPanel implements CommandObject {
+
+ Message displayed = null;
+ DataHandler dataHandler = null;
+ String verb = null;
+ Component mainbody;
+ TextArea headers;
+
+ public MessageViewer() {
+ this(null);
+ }
+
+ public MessageViewer(Message what) {
+ // set our layout
+ super(new GridBagLayout());
+
+ // add the toolbar
+ addToolbar();
+
+ GridBagConstraints gb = new GridBagConstraints();
+ gb.gridwidth = GridBagConstraints.REMAINDER;
+ gb.fill = GridBagConstraints.BOTH;
+ gb.weightx = 1.0;
+ gb.weighty = 0.0;
+
+ // add the headers
+ headers = new TextArea("", 4, 80, TextArea.SCROLLBARS_NONE);
+ headers.setEditable(false);
+ add(headers, gb);
+
+ // now display our message
+ setMessage(what);
+ }
+
+ /**
+ * sets the current message to be displayed in the viewer
+ */
+ public void setMessage(Message what) {
+ displayed = what;
+
+ if (mainbody != null)
+ remove(mainbody);
+
+ if (what != null) {
+ loadHeaders();
+ mainbody = getBodyComponent();
+ } else {
+ headers.setText("");
+ TextArea dummy = new TextArea("", 24, 80, TextArea.SCROLLBARS_NONE);
+ dummy.setEditable(false);
+ mainbody = dummy;
+ }
+
+ // add the main body
+ GridBagConstraints gb = new GridBagConstraints();
+ gb.gridwidth = GridBagConstraints.REMAINDER;
+ gb.fill = GridBagConstraints.BOTH;
+ gb.weightx = 1.0;
+ gb.weighty = 1.0;
+ add(mainbody, gb);
+
+ invalidate();
+ validate();
+ }
+
+ protected void addToolbar() {
+ GridBagConstraints gb = new GridBagConstraints();
+ gb.gridheight = 1;
+ gb.gridwidth = 1;
+ gb.fill = GridBagConstraints.NONE;
+ gb.anchor = GridBagConstraints.WEST;
+ gb.weightx = 0.0;
+ gb.weighty = 0.0;
+ gb.insets = new Insets(4,4,4,4);
+
+ // structure button
+ gb.gridwidth = GridBagConstraints.REMAINDER; // only for the last one
+ Button b = new Button("Structure");
+ b.addActionListener( new StructureAction());
+ add(b, gb);
+ }
+
+ protected void loadHeaders() {
+ // setup what we want in our viewer
+ StringBuffer sb = new StringBuffer();
+
+ // date
+ sb.append("Date: ");
+ try {
+ Date duh = displayed.getSentDate();
+ if (duh != null) {
+ sb.append(duh.toString());
+ } else {
+ sb.append("Unknown");
+ }
+
+ sb.append("\n");
+
+ // from
+ sb.append("From: ");
+ Address[] adds = displayed.getFrom();
+ if (adds != null && adds.length > 0) {
+ sb.append(adds[0].toString());
+ }
+ sb.append("\n");
+
+ // to
+ sb.append("To: ");
+ adds = displayed.getRecipients(Message.RecipientType.TO);
+ if (adds != null && adds.length > 0) {
+ sb.append(adds[0].toString());
+ }
+ sb.append("\n");
+
+ // subject
+ sb.append("Subject: ");
+ sb.append(displayed.getSubject());
+
+ headers.setText(sb.toString());
+ } catch (MessagingException me) {
+ headers.setText("");
+ }
+ }
+
+ protected Component getBodyComponent() {
+ //------------
+ // now get a content viewer for the main type...
+ //------------
+ try {
+ DataHandler dh = displayed.getDataHandler();
+ CommandInfo ci = dh.getCommand("view");
+ if (ci == null) {
+ throw new MessagingException("view command failed on: " +
+ displayed.getContentType());
+ }
+
+ Object bean = dh.getBean(ci);
+ if (bean instanceof Component) {
+ return (Component)bean;
+ } else {
+ throw new MessagingException("bean is not a component " +
+ bean.getClass().toString());
+ }
+ } catch (MessagingException me) {
+ return new Label(me.toString());
+ }
+ }
+
+ /**
+ * the CommandObject method to accept our DataHandler
+ * @param dh the datahandler used to get the content
+ */
+ public void setCommandContext(String verb,
+ DataHandler dh) throws IOException {
+ this.verb = verb;
+ dataHandler = dh;
+
+ Object o = dh.getContent();
+ if (o instanceof Message) {
+ setMessage((Message)o);
+ }
+ else {
+ System.out.println(
+ "MessageViewer - content not a Message object, " + o);
+ if (o != null){
+ System.out.println(o.getClass().toString());
+ }
+ }
+ }
+
+
+ class StructureAction implements ActionListener {
+ StringBuffer sb;
+
+ public void actionPerformed(ActionEvent e) {
+ System.out.println("\n\nMessage Structure");
+ dumpPart("", displayed);
+ }
+
+ protected void dumpPart(String prefix, Part p) {
+ try {
+ System.out.println(prefix + "----------------");
+ System.out.println(prefix +
+ "Content-Type: " + p.getContentType());
+ System.out.println(prefix +
+ "Class: " + p.getClass().toString());
+
+ Object o = p.getContent();
+ if (o == null) {
+ System.out.println(prefix + "Content: is null");
+ } else {
+ System.out.println(prefix +
+ "Content: " + o.getClass().toString());
+ }
+
+ if (o instanceof Multipart) {
+ String newpref = prefix + "\t";
+ Multipart mp = (Multipart)o;
+ int count = mp.getCount();
+ for (int i = 0; i < count; i++) {
+ dumpPart(newpref, mp.getBodyPart(i));
+ }
+ }
+ } catch (MessagingException e) {
+ e.printStackTrace();
+ } catch (IOException ioex) {
+ System.out.println("Cannot get content" + ioex.getMessage());
+ }
+ }
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/client/MultipartViewer.java b/src/Java/Jars/javamail-samples/javamail-samples/client/MultipartViewer.java
new file mode 100644
index 0000000..f72b00f
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/client/MultipartViewer.java
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 1997-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.io.*;
+import java.beans.*;
+import javax.activation.*;
+import javax.mail.*;
+import javax.swing.JPanel;
+
+
+/**
+ * A Viewer Bean for the type multipart/mixed
+ *
+ * @author Christopher Cotton
+ */
+
+public class MultipartViewer extends JPanel implements CommandObject {
+
+ protected DataHandler dh = null;
+ protected String verb = null;
+
+ public MultipartViewer() {
+ super(new GridBagLayout());
+ }
+
+
+ public void setCommandContext(String verb, DataHandler dh) throws IOException {
+ this.verb = verb;
+ this.dh = dh;
+
+ // get the content, and hope it is a Multipart Object
+ Object content = dh.getContent();
+ if (content instanceof Multipart) {
+ setupDisplay((Multipart)content);
+ } else {
+ setupErrorDisplay(content);
+ }
+ }
+
+ protected void setupDisplay(Multipart mp) {
+ // we display the first body part in a main frame on the left, and then
+ // on the right we display the rest of the parts as attachments
+
+ GridBagConstraints gc = new GridBagConstraints();
+ gc.gridheight = GridBagConstraints.REMAINDER;
+ gc.fill = GridBagConstraints.BOTH;
+ gc.weightx = 1.0;
+ gc.weighty = 1.0;
+
+ // get the first part
+ try {
+ BodyPart bp = mp.getBodyPart(0);
+ Component comp = getComponent(bp);
+ add(comp, gc);
+
+ } catch (MessagingException me) {
+ add(new Label(me.toString()), gc);
+ }
+
+ // see if there are more than one parts
+ try {
+ int count = mp.getCount();
+
+ // setup how to display them
+ gc.gridwidth = GridBagConstraints.REMAINDER;
+ gc.gridheight = 1;
+ gc.fill = GridBagConstraints.NONE;
+ gc.anchor = GridBagConstraints.NORTH;
+ gc.weightx = 0.0;
+ gc.weighty = 0.0;
+ gc.insets = new Insets(4,4,4,4);
+
+ // for each one we create a button with the content type
+ for(int i = 1; i < count; i++) { // we skip the first one
+ BodyPart curr = mp.getBodyPart(i);
+ String label = null;
+ if (label == null) label = curr.getFileName();
+ if (label == null) label = curr.getDescription();
+ if (label == null) label = curr.getContentType();
+
+ Button but = new Button(label);
+ but.addActionListener( new AttachmentViewer(curr));
+ add(but, gc);
+ }
+
+
+ } catch(MessagingException me2) {
+ me2.printStackTrace();
+ }
+
+ }
+
+ protected Component getComponent(BodyPart bp) {
+
+ try {
+ DataHandler dh = bp.getDataHandler();
+ CommandInfo ci = dh.getCommand("view");
+ if (ci == null) {
+ throw new MessagingException(
+ "view command failed on: " +
+ bp.getContentType());
+ }
+
+ Object bean = dh.getBean(ci);
+
+ if (bean instanceof Component) {
+ return (Component)bean;
+ } else {
+ if (bean == null)
+ throw new MessagingException(
+ "bean is null, class " + ci.getCommandClass() +
+ " , command " + ci.getCommandName());
+ else
+ throw new MessagingException(
+ "bean is not a awt.Component" +
+ bean.getClass().toString());
+ }
+ }
+ catch (MessagingException me) {
+ return new Label(me.toString());
+ }
+ }
+
+
+
+ protected void setupErrorDisplay(Object content) {
+ String error;
+
+ if (content == null)
+ error = "Content is null";
+ else
+ error = "Object not of type Multipart, content class = " +
+ content.getClass().toString();
+
+ System.out.println(error);
+ Label lab = new Label(error);
+ add(lab);
+ }
+
+ class AttachmentViewer implements ActionListener {
+
+ BodyPart bp = null;
+
+ public AttachmentViewer(BodyPart part) {
+ bp = part;
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ ComponentFrame f = new ComponentFrame(
+ getComponent(bp), "Attachment");
+ f.pack();
+ f.show();
+ }
+ }
+
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/client/README.txt b/src/Java/Jars/javamail-samples/javamail-samples/client/README.txt
new file mode 100644
index 0000000..2b00943
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/client/README.txt
@@ -0,0 +1,124 @@
+SimpleClient
+------------
+
+Notes:
+======
+
+This should not be taken as a demo of how to use the Swing API, but
+rather a very simple graphical mail client. It shows how viewers can
+be used to display the content from mail messages. It also (like the
+other demos) shows how to retrieve Folders from a Store, Messages
+from a Folder, and content from Messages.
+
+
+To run the demo:
+================
+
+ 1. If you're using JDK 1.1.x, download the latest version of the JFC
+ (Swing) APIs from http://java.sun.com/products/jfc/download.html.
+ The SimpleClient uses at least version 1.1 of Swing.
+
+ If you're using JDK 1.2 (J2SE 1.2) or newer, Swing is included
+ and no separate download is necessary.
+
+ We *strongly* encourage you to use the latest version of J2SE,
+ which you can download from http://java.sun.com/j2se/.
+
+ 2. Set your CLASSPATH to include the "mail.jar", "activation.jar",
+ and (if you're using JDK 1.1.x and downloaded Swing separately)
+ "swingall.jar", and the current directory. For example:
+
+ For JDK 1.1 on UNIX:
+
+ export CLASSPATH=/u/me/download/mail.jar:/u/me/download/activation.jar:/u/me/download/swingall.jar:.
+
+ For JDK 1.2 and newer on UNIX:
+
+ export CLASSPATH=/u/me/download/mail.jar:/u/me/download/activation.jar:.
+
+ 3. Go to the demo/client directory
+
+ 4. Compile all the files using your Java compiler. For example:
+
+ javac *.java
+
+ 5. Run the demo. For example:
+
+ java SimpleClient -L imap://username:password@hostname/
+
+ Note that SimpleClient expects to read the "simple.mailcap"
+ file from the current directory. The simple.mailcap file
+ contains configuration information about viewers needed by
+ the SimpleClient demo program.
+
+
+
+Overview of the Classes
+=======================
+
+Main Classes:
+
+ SimpleClient = contains main().
+ Uses the parameters to the application to
+ locate the correct Store. e.g.
+
+ SimpleClient -L imap://cotton:secret@snow-goon/
+
+ It will create the main frame and
+ creates a tree. The tree uses the
+ StoreTreeNodes and FolderTreeNodes.
+
+ StoreTreeNode = subclass of Swing's DefaultMutableTreeNode.
+ This class shows how to get Folders from
+ the Store.
+
+ FolderTreeNode = subclass of Swing's DefaultMutableTreeNode.
+ If the folder has messages, it will create
+ a FolderViewer. Otherwise it will add the
+ subfolders to the tree.
+
+ SimpleAuthenticator = subclass of javax.mail.Authenticator. If
+ the Store is missing the username or the
+ password, this authenticator will be used.
+ It displays a dialog requesting the
+ information from the user.
+
+
+Viewing Folders:
+
+ FolderViewer = Uses a Swing Table to display all of the
+ Message in a Folder. The "model" of the
+ data for this Table is a FolderModel which
+ knows how to get displayable information
+ from a Message.
+
+JAF Viewers:
+
+ MessageViewer = Uses the content of the DataHandler. The
+ content will be a javax.mail.Message
+ object. Displays the headers and then
+ uses the JAF to find another viewer for
+ the content type of the Message. (either
+ multipart/mixed, image/gif, or text/plain)
+
+ MultipartViewer = Uses the content of the DataHandler. The
+ content will be a javax.mail.Multipart
+ object. Uses the JAF to find another
+ viewer for the first BodyPart's content.
+ Also puts Buttons (as "attachments") for
+ the rest of the BodyParts. When the
+ Button are pressed, it uses the JAF to
+ find a viewer for the BodyPart's content,
+ and displays it in a separate frame (using
+ ComponentFrame).
+
+ TextViewer = Uses the content of the DataHandler. The
+ content will be either a java.lang.String
+ object, or a java.io.InputStream object.
+ Creates a TextArea and sets the text using
+ the String or InputStream.
+
+Support Classes:
+
+ ComponentFrame = support class which takes a java.awt.Component
+ and displays it in a Frame.
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/client/SimpleAuthenticator.java b/src/Java/Jars/javamail-samples/javamail-samples/client/SimpleAuthenticator.java
new file mode 100644
index 0000000..f8d6dee
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/client/SimpleAuthenticator.java
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 1997-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import javax.mail.*;
+import java.net.InetAddress;
+import java.awt.*;
+import javax.swing.*;
+
+/**
+ * Simple Authenticator for requesting password information.
+ *
+ * @author Christopher Cotton
+ * @author Bill Shannon
+ */
+
+public class SimpleAuthenticator extends Authenticator {
+
+ Frame frame;
+ String username;
+ String password;
+
+ public SimpleAuthenticator(Frame f) {
+ this.frame = f;
+ }
+
+ protected PasswordAuthentication getPasswordAuthentication() {
+
+ // given a prompt?
+ String prompt = getRequestingPrompt();
+ if (prompt == null)
+ prompt = "Please login...";
+
+ // protocol
+ String protocol = getRequestingProtocol();
+ if (protocol == null)
+ protocol = "Unknown protocol";
+
+ // get the host
+ String host = null;
+ InetAddress inet = getRequestingSite();
+ if (inet != null)
+ host = inet.getHostName();
+ if (host == null)
+ host = "Unknown host";
+
+ // port
+ String port = "";
+ int portnum = getRequestingPort();
+ if (portnum != -1)
+ port = ", port " + portnum + " ";
+
+ // Build the info string
+ String info = "Connecting to " + protocol + " mail service on host " +
+ host + port;
+
+ //JPanel d = new JPanel();
+ // XXX - for some reason using a JPanel here causes JOptionPane
+ // to display incorrectly, so we workaround the problem using
+ // an anonymous JComponent.
+ JComponent d = new JComponent() { };
+
+ GridBagLayout gb = new GridBagLayout();
+ GridBagConstraints c = new GridBagConstraints();
+ d.setLayout(gb);
+ c.insets = new Insets(2, 2, 2, 2);
+
+ c.anchor = GridBagConstraints.WEST;
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ c.weightx = 0.0;
+ d.add(constrain(new JLabel(info), gb, c));
+ d.add(constrain(new JLabel(prompt), gb, c));
+
+ c.gridwidth = 1;
+ c.anchor = GridBagConstraints.EAST;
+ c.fill = GridBagConstraints.NONE;
+ c.weightx = 0.0;
+ d.add(constrain(new JLabel("Username:"), gb, c));
+
+ c.anchor = GridBagConstraints.EAST;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ c.weightx = 1.0;
+ String user = getDefaultUserName();
+ JTextField username = new JTextField(user, 20);
+ d.add(constrain(username, gb, c));
+
+ c.gridwidth = 1;
+ c.fill = GridBagConstraints.NONE;
+ c.anchor = GridBagConstraints.EAST;
+ c.weightx = 0.0;
+ d.add(constrain(new JLabel("Password:"), gb, c));
+
+ c.anchor = GridBagConstraints.EAST;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ c.weightx = 1.0;
+ JPasswordField password = new JPasswordField("", 20);
+ d.add(constrain(password, gb, c));
+ // XXX - following doesn't work
+ if (user != null && user.length() > 0)
+ password.requestFocus();
+ else
+ username.requestFocus();
+
+ int result = JOptionPane.showConfirmDialog(frame, d, "Login",
+ JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
+
+ if (result == JOptionPane.OK_OPTION)
+ return new PasswordAuthentication(username.getText(),
+ password.getText());
+ else
+ return null;
+ }
+
+ private Component constrain(Component cmp,
+ GridBagLayout gb, GridBagConstraints c) {
+ gb.setConstraints(cmp, c);
+ return (cmp);
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/client/SimpleClient.java b/src/Java/Jars/javamail-samples/javamail-samples/client/SimpleClient.java
new file mode 100644
index 0000000..68c7a78
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/client/SimpleClient.java
@@ -0,0 +1,169 @@
+/*
+ * Copyright (c) 1997-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.util.*;
+import java.io.*;
+import javax.mail.*;
+import javax.mail.internet.*;
+import javax.activation.*;
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.table.*;
+import javax.swing.tree.*;
+import javax.swing.event.*;
+
+
+/**
+ * Demo app that shows a very simple Mail Client
+ *
+ * @author Christopher Cotton
+ * @author Bill Shannon
+ */
+
+public class SimpleClient {
+
+ static Vector url = new Vector();
+ static FolderViewer fv;
+ static MessageViewer mv;
+
+ public static void main(String argv[]) {
+ boolean usage = false;
+
+ for (int optind = 0; optind < argv.length; optind++) {
+ if (argv[optind].equals("-L")) {
+ url.addElement(argv[++optind]);
+ } else if (argv[optind].startsWith("-")) {
+ usage = true;
+ break;
+ } else {
+ usage = true;
+ break;
+ }
+ }
+
+ if (usage || url.size() == 0) {
+ System.out.println("Usage: SimpleClient -L url");
+ System.out.println(" where url is protocol://username:password@hostname/");
+ System.exit(1);
+ }
+
+ try {
+ // Set up our Mailcap entries. This will allow the JAF
+ // to locate our viewers.
+ File capfile = new File("simple.mailcap");
+ if (!capfile.isFile()) {
+ System.out.println(
+ "Cannot locate the \"simple.mailcap\" file.");
+ System.exit(1);
+ }
+
+ CommandMap.setDefaultCommandMap( new MailcapCommandMap(
+ new FileInputStream(capfile)));
+
+ JFrame frame = new JFrame("Simple JavaMail Client");
+ frame.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {System.exit(0);}});
+ //frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+
+ // Get a Store object
+ SimpleAuthenticator auth = new SimpleAuthenticator(frame);
+ Session session =
+ Session.getDefaultInstance(System.getProperties(), auth);
+ //session.setDebug(true);
+
+ DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
+
+ // create a node for each store we have
+ for (Enumeration e = url.elements() ; e.hasMoreElements() ;) {
+ String urlstring = (String) e.nextElement();
+ URLName urln = new URLName(urlstring);
+ Store store = session.getStore(urln);
+
+ StoreTreeNode storenode = new StoreTreeNode(store);
+ root.add(storenode);
+ }
+
+ DefaultTreeModel treeModel = new DefaultTreeModel(root);
+ JTree tree = new JTree(treeModel);
+ tree.addTreeSelectionListener(new TreePress());
+
+ /* Put the Tree in a scroller. */
+ JScrollPane sp = new JScrollPane();
+ sp.setPreferredSize(new Dimension(250, 300));
+ sp.getViewport().add(tree);
+
+ /* Create a double buffered JPanel */
+ JPanel sv = new JPanel(new BorderLayout());
+ sv.add("Center", sp);
+
+ fv = new FolderViewer(null);
+
+ JSplitPane jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
+ sv, fv);
+ jsp.setOneTouchExpandable(true);
+ mv = new MessageViewer();
+ JSplitPane jsp2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
+ jsp, mv);
+ jsp2.setOneTouchExpandable(true);
+
+ frame.getContentPane().add(jsp2);
+ frame.pack();
+ frame.show();
+
+ } catch (Exception ex) {
+ System.out.println("SimpletClient caught exception");
+ ex.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+}
+
+class TreePress implements TreeSelectionListener {
+
+ public void valueChanged(TreeSelectionEvent e) {
+ TreePath path = e.getNewLeadSelectionPath();
+ if (path != null) {
+ Object o = path.getLastPathComponent();
+ if (o instanceof FolderTreeNode) {
+ FolderTreeNode node = (FolderTreeNode)o;
+ Folder folder = node.getFolder();
+
+ try {
+ if ((folder.getType() & Folder.HOLDS_MESSAGES) != 0) {
+ SimpleClient.fv.setFolder(folder);
+ }
+ } catch (MessagingException me) { }
+ }
+ }
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/client/StoreTreeNode.java b/src/Java/Jars/javamail-samples/javamail-samples/client/StoreTreeNode.java
new file mode 100644
index 0000000..e552dcc
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/client/StoreTreeNode.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 1997-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.mail.*;
+
+/**
+ * Node which represents a Store in the javax.mail apis.
+ *
+ * @author Christopher Cotton
+ */
+public class StoreTreeNode extends DefaultMutableTreeNode {
+
+ protected Store store = null;
+ protected Folder folder = null;
+ protected String display = null;
+
+ /**
+ * creates a tree node that points to the particular Store.
+ *
+ * @param what the store for this node
+ */
+ public StoreTreeNode(Store what) {
+ super(what);
+ store = what;
+ }
+
+
+ /**
+ * a Store is never a leaf node. It can always contain stuff
+ */
+ public boolean isLeaf() {
+ return false;
+ }
+
+
+ /**
+ * return the number of children for this store node. The first
+ * time this method is called we load up all of the folders
+ * under the store's defaultFolder
+ */
+
+ public int getChildCount() {
+ if (folder == null) {
+ loadChildren();
+ }
+ return super.getChildCount();
+ }
+
+ protected void loadChildren() {
+ try {
+ // connect to the Store if we need to
+ if (!store.isConnected()) {
+ store.connect();
+ }
+
+ // get the default folder, and list the
+ // subscribed folders on it
+ folder = store.getDefaultFolder();
+ // Folder[] sub = folder.listSubscribed();
+ Folder[] sub = folder.list();
+
+ // add a FolderTreeNode for each Folder
+ int num = sub.length;
+ for(int i = 0; i < num; i++) {
+ FolderTreeNode node = new FolderTreeNode(sub[i]);
+ // we used insert here, since add() would make
+ // another recursive call to getChildCount();
+ insert(node, i);
+ }
+
+ } catch (MessagingException me) {
+ me.printStackTrace();
+ }
+ }
+
+ /**
+ * We override toString() so we can display the store URLName
+ * without the password.
+ */
+
+ public String toString() {
+ if (display == null) {
+ URLName url = store.getURLName();
+ if (url == null) {
+ display = store.toString();
+ } else {
+ // don't show the password
+ URLName too = new URLName( url.getProtocol(), url.getHost(), url.getPort(),
+ url.getFile(), url.getUsername(), null);
+ display = too.toString();
+ }
+ }
+
+ return display;
+ }
+
+
+}
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/client/TextViewer.java b/src/Java/Jars/javamail-samples/javamail-samples/client/TextViewer.java
new file mode 100644
index 0000000..0ad57c0
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/client/TextViewer.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 1997-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.awt.*;
+import java.io.*;
+import java.beans.*;
+import javax.activation.*;
+import javax.swing.JPanel;
+import javax.swing.JTextArea;
+import javax.swing.JScrollPane;
+
+
+/**
+ * A very simple TextViewer Bean for the MIMEType "text/plain"
+ *
+ * @author Christopher Cotton
+ */
+
+public class TextViewer extends JPanel implements CommandObject
+{
+
+ private JTextArea text_area = null;
+ private DataHandler dh = null;
+ private String verb = null;
+
+ /**
+ * Constructor
+ */
+ public TextViewer() {
+ super(new GridLayout(1,1));
+
+ // create the text area
+ text_area = new JTextArea();
+ text_area.setEditable(false);
+ text_area.setLineWrap(true);
+
+ // create a scroll pane for the JTextArea
+ JScrollPane sp = new JScrollPane();
+ sp.setPreferredSize(new Dimension(300, 300));
+ sp.getViewport().add(text_area);
+
+ add(sp);
+ }
+
+
+ public void setCommandContext(String verb, DataHandler dh)
+ throws IOException {
+
+ this.verb = verb;
+ this.dh = dh;
+
+ this.setInputStream( dh.getInputStream() );
+ }
+
+
+ /**
+ * set the data stream, component to assume it is ready to
+ * be read.
+ */
+ public void setInputStream(InputStream ins) {
+
+ int bytes_read = 0;
+ // check that we can actually read
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ byte data[] = new byte[1024];
+
+ try {
+ while((bytes_read = ins.read(data)) >0)
+ baos.write(data, 0, bytes_read);
+ ins.close();
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+
+ // convert the buffer into a string
+ // place in the text area
+ text_area.setText(baos.toString());
+
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/client/simple.mailcap b/src/Java/Jars/javamail-samples/javamail-samples/client/simple.mailcap
new file mode 100644
index 0000000..e65e13a
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/client/simple.mailcap
@@ -0,0 +1,9 @@
+#
+# Example command map, using the MailcapCommandMap.
+#
+# for our viewers
+#
+message/*;; x-java-view=MessageViewer
+text/plain;; x-java-view=TextViewer
+multipart/*;; x-java-view=MultipartViewer
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/copier.java b/src/Java/Jars/javamail-samples/javamail-samples/copier.java
new file mode 100644
index 0000000..4fd6f80
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/copier.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 1996-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+/**
+ *
+ * @author Christopher Cotton
+ */
+
+import javax.mail.*;
+
+/**
+ * copier will copy a specified number of messages from one folder
+ * to another folder. it demonstrates how to use the JavaMail APIs
+ * to copy messages.
+ *
+ * Usage for copier: copier store urlname
+ * src folderdest folderstart msg #end msg #
+ *
+ */
+
+public class copier {
+
+ public static void main(String argv[]) {
+ boolean debug = false; // change to get more errors
+
+ if (argv.length != 5) {
+ System.out.println( "usage: copier " +
+ "");
+ return;
+ }
+
+ try {
+ URLName url = new URLName(argv[0]);
+ String src = argv[1]; // source folder
+ String dest = argv[2]; // dest folder
+ int start = Integer.parseInt(argv[3]); // copy from message #
+ int end = Integer.parseInt(argv[4]); // to message #
+
+ // Get the default Session object
+
+ Session session = Session.getInstance(System.getProperties(), null);
+ // session.setDebug(debug);
+
+ // Get a Store object that implements the protocol.
+ Store store = session.getStore(url);
+ store.connect();
+ System.out.println("Connected...");
+
+ // Open Source Folder
+ Folder folder = store.getFolder(src);
+ folder.open(Folder.READ_WRITE);
+ System.out.println("Opened source...");
+
+ if (folder.getMessageCount() == 0) {
+ System.out.println("Source folder has no messages ..");
+ folder.close(false);
+ store.close();
+ }
+
+ // Open destination folder, create if needed
+ Folder dfolder = store.getFolder(dest);
+ if (!dfolder.exists()) // create
+ dfolder.create(Folder.HOLDS_MESSAGES);
+
+ Message[] msgs = folder.getMessages(start, end);
+ System.out.println("Got messages...");
+
+ // Copy messages into destination,
+ folder.copyMessages(msgs, dfolder);
+ System.out.println("Copied messages...");
+
+ // Close the folder and store
+ folder.close(false);
+ store.close();
+ System.out.println("Closed folder and store...");
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ System.exit(0);
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/folderlist.java b/src/Java/Jars/javamail-samples/javamail-samples/folderlist.java
new file mode 100644
index 0000000..10bcf82
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/folderlist.java
@@ -0,0 +1,185 @@
+/*
+ * Copyright (c) 1996-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.util.Properties;
+import javax.mail.*;
+
+import com.sun.mail.imap.*;
+
+/**
+ * Demo app that exercises the Message interfaces.
+ * List information about folders.
+ *
+ * @author John Mani
+ * @author Bill Shannon
+ */
+
+public class folderlist {
+ static String protocol = null;
+ static String host = null;
+ static String user = null;
+ static String password = null;
+ static String url = null;
+ static String root = null;
+ static String pattern = "%";
+ static boolean recursive = false;
+ static boolean verbose = false;
+ static boolean debug = false;
+
+ public static void main(String argv[]) throws Exception {
+ int optind;
+ for (optind = 0; optind < argv.length; optind++) {
+ if (argv[optind].equals("-T")) {
+ protocol = argv[++optind];
+ } else if (argv[optind].equals("-H")) {
+ host = argv[++optind];
+ } else if (argv[optind].equals("-U")) {
+ user = argv[++optind];
+ } else if (argv[optind].equals("-P")) {
+ password = argv[++optind];
+ } else if (argv[optind].equals("-L")) {
+ url = argv[++optind];
+ } else if (argv[optind].equals("-R")) {
+ root = argv[++optind];
+ } else if (argv[optind].equals("-r")) {
+ recursive = true;
+ } else if (argv[optind].equals("-v")) {
+ verbose = true;
+ } else if (argv[optind].equals("-D")) {
+ debug = true;
+ } else if (argv[optind].equals("--")) {
+ optind++;
+ break;
+ } else if (argv[optind].startsWith("-")) {
+ System.out.println(
+"Usage: folderlist [-T protocol] [-H host] [-U user] [-P password] [-L url]");
+ System.out.println(
+"\t[-R root] [-r] [-v] [-D] [pattern]");
+ System.exit(1);
+ } else {
+ break;
+ }
+ }
+ if (optind < argv.length)
+ pattern = argv[optind];
+
+ // Get a Properties object
+ Properties props = System.getProperties();
+
+ // Get a Session object
+ Session session = Session.getInstance(props, null);
+ session.setDebug(debug);
+
+ // Get a Store object
+ Store store = null;
+ Folder rf = null;
+ if (url != null) {
+ URLName urln = new URLName(url);
+ store = session.getStore(urln);
+ store.connect();
+ } else {
+ if (protocol != null)
+ store = session.getStore(protocol);
+ else
+ store = session.getStore();
+
+ // Connect
+ if (host != null || user != null || password != null)
+ store.connect(host, user, password);
+ else
+ store.connect();
+ }
+
+ // List namespace
+ if (root != null)
+ rf = store.getFolder(root);
+ else
+ rf = store.getDefaultFolder();
+
+ dumpFolder(rf, false, "");
+ if ((rf.getType() & Folder.HOLDS_FOLDERS) != 0) {
+ Folder[] f = rf.list(pattern);
+ for (int i = 0; i < f.length; i++)
+ dumpFolder(f[i], recursive, " ");
+ }
+
+ store.close();
+ }
+
+ static void dumpFolder(Folder folder, boolean recurse, String tab)
+ throws Exception {
+ System.out.println(tab + "Name: " + folder.getName());
+ System.out.println(tab + "Full Name: " + folder.getFullName());
+ System.out.println(tab + "URL: " + folder.getURLName());
+
+ if (verbose) {
+ if (!folder.isSubscribed())
+ System.out.println(tab + "Not Subscribed");
+
+ if ((folder.getType() & Folder.HOLDS_MESSAGES) != 0) {
+ if (folder.hasNewMessages())
+ System.out.println(tab + "Has New Messages");
+ System.out.println(tab + "Total Messages: " +
+ folder.getMessageCount());
+ System.out.println(tab + "New Messages: " +
+ folder.getNewMessageCount());
+ System.out.println(tab + "Unread Messages: " +
+ folder.getUnreadMessageCount());
+ }
+ if ((folder.getType() & Folder.HOLDS_FOLDERS) != 0)
+ System.out.println(tab + "Is Directory");
+
+ /*
+ * Demonstrate use of IMAP folder attributes
+ * returned by the IMAP LIST response.
+ */
+ if (folder instanceof IMAPFolder) {
+ IMAPFolder f = (IMAPFolder)folder;
+ String[] attrs = f.getAttributes();
+ if (attrs != null && attrs.length > 0) {
+ System.out.println(tab + "IMAP Attributes:");
+ for (int i = 0; i < attrs.length; i++)
+ System.out.println(tab + " " + attrs[i]);
+ }
+ }
+ }
+
+ System.out.println();
+
+ if ((folder.getType() & Folder.HOLDS_FOLDERS) != 0) {
+ if (recurse) {
+ Folder[] f = folder.list();
+ for (int i = 0; i < f.length; i++)
+ dumpFolder(f[i], recurse, tab + " ");
+ }
+ }
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/logging/FileErrorManager.java b/src/Java/Jars/javamail-samples/javamail-samples/logging/FileErrorManager.java
new file mode 100644
index 0000000..fa16476
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/logging/FileErrorManager.java
@@ -0,0 +1,329 @@
+/*
+ * Copyright (c) 2009-2017 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009-2017 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.io.*;
+import java.lang.reflect.Constructor;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.logging.ErrorManager;
+import java.util.logging.Level;
+import java.util.logging.LogManager;
+
+/**
+ * An error manager used to store mime messages from the MailHandler
+ * 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:
+ *
+ * File dir = new File("path to dir");
+ * FileErrorManager em = new FileErrorManager(dir);
+ *
+ *
+ *
+ * Configuration:
+ * The code to setup this error manager via the logging properties can be as
+ * simple as the following:
+ *
+ *
+ * If properties are not defined, or contain invalid values, then the specified
+ * default values are used.
+ *
+ *
FileErrorManager.pattern the absolute file path to the directory which
+ * will store any failed email messages. (defaults to the value of the system
+ * property java.io.tmpdir)
+ *
+ *
+ * @author Jason Mehrens
+ */
+public class FileErrorManager extends ErrorManager {
+
+ /**
+ * Stores the LogManager.
+ */
+ private static final LogManager manager = LogManager.getLogManager();
+ /**
+ * Used to report errors that this error manager fails to report.
+ */
+ private final ErrorManager next = new ErrorManager();
+ /**
+ * Directory of the email store.
+ */
+ private final File emailStore;
+
+ /**
+ * 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 dir is null
+ * @throws IllegalArgumentException if dir is a
+ * java.io.File 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.
+ */
+ public FileErrorManager(File dir) {
+ 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.
+ */
+ @Override
+ public void error(String msg, Exception ex, int code) {
+ if (isRawEmail(msg)) {
+ try {
+ storeEmail(msg);
+ } catch (final IOException | RuntimeException IOE) {
+ next.error(msg, ex, code);
+ super.error(emailStore.toString(), IOE, ErrorManager.GENERIC_FAILURE);
+ }
+ } else {
+ next.error(msg, ex, code);
+ }
+ }
+
+ /**
+ * Performs the initialization for this object.
+ */
+ private void init() {
+ if (next == null) {
+ throw new NullPointerException(ErrorManager.class.getName());
+ }
+
+ File dir = this.emailStore;
+ if (dir.getClass() != File.class) { //For security reasons.
+ throw new IllegalArgumentException(dir.getClass().getName());
+ }
+
+ if (!dir.isDirectory()) {
+ throw new IllegalArgumentException("File must be a directory.");
+ }
+
+ if (!dir.canWrite()) { //Can throw under a security manager.
+ super.error(dir.getAbsolutePath(),
+ new SecurityException("write"), ErrorManager.OPEN_FAILURE);
+ }
+
+ //For now, only absolute paths are allowed.
+ if (!dir.isAbsolute()) {
+ throw new IllegalArgumentException("Only absolute paths are allowed.");
+ }
+
+ if (!dir.canRead()) { //Can throw under a security manager.
+ super.error(dir.getAbsolutePath(),
+ new SecurityException("read"), ErrorManager.OPEN_FAILURE);
+ }
+ }
+
+ /**
+ * Creates a common temp file prefix.
+ *
+ * @return the file prefix.
+ */
+ private String prefixName() {
+ return "FileErrorManager";
+ }
+
+ /**
+ * Creates a common temp file suffix.
+ *
+ * @return the file suffix.
+ */
+ private String suffixName() {
+ 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.
+ */
+ private boolean isRawEmail(String msg) {
+ if (msg != null && msg.length() > 0) {
+ return !msg.startsWith(Level.SEVERE.getName());
+ }
+ return false;
+ }
+
+ /**
+ * Stores the given string in a file.
+ *
+ * @param email the message to store.
+ * @throws IOException if there is a problem.
+ */
+ private void storeEmail(String email) throws IOException {
+ File tmp = null;
+ FileOutputStream out = null;
+ for (;;) {
+ tmp = File.createTempFile(prefixName(), suffixName(), emailStore);
+ try {
+ out = new FileOutputStream(tmp);
+ break;
+ } catch (FileNotFoundException FNFE) {
+ if (!tmp.exists()) { //retry if file is locked
+ throw FNFE;
+ }
+ }
+ }
+
+ try (PrintStream ps = new PrintStream(wrap(out), false, "UTF-8")) {
+ ps.print(email);
+ ps.flush();
+ tmp = null; //Don't delete 'tmp' if all bytes were written.
+ } finally {
+ close(out);
+ delete(tmp); //Only deletes if not null.
+ }
+ }
+
+ /**
+ * Null safe close method.
+ *
+ * @param out closes the given stream.
+ */
+ private void close(OutputStream out) {
+ if (out != null) {
+ try {
+ out.close();
+ } catch (IOException IOE) {
+ super.error(out.toString(), IOE, ErrorManager.CLOSE_FAILURE);
+ }
+ }
+ }
+
+ /**
+ * Null safe delete method.
+ *
+ * @param tmp the file to delete.
+ */
+ private void delete(File tmp) {
+ if (tmp != null) {
+ try {
+ if (!tmp.delete() && tmp.exists()) {
+ try {
+ try {
+ tmp.deleteOnExit();
+ } catch (final LinkageError shutdown) {
+ throw new RuntimeException(shutdown);
+ }
+ } catch (final RuntimeException shutdown) {
+ if (!tmp.delete()) {
+ super.error(tmp.getAbsolutePath(), shutdown,
+ ErrorManager.CLOSE_FAILURE);
+ }
+ }
+ }
+ } catch (SecurityException SE) {
+ super.error(tmp.toString(), SE, ErrorManager.CLOSE_FAILURE);
+ }
+ }
+ }
+
+ /**
+ * Gets the location of the email store.
+ *
+ * @return the File location.
+ */
+ private File getEmailStore() {
+ String dir = manager.getProperty(
+ getClass().getName().concat(".pattern"));
+ if (dir == null) {
+ dir = AccessController.doPrivileged(new PrivilegedAction() {
+
+ @Override
+ public String run() {
+ return System.getProperty("java.io.tmpdir", ".");
+ }
+ });
+ }
+ return new File(dir);
+ }
+
+ /**
+ * Wraps the given stream as a NewLineOutputStream.
+ *
+ * @param out the stream to wrap.
+ * @return the original or wrapped output stream.
+ */
+ @SuppressWarnings("UseSpecificCatch")
+ private OutputStream wrap(OutputStream out) {
+ assert out != null;
+ Class> k;
+ try {
+ k = Class.forName("NewlineOutputStream");
+ if (OutputStream.class.isAssignableFrom(k)) {
+ Constructor> c = k.getConstructor(OutputStream.class);
+ return (OutputStream) c.newInstance(out);
+ } else {
+ super.error("Unable to switch newlines",
+ new ClassNotFoundException(k.getName()),
+ ErrorManager.GENERIC_FAILURE);
+ }
+ } catch (RuntimeException re) {
+ super.error("Unable to switch newlines",
+ re, ErrorManager.GENERIC_FAILURE);
+ } catch (Exception ex) {
+ super.error("Unable to switch newlines",
+ ex, ErrorManager.GENERIC_FAILURE);
+ } catch (LinkageError le) {
+ super.error("Unable to switch newlines",
+ new ClassNotFoundException("", le),
+ ErrorManager.GENERIC_FAILURE);
+ }
+ return out;
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/logging/MailHandlerDemo.java b/src/Java/Jars/javamail-samples/javamail-samples/logging/MailHandlerDemo.java
new file mode 100644
index 0000000..929c804
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/logging/MailHandlerDemo.java
@@ -0,0 +1,668 @@
+/*
+ * Copyright (c) 2009-2016 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009-2016 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import com.sun.mail.util.logging.CollectorFormatter;
+import com.sun.mail.util.logging.DurationFilter;
+import com.sun.mail.util.logging.MailHandler;
+import com.sun.mail.util.logging.SeverityComparator;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.lang.management.ManagementFactory;
+import java.util.*;
+import java.util.logging.*;
+import javax.activation.DataHandler;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.internet.InternetAddress;
+
+/**
+ * Demo for the different configurations for the MailHandler. If the logging
+ * properties file or class is not specified then this demo will apply some
+ * default settings to store emails in the user's temp directory.
+ *
+ * @author Jason Mehrens
+ */
+public class MailHandlerDemo {
+
+ /**
+ * This class name.
+ */
+ private static final String CLASS_NAME = MailHandlerDemo.class.getName();
+ /**
+ * The logger for this class name.
+ */
+ private static final Logger LOGGER = Logger.getLogger(CLASS_NAME);
+
+ /**
+ * Runs the demo.
+ *
+ * @param args the command line arguments
+ * @throws IOException if there is a problem.
+ */
+ public static void main(String[] args) throws IOException {
+ List l = Arrays.asList(args);
+ if (l.contains("/?") || l.contains("-?") || l.contains("-help")) {
+ LOGGER.info("Usage: java MailHandlerDemo "
+ + "[[-all] | [-body] | [-custom] | [-debug] | [-low] "
+ + "| [-simple] | [-pushlevel] | [-pushfilter] "
+ + "| [-pushnormal] | [-pushonly]] "
+ + "\n\n"
+ + "-all\t\t: Execute all demos.\n"
+ + "-body\t\t: An email with all records and only a body.\n"
+ + "-custom\t\t: An email with attachments and dynamic names.\n"
+ + "-debug\t\t: Output basic debug information about the JVM "
+ + "and log configuration.\n"
+ + "-low\t\t: Generates multiple emails due to low capacity."
+ + "\n"
+ + "-simple\t\t: An email with all records with body and "
+ + "an attachment.\n"
+ + "-pushlevel\t: Generates high priority emails when the"
+ + " push level is triggered and normal priority when "
+ + "flushed.\n"
+ + "-pushFilter\t: Generates high priority emails when the "
+ + "push level and the push filter is triggered and normal "
+ + "priority emails when flushed.\n"
+ + "-pushnormal\t: Generates multiple emails when the "
+ + "MemoryHandler push level is triggered. All generated "
+ + "email are sent as normal priority.\n"
+ + "-pushonly\t: Generates multiple emails when the "
+ + "MemoryHandler push level is triggered. Generates high "
+ + "priority emails when the push level is triggered and "
+ + "normal priority when flushed.\n");
+ } else {
+ final boolean debug = init(l); //may create log messages.
+ try {
+ LOGGER.log(Level.FINEST, "This is the finest part of the demo.",
+ new MessagingException("Fake JavaMail issue."));
+ LOGGER.log(Level.FINER, "This is the finer part of the demo.",
+ new NullPointerException("Fake bug."));
+ LOGGER.log(Level.FINE, "This is the fine part of the demo.");
+ LOGGER.log(Level.CONFIG, "Logging config file is {0}.",
+ getConfigLocation());
+ LOGGER.log(Level.INFO, "Your temp directory is {0}, "
+ + "please wait...", getTempDir());
+
+ try { //Waste some time for the custom formatter.
+ Thread.sleep(3L * 1000L);
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ }
+
+ LOGGER.log(Level.WARNING, "This is a warning.",
+ new FileNotFoundException("Fake file chooser issue."));
+ LOGGER.log(Level.SEVERE, "The end of the demo.",
+ new IOException("Fake access denied issue."));
+ } finally {
+ closeHandlers();
+ }
+
+ //Force parse errors. This does have side effects.
+ if (debug && getConfigLocation() != null) {
+ LogManager.getLogManager().readConfiguration();
+ }
+ }
+ }
+
+ /**
+ * Used debug problems with the logging.properties. The system property
+ * java.security.debug=access,stack can be used to trace access to the
+ * LogManager reset.
+ *
+ * @param prefix a string to prefix the output.
+ * @param err any PrintStream or null for System.out.
+ */
+ @SuppressWarnings("UseOfSystemOutOrSystemErr")
+ private static void checkConfig(String prefix, PrintStream err) {
+ if (prefix == null || prefix.trim().length() == 0) {
+ prefix = "DEBUG";
+ }
+
+ if (err == null) {
+ err = System.out;
+ }
+
+ try {
+ err.println(prefix + ": java.version="
+ + System.getProperty("java.version"));
+ err.println(prefix + ": LOGGER=" + LOGGER.getLevel());
+ err.println(prefix + ": JVM id "
+ + ManagementFactory.getRuntimeMXBean().getName());
+ err.println(prefix + ": java.security.debug="
+ + System.getProperty("java.security.debug"));
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ err.println(prefix + ": SecurityManager.class="
+ + sm.getClass().getName());
+ err.println(prefix + ": SecurityManager classLoader="
+ + toString(sm.getClass().getClassLoader()));
+ err.println(prefix + ": SecurityManager.toString=" + sm);
+ } else {
+ err.println(prefix + ": SecurityManager.class=null");
+ err.println(prefix + ": SecurityManager.toString=null");
+ err.println(prefix + ": SecurityManager classLoader=null");
+ }
+
+ String policy = System.getProperty("java.security.policy");
+ if (policy != null) {
+ File f = new File(policy);
+ err.println(prefix + ": AbsolutePath=" + f.getAbsolutePath());
+ err.println(prefix + ": CanonicalPath=" + f.getCanonicalPath());
+ err.println(prefix + ": length=" + f.length());
+ err.println(prefix + ": canRead=" + f.canRead());
+ err.println(prefix + ": lastModified="
+ + new java.util.Date(f.lastModified()));
+ }
+
+ LogManager manager = LogManager.getLogManager();
+ String key = "java.util.logging.config.file";
+ String cfg = System.getProperty(key);
+ if (cfg != null) {
+ err.println(prefix + ": " + cfg);
+ File f = new File(cfg);
+ err.println(prefix + ": AbsolutePath=" + f.getAbsolutePath());
+ err.println(prefix + ": CanonicalPath=" + f.getCanonicalPath());
+ err.println(prefix + ": length=" + f.length());
+ err.println(prefix + ": canRead=" + f.canRead());
+ err.println(prefix + ": lastModified="
+ + new java.util.Date(f.lastModified()));
+ } else {
+ err.println(prefix + ": " + key
+ + " is not set as a system property.");
+ }
+ err.println(prefix + ": LogManager.class="
+ + manager.getClass().getName());
+ err.println(prefix + ": LogManager classLoader="
+ + toString(manager.getClass().getClassLoader()));
+ err.println(prefix + ": LogManager.toString=" + manager);
+ err.println(prefix + ": MailHandler classLoader="
+ + toString(MailHandler.class.getClassLoader()));
+ err.println(prefix + ": Context ClassLoader="
+ + toString(Thread.currentThread().getContextClassLoader()));
+ err.println(prefix + ": Session ClassLoader="
+ + toString(Session.class.getClassLoader()));
+ err.println(prefix + ": DataHandler ClassLoader="
+ + toString(DataHandler.class.getClassLoader()));
+
+ final String p = MailHandler.class.getName();
+ key = p.concat(".mail.to");
+ String to = manager.getProperty(key);
+ err.println(prefix + ": TO=" + to);
+ if (to != null) {
+ err.println(prefix + ": TO="
+ + Arrays.toString(InternetAddress.parse(to, true)));
+ }
+
+ key = p.concat(".mail.from");
+ String from = manager.getProperty(key);
+ if (from == null || from.length() == 0) {
+ Session session = Session.getInstance(new Properties());
+ InternetAddress local = InternetAddress.getLocalAddress(session);
+ err.println(prefix + ": FROM=" + local);
+ } else {
+ err.println(prefix + ": FROM="
+ + Arrays.asList(InternetAddress.parse(from, false)));
+ err.println(prefix + ": FROM="
+ + Arrays.asList(InternetAddress.parse(from, true)));
+ }
+
+ synchronized (manager) {
+ final Enumeration e = manager.getLoggerNames();
+ while (e.hasMoreElements()) {
+ final Logger l = manager.getLogger(e.nextElement());
+ if (l != null) {
+ final Handler[] handlers = l.getHandlers();
+ if (handlers.length > 0) {
+ err.println(prefix + ": " + l.getClass().getName()
+ + ", " + l.getName());
+ for (Handler h : handlers) {
+ err.println(prefix + ":\t" + toString(prefix, err, h));
+ }
+ }
+ }
+ }
+ }
+ } catch (Throwable error) {
+ err.print(prefix + ": ");
+ error.printStackTrace(err);
+ }
+ err.flush();
+ }
+
+ /**
+ * Gets the class loader list.
+ *
+ * @param cl the class loader or null.
+ * @return the class loader list.
+ */
+ private static String toString(ClassLoader cl) {
+ StringBuilder buf = new StringBuilder();
+ buf.append(cl);
+ while (cl != null) {
+ cl = cl.getParent();
+ buf.append("<-").append(cl);
+ }
+ return buf.toString();
+ }
+
+ /**
+ * Gets a formatting string describing the given handler.
+ *
+ * @param prefix the output prefix.
+ * @param err the error stream.
+ * @param h the handler.
+ * @return the formatted string.
+ */
+ private static String toString(String prefix, PrintStream err, Handler h) {
+ StringBuilder buf = new StringBuilder();
+ buf.append(h.getClass().getName());
+ try {
+ if (h instanceof MailHandler) {
+ MailHandler mh = (MailHandler) h;
+ buf.append(", ").append(mh.getSubject());
+ }
+ } catch (SecurityException error) {
+ err.print(prefix + ": ");
+ error.printStackTrace(err);
+ }
+
+ try {
+ buf.append(", ").append(h.getFormatter());
+ } catch (SecurityException error) {
+ err.print(prefix + ": ");
+ error.printStackTrace(err);
+ }
+
+ try {
+ if (h instanceof MailHandler) {
+ MailHandler mh = (MailHandler) h;
+ buf.append(", ").append(Arrays.toString(
+ mh.getAttachmentFormatters()));
+ }
+ } catch (SecurityException error) {
+ err.print(prefix + ": ");
+ error.printStackTrace(err);
+ }
+
+ try {
+ buf.append(", ").append(h.getLevel());
+ } catch (SecurityException error) {
+ err.print(prefix + ": ");
+ error.printStackTrace(err);
+ }
+
+ try {
+ buf.append(", ").append(h.getFilter());
+ } catch (SecurityException error) {
+ err.print(prefix + ": ");
+ error.printStackTrace(err);
+ }
+
+ try {
+ buf.append(", ").append(h.getErrorManager());
+ } catch (SecurityException error) {
+ err.print(prefix + ": ");
+ error.printStackTrace(err);
+ }
+
+ buf.append(", ").append(toString(h.getClass().getClassLoader()));
+ return buf.toString();
+ }
+
+ /**
+ * Example for body only messages. On close the remaining messages are sent.
+ * ##logging.properties
+ * MailHandlerDemo.handlers=com.sun.mail.util.logging.MailHandler
+ * com.sun.mail.util.logging.MailHandler.subject=Body only demo
+ * ##
+ *
+ */
+ private static void initBodyOnly() {
+ MailHandler h = new MailHandler();
+ h.setSubject("Body only demo");
+ LOGGER.addHandler(h);
+ }
+
+ /**
+ * Example showing that when the mail handler reaches capacity it will
+ * format and send the current records. Capacity is used to roughly limit
+ * the size of an outgoing message. On close any remaining messages are
+ * sent.
+ * ##logging.properties
+ * MailHandlerDemo.handlers=com.sun.mail.util.logging.MailHandler
+ * com.sun.mail.util.logging.MailHandler.subject=Low capacity demo
+ * com.sun.mail.util.logging.MailHandler.capacity=5
+ * ##
+ *
+ */
+ private static void initLowCapacity() {
+ MailHandler h = new MailHandler(5);
+ h.setSubject("Low capacity demo");
+ LOGGER.addHandler(h);
+ }
+
+ /**
+ * Example for body only messages. On close any remaining messages are sent.
+ * ##logging.properties
+ * MailHandlerDemo.handlers=com.sun.mail.util.logging.MailHandler
+ * com.sun.mail.util.logging.MailHandler.subject=Body and attachment demo
+ * com.sun.mail.util.logging.MailHandler.attachment.formatters=java.util.logging.XMLFormatter
+ * com.sun.mail.util.logging.MailHandler.attachment.names=data.xml
+ * ##
+ *
+ */
+ private static void initSimpleAttachment() {
+ MailHandler h = new MailHandler();
+ h.setSubject("Body and attachment demo");
+ h.setAttachmentFormatters(new XMLFormatter());
+ h.setAttachmentNames("data.xml");
+ LOGGER.addHandler(h);
+ }
+
+ /**
+ * Example setup for priority messages by level. If the push level is
+ * triggered the message is high priority. Otherwise, on close any remaining
+ * messages are sent.
+ * ##logging.properties
+ * MailHandlerDemo.handlers=com.sun.mail.util.logging.MailHandler
+ * com.sun.mail.util.logging.MailHandler.subject=Push level demo
+ * com.sun.mail.util.logging.MailHandler.pushLevel=WARNING
+ * ##
+ *
+ */
+ private static void initWithPushLevel() {
+ MailHandler h = new MailHandler();
+ h.setSubject("Push level demo");
+ h.setPushLevel(Level.WARNING);
+ LOGGER.addHandler(h);
+ }
+
+ /**
+ * Example for priority messages by generation rate. If the push filter is
+ * triggered the message is high priority. Otherwise, on close any remaining
+ * messages are sent. If the capacity is set to the
+ * ##logging.properties
+ * MailHandlerDemo.handlers=com.sun.mail.util.logging.MailHandler
+ * com.sun.mail.util.logging.MailHandler.subject=Push filter demo
+ * com.sun.mail.util.logging.MailHandler.pushLevel=ALL
+ * com.sun.mail.util.logging.MailHandler.pushFilter=com.sun.mail.util.logging.DurationFilter
+ * com.sun.mail.util.logging.DurationFilter.records=2
+ * com.sun.mail.util.logging.DurationFilter.duration=1 * 60 * 1000
+ * ##
+ *
+ */
+ private static void initWithPushFilter() {
+ MailHandler h = new MailHandler();
+ h.setSubject("Push filter demo");
+ h.setPushLevel(Level.ALL);
+ h.setPushFilter(new DurationFilter(2, 1L * 60L * 1000L));
+ LOGGER.addHandler(h);
+ }
+
+ /**
+ * Example for circular buffer behavior. The level, push level, and capacity
+ * are set the same so that the memory handler push results in a mail
+ * handler push. All messages are high priority. On close any remaining
+ * records are discarded because they never reach the mail handler.
+ * ##logging.properties
+ * MailHandlerDemo.handlers=java.util.logging.MemoryHandler
+ * java.util.logging.MemoryHandler.target=com.sun.mail.util.logging.MailHandler
+ * com.sun.mail.util.logging.MailHandler.level=ALL
+ * java.util.logging.MemoryHandler.level=ALL
+ * java.util.logging.MemoryHandler.push=WARNING
+ * com.sun.mail.util.logging.MailHandler.subject=Push only demo
+ * com.sun.mail.util.logging.MailHandler.pushLevel=WARNING
+ * ##
+ *
+ */
+ private static void initPushOnly() {
+ final int capacity = 3;
+ final Level pushLevel = Level.WARNING;
+ final MailHandler h = new MailHandler(capacity);
+ h.setPushLevel(pushLevel);
+ h.setSubject("Push only demo");
+ MemoryHandler m = new MemoryHandler(h, capacity, pushLevel);
+ h.setLevel(m.getLevel());
+ LOGGER.addHandler(m);
+ pushOnlyHandler = h;
+ }
+
+ /**
+ * Holds on to the push only handler. Only declared here to apply fallback
+ * settings.
+ */
+ private static Handler pushOnlyHandler;
+
+ /**
+ * Example for circular buffer behavior as normal priority. The push level,
+ * and capacity are set the same so that the memory handler push results in
+ * a mail handler push. All messages are normal priority. On close any
+ * remaining records are discarded because they never reach the mail
+ * handler. Use the LogManager config option or extend the MemoryHandler to
+ * emulate this behavior via the logging.properties.
+ */
+ private static void initPushNormal() {
+ final int capacity = 3;
+ final MailHandler h = new MailHandler(capacity);
+ h.setSubject("Push normal demo");
+ MemoryHandler m = new MemoryHandler(h, capacity, Level.WARNING) {
+
+ @Override
+ public void push() {
+ super.push(); //push to target.
+ super.flush(); //make the target send the email.
+ }
+ };
+ LOGGER.addHandler(m);
+ pushNormalHandler = h;
+ }
+
+ /**
+ * Holds on to the push normal handler. Only declared here to apply fallback
+ * settings.
+ */
+ private static Handler pushNormalHandler;
+
+ /**
+ * Example for various kinds of custom sorting, formatting, and filtering
+ * for multiple attachment messages. The subject will contain the most
+ * severe record and a count of remaining records. The log records are
+ * ordered from most severe to least severe. The body uses a custom
+ * formatter that includes a summary by date and time. The attachment use
+ * XML and plain text formats. Each attachment has a different set of
+ * filtering. The attachment names are generated from either a fixed name or
+ * are built using the number and type of the records formatted. On close
+ * any remaining messages are sent. Use the LogManager config option or
+ * extend the MemoryHandler to emulate this behavior via the
+ * logging.properties.
+ */
+ private static void initCustomAttachments() {
+ MailHandler h = new MailHandler();
+
+ //Sort records by severity keeping the severe messages at the top.
+ h.setComparator(Collections.reverseOrder(new SeverityComparator()));
+
+ //Use subject to provide a hint as to what is in the email.
+ h.setSubject(new CollectorFormatter());
+
+ //Make the body give a simple summary of what happened.
+ h.setFormatter(new SummaryFormatter());
+
+ //Create 3 attachments.
+ h.setAttachmentFormatters(new XMLFormatter(),
+ new XMLFormatter(), new SimpleFormatter());
+
+ //Filter each attachment differently.
+ h.setAttachmentFilters(null,
+ new DurationFilter(3L, 1000L),
+ new DurationFilter(1L, 15L * 60L * 1000L));
+
+ //Creating the attachment name formatters.
+ h.setAttachmentNames(new CollectorFormatter("all.xml"),
+ new CollectorFormatter("{3} records and {5} errors.xml"),
+ new CollectorFormatter("{5,choice,0#no errors|1#1 error|1<"
+ + "{5,number,integer} errors}.txt"));
+
+ LOGGER.addHandler(h);
+ }
+
+ /**
+ * Sets up the demos that will run.
+ *
+ * @param l the list of arguments.
+ * @return true if debug is on.
+ */
+ private static boolean init(List l) {
+ l = new ArrayList(l);
+ Session session = Session.getInstance(System.getProperties());
+ boolean all = l.remove("-all") || l.isEmpty();
+ if (l.remove("-body") || all) {
+ initBodyOnly();
+ }
+
+ if (l.remove("-custom") || all) {
+ initCustomAttachments();
+ }
+
+ if (l.remove("-low") || all) {
+ initLowCapacity();
+ }
+
+ if (l.remove("-pushfilter") || all) {
+ initWithPushFilter();
+ }
+
+ if (l.remove("-pushlevel") || all) {
+ initWithPushLevel();
+ }
+
+ if (l.remove("-pushnormal") || all) {
+ initPushNormal();
+ }
+
+ if (l.remove("-pushonly") || all) {
+ initPushOnly();
+ }
+
+ if (l.remove("-simple") || all) {
+ initSimpleAttachment();
+ }
+
+ boolean fallback = applyFallbackSettings();
+ boolean debug = l.remove("-debug") || session.getDebug();
+ if (debug) {
+ checkConfig(CLASS_NAME, session.getDebugOut());
+ }
+
+ if (!l.isEmpty()) {
+ LOGGER.log(Level.SEVERE, "Unknown commands: {0}", l);
+ }
+
+ if (fallback) {
+ LOGGER.info("Check your user temp dir for output.");
+ }
+ return debug;
+ }
+
+ /**
+ * Close and remove all handlers added to the class logger.
+ */
+ private static void closeHandlers() {
+ Handler[] handlers = LOGGER.getHandlers();
+ for (Handler h : handlers) {
+ h.close();
+ LOGGER.removeHandler(h);
+ }
+ }
+
+ /**
+ * Apply some fallback settings if no configuration file was specified.
+ *
+ * @return true if fallback settings were applied.
+ */
+ private static boolean applyFallbackSettings() {
+ if (getConfigLocation() == null) {
+ LOGGER.setLevel(Level.ALL);
+ Handler[] handlers = LOGGER.getHandlers();
+ for (Handler h : handlers) {
+ fallbackSettings(h);
+ }
+ fallbackSettings(pushOnlyHandler);
+ fallbackSettings(pushNormalHandler);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Common fallback settings for a single handler.
+ *
+ * @param h the handler.
+ */
+ private static void fallbackSettings(Handler h) {
+ if (h != null) {
+ h.setErrorManager(new FileErrorManager());
+ h.setLevel(Level.ALL);
+ }
+ }
+
+ /**
+ * Gets the system temp directory.
+ *
+ * @return the system temp directory.
+ */
+ private static String getTempDir() {
+ return System.getProperty("java.io.tmpdir");
+ }
+
+ /**
+ * Gets the configuration file or class name.
+ *
+ * @return the file name or class name.
+ */
+ private static String getConfigLocation() {
+ String file = System.getProperty("java.util.logging.config.file");
+ if (file == null) {
+ return System.getProperty("java.util.logging.config.class");
+ }
+ return file;
+ }
+
+ /**
+ * No objects are allowed.
+ * @throws IllegalAccessException always.
+ */
+ private MailHandlerDemo() throws IllegalAccessException {
+ throw new IllegalAccessException();
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/logging/README.txt b/src/Java/Jars/javamail-samples/javamail-samples/logging/README.txt
new file mode 100644
index 0000000..c6b7add
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/logging/README.txt
@@ -0,0 +1,103 @@
+Logging Demo
+------------
+
+Notes:
+======
+
+This should not be taken as a demo of how to use the logging API, but
+rather how to use the features of the MailHandler.
+
+To run the demo:
+================
+
+ 1. The demo requires Java version 1.5 or newer.
+ We *strongly* encourage you to use the latest version of J2SE,
+ which you can download from
+ http://www.oracle.com/technetwork/java/javase/downloads.
+
+ 2. Set your CLASSPATH to include the "mail.jar" and "activation.jar".
+
+ For JDK 1.1 on UNIX:
+
+ export CLASSPATH=/u/me/download/mail.jar:/u/me/download/activation.jar.
+
+ For JDK 1.2 and newer on UNIX:
+
+ export CLASSPATH=/u/me/download/mail.jar:/u/me/download/activation.jar:.
+
+ 3. Go to the demo/logging directory
+
+ 4. Compile all the files using your Java compiler. For example:
+
+ javac *.java
+
+ 5. Not required but, you should edit the maildemo.properties and change the
+ mail.to address and mail.host to your mail server ip or host name.
+
+ 6. Run the demo. For example:
+
+ java -Dmail.debug=false -Djava.util.logging.config.file=/u/me/download/javamail/demo/maildemo.properties MailHandlerDemo
+
+
+
+Overview of the Classes
+=======================
+
+Main Classes:
+
+ MailHandlerDemo = The main method creates log messages
+ for the MailHander to capture. The
+ initXXX methods describe some of the
+ common setup code for different types
+ of email messages.
+
+ Usage: java MailHandlerDemo [[-all] | [-body] | [-debug]
+ | [-low] | [-simple] | [-pushlevel]
+ | [-pushfilter] | [-pushnormal]| [-pushonly]]
+
+ Options:
+ -all : Execute all demos.
+ -body : An email with all records and only a body.
+ -custom : An email with attachments and dynamic names.
+ -debug : Output basic debug information about the
+ JVM and log configuration.
+ -low : Generates multiple emails due to low
+ capacity.
+ -simple : An email with all records with body and an
+ attachment.
+ -pushlevel : Generates high priority emails when
+ the push level is triggered and
+ normal priority when flushed.
+ -pushFilter : Generates high priority emails when
+ the push level and the push filter
+ is triggered and normal priority
+ emails when flushed.
+ -pushnormal : Generates multiple emails when the
+ MemoryHandler push level is
+ triggered. All generated email are
+ sent as normal priority.
+ -pushonly : Generates multiple emails when the
+ MemoryHandler push level is
+ triggered. Generates high priority
+ emails when the push level is
+ triggered and normal priority when
+ flushed.
+
+
+ FileErrorManager = Used to store email messages to the
+ local file system when mail transport
+ fails. This is installed as a
+ fallback in case the logging config is
+ not specified.
+
+ SummaryFormatter = An example compact formatter with summary
+ for use with the body of an email message.
+
+Support files:
+
+ maildemo.properties = A sample LogManager properties file for
+ the MailHandlerDemo.
+
+ maildemo.policy = A sample security policy file to use with
+ the MailHandlerDemo. This can be used to
+ enable security tracing.
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/logging/SummaryFormatter.java b/src/Java/Jars/javamail-samples/javamail-samples/logging/SummaryFormatter.java
new file mode 100644
index 0000000..6630fa2
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/logging/SummaryFormatter.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2009-2014 Oracle and/or its affiliates. All rights reserved.
+ * 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import com.sun.mail.util.logging.CollectorFormatter;
+import com.sun.mail.util.logging.CompactFormatter;
+import java.util.logging.Formatter;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+
+/**
+ * A compact formatter used to summarize an error report.
+ *
+ * @author Jason Mehrens
+ */
+public final class SummaryFormatter extends Formatter {
+
+ /**
+ * The line formatter.
+ */
+ private final CompactFormatter format;
+ /**
+ * The footer formatter.
+ */
+ private final CollectorFormatter footer;
+
+ /**
+ * Creates the formatter.
+ */
+ public SummaryFormatter() {
+ format = new CompactFormatter("[%4$s]\t%5$s %6$s%n");
+ footer = new CollectorFormatter("\nThese {3} messages occurred between "
+ + "{7,time,EEE, MMM dd HH:mm:ss:S ZZZ yyyy} and "
+ + "{8,time,EEE, MMM dd HH:mm:ss:S ZZZ yyyy}\n", format, null);
+ }
+
+ /**
+ * Gets the header information.
+ *
+ * @param h the handler or null.
+ * @return the header.
+ */
+ @Override
+ public String getHead(Handler h) {
+ footer.getHead(h);
+ return format.getHead(h);
+ }
+
+ /**
+ * Formats the given record.
+ *
+ * @param record the log record.
+ * @return the formatted record.
+ * @throws NullPointerException if record is null.
+ */
+ public String format(LogRecord record) {
+ String data = format.format(record);
+ footer.format(record); //Track record times for footer.
+ return data;
+ }
+
+ /**
+ * Gets and resets the footer information.
+ *
+ * @param h the handler or null.
+ * @return the footer.
+ */
+ @Override
+ public String getTail(Handler h) {
+ format.getTail(h);
+ return footer.getTail(h);
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/logging/maildemo.policy b/src/Java/Jars/javamail-samples/javamail-samples/logging/maildemo.policy
new file mode 100644
index 0000000..e176359
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/logging/maildemo.policy
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+grant {
+ permission java.util.logging.LoggingPermission "control";
+ permission java.util.PropertyPermission "*", "read, write";
+ permission java.net.SocketPermission "*", "resolve, connect";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.util.logging.resources";
+ permission java.io.FilePermission "<>", "read, write";
+ permission java.lang.RuntimePermission "getClassLoader";
+};
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/logging/maildemo.properties b/src/Java/Jars/javamail-samples/javamail-samples/logging/maildemo.properties
new file mode 100644
index 0000000..b221f2b
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/logging/maildemo.properties
@@ -0,0 +1,72 @@
+#
+# Copyright (c) 2009-2016 Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2009-2016 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
+# documentation and/or other materials provided with the distribution.
+#
+# - 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.
+
+
+
+
+# This can be used by setting the system property
+# -Djava.util.logging.config.file=path to this file
+
+# Taken from the JDK defaults.
+handlers= java.util.logging.ConsoleHandler
+.level= INFO
+java.util.logging.ConsoleHandler.level = INFO
+java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
+
+
+# Set the mail handler demo logger level
+MailHandlerDemo.level = ALL
+
+# Configure the MailHandler.
+com.sun.mail.util.logging.MailHandler.level = ALL
+com.sun.mail.util.logging.MailHandler.mail.host = my-mail-server
+com.sun.mail.util.logging.MailHandler.mail.from = me@example.com
+com.sun.mail.util.logging.MailHandler.mail.to = me@example.com
+com.sun.mail.util.logging.MailHandler.verify = local
+
+# Add attachments if needed.
+#com.sun.mail.util.logging.MailHandler.attachment.formatters = java.util.logging.SimpleFormatter, java.util.logging.XMLFormatter
+
+# No filters.
+#com.sun.mail.util.logging.MailHandler.attachment.filters = null, null
+
+# Formatter class name or strings.
+#com.sun.mail.util.logging.MailHandler.attachment.names = simple.txt, error.xml
+
+
+# Store messages on error by installing the FileErrorManager (demo code).
+com.sun.mail.util.logging.MailHandler.errorManager = FileErrorManager
+
+# Configure the FileErrorManager for demo (not required).
+# FileErrorManager.pattern = path-to-dir
+
+# Debug mail transport issues.
+mail.debug = false
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/monitor.java b/src/Java/Jars/javamail-samples/javamail-samples/monitor.java
new file mode 100644
index 0000000..2f206d6
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/monitor.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 1996-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.util.*;
+import java.io.*;
+import javax.mail.*;
+import javax.mail.event.*;
+import javax.activation.*;
+
+import com.sun.mail.imap.*;
+
+/* Monitors given mailbox for new mail */
+
+public class monitor {
+
+ public static void main(String argv[]) {
+ if (argv.length != 5) {
+ System.out.println(
+ "Usage: monitor ");
+ System.exit(1);
+ }
+ System.out.println("\nTesting monitor\n");
+
+ try {
+ Properties props = System.getProperties();
+
+ // Get a Session object
+ Session session = Session.getInstance(props, null);
+ // session.setDebug(true);
+
+ // Get a Store object
+ Store store = session.getStore("imap");
+
+ // Connect
+ store.connect(argv[0], argv[1], argv[2]);
+
+ // Open a Folder
+ Folder folder = store.getFolder(argv[3]);
+ if (folder == null || !folder.exists()) {
+ System.out.println("Invalid folder");
+ System.exit(1);
+ }
+
+ folder.open(Folder.READ_WRITE);
+
+ // Add messageCountListener to listen for new messages
+ folder.addMessageCountListener(new MessageCountAdapter() {
+ public void messagesAdded(MessageCountEvent ev) {
+ Message[] msgs = ev.getMessages();
+ System.out.println("Got " + msgs.length + " new messages");
+
+ // Just dump out the new messages
+ for (int i = 0; i < msgs.length; i++) {
+ try {
+ System.out.println("-----");
+ System.out.println("Message " +
+ msgs[i].getMessageNumber() + ":");
+ msgs[i].writeTo(System.out);
+ } catch (IOException ioex) {
+ ioex.printStackTrace();
+ } catch (MessagingException mex) {
+ mex.printStackTrace();
+ }
+ }
+ }
+ });
+
+ // Check mail once in "freq" MILLIseconds
+ int freq = Integer.parseInt(argv[4]);
+ boolean supportsIdle = false;
+ try {
+ if (folder instanceof IMAPFolder) {
+ IMAPFolder f = (IMAPFolder)folder;
+ f.idle();
+ supportsIdle = true;
+ }
+ } catch (FolderClosedException fex) {
+ throw fex;
+ } catch (MessagingException mex) {
+ supportsIdle = false;
+ }
+ for (;;) {
+ if (supportsIdle && folder instanceof IMAPFolder) {
+ IMAPFolder f = (IMAPFolder)folder;
+ f.idle();
+ System.out.println("IDLE done");
+ } else {
+ Thread.sleep(freq); // sleep for freq milliseconds
+
+ // This is to force the IMAP server to send us
+ // EXISTS notifications.
+ folder.getMessageCount();
+ }
+ }
+
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/mover.java b/src/Java/Jars/javamail-samples/javamail-samples/mover.java
new file mode 100644
index 0000000..00c6d94
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/mover.java
@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 1996-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.io.*;
+import java.util.*;
+import javax.mail.*;
+import javax.mail.internet.*;
+
+/* MOVE messages between mailboxes */
+
+public class mover {
+
+ static String protocol = "imap";
+ static String host = null;
+ static String user = null;
+ static String password = null;
+ static String src = null;
+ static String dest = null;
+ static boolean expunge = false;
+ static String url = null;
+
+ public static void main(String argv[]) {
+ int start = 1; int end = -1;
+ int optind;
+
+ for (optind = 0; optind < argv.length; optind++) {
+ if (argv[optind].equals("-T")) { // protocol
+ protocol = argv[++optind];
+ } else if (argv[optind].equals("-H")) { // host
+ host = argv[++optind];
+ } else if (argv[optind].equals("-U")) { // user
+ user = argv[++optind];
+ } else if (argv[optind].equals("-P")) { // password
+ password = argv[++optind];
+ } else if (argv[optind].equals("-L")) {
+ url = argv[++optind];
+ } else if (argv[optind].equals("-s")) { // Source mbox
+ src = argv[++optind];
+ } else if (argv[optind].equals("-d")) { // Destination mbox
+ dest = argv[++optind];
+ } else if (argv[optind].equals("-x")) { // Expunge ?
+ expunge = true;
+ } else if (argv[optind].equals("--")) {
+ optind++;
+ break;
+ } else if (argv[optind].startsWith("-")) {
+ System.out.println(
+"Usage: mover [-T protocol] [-H host] [-U user] [-P password] [-L url] [-v]");
+ System.out.println(
+"\t[-s source mbox] [-d destination mbox] [-x] [msgnum1] [msgnum2]");
+ System.out.println(
+"\t The -x option => EXPUNGE deleted messages");
+ System.out.println(
+"\t msgnum1 => start of message-range; msgnum2 => end of message-range");
+ System.exit(1);
+ } else {
+ break;
+ }
+ }
+
+ if (optind < argv.length)
+ start = Integer.parseInt(argv[optind++]); // start msg
+
+ if (optind < argv.length)
+ end = Integer.parseInt(argv[optind++]); // end msg
+
+ try {
+ // Get a Properties object
+ Properties props = System.getProperties();
+
+ // Get a Session object
+ Session session = Session.getInstance(props, null);
+
+ // Get a Store object
+ Store store = null;
+ if (url != null) {
+ URLName urln = new URLName(url);
+ store = session.getStore(urln);
+ store.connect();
+ } else {
+ if (protocol != null)
+ store = session.getStore(protocol);
+ else
+ store = session.getStore();
+
+ // Connect
+ if (host != null || user != null || password != null)
+ store.connect(host, user, password);
+ else
+ store.connect();
+ }
+
+
+ // Open source Folder
+ Folder folder = store.getFolder(src);
+ if (folder == null || !folder.exists()) {
+ System.out.println("Invalid folder: " + src);
+ System.exit(1);
+ }
+
+ folder.open(Folder.READ_WRITE);
+
+ int count = folder.getMessageCount();
+ if (count == 0) { // No messages in the source folder
+ System.out.println(folder.getName() + " is empty");
+ // Close folder, store and return
+ folder.close(false);
+ store.close();
+ return;
+ }
+
+ // Open destination folder, create if reqd
+ Folder dfolder = store.getFolder(dest);
+ if (!dfolder.exists())
+ dfolder.create(Folder.HOLDS_MESSAGES);
+
+ if (end == -1)
+ end = count;
+
+ // Get the message objects to copy
+ Message[] msgs = folder.getMessages(start, end);
+ System.out.println("Moving " + msgs.length + " messages");
+
+ if (msgs.length != 0) {
+ folder.copyMessages(msgs, dfolder);
+ folder.setFlags(msgs, new Flags(Flags.Flag.DELETED), true);
+
+ // Dump out the Flags of the moved messages, to insure that
+ // all got deleted
+ for (int i = 0; i < msgs.length; i++) {
+ if (!msgs[i].isSet(Flags.Flag.DELETED))
+ System.out.println("Message # " + msgs[i] +
+ " not deleted");
+ }
+ }
+
+ // Close folders and store
+ folder.close(expunge);
+ store.close();
+
+ } catch (MessagingException mex) {
+ Exception ex = mex;
+ do {
+ System.out.println(ex.getMessage());
+ if (ex instanceof MessagingException)
+ ex = ((MessagingException)ex).getNextException();
+ else
+ ex = null;
+ } while (ex != null);
+ }
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/msgmultisendsample.java b/src/Java/Jars/javamail-samples/javamail-samples/msgmultisendsample.java
new file mode 100644
index 0000000..b804d36
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/msgmultisendsample.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 1996-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.util.*;
+import java.io.*;
+import javax.mail.*;
+import javax.mail.internet.*;
+import javax.activation.*;
+
+/**
+ * msgmultisendsample creates a simple multipart/mixed message and sends it.
+ * Both body parts are text/plain.
+ *
+ * usage: java msgmultisendsample to from smtp true|false
+ * where to and from are the destination and
+ * origin email addresses, respectively, and smtp
+ * is the hostname of the machine that has smtp server
+ * running. The last parameter either turns on or turns off
+ * debugging during sending.
+ *
+ * @author Max Spivak
+ */
+public class msgmultisendsample {
+ static String msgText1 = "This is a message body.\nHere's line two.";
+ static String msgText2 = "This is the text in the message attachment.";
+
+ public static void main(String[] args) {
+ if (args.length != 4) {
+ System.out.println("usage: java msgmultisend true|false");
+ return;
+ }
+
+ String to = args[0];
+ String from = args[1];
+ String host = args[2];
+ boolean debug = Boolean.valueOf(args[3]).booleanValue();
+
+ // create some properties and get the default Session
+ Properties props = new Properties();
+ props.put("mail.smtp.host", host);
+
+ Session session = Session.getInstance(props, null);
+ session.setDebug(debug);
+
+ try {
+ // create a message
+ MimeMessage msg = new MimeMessage(session);
+ msg.setFrom(new InternetAddress(from));
+ InternetAddress[] address = {new InternetAddress(to)};
+ msg.setRecipients(Message.RecipientType.TO, address);
+ msg.setSubject("JavaMail APIs Multipart Test");
+ msg.setSentDate(new Date());
+
+ // create and fill the first message part
+ MimeBodyPart mbp1 = new MimeBodyPart();
+ mbp1.setText(msgText1);
+
+ // create and fill the second message part
+ MimeBodyPart mbp2 = new MimeBodyPart();
+ // Use setText(text, charset), to show it off !
+ mbp2.setText(msgText2, "us-ascii");
+
+ // create the Multipart and its parts to it
+ Multipart mp = new MimeMultipart();
+ mp.addBodyPart(mbp1);
+ mp.addBodyPart(mbp2);
+
+ // add the Multipart to the message
+ msg.setContent(mp);
+
+ // send the message
+ Transport.send(msg);
+ } catch (MessagingException mex) {
+ mex.printStackTrace();
+ Exception ex = null;
+ if ((ex = mex.getNextException()) != null) {
+ ex.printStackTrace();
+ }
+ }
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/msgsend.java b/src/Java/Jars/javamail-samples/javamail-samples/msgsend.java
new file mode 100644
index 0000000..8ce708b
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/msgsend.java
@@ -0,0 +1,248 @@
+/*
+ * Copyright (c) 1997-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.io.*;
+import java.util.Properties;
+import java.util.Date;
+
+import javax.mail.*;
+import javax.mail.internet.*;
+
+/**
+ * Demo app that shows how to construct and send an RFC822
+ * (singlepart) message.
+ *
+ * XXX - allow more than one recipient on the command line
+ *
+ * @author Max Spivak
+ * @author Bill Shannon
+ */
+
+public class msgsend {
+
+ public static void main(String[] argv) {
+ String to, subject = null, from = null,
+ cc = null, bcc = null, url = null;
+ String mailhost = null;
+ String mailer = "msgsend";
+ String file = null;
+ String protocol = null, host = null, user = null, password = null;
+ String record = null; // name of folder in which to record mail
+ boolean debug = false;
+ BufferedReader in =
+ new BufferedReader(new InputStreamReader(System.in));
+ int optind;
+
+ /*
+ * Process command line arguments.
+ */
+ for (optind = 0; optind < argv.length; optind++) {
+ if (argv[optind].equals("-T")) {
+ protocol = argv[++optind];
+ } else if (argv[optind].equals("-H")) {
+ host = argv[++optind];
+ } else if (argv[optind].equals("-U")) {
+ user = argv[++optind];
+ } else if (argv[optind].equals("-P")) {
+ password = argv[++optind];
+ } else if (argv[optind].equals("-M")) {
+ mailhost = argv[++optind];
+ } else if (argv[optind].equals("-f")) {
+ record = argv[++optind];
+ } else if (argv[optind].equals("-a")) {
+ file = argv[++optind];
+ } else if (argv[optind].equals("-s")) {
+ subject = argv[++optind];
+ } else if (argv[optind].equals("-o")) { // originator
+ from = argv[++optind];
+ } else if (argv[optind].equals("-c")) {
+ cc = argv[++optind];
+ } else if (argv[optind].equals("-b")) {
+ bcc = argv[++optind];
+ } else if (argv[optind].equals("-L")) {
+ url = argv[++optind];
+ } else if (argv[optind].equals("-d")) {
+ debug = true;
+ } else if (argv[optind].equals("--")) {
+ optind++;
+ break;
+ } else if (argv[optind].startsWith("-")) {
+ System.out.println(
+"Usage: msgsend [[-L store-url] | [-T prot] [-H host] [-U user] [-P passwd]]");
+ System.out.println(
+"\t[-s subject] [-o from-address] [-c cc-addresses] [-b bcc-addresses]");
+ System.out.println(
+"\t[-f record-mailbox] [-M transport-host] [-a attach-file] [-d] [address]");
+ System.exit(1);
+ } else {
+ break;
+ }
+ }
+
+ try {
+ /*
+ * Prompt for To and Subject, if not specified.
+ */
+ if (optind < argv.length) {
+ // XXX - concatenate all remaining arguments
+ to = argv[optind];
+ System.out.println("To: " + to);
+ } else {
+ System.out.print("To: ");
+ System.out.flush();
+ to = in.readLine();
+ }
+ if (subject == null) {
+ System.out.print("Subject: ");
+ System.out.flush();
+ subject = in.readLine();
+ } else {
+ System.out.println("Subject: " + subject);
+ }
+
+ /*
+ * Initialize the JavaMail Session.
+ */
+ Properties props = System.getProperties();
+ // XXX - could use Session.getTransport() and Transport.connect()
+ // XXX - assume we're using SMTP
+ if (mailhost != null)
+ props.put("mail.smtp.host", mailhost);
+
+ // Get a Session object
+ Session session = Session.getInstance(props, null);
+ if (debug)
+ session.setDebug(true);
+
+ /*
+ * Construct the message and send it.
+ */
+ Message msg = new MimeMessage(session);
+ if (from != null)
+ msg.setFrom(new InternetAddress(from));
+ else
+ msg.setFrom();
+
+ msg.setRecipients(Message.RecipientType.TO,
+ InternetAddress.parse(to, false));
+ if (cc != null)
+ msg.setRecipients(Message.RecipientType.CC,
+ InternetAddress.parse(cc, false));
+ if (bcc != null)
+ msg.setRecipients(Message.RecipientType.BCC,
+ InternetAddress.parse(bcc, false));
+
+ msg.setSubject(subject);
+
+ String text = collect(in);
+
+ if (file != null) {
+ // Attach the specified file.
+ // We need a multipart message to hold the attachment.
+ MimeBodyPart mbp1 = new MimeBodyPart();
+ mbp1.setText(text);
+ MimeBodyPart mbp2 = new MimeBodyPart();
+ mbp2.attachFile(file);
+ MimeMultipart mp = new MimeMultipart();
+ mp.addBodyPart(mbp1);
+ mp.addBodyPart(mbp2);
+ msg.setContent(mp);
+ } else {
+ // If the desired charset is known, you can use
+ // setText(text, charset)
+ msg.setText(text);
+ }
+
+ msg.setHeader("X-Mailer", mailer);
+ msg.setSentDate(new Date());
+
+ // send the thing off
+ Transport.send(msg);
+
+ System.out.println("\nMail was sent successfully.");
+
+ /*
+ * Save a copy of the message, if requested.
+ */
+ if (record != null) {
+ // Get a Store object
+ Store store = null;
+ if (url != null) {
+ URLName urln = new URLName(url);
+ store = session.getStore(urln);
+ store.connect();
+ } else {
+ if (protocol != null)
+ store = session.getStore(protocol);
+ else
+ store = session.getStore();
+
+ // Connect
+ if (host != null || user != null || password != null)
+ store.connect(host, user, password);
+ else
+ store.connect();
+ }
+
+ // Get record Folder. Create if it does not exist.
+ Folder folder = store.getFolder(record);
+ if (folder == null) {
+ System.err.println("Can't get record folder.");
+ System.exit(1);
+ }
+ if (!folder.exists())
+ folder.create(Folder.HOLDS_MESSAGES);
+
+ Message[] msgs = new Message[1];
+ msgs[0] = msg;
+ folder.appendMessages(msgs);
+
+ System.out.println("Mail was recorded successfully.");
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Read the body of the message until EOF.
+ */
+ public static String collect(BufferedReader in) throws IOException {
+ String line;
+ StringBuffer sb = new StringBuffer();
+ while ((line = in.readLine()) != null) {
+ sb.append(line);
+ sb.append("\n");
+ }
+ return sb.toString();
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/msgsendsample.java b/src/Java/Jars/javamail-samples/javamail-samples/msgsendsample.java
new file mode 100644
index 0000000..f2f49ef
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/msgsendsample.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 1996-2011 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.util.*;
+import java.io.*;
+import javax.mail.*;
+import javax.mail.internet.*;
+import javax.activation.*;
+
+/**
+ * msgsendsample creates a very simple text/plain message and sends it.
+ *
+ * usage: java msgsendsample to from smtphost true|false
+ * where to and from are the destination and
+ * origin email addresses, respectively, and smtphost
+ * is the hostname of the machine that has the smtp server
+ * running. The last parameter either turns on or turns off
+ * debugging during sending.
+ *
+ * @author Max Spivak
+ */
+public class msgsendsample {
+ static String msgText = "This is a message body.\nHere's the second line.";
+
+ public static void main(String[] args) {
+ if (args.length != 4) {
+ usage();
+ System.exit(1);
+ }
+
+ System.out.println();
+
+ String to = args[0];
+ String from = args[1];
+ String host = args[2];
+ boolean debug = Boolean.valueOf(args[3]).booleanValue();
+
+ // create some properties and get the default Session
+ Properties props = new Properties();
+ props.put("mail.smtp.host", host);
+ if (debug) props.put("mail.debug", args[3]);
+
+ Session session = Session.getInstance(props, null);
+ session.setDebug(debug);
+
+ try {
+ // create a message
+ MimeMessage msg = new MimeMessage(session);
+ msg.setFrom(new InternetAddress(from));
+ InternetAddress[] address = {new InternetAddress(to)};
+ msg.setRecipients(Message.RecipientType.TO, address);
+ msg.setSubject("JavaMail APIs Test");
+ msg.setSentDate(new Date());
+ // If the desired charset is known, you can use
+ // setText(text, charset)
+ msg.setText(msgText);
+
+ Transport.send(msg);
+ } catch (MessagingException mex) {
+ System.out.println("\n--Exception handling in msgsendsample.java");
+
+ mex.printStackTrace();
+ System.out.println();
+ Exception ex = mex;
+ do {
+ if (ex instanceof SendFailedException) {
+ SendFailedException sfex = (SendFailedException)ex;
+ Address[] invalid = sfex.getInvalidAddresses();
+ if (invalid != null) {
+ System.out.println(" ** Invalid Addresses");
+ for (int i = 0; i < invalid.length; i++)
+ System.out.println(" " + invalid[i]);
+ }
+ Address[] validUnsent = sfex.getValidUnsentAddresses();
+ if (validUnsent != null) {
+ System.out.println(" ** ValidUnsent Addresses");
+ for (int i = 0; i < validUnsent.length; i++)
+ System.out.println(" "+validUnsent[i]);
+ }
+ Address[] validSent = sfex.getValidSentAddresses();
+ if (validSent != null) {
+ System.out.println(" ** ValidSent Addresses");
+ for (int i = 0; i < validSent.length; i++)
+ System.out.println(" "+validSent[i]);
+ }
+ }
+ System.out.println();
+ if (ex instanceof MessagingException)
+ ex = ((MessagingException)ex).getNextException();
+ else
+ ex = null;
+ } while (ex != null);
+ }
+ }
+
+ private static void usage() {
+ System.out.println("usage: java msgsendsample true|false");
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/msgshow.java b/src/Java/Jars/javamail-samples/javamail-samples/msgshow.java
new file mode 100644
index 0000000..f93ab06
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/msgshow.java
@@ -0,0 +1,445 @@
+/*
+ * Copyright (c) 1997-2012 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.util.*;
+import java.io.*;
+import javax.mail.*;
+import javax.mail.event.*;
+import javax.mail.internet.*;
+
+/*
+ * Demo app that exercises the Message interfaces.
+ * Show information about and contents of messages.
+ *
+ * @author John Mani
+ * @author Bill Shannon
+ */
+
+public class msgshow {
+
+ static String protocol;
+ static String host = null;
+ static String user = null;
+ static String password = null;
+ static String mbox = null;
+ static String url = null;
+ static int port = -1;
+ static boolean verbose = false;
+ static boolean debug = false;
+ static boolean showStructure = false;
+ static boolean showMessage = false;
+ static boolean showAlert = false;
+ static boolean saveAttachments = false;
+ static int attnum = 1;
+
+ public static void main(String argv[]) {
+ int optind;
+ InputStream msgStream = System.in;
+
+ for (optind = 0; optind < argv.length; optind++) {
+ if (argv[optind].equals("-T")) {
+ protocol = argv[++optind];
+ } else if (argv[optind].equals("-H")) {
+ host = argv[++optind];
+ } else if (argv[optind].equals("-U")) {
+ user = argv[++optind];
+ } else if (argv[optind].equals("-P")) {
+ password = argv[++optind];
+ } else if (argv[optind].equals("-v")) {
+ verbose = true;
+ } else if (argv[optind].equals("-D")) {
+ debug = true;
+ } else if (argv[optind].equals("-f")) {
+ mbox = argv[++optind];
+ } else if (argv[optind].equals("-L")) {
+ url = argv[++optind];
+ } else if (argv[optind].equals("-p")) {
+ port = Integer.parseInt(argv[++optind]);
+ } else if (argv[optind].equals("-s")) {
+ showStructure = true;
+ } else if (argv[optind].equals("-S")) {
+ saveAttachments = true;
+ } else if (argv[optind].equals("-m")) {
+ showMessage = true;
+ } else if (argv[optind].equals("-a")) {
+ showAlert = true;
+ } else if (argv[optind].equals("--")) {
+ optind++;
+ break;
+ } else if (argv[optind].startsWith("-")) {
+ System.out.println(
+"Usage: msgshow [-L url] [-T protocol] [-H host] [-p port] [-U user]");
+ System.out.println(
+"\t[-P password] [-f mailbox] [msgnum ...] [-v] [-D] [-s] [-S] [-a]");
+ System.out.println(
+"or msgshow -m [-v] [-D] [-s] [-S] [-f msg-file]");
+ System.exit(1);
+ } else {
+ break;
+ }
+ }
+
+ try {
+ // Get a Properties object
+ Properties props = System.getProperties();
+
+ // Get a Session object
+ Session session = Session.getInstance(props, null);
+ session.setDebug(debug);
+
+ if (showMessage) {
+ MimeMessage msg;
+ if (mbox != null)
+ msg = new MimeMessage(session,
+ new BufferedInputStream(new FileInputStream(mbox)));
+ else
+ msg = new MimeMessage(session, msgStream);
+ dumpPart(msg);
+ System.exit(0);
+ }
+
+ // Get a Store object
+ Store store = null;
+ if (url != null) {
+ URLName urln = new URLName(url);
+ store = session.getStore(urln);
+ if (showAlert) {
+ store.addStoreListener(new StoreListener() {
+ public void notification(StoreEvent e) {
+ String s;
+ if (e.getMessageType() == StoreEvent.ALERT)
+ s = "ALERT: ";
+ else
+ s = "NOTICE: ";
+ System.out.println(s + e.getMessage());
+ }
+ });
+ }
+ store.connect();
+ } else {
+ if (protocol != null)
+ store = session.getStore(protocol);
+ else
+ store = session.getStore();
+
+ // Connect
+ if (host != null || user != null || password != null)
+ store.connect(host, port, user, password);
+ else
+ store.connect();
+ }
+
+
+ // Open the Folder
+
+ Folder folder = store.getDefaultFolder();
+ if (folder == null) {
+ System.out.println("No default folder");
+ System.exit(1);
+ }
+
+ if (mbox == null)
+ mbox = "INBOX";
+ folder = folder.getFolder(mbox);
+ if (folder == null) {
+ System.out.println("Invalid folder");
+ System.exit(1);
+ }
+
+ // try to open read/write and if that fails try read-only
+ try {
+ folder.open(Folder.READ_WRITE);
+ } catch (MessagingException ex) {
+ folder.open(Folder.READ_ONLY);
+ }
+ int totalMessages = folder.getMessageCount();
+
+ if (totalMessages == 0) {
+ System.out.println("Empty folder");
+ folder.close(false);
+ store.close();
+ System.exit(1);
+ }
+
+ if (verbose) {
+ int newMessages = folder.getNewMessageCount();
+ System.out.println("Total messages = " + totalMessages);
+ System.out.println("New messages = " + newMessages);
+ System.out.println("-------------------------------");
+ }
+
+ if (optind >= argv.length) {
+ // Attributes & Flags for all messages ..
+ Message[] msgs = folder.getMessages();
+
+ // Use a suitable FetchProfile
+ FetchProfile fp = new FetchProfile();
+ fp.add(FetchProfile.Item.ENVELOPE);
+ fp.add(FetchProfile.Item.FLAGS);
+ fp.add("X-Mailer");
+ folder.fetch(msgs, fp);
+
+ for (int i = 0; i < msgs.length; i++) {
+ System.out.println("--------------------------");
+ System.out.println("MESSAGE #" + (i + 1) + ":");
+ dumpEnvelope(msgs[i]);
+ // dumpPart(msgs[i]);
+ }
+ } else {
+ while (optind < argv.length) {
+ int msgnum = Integer.parseInt(argv[optind++]);
+ System.out.println("Getting message number: " + msgnum);
+ Message m = null;
+
+ try {
+ m = folder.getMessage(msgnum);
+ dumpPart(m);
+ } catch (IndexOutOfBoundsException iex) {
+ System.out.println("Message number out of range");
+ }
+ }
+ }
+
+ folder.close(false);
+ store.close();
+ } catch (Exception ex) {
+ System.out.println("Oops, got exception! " + ex.getMessage());
+ ex.printStackTrace();
+ System.exit(1);
+ }
+ System.exit(0);
+ }
+
+ public static void dumpPart(Part p) throws Exception {
+ if (p instanceof Message)
+ dumpEnvelope((Message)p);
+
+ /** Dump input stream ..
+
+ InputStream is = p.getInputStream();
+ // If "is" is not already buffered, wrap a BufferedInputStream
+ // around it.
+ if (!(is instanceof BufferedInputStream))
+ is = new BufferedInputStream(is);
+ int c;
+ while ((c = is.read()) != -1)
+ System.out.write(c);
+
+ **/
+
+ String ct = p.getContentType();
+ try {
+ pr("CONTENT-TYPE: " + (new ContentType(ct)).toString());
+ } catch (ParseException pex) {
+ pr("BAD CONTENT-TYPE: " + ct);
+ }
+ String filename = p.getFileName();
+ if (filename != null)
+ pr("FILENAME: " + filename);
+
+ /*
+ * Using isMimeType to determine the content type avoids
+ * fetching the actual content data until we need it.
+ */
+ if (p.isMimeType("text/plain")) {
+ pr("This is plain text");
+ pr("---------------------------");
+ if (!showStructure && !saveAttachments)
+ System.out.println((String)p.getContent());
+ } else if (p.isMimeType("multipart/*")) {
+ pr("This is a Multipart");
+ pr("---------------------------");
+ Multipart mp = (Multipart)p.getContent();
+ level++;
+ int count = mp.getCount();
+ for (int i = 0; i < count; i++)
+ dumpPart(mp.getBodyPart(i));
+ level--;
+ } else if (p.isMimeType("message/rfc822")) {
+ pr("This is a Nested Message");
+ pr("---------------------------");
+ level++;
+ dumpPart((Part)p.getContent());
+ level--;
+ } else {
+ if (!showStructure && !saveAttachments) {
+ /*
+ * If we actually want to see the data, and it's not a
+ * MIME type we know, fetch it and check its Java type.
+ */
+ Object o = p.getContent();
+ if (o instanceof String) {
+ pr("This is a string");
+ pr("---------------------------");
+ System.out.println((String)o);
+ } else if (o instanceof InputStream) {
+ pr("This is just an input stream");
+ pr("---------------------------");
+ InputStream is = (InputStream)o;
+ int c;
+ while ((c = is.read()) != -1)
+ System.out.write(c);
+ } else {
+ pr("This is an unknown type");
+ pr("---------------------------");
+ pr(o.toString());
+ }
+ } else {
+ // just a separator
+ pr("---------------------------");
+ }
+ }
+
+ /*
+ * If we're saving attachments, write out anything that
+ * looks like an attachment into an appropriately named
+ * file. Don't overwrite existing files to prevent
+ * mistakes.
+ */
+ if (saveAttachments && level != 0 && p instanceof MimeBodyPart &&
+ !p.isMimeType("multipart/*")) {
+ String disp = p.getDisposition();
+ // many mailers don't include a Content-Disposition
+ if (disp == null || disp.equalsIgnoreCase(Part.ATTACHMENT)) {
+ if (filename == null)
+ filename = "Attachment" + attnum++;
+ pr("Saving attachment to file " + filename);
+ try {
+ File f = new File(filename);
+ if (f.exists())
+ // XXX - could try a series of names
+ throw new IOException("file exists");
+ ((MimeBodyPart)p).saveFile(f);
+ } catch (IOException ex) {
+ pr("Failed to save attachment: " + ex);
+ }
+ pr("---------------------------");
+ }
+ }
+ }
+
+ public static void dumpEnvelope(Message m) throws Exception {
+ pr("This is the message envelope");
+ pr("---------------------------");
+ Address[] a;
+ // FROM
+ if ((a = m.getFrom()) != null) {
+ for (int j = 0; j < a.length; j++)
+ pr("FROM: " + a[j].toString());
+ }
+
+ // REPLY TO
+ if ((a = m.getReplyTo()) != null) {
+ for (int j = 0; j < a.length; j++)
+ pr("REPLY TO: " + a[j].toString());
+ }
+
+ // TO
+ if ((a = m.getRecipients(Message.RecipientType.TO)) != null) {
+ for (int j = 0; j < a.length; j++) {
+ pr("TO: " + a[j].toString());
+ InternetAddress ia = (InternetAddress)a[j];
+ if (ia.isGroup()) {
+ InternetAddress[] aa = ia.getGroup(false);
+ for (int k = 0; k < aa.length; k++)
+ pr(" GROUP: " + aa[k].toString());
+ }
+ }
+ }
+
+ // SUBJECT
+ pr("SUBJECT: " + m.getSubject());
+
+ // DATE
+ Date d = m.getSentDate();
+ pr("SendDate: " +
+ (d != null ? d.toString() : "UNKNOWN"));
+
+ // FLAGS
+ Flags flags = m.getFlags();
+ StringBuffer sb = new StringBuffer();
+ Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags
+
+ boolean first = true;
+ for (int i = 0; i < sf.length; i++) {
+ String s;
+ Flags.Flag f = sf[i];
+ if (f == Flags.Flag.ANSWERED)
+ s = "\\Answered";
+ else if (f == Flags.Flag.DELETED)
+ s = "\\Deleted";
+ else if (f == Flags.Flag.DRAFT)
+ s = "\\Draft";
+ else if (f == Flags.Flag.FLAGGED)
+ s = "\\Flagged";
+ else if (f == Flags.Flag.RECENT)
+ s = "\\Recent";
+ else if (f == Flags.Flag.SEEN)
+ s = "\\Seen";
+ else
+ continue; // skip it
+ if (first)
+ first = false;
+ else
+ sb.append(' ');
+ sb.append(s);
+ }
+
+ String[] uf = flags.getUserFlags(); // get the user flag strings
+ for (int i = 0; i < uf.length; i++) {
+ if (first)
+ first = false;
+ else
+ sb.append(' ');
+ sb.append(uf[i]);
+ }
+ pr("FLAGS: " + sb.toString());
+
+ // X-MAILER
+ String[] hdrs = m.getHeader("X-Mailer");
+ if (hdrs != null)
+ pr("X-Mailer: " + hdrs[0]);
+ else
+ pr("X-Mailer NOT available");
+ }
+
+ static String indentStr = " ";
+ static int level = 0;
+
+ /**
+ * Print a, possibly indented, string.
+ */
+ public static void pr(String s) {
+ if (showStructure)
+ System.out.print(indentStr.substring(0, level * 2));
+ System.out.println(s);
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/namespace.java b/src/Java/Jars/javamail-samples/javamail-samples/namespace.java
new file mode 100644
index 0000000..3b16d30
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/namespace.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 1997-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.util.*;
+import java.io.*;
+import javax.mail.*;
+
+/*
+ * Demo app that exercises the namespace interfaces.
+ * Show the namespaces supported by a store.
+ *
+ * @author Bill Shannon
+ */
+
+public class namespace {
+
+ static String protocol;
+ static String host = null;
+ static String user = null;
+ static String password = null;
+ static String url = null;
+ static int port = -1;
+ static boolean debug = false;
+ static String suser = "other";
+
+ public static void main(String argv[]) {
+ int msgnum = -1;
+ int optind;
+
+ for (optind = 0; optind < argv.length; optind++) {
+ if (argv[optind].equals("-T")) {
+ protocol = argv[++optind];
+ } else if (argv[optind].equals("-H")) {
+ host = argv[++optind];
+ } else if (argv[optind].equals("-U")) {
+ user = argv[++optind];
+ } else if (argv[optind].equals("-P")) {
+ password = argv[++optind];
+ } else if (argv[optind].equals("-D")) {
+ debug = true;
+ } else if (argv[optind].equals("-L")) {
+ url = argv[++optind];
+ } else if (argv[optind].equals("-p")) {
+ port = Integer.parseInt(argv[++optind]);
+ } else if (argv[optind].equals("-u")) {
+ suser = argv[++optind];
+ } else if (argv[optind].equals("--")) {
+ optind++;
+ break;
+ } else if (argv[optind].startsWith("-")) {
+ System.out.println(
+"Usage: namespace [-L url] [-T protocol] [-H host] [-p port] [-U user]");
+ System.out.println(
+"\t[-P password] [-u other-user] [-D]");
+ System.exit(1);
+ } else {
+ break;
+ }
+ }
+
+ try {
+ // Get a Properties object
+ Properties props = System.getProperties();
+
+ // Get a Session object
+ Session session = Session.getInstance(props, null);
+ session.setDebug(debug);
+
+ // Get a Store object
+ Store store = null;
+ if (url != null) {
+ URLName urln = new URLName(url);
+ store = session.getStore(urln);
+ store.connect();
+ } else {
+ if (protocol != null)
+ store = session.getStore(protocol);
+ else
+ store = session.getStore();
+
+ // Connect
+ if (host != null || user != null || password != null)
+ store.connect(host, port, user, password);
+ else
+ store.connect();
+ }
+
+ printFolders("Personal", store.getPersonalNamespaces());
+ printFolders("User \"" + suser + "\"",
+ store.getUserNamespaces(suser));
+ printFolders("Shared", store.getSharedNamespaces());
+
+ store.close();
+ } catch (Exception ex) {
+ System.out.println("Oops, got exception! " + ex.getMessage());
+ ex.printStackTrace();
+ }
+ System.exit(0);
+ }
+
+ private static void printFolders(String name, Folder[] folders)
+ throws MessagingException {
+ System.out.println(name + " Namespace:");
+ if (folders == null || folders.length == 0) {
+ System.out.println(" ");
+ return;
+ }
+ for (int i = 0; i < folders.length; i++) {
+ String fn = folders[i].getFullName();
+ if (fn.length() == 0)
+ fn = "";
+ try {
+ System.out.println(" " + fn +
+ ", delimiter \"" + folders[i].getSeparator() + "\"");
+ Folder[] fl = folders[i].list();
+ if (fl.length > 0) {
+ System.out.println(" Subfolders:");
+ for (int j = 0; j < fl.length; j++)
+ System.out.println(" " + fl[j].getFullName());
+ }
+ } catch (FolderNotFoundException ex) { }
+ }
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/outlook/MSBodyPart.java b/src/Java/Jars/javamail-samples/javamail-samples/outlook/MSBodyPart.java
new file mode 100644
index 0000000..faa1d46
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/outlook/MSBodyPart.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 1997-2011 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.io.*;
+import javax.activation.*;
+import javax.mail.*;
+import javax.mail.internet.*;
+
+/**
+ * A special MimeBodyPart used with MSMessage.
+ *
+ * @author John Mani
+ * @author Bill Shannon
+ */
+public class MSBodyPart extends MimeBodyPart {
+ private int start;
+ private int end;
+ private String type = UNKNOWN;
+ private String disposition;
+ private String encoding;
+ private String filename = UNKNOWN;
+
+ private static final String UNKNOWN = "UNKNOWN";
+
+ public MSBodyPart(byte[] content, int start, int end,
+ String disposition, String encoding) {
+ this.content = content;
+ this.start = start;
+ this.end = end;
+ this.disposition = disposition;
+ this.encoding = encoding;
+ }
+
+ public String getContentType() throws MessagingException {
+ // try to figure this out from the filename extension
+ if (type == UNKNOWN)
+ processBegin();
+ return type;
+ }
+
+ public String getEncoding() throws MessagingException {
+ return encoding;
+ }
+
+ public String getDisposition() throws MessagingException {
+ return disposition;
+ }
+
+ public String getFileName() throws MessagingException {
+ // get filename from the "begin" line
+ if (filename == UNKNOWN)
+ processBegin();
+ return filename;
+ }
+
+ protected InputStream getContentStream() {
+ return new ByteArrayInputStream(content, start, end - start);
+ }
+
+ /**
+ * Process the "begin" line to extract the filename,
+ * and from it determine the Content-Type.
+ */
+ private void processBegin() {
+ InputStream in = getContentStream();
+ try {
+ BufferedReader r = new BufferedReader(new InputStreamReader(in));
+ String begin = r.readLine();
+ // format is "begin 666 filename.txt"
+ if (begin != null && begin.regionMatches(true, 0, "begin ", 0, 6)) {
+ int i = begin.indexOf(' ', 6);
+ if (i > 0) {
+ filename = begin.substring(i + 1);
+ FileTypeMap map = FileTypeMap.getDefaultFileTypeMap();
+ type = map.getContentType(filename);
+ if (type == null)
+ type = "application/octet-stream";
+ }
+ }
+ } catch (IOException ex) {
+ // ignore
+ } finally {
+ try {
+ in.close();
+ } catch (IOException ex) {
+ // ignore it
+ }
+ if (filename == UNKNOWN)
+ filename = null;
+ if (type == UNKNOWN || type == null)
+ type = "text/plain";
+ }
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/outlook/MSMessage.java b/src/Java/Jars/javamail-samples/javamail-samples/outlook/MSMessage.java
new file mode 100644
index 0000000..e0e03e9
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/outlook/MSMessage.java
@@ -0,0 +1,231 @@
+/*
+ * Copyright (c) 1997-2011 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.io.*;
+import javax.mail.*;
+import javax.mail.internet.*;
+import javax.activation.*;
+
+/**
+ * This class models a UUEncoded Message sent from MS Outlook etc.
+ *
+ * The message structure looks like this :=
+ * [text body] [uuencoded attachment]*
+ *
+ * i.e., an optional text/plain main-body, followed by zero or more
+ * UUENCODE-ed attachments.
+ *
+ * @author John Mani
+ * @author Bill Shannon
+ * @see javax.mail.internet.MimeMessage
+ */
+
+public class MSMessage extends MimeMessage {
+ private String type;
+
+ /**
+ * Constructor that converts a MimeMessage object into a MSMessage.
+ *
+ * @exception MessagingException if the given MimeMessage
+ * is not a non-MIME MS message, or if an
+ * IOException occurs when accessing the given
+ * MimeMessage object
+ */
+ public MSMessage(Session session, MimeMessage msg)
+ throws MessagingException {
+ super(session);
+
+ if (!isMSMessage(msg)) // sanity check
+ throw new MessagingException("Not an MS message");
+
+ class FastByteArrayOutputStream extends ByteArrayOutputStream {
+ ByteArrayInputStream toByteArrayInputStream() {
+ return new ByteArrayInputStream(buf, 0, count);
+ }
+ }
+
+ // extract the bytes of the given message
+ // ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ FastByteArrayOutputStream bos = new FastByteArrayOutputStream();
+ try {
+ msg.writeTo(bos);
+ } catch (IOException ioex) {
+ throw new MessagingException("IOException", ioex);
+ } catch (Exception ex) {
+ throw new MessagingException("Exception", ex);
+ }
+ //parse(new ByteArrayInputStream(bos.toByteArray()));
+ parse(bos.toByteArrayInputStream());
+ }
+
+ /**
+ * Constructor to create a MSMessage from the given InputStream.
+ */
+ public MSMessage(Session session, InputStream is)
+ throws MessagingException {
+ super(session); // setup headerstore etc
+ parse(is);
+ }
+
+ // parse input stream
+ protected void parse(InputStream is) throws MessagingException {
+ // Create a buffered input stream for efficiency
+ if (!(is instanceof ByteArrayInputStream) &&
+ !(is instanceof BufferedInputStream))
+ is = new BufferedInputStream(is);
+
+ // Load headerstore
+ headers.load(is);
+
+ /*
+ * Load the content into a byte[].
+ * This byte[] is shared among the bodyparts.
+ */
+ try {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ int b;
+ // XXX - room for performance improvement
+ while ((b = is.read()) != -1)
+ bos.write(b);
+ content = bos.toByteArray();
+ } catch (IOException ioex) {
+ throw new MessagingException("IOException", ioex);
+ }
+
+ /*
+ * Check whether this is multipart.
+ */
+ boolean isMulti = false;
+ // check for presence of X-MS-Attachment header
+ String[] att = getHeader("X-MS-Attachment");
+ if (att != null && att.length > 0)
+ isMulti = true;
+ else {
+ /*
+ * Fall back to scanning the content.
+ * We scan the content until we find a sequence that looks
+ * like the start of a uuencoded block, i.e., "begin".
+ * If found, we claim that this is a multipart message.
+ */
+ for (int i = 0; i < content.length; i++) {
+ int b = content[i] & 0xff; // mask higher byte
+ if (b == '\r' || b == '\n') {
+ // start of a new line
+ if ((i + 5) < content.length) {
+ // can there be a "begin" now?
+ String s = toString(content, i+1, i+6);
+ if (s.equalsIgnoreCase("begin")) {
+ isMulti= true;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ if (isMulti) {
+ type = "multipart/mixed";
+ dh = new DataHandler(new MSMultipartDataSource(this, content));
+ } else {
+ type = "text/plain"; // charset = ?
+ dh = new DataHandler(new MimePartDataSource(this));
+ }
+
+ modified = false;
+ }
+
+ /**
+ * Return content-type
+ */
+ public String getContentType() throws MessagingException {
+ return type;
+ }
+
+ /**
+ * Return content-disposition
+ */
+ public String getDisposition() throws MessagingException {
+ return "inline";
+ }
+
+ /**
+ * Return content-transfer-encoding
+ */
+ public String getEncoding() throws MessagingException {
+ return "7bit";
+ }
+
+ /**
+ * Check whether the given MimeMessage object represents a
+ * non-MIME message sent by Outlook. Such a message will
+ * have no MIME-Version header, may have an X-Mailer header
+ * that includes the word "Microsoft", and will have at least
+ * one X-MS-Attachment header.
+ */
+ public static boolean isMSMessage(MimeMessage msg)
+ throws MessagingException {
+ // Check whether the MIME header is present
+ if (msg.getHeader("MIME-Version") != null)
+ // MIME-Version header present, should be a MIME message
+ return false;
+
+ /*
+ * XXX - disabled X-Mailer check because many sample messages
+ * I saw didn't have an X-Mailer header at all.
+ */
+ if (false) {
+ // Check X-Mailer
+ String mailer = msg.getHeader("X-mailer", null);
+ if (mailer == null) // No X-mailer ?
+ return false; // Oh well !
+ if (mailer.indexOf("Microsoft") == -1) // Not MS stuff ?
+ return false;
+ }
+
+ // Check X-MS-Attachment header
+ // XXX - not all such messages have this header
+ String[] att = msg.getHeader("X-MS-Attachment");
+ if (att == null || att.length == 0)
+ return false;
+
+ return true;
+ }
+
+ // convert given byte array of ASCII characters to string
+ static String toString(byte[] b, int start, int end) {
+ int size = end - start;
+ char[] theChars = new char[size];
+
+ for (int i = 0, j = start; i < size; )
+ theChars[i++] = (char)b[j++];
+ return new String(theChars);
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/outlook/MSMultipartDataSource.java b/src/Java/Jars/javamail-samples/javamail-samples/outlook/MSMultipartDataSource.java
new file mode 100644
index 0000000..9788e19
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/outlook/MSMultipartDataSource.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 1997-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.util.*;
+import javax.mail.*;
+import javax.mail.internet.*;
+
+/**
+ * A special MultipartDataSource used with MSMessage.
+ *
+ * @author John Mani
+ * @author Bill Shannon
+ */
+public class MSMultipartDataSource extends MimePartDataSource
+ implements MultipartDataSource {
+ //private List parts;
+ private List parts;
+
+ public MSMultipartDataSource(MimePart part, byte[] content)
+ throws MessagingException {
+ super(part);
+ //parts = new ArrayList();
+ parts = new ArrayList();
+
+ /*
+ * Parse the text of the message to find the attachments.
+ *
+ * Currently we just look for the lines that mark the
+ * begin and end of uuencoded data, but this can be
+ * fooled by similar text in the message body. Instead,
+ * we could use the Encoding header, which indicates how
+ * many lines are in each body part. For example:
+ *
+ * Encoding: 41 TEXT, 38 UUENCODE, 3155 UUENCODE, 1096 UUENCODE
+ *
+ * Similarly, we could get the filenames of the attachments
+ * from the X-MS-Attachment headers. For example:
+ *
+ * X-MS-Attachment: ATT00000.htx 0 00-00-1980 00:00
+ * X-MS-Attachment: Serengeti 2GG.mpp 0 00-00-1980 00:00
+ * X-MS-Attachment: project team update 031298.doc 0 00-00-1980 00:00
+ *
+ * (Note that there might be unquoted spaces in the filename.)
+ */
+ int pos = startsWith(content, 0, "begin");
+ if (pos == -1)
+ throw new MessagingException("invalid multipart");
+
+ if (pos > 0) // we have an unencoded main body part
+ parts.add(new MSBodyPart(content, 0, pos, "inline", "7bit"));
+ else // no main body part
+ pos = 0;
+
+ // now collect all the uuencoded individual body parts
+ int start;
+ for (;;) {
+ start = startsWith(content, pos, "begin");
+ if (start == -1)
+ break;
+ pos = startsWith(content, start, "end");
+ if (pos == -1)
+ break;
+ pos += 3; // skip to the end of "end"
+ parts.add(new MSBodyPart(content, start, pos,
+ "attachment", "uuencode"));
+ }
+ }
+
+ public int getCount() {
+ return parts.size();
+ }
+
+ public BodyPart getBodyPart(int index) throws MessagingException {
+ return (BodyPart)parts.get(index);
+ }
+
+ /**
+ * This method scans the given byte[], beginning at "start", for
+ * lines that begin with the sequence "seq". If found, the start
+ * position of the sequence within the byte[] is returned.
+ */
+ private int startsWith(byte[] content, int start, String seq) {
+ int slen = seq.length();
+ boolean bol = true;
+ for (int i = start; i < content.length; i++) {
+ if (bol) {
+ if ((i + slen) < content.length) {
+ String s = MSMessage.toString(content, i, i + slen);
+ if (s.equalsIgnoreCase(seq))
+ return i;
+ }
+ }
+ int b = content[i] & 0xff;
+ bol = b == '\r' || b == '\n';
+ }
+ return -1;
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/outlook/README.txt b/src/Java/Jars/javamail-samples/javamail-samples/outlook/README.txt
new file mode 100644
index 0000000..36cdea5
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/outlook/README.txt
@@ -0,0 +1,9 @@
+The classes in this directory allow processing old style non-MIME
+messages created by Microsoft Outlook. Use them like this:
+
+ if (MSMessage.isMSMessage(msg))
+ msg = new MSMessage(session, msg);
+
+Note that these classes are not particularly efficient or optimized,
+but they show how to process these non-MIME messages and make them
+look like MIME messages.
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/populate.java b/src/Java/Jars/javamail-samples/javamail-samples/populate.java
new file mode 100644
index 0000000..0969eb2
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/populate.java
@@ -0,0 +1,252 @@
+/*
+ * Copyright (c) 1997-2016 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import javax.mail.*;
+import javax.mail.internet.*;
+
+/*
+ * Copy folder hierarchies between different Stores. This is a useful
+ * utility to populate new (and possibly empty) mail stores. Specify
+ * both the source and destination folders as URLs.
+ *
+ * @author John Mani
+ * @author Bill Shannon
+ */
+
+public class populate {
+
+ static boolean force = false;
+ static boolean skipSpecial = false;
+ static boolean clear = false;
+ static boolean dontPreserveFlags = false;
+ static boolean warn = false;
+
+ public static void main(String argv[]) {
+ String srcURL = null;
+ String dstURL = null;
+ boolean debug = false;
+
+ int optind;
+
+ for (optind = 0; optind < argv.length; optind++) {
+ if (argv[optind].equals("-s")) {
+ srcURL = argv[++optind];
+ } else if (argv[optind].equals("-d")) {
+ dstURL = argv[++optind];
+ } else if (argv[optind].equals("-D")) {
+ debug = true;
+ } else if (argv[optind].equals("-f")) {
+ force = true;
+ } else if (argv[optind].equals("-S")) {
+ skipSpecial = true;
+ } else if (argv[optind].equals("-c")) {
+ clear = true;
+ } else if (argv[optind].equals("-P")) {
+ dontPreserveFlags = true;
+ } else if (argv[optind].equals("-W")) {
+ warn = true;
+ } else if (argv[optind].equals("--")) {
+ optind++;
+ break;
+ } else if (argv[optind].startsWith("-")) {
+ printUsage();
+ System.exit(1);
+ } else {
+ break;
+ }
+ }
+
+ try {
+
+ if (srcURL == null || dstURL == null) {
+ printUsage();
+ System.exit(1);
+ }
+
+ Session session = Session.getInstance(
+ System.getProperties(), null);
+ session.setDebug(debug);
+
+ // Get source folder
+ URLName srcURLName = new URLName(srcURL);
+ Folder srcFolder;
+ // Check if the source URL has a folder specified. If
+ // not, we use the default folder
+ if (srcURLName.getFile() == null) {
+ Store s = session.getStore(srcURLName);
+ s.connect();
+ srcFolder = s.getDefaultFolder();
+ } else {
+ srcFolder = session.getFolder(new URLName(srcURL));
+ if (!srcFolder.exists()) {
+ System.out.println("source folder does not exist");
+ srcFolder.getStore().close();
+ System.exit(1);
+ }
+ }
+
+ // Set up destination folder
+ URLName dstURLName = new URLName(dstURL);
+ Folder dstFolder;
+ // Check if the destination URL has a folder specified. If
+ // not, we use the source folder name
+ if (dstURLName.getFile() == null) {
+ Store s = session.getStore(dstURLName);
+ s.connect();
+ dstFolder = s.getFolder(srcFolder.getName());
+ } else
+ dstFolder = session.getFolder(dstURLName);
+
+ if (clear && dstFolder.exists()) {
+ if (!dstFolder.delete(true)) {
+ System.out.println("couldn't delete " +
+ dstFolder.getFullName());
+ return;
+ }
+ }
+ copy(srcFolder, dstFolder);
+
+ // Close the respective stores.
+ srcFolder.getStore().close();
+ dstFolder.getStore().close();
+
+ } catch (MessagingException mex) {
+ System.out.println(mex.getMessage());
+ mex.printStackTrace();
+ }
+ }
+
+ private static void copy(Folder src, Folder dst)
+ throws MessagingException {
+ System.out.println("Populating " + dst.getFullName());
+
+ Folder ddst = dst;
+ Folder[] srcFolders = null;
+ if ((src.getType() & Folder.HOLDS_FOLDERS) != 0)
+ srcFolders = src.list();
+ boolean srcHasChildren = srcFolders != null && srcFolders.length > 0;
+
+ if (!dst.exists()) {
+ // Create it.
+ boolean dstHoldsOnlyFolders = false;
+ if (!dst.create(src.getType())) {
+ // might not be able to create a folder that holds both
+ if (!dst.create(srcHasChildren ? Folder.HOLDS_FOLDERS :
+ Folder.HOLDS_MESSAGES)) {
+ // might only be able to create one type (Gmail)
+ if (!dst.create(Folder.HOLDS_MESSAGES)) {
+ System.out.println("couldn't create " +
+ dst.getFullName());
+ return;
+ }
+ }
+ dstHoldsOnlyFolders = srcHasChildren;
+ }
+
+ // Copy over any messges from src to dst
+ if ((src.getType() & Folder.HOLDS_MESSAGES) != 0) {
+ src.open(Folder.READ_ONLY);
+ if (dstHoldsOnlyFolders) {
+ if (src.getMessageCount() > 0) {
+ System.out.println("Unable to copy messages from " +
+ src.getFullName() + " to " + dst.getFullName() +
+ " because destination holds only folders");
+ }
+ } else
+ copyMessages(src, dst);
+ src.close(false);
+ }
+ } else {
+ System.out.println(dst.getFullName() + " already exists");
+ // Copy over any messges from src to dst
+ if (force && (src.getType() & Folder.HOLDS_MESSAGES) != 0) {
+ src.open(Folder.READ_ONLY);
+ copyMessages(src, dst);
+ src.close(false);
+ }
+ }
+
+ // Copy over subfolders
+ if (srcHasChildren) {
+ for (int i = 0; i < srcFolders.length; i++) {
+ // skip special directories?
+ if (skipSpecial) {
+ if (srcFolders[i].getName().equals("SCCS") ||
+ srcFolders[i].getName().equals("Drafts") ||
+ srcFolders[i].getName().equals("Trash") ||
+ srcFolders[i].getName().equals("Shared Folders"))
+ continue;
+ }
+ copy(srcFolders[i], dst.getFolder(srcFolders[i].getName()));
+ }
+ }
+ }
+
+ /**
+ * Copy message from src to dst. If dontPreserveFlags is set
+ * we first copy the messages to memory, clear all the flags,
+ * and then copy to the destination.
+ */
+ private static void copyMessages(Folder src, Folder dst)
+ throws MessagingException {
+ Message[] msgs = src.getMessages();
+ if (dontPreserveFlags) {
+ for (int i = 0; i < msgs.length; i++) {
+ MimeMessage m = new MimeMessage((MimeMessage)msgs[i]);
+ m.setFlags(m.getFlags(), false);
+ msgs[i] = m;
+ }
+ }
+ if (warn) {
+ // have to copy messages one at a time
+ for (int i = 0; i < msgs.length; i++) {
+ try {
+ src.copyMessages(new Message[] { msgs[i] }, dst);
+ } catch (MessagingException mex) {
+ System.out.println("WARNING: Copy of message " + (i + 1) +
+ " from " + src.getFullName() +
+ " to " + dst.getFullName() +
+ " failed: " + mex.toString());
+ }
+ }
+ } else
+ src.copyMessages(msgs, dst);
+ }
+
+ private static void printUsage() {
+ System.out.println("populate [-D] [-f] [-S] [-c] " +
+ "-s source_url -d dest_url");
+ System.out.println("URLs are of the form: " +
+ "protocol://username:password@hostname/foldername");
+ System.out.println("The destination URL does not need a foldername," +
+ " in which case, the source foldername is used");
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/registry.java b/src/Java/Jars/javamail-samples/javamail-samples/registry.java
new file mode 100644
index 0000000..0578c9e
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/registry.java
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 1997-2013 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.util.*;
+
+import javax.mail.*;
+import javax.mail.internet.*;
+
+/**
+ * This class demonstrates how to query the registry for available
+ * Providers, set default providers, etc. See section 5.2 in the
+ * JavaMail Spec for details on how to use the registry.
+ *
+ * See the comments inline for what's happening.
+ *
+ * @author Max Spivak
+ */
+
+public class registry {
+ // let's remember a few providers
+ static Provider _aProvider, _bProvider, _sunSMTP, _sunIMAP;
+
+ public static void main(String[] args) {
+ Properties props = new Properties();
+
+ // set smtp and imap to be our default
+ // transport and store protocols, respectively
+ props.put("mail.transport.protocol", "smtp");
+ props.put("mail.store.protocol", "imap");
+
+ //
+ props.put("mail.smtp.class", "com.sun.mail.smtp.SMTPTransport");
+ props.put("mail.imap.class", "com.sun.mail.imap.IMAPStore");
+
+ Session session = Session.getInstance(props, null);
+ //session.setDebug(true);
+
+ // Retrieve all configured providers from the Session
+ System.out.println("\n------ getProviders()----------");
+ Provider[] providers = session.getProviders();
+ for (int i = 0; i < providers.length; i++) {
+ System.out.println("** " + providers[i]);
+
+ // let's remember some providers so that we can use them later
+ // (I'm explicitly showing multiple ways of testing Providers)
+ // BTW, no Provider "ACME Corp" will be found in the default
+ // setup b/c its not in any javamail.providers resource files
+ String s = null;
+ if (((s = providers[i].getVendor()) != null) &&
+ s.startsWith("ACME Corp")) {
+ _aProvider = providers[i];
+ }
+
+ // this Provider won't be found by default either
+ if (providers[i].getClassName().endsWith("application.smtp"))
+ _bProvider = providers[i];
+
+ // this Provider will be found since com.sun.mail.imap.IMAPStore
+ // is configured in javamail.default.providers
+ if (providers[i].getClassName().equals("com.sun.mail.imap.IMAPStore")){
+ _sunIMAP = providers[i];
+ }
+
+ // this Provider will be found as well since there is an
+ // Oracle SMTP transport configured by
+ // default in javamail.default.providers
+ if (((s = providers[i].getVendor()) != null) &&
+ s.startsWith("Oracle") &&
+ providers[i].getType() == Provider.Type.TRANSPORT &&
+ providers[i].getProtocol().equalsIgnoreCase("smtp")) {
+ _sunSMTP = providers[i];
+ }
+ }
+
+ System.out.println("\n------ initial protocol defaults -------");
+ try {
+ System.out.println("imap: " + session.getProvider("imap"));
+ System.out.println("smtp: " + session.getProvider("smtp"));
+ // the NNTP provider will fail since we don't have one configured
+ System.out.println("nntp: " + session.getProvider("nntp"));
+ } catch (NoSuchProviderException mex) {
+ System.out.println(">> This exception is OK since there is no NNTP Provider configured by default");
+ mex.printStackTrace();
+ }
+
+ System.out.println("\n------ set new protocol defaults ------");
+ // set some new defaults
+ try {
+ // since _aProvider isn't configured, this will fail
+ session.setProvider(_aProvider); // will fail
+ } catch (NoSuchProviderException mex) {
+ System.out.println(">> Exception expected: _aProvider is null");
+ mex.printStackTrace();
+ }
+ try {
+ // _sunIMAP provider should've configured correctly; should work
+ session.setProvider(_sunIMAP);
+ } catch (NoSuchProviderException mex) { mex.printStackTrace(); }
+ try {
+ System.out.println("imap: " + session.getProvider("imap"));
+ System.out.println("smtp: " + session.getProvider("smtp"));
+ } catch (NoSuchProviderException mex) { mex.printStackTrace(); }
+
+
+ System.out.println("\n\n----- get some stores ---------");
+ // multiple ways to retrieve stores. these will print out the
+ // string "imap:" since its the URLName for the store
+ try {
+ System.out.println("getStore(): " + session.getStore());
+ System.out.println("getStore(Provider): " +
+ session.getStore(_sunIMAP));
+ } catch (NoSuchProviderException mex) {
+ mex.printStackTrace();
+ }
+
+ try {
+ System.out.println("getStore(imap): " + session.getStore("imap"));
+ // pop3 will fail since it doesn't exist
+ System.out.println("getStore(pop3): " + session.getStore("pop3"));
+ } catch (NoSuchProviderException mex) {
+ System.out.println(">> Exception expected: no pop3 provider");
+ mex.printStackTrace();
+ }
+
+
+ System.out.println("\n\n----- now for transports/addresses ---------");
+ // retrieve transports; these will print out "smtp:" (like stores did)
+ try {
+ System.out.println("getTransport(): " + session.getTransport());
+ System.out.println("getTransport(Provider): " +
+ session.getTransport(_sunSMTP));
+ System.out.println("getTransport(smtp): " +
+ session.getTransport("smtp"));
+ System.out.println("getTransport(Address): " +
+ session.getTransport(new InternetAddress("mspivak@apilon")));
+ // News will fail since there's no news provider configured
+ System.out.println("getTransport(News): " +
+ session.getTransport(new NewsAddress("rec.humor")));
+ } catch (MessagingException mex) {
+ System.out.println(">> Exception expected: no news provider configured");
+ mex.printStackTrace();
+ }
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/search.java b/src/Java/Jars/javamail-samples/javamail-samples/search.java
new file mode 100644
index 0000000..9be8a7b
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/search.java
@@ -0,0 +1,322 @@
+/*
+ * Copyright (c) 1997-2013 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.util.*;
+import java.io.*;
+import javax.mail.*;
+import javax.mail.internet.*;
+import javax.mail.search.*;
+import javax.activation.*;
+
+/*
+ * Search the given folder for messages matching the given
+ * criteria.
+ *
+ * @author John Mani
+ */
+
+public class search {
+
+ static String protocol = "imap";
+ static String host = null;
+ static String user = null;
+ static String password = null;
+ static String mbox = "INBOX";
+ static String url = null;
+ static boolean debug = false;
+
+ public static void main(String argv[]) {
+ int optind;
+
+ String subject = null;
+ String from = null;
+ boolean or = false;
+ boolean today = false;
+ int size = -1;
+
+ for (optind = 0; optind < argv.length; optind++) {
+ if (argv[optind].equals("-T")) {
+ protocol = argv[++optind];
+ } else if (argv[optind].equals("-H")) {
+ host = argv[++optind];
+ } else if (argv[optind].equals("-U")) {
+ user = argv[++optind];
+ } else if (argv[optind].equals("-P")) {
+ password = argv[++optind];
+ } else if (argv[optind].equals("-or")) {
+ or = true;
+ } else if (argv[optind].equals("-D")) {
+ debug = true;
+ } else if (argv[optind].equals("-f")) {
+ mbox = argv[++optind];
+ } else if (argv[optind].equals("-L")) {
+ url = argv[++optind];
+ } else if (argv[optind].equals("-subject")) {
+ subject = argv[++optind];
+ } else if (argv[optind].equals("-from")) {
+ from = argv[++optind];
+ } else if (argv[optind].equals("-today")) {
+ today = true;
+ } else if (argv[optind].equals("-size")) {
+ size = Integer.parseInt(argv[++optind]);
+ } else if (argv[optind].equals("--")) {
+ optind++;
+ break;
+ } else if (argv[optind].startsWith("-")) {
+ System.out.println(
+ "Usage: search [-D] [-L url] [-T protocol] [-H host] " +
+ "[-U user] [-P password] [-f mailbox] " +
+ "[-subject subject] [-from from] [-or] [-today]");
+ System.exit(1);
+ } else {
+ break;
+ }
+ }
+
+ try {
+
+ if ((subject == null) && (from == null) && !today && size < 0) {
+ System.out.println(
+ "Specify either -subject, -from, -today, or -size");
+ System.exit(1);
+ }
+
+ // Get a Properties object
+ Properties props = System.getProperties();
+
+ // Get a Session object
+ Session session = Session.getInstance(props, null);
+ session.setDebug(debug);
+
+ // Get a Store object
+ Store store = null;
+ if (url != null) {
+ URLName urln = new URLName(url);
+ store = session.getStore(urln);
+ store.connect();
+ } else {
+ if (protocol != null)
+ store = session.getStore(protocol);
+ else
+ store = session.getStore();
+
+ // Connect
+ if (host != null || user != null || password != null)
+ store.connect(host, user, password);
+ else
+ store.connect();
+ }
+
+
+ // Open the Folder
+
+ Folder folder = store.getDefaultFolder();
+ if (folder == null) {
+ System.out.println("Cant find default namespace");
+ System.exit(1);
+ }
+
+ folder = folder.getFolder(mbox);
+ if (folder == null) {
+ System.out.println("Invalid folder");
+ System.exit(1);
+ }
+
+ folder.open(Folder.READ_ONLY);
+ SearchTerm term = null;
+
+ if (subject != null)
+ term = new SubjectTerm(subject);
+ if (from != null) {
+ FromStringTerm fromTerm = new FromStringTerm(from);
+ if (term != null) {
+ if (or)
+ term = new OrTerm(term, fromTerm);
+ else
+ term = new AndTerm(term, fromTerm);
+ }
+ else
+ term = fromTerm;
+ }
+ if (today) {
+ Calendar c = Calendar.getInstance();
+ c.set(Calendar.HOUR, 0);
+ c.set(Calendar.MINUTE, 0);
+ c.set(Calendar.SECOND, 0);
+ c.set(Calendar.MILLISECOND, 0);
+ c.set(Calendar.AM_PM, Calendar.AM);
+ ReceivedDateTerm startDateTerm =
+ new ReceivedDateTerm(ComparisonTerm.GE, c.getTime());
+ c.add(Calendar.DATE, 1); // next day
+ ReceivedDateTerm endDateTerm =
+ new ReceivedDateTerm(ComparisonTerm.LT, c.getTime());
+ SearchTerm dateTerm = new AndTerm(startDateTerm, endDateTerm);
+ if (term != null) {
+ if (or)
+ term = new OrTerm(term, dateTerm);
+ else
+ term = new AndTerm(term, dateTerm);
+ }
+ else
+ term = dateTerm;
+ }
+
+ if (size >= 0) {
+ SizeTerm sizeTerm = new SizeTerm(ComparisonTerm.GT, size);
+ if (term != null) {
+ if (or)
+ term = new OrTerm(term, sizeTerm);
+ else
+ term = new AndTerm(term, sizeTerm);
+ }
+ else
+ term = sizeTerm;
+ }
+
+ Message[] msgs = folder.search(term);
+ System.out.println("FOUND " + msgs.length + " MESSAGES");
+ if (msgs.length == 0) // no match
+ System.exit(1);
+
+ // Use a suitable FetchProfile
+ FetchProfile fp = new FetchProfile();
+ fp.add(FetchProfile.Item.ENVELOPE);
+ folder.fetch(msgs, fp);
+
+ for (int i = 0; i < msgs.length; i++) {
+ System.out.println("--------------------------");
+ System.out.println("MESSAGE #" + (i + 1) + ":");
+ dumpPart(msgs[i]);
+ }
+
+ folder.close(false);
+ store.close();
+ } catch (Exception ex) {
+ System.out.println("Oops, got exception! " + ex.getMessage());
+ ex.printStackTrace();
+ }
+
+ System.exit(1);
+ }
+
+ public static void dumpPart(Part p) throws Exception {
+ if (p instanceof Message) {
+ Message m = (Message)p;
+ Address[] a;
+ // FROM
+ if ((a = m.getFrom()) != null) {
+ for (int j = 0; j < a.length; j++)
+ System.out.println("FROM: " + a[j].toString());
+ }
+
+ // TO
+ if ((a = m.getRecipients(Message.RecipientType.TO)) != null) {
+ for (int j = 0; j < a.length; j++)
+ System.out.println("TO: " + a[j].toString());
+ }
+
+ // SUBJECT
+ System.out.println("SUBJECT: " + m.getSubject());
+
+ // DATE
+ Date d = m.getSentDate();
+ System.out.println("SendDate: " +
+ (d != null ? d.toLocaleString() : "UNKNOWN"));
+
+ // FLAGS:
+ Flags flags = m.getFlags();
+ StringBuffer sb = new StringBuffer();
+ Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags
+
+ boolean first = true;
+ for (int i = 0; i < sf.length; i++) {
+ String s;
+ Flags.Flag f = sf[i];
+ if (f == Flags.Flag.ANSWERED)
+ s = "\\Answered";
+ else if (f == Flags.Flag.DELETED)
+ s = "\\Deleted";
+ else if (f == Flags.Flag.DRAFT)
+ s = "\\Draft";
+ else if (f == Flags.Flag.FLAGGED)
+ s = "\\Flagged";
+ else if (f == Flags.Flag.RECENT)
+ s = "\\Recent";
+ else if (f == Flags.Flag.SEEN)
+ s = "\\Seen";
+ else
+ continue; // skip it
+ if (first)
+ first = false;
+ else
+ sb.append(' ');
+ sb.append(s);
+ }
+
+ String[] uf = flags.getUserFlags(); // get the user flag strings
+ for (int i = 0; i < uf.length; i++) {
+ if (first)
+ first = false;
+ else
+ sb.append(' ');
+ sb.append(uf[i]);
+ }
+ System.out.println("FLAGS = " + sb.toString());
+ }
+
+ System.out.println("CONTENT-TYPE: " + p.getContentType());
+
+ /* Dump input stream
+ InputStream is = ((MimeMessage)m).getInputStream();
+ int c;
+ while ((c = is.read()) != -1)
+ System.out.write(c);
+ */
+
+ Object o = p.getContent();
+ if (o instanceof String) {
+ System.out.println("This is a String");
+ System.out.println((String)o);
+ } else if (o instanceof Multipart) {
+ System.out.println("This is a Multipart");
+ Multipart mp = (Multipart)o;
+ int count = mp.getCount();
+ for (int i = 0; i < count; i++)
+ dumpPart(mp.getBodyPart(i));
+ } else if (o instanceof InputStream) {
+ System.out.println("This is just an input stream");
+ InputStream is = (InputStream)o;
+ int c;
+ while ((c = is.read()) != -1)
+ System.out.write(c);
+ }
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/sendfile.java b/src/Java/Jars/javamail-samples/javamail-samples/sendfile.java
new file mode 100644
index 0000000..7ab3ccd
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/sendfile.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 1996-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.util.*;
+import java.io.*;
+import javax.mail.*;
+import javax.mail.internet.*;
+import javax.activation.*;
+
+/**
+ * sendfile will create a multipart message with the second
+ * block of the message being the given file.
+ *
+ * This demonstrates how to use the FileDataSource to send
+ * a file via mail.
+ *
+ * usage: java sendfile to from smtp file true|false
+ * where to and from are the destination and
+ * origin email addresses, respectively, and smtp
+ * is the hostname of the machine that has smtp server
+ * running. file is the file to send. The next parameter
+ * either turns on or turns off debugging during sending.
+ *
+ * @author Christopher Cotton
+ */
+public class sendfile {
+
+ public static void main(String[] args) {
+ if (args.length != 5) {
+ System.out.println("usage: java sendfile true|false");
+ System.exit(1);
+ }
+
+ String to = args[0];
+ String from = args[1];
+ String host = args[2];
+ String filename = args[3];
+ boolean debug = Boolean.valueOf(args[4]).booleanValue();
+ String msgText1 = "Sending a file.\n";
+ String subject = "Sending a file";
+
+ // create some properties and get the default Session
+ Properties props = System.getProperties();
+ props.put("mail.smtp.host", host);
+
+ Session session = Session.getInstance(props, null);
+ session.setDebug(debug);
+
+ try {
+ // create a message
+ MimeMessage msg = new MimeMessage(session);
+ msg.setFrom(new InternetAddress(from));
+ InternetAddress[] address = {new InternetAddress(to)};
+ msg.setRecipients(Message.RecipientType.TO, address);
+ msg.setSubject(subject);
+
+ // create and fill the first message part
+ MimeBodyPart mbp1 = new MimeBodyPart();
+ mbp1.setText(msgText1);
+
+ // create the second message part
+ MimeBodyPart mbp2 = new MimeBodyPart();
+
+ // attach the file to the message
+ mbp2.attachFile(filename);
+
+ /*
+ * Use the following approach instead of the above line if
+ * you want to control the MIME type of the attached file.
+ * Normally you should never need to do this.
+ *
+ FileDataSource fds = new FileDataSource(filename) {
+ public String getContentType() {
+ return "application/octet-stream";
+ }
+ };
+ mbp2.setDataHandler(new DataHandler(fds));
+ mbp2.setFileName(fds.getName());
+ */
+
+ // create the Multipart and add its parts to it
+ Multipart mp = new MimeMultipart();
+ mp.addBodyPart(mbp1);
+ mp.addBodyPart(mbp2);
+
+ // add the Multipart to the message
+ msg.setContent(mp);
+
+ // set the Date: header
+ msg.setSentDate(new Date());
+
+ /*
+ * If you want to control the Content-Transfer-Encoding
+ * of the attached file, do the following. Normally you
+ * should never need to do this.
+ *
+ msg.saveChanges();
+ mbp2.setHeader("Content-Transfer-Encoding", "base64");
+ */
+
+ // send the message
+ Transport.send(msg);
+
+ } catch (MessagingException mex) {
+ mex.printStackTrace();
+ Exception ex = null;
+ if ((ex = mex.getNextException()) != null) {
+ ex.printStackTrace();
+ }
+ } catch (IOException ioex) {
+ ioex.printStackTrace();
+ }
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/sendhtml.java b/src/Java/Jars/javamail-samples/javamail-samples/sendhtml.java
new file mode 100644
index 0000000..5d67cdf
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/sendhtml.java
@@ -0,0 +1,237 @@
+/*
+ * Copyright (c) 1998-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.io.*;
+import java.util.Properties;
+import java.util.Date;
+
+import javax.mail.*;
+import javax.activation.*;
+import javax.mail.internet.*;
+import javax.mail.util.*;
+
+/**
+ * Demo app that shows how to construct and send a single part html
+ * message. Note that the same basic technique can be used to send
+ * data of any type.
+ *
+ * @author John Mani
+ * @author Bill Shannon
+ * @author Max Spivak
+ */
+
+public class sendhtml {
+
+ public static void main(String[] argv) {
+ new sendhtml(argv);
+ }
+
+ public sendhtml(String[] argv) {
+
+ String to, subject = null, from = null,
+ cc = null, bcc = null, url = null;
+ String mailhost = null;
+ String mailer = "sendhtml";
+ String protocol = null, host = null, user = null, password = null;
+ String record = null; // name of folder in which to record mail
+ boolean debug = false;
+ BufferedReader in =
+ new BufferedReader(new InputStreamReader(System.in));
+ int optind;
+
+ for (optind = 0; optind < argv.length; optind++) {
+ if (argv[optind].equals("-T")) {
+ protocol = argv[++optind];
+ } else if (argv[optind].equals("-H")) {
+ host = argv[++optind];
+ } else if (argv[optind].equals("-U")) {
+ user = argv[++optind];
+ } else if (argv[optind].equals("-P")) {
+ password = argv[++optind];
+ } else if (argv[optind].equals("-M")) {
+ mailhost = argv[++optind];
+ } else if (argv[optind].equals("-f")) {
+ record = argv[++optind];
+ } else if (argv[optind].equals("-s")) {
+ subject = argv[++optind];
+ } else if (argv[optind].equals("-o")) { // originator
+ from = argv[++optind];
+ } else if (argv[optind].equals("-c")) {
+ cc = argv[++optind];
+ } else if (argv[optind].equals("-b")) {
+ bcc = argv[++optind];
+ } else if (argv[optind].equals("-L")) {
+ url = argv[++optind];
+ } else if (argv[optind].equals("-d")) {
+ debug = true;
+ } else if (argv[optind].equals("--")) {
+ optind++;
+ break;
+ } else if (argv[optind].startsWith("-")) {
+ System.out.println(
+"Usage: sendhtml [[-L store-url] | [-T prot] [-H host] [-U user] [-P passwd]]");
+ System.out.println(
+"\t[-s subject] [-o from-address] [-c cc-addresses] [-b bcc-addresses]");
+ System.out.println(
+"\t[-f record-mailbox] [-M transport-host] [-d] [address]");
+ System.exit(1);
+ } else {
+ break;
+ }
+ }
+
+ try {
+ if (optind < argv.length) {
+ // XXX - concatenate all remaining arguments
+ to = argv[optind];
+ System.out.println("To: " + to);
+ } else {
+ System.out.print("To: ");
+ System.out.flush();
+ to = in.readLine();
+ }
+ if (subject == null) {
+ System.out.print("Subject: ");
+ System.out.flush();
+ subject = in.readLine();
+ } else {
+ System.out.println("Subject: " + subject);
+ }
+
+ Properties props = System.getProperties();
+ // XXX - could use Session.getTransport() and Transport.connect()
+ // XXX - assume we're using SMTP
+ if (mailhost != null)
+ props.put("mail.smtp.host", mailhost);
+
+ // Get a Session object
+ Session session = Session.getInstance(props, null);
+ if (debug)
+ session.setDebug(true);
+
+ // construct the message
+ Message msg = new MimeMessage(session);
+ if (from != null)
+ msg.setFrom(new InternetAddress(from));
+ else
+ msg.setFrom();
+
+ msg.setRecipients(Message.RecipientType.TO,
+ InternetAddress.parse(to, false));
+ if (cc != null)
+ msg.setRecipients(Message.RecipientType.CC,
+ InternetAddress.parse(cc, false));
+ if (bcc != null)
+ msg.setRecipients(Message.RecipientType.BCC,
+ InternetAddress.parse(bcc, false));
+
+ msg.setSubject(subject);
+
+ collect(in, msg);
+
+ msg.setHeader("X-Mailer", mailer);
+ msg.setSentDate(new Date());
+
+ // send the thing off
+ Transport.send(msg);
+
+ System.out.println("\nMail was sent successfully.");
+
+ // Keep a copy, if requested.
+
+ if (record != null) {
+ // Get a Store object
+ Store store = null;
+ if (url != null) {
+ URLName urln = new URLName(url);
+ store = session.getStore(urln);
+ store.connect();
+ } else {
+ if (protocol != null)
+ store = session.getStore(protocol);
+ else
+ store = session.getStore();
+
+ // Connect
+ if (host != null || user != null || password != null)
+ store.connect(host, user, password);
+ else
+ store.connect();
+ }
+
+ // Get record Folder. Create if it does not exist.
+ Folder folder = store.getFolder(record);
+ if (folder == null) {
+ System.err.println("Can't get record folder.");
+ System.exit(1);
+ }
+ if (!folder.exists())
+ folder.create(Folder.HOLDS_MESSAGES);
+
+ Message[] msgs = new Message[1];
+ msgs[0] = msg;
+ folder.appendMessages(msgs);
+
+ System.out.println("Mail was recorded successfully.");
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void collect(BufferedReader in, Message msg)
+ throws MessagingException, IOException {
+ String line;
+ String subject = msg.getSubject();
+ StringBuffer sb = new StringBuffer();
+ sb.append("\n");
+ sb.append("\n");
+ sb.append("\n");
+ sb.append(subject + "\n");
+ sb.append("\n");
+ sb.append("\n");
+
+ sb.append("\n");
+ sb.append("
" + subject + "
" + "\n");
+
+ while ((line = in.readLine()) != null) {
+ sb.append(line);
+ sb.append("\n");
+ }
+
+ sb.append("\n");
+ sb.append("\n");
+
+ msg.setDataHandler(new DataHandler(
+ new ByteArrayDataSource(sb.toString(), "text/html")));
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/smtpsend.java b/src/Java/Jars/javamail-samples/javamail-samples/smtpsend.java
new file mode 100644
index 0000000..b43cc52
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/smtpsend.java
@@ -0,0 +1,371 @@
+/*
+ * Copyright (c) 1997-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.io.*;
+import java.net.InetAddress;
+import java.util.Properties;
+import java.util.Date;
+
+import javax.mail.*;
+import javax.mail.internet.*;
+
+import com.sun.mail.smtp.*;
+
+/**
+ * Demo app that shows how to construct and send an RFC822
+ * (singlepart) message.
+ *
+ * XXX - allow more than one recipient on the command line
+ *
+ * This is just a variant of msgsend.java that demonstrates use of
+ * some SMTP-specific features.
+ *
+ * @author Max Spivak
+ * @author Bill Shannon
+ */
+
+public class smtpsend {
+
+ /**
+ * Example of how to extend the SMTPTransport class.
+ * This example illustrates how to issue the XACT
+ * command before the SMTPTransport issues the DATA
+ * command.
+ *
+ public static class SMTPExtension extends SMTPTransport {
+ public SMTPExtension(Session session, URLName url) {
+ super(session, url);
+ // to check that we're being used
+ System.out.println("SMTPExtension: constructed");
+ }
+
+ protected synchronized OutputStream data() throws MessagingException {
+ if (supportsExtension("XACCOUNTING"))
+ issueCommand("XACT", 250);
+ return super.data();
+ }
+ }
+ */
+
+ public static void main(String[] argv) {
+ String to, subject = null, from = null,
+ cc = null, bcc = null, url = null;
+ String mailhost = null;
+ String mailer = "smtpsend";
+ String file = null;
+ String protocol = null, host = null, user = null, password = null;
+ String record = null; // name of folder in which to record mail
+ boolean debug = false;
+ boolean verbose = false;
+ boolean auth = false;
+ String prot = "smtp";
+ BufferedReader in =
+ new BufferedReader(new InputStreamReader(System.in));
+ int optind;
+
+ /*
+ * Process command line arguments.
+ */
+ for (optind = 0; optind < argv.length; optind++) {
+ if (argv[optind].equals("-T")) {
+ protocol = argv[++optind];
+ } else if (argv[optind].equals("-H")) {
+ host = argv[++optind];
+ } else if (argv[optind].equals("-U")) {
+ user = argv[++optind];
+ } else if (argv[optind].equals("-P")) {
+ password = argv[++optind];
+ } else if (argv[optind].equals("-M")) {
+ mailhost = argv[++optind];
+ } else if (argv[optind].equals("-f")) {
+ record = argv[++optind];
+ } else if (argv[optind].equals("-a")) {
+ file = argv[++optind];
+ } else if (argv[optind].equals("-s")) {
+ subject = argv[++optind];
+ } else if (argv[optind].equals("-o")) { // originator
+ from = argv[++optind];
+ } else if (argv[optind].equals("-c")) {
+ cc = argv[++optind];
+ } else if (argv[optind].equals("-b")) {
+ bcc = argv[++optind];
+ } else if (argv[optind].equals("-L")) {
+ url = argv[++optind];
+ } else if (argv[optind].equals("-d")) {
+ debug = true;
+ } else if (argv[optind].equals("-v")) {
+ verbose = true;
+ } else if (argv[optind].equals("-A")) {
+ auth = true;
+ } else if (argv[optind].equals("-S")) {
+ prot = "smtps";
+ } else if (argv[optind].equals("--")) {
+ optind++;
+ break;
+ } else if (argv[optind].startsWith("-")) {
+ System.out.println(
+"Usage: smtpsend [[-L store-url] | [-T prot] [-H host] [-U user] [-P passwd]]");
+ System.out.println(
+"\t[-s subject] [-o from-address] [-c cc-addresses] [-b bcc-addresses]");
+ System.out.println(
+"\t[-f record-mailbox] [-M transport-host] [-d] [-a attach-file]");
+ System.out.println(
+"\t[-v] [-A] [-S] [address]");
+ System.exit(1);
+ } else {
+ break;
+ }
+ }
+
+ try {
+ /*
+ * Prompt for To and Subject, if not specified.
+ */
+ if (optind < argv.length) {
+ // XXX - concatenate all remaining arguments
+ to = argv[optind];
+ System.out.println("To: " + to);
+ } else {
+ System.out.print("To: ");
+ System.out.flush();
+ to = in.readLine();
+ }
+ if (subject == null) {
+ System.out.print("Subject: ");
+ System.out.flush();
+ subject = in.readLine();
+ } else {
+ System.out.println("Subject: " + subject);
+ }
+
+ /*
+ * Initialize the JavaMail Session.
+ */
+ Properties props = System.getProperties();
+ if (mailhost != null)
+ props.put("mail." + prot + ".host", mailhost);
+ if (auth)
+ props.put("mail." + prot + ".auth", "true");
+
+ /*
+ * Create a Provider representing our extended SMTP transport
+ * and set the property to use our provider.
+ *
+ Provider p = new Provider(Provider.Type.TRANSPORT, prot,
+ "smtpsend$SMTPExtension", "JavaMail demo", "no version");
+ props.put("mail." + prot + ".class", "smtpsend$SMTPExtension");
+ */
+
+ // Get a Session object
+ Session session = Session.getInstance(props, null);
+ if (debug)
+ session.setDebug(true);
+
+ /*
+ * Register our extended SMTP transport.
+ *
+ session.addProvider(p);
+ */
+
+ /*
+ * Construct the message and send it.
+ */
+ Message msg = new MimeMessage(session);
+ if (from != null)
+ msg.setFrom(new InternetAddress(from));
+ else
+ msg.setFrom();
+
+ msg.setRecipients(Message.RecipientType.TO,
+ InternetAddress.parse(to, false));
+ if (cc != null)
+ msg.setRecipients(Message.RecipientType.CC,
+ InternetAddress.parse(cc, false));
+ if (bcc != null)
+ msg.setRecipients(Message.RecipientType.BCC,
+ InternetAddress.parse(bcc, false));
+
+ msg.setSubject(subject);
+
+ String text = collect(in);
+
+ if (file != null) {
+ // Attach the specified file.
+ // We need a multipart message to hold the attachment.
+ MimeBodyPart mbp1 = new MimeBodyPart();
+ mbp1.setText(text);
+ MimeBodyPart mbp2 = new MimeBodyPart();
+ mbp2.attachFile(file);
+ MimeMultipart mp = new MimeMultipart();
+ mp.addBodyPart(mbp1);
+ mp.addBodyPart(mbp2);
+ msg.setContent(mp);
+ } else {
+ // If the desired charset is known, you can use
+ // setText(text, charset)
+ msg.setText(text);
+ }
+
+ msg.setHeader("X-Mailer", mailer);
+ msg.setSentDate(new Date());
+
+ // send the thing off
+ /*
+ * The simple way to send a message is this:
+ *
+ Transport.send(msg);
+ *
+ * But we're going to use some SMTP-specific features for
+ * demonstration purposes so we need to manage the Transport
+ * object explicitly.
+ */
+ SMTPTransport t =
+ (SMTPTransport)session.getTransport(prot);
+ try {
+ if (auth)
+ t.connect(mailhost, user, password);
+ else
+ t.connect();
+ t.sendMessage(msg, msg.getAllRecipients());
+ } finally {
+ if (verbose)
+ System.out.println("Response: " +
+ t.getLastServerResponse());
+ t.close();
+ }
+
+ System.out.println("\nMail was sent successfully.");
+
+ /*
+ * Save a copy of the message, if requested.
+ */
+ if (record != null) {
+ // Get a Store object
+ Store store = null;
+ if (url != null) {
+ URLName urln = new URLName(url);
+ store = session.getStore(urln);
+ store.connect();
+ } else {
+ if (protocol != null)
+ store = session.getStore(protocol);
+ else
+ store = session.getStore();
+
+ // Connect
+ if (host != null || user != null || password != null)
+ store.connect(host, user, password);
+ else
+ store.connect();
+ }
+
+ // Get record Folder. Create if it does not exist.
+ Folder folder = store.getFolder(record);
+ if (folder == null) {
+ System.err.println("Can't get record folder.");
+ System.exit(1);
+ }
+ if (!folder.exists())
+ folder.create(Folder.HOLDS_MESSAGES);
+
+ Message[] msgs = new Message[1];
+ msgs[0] = msg;
+ folder.appendMessages(msgs);
+
+ System.out.println("Mail was recorded successfully.");
+ }
+
+ } catch (Exception e) {
+ /*
+ * Handle SMTP-specific exceptions.
+ */
+ if (e instanceof SendFailedException) {
+ MessagingException sfe = (MessagingException)e;
+ if (sfe instanceof SMTPSendFailedException) {
+ SMTPSendFailedException ssfe =
+ (SMTPSendFailedException)sfe;
+ System.out.println("SMTP SEND FAILED:");
+ if (verbose)
+ System.out.println(ssfe.toString());
+ System.out.println(" Command: " + ssfe.getCommand());
+ System.out.println(" RetCode: " + ssfe.getReturnCode());
+ System.out.println(" Response: " + ssfe.getMessage());
+ } else {
+ if (verbose)
+ System.out.println("Send failed: " + sfe.toString());
+ }
+ Exception ne;
+ while ((ne = sfe.getNextException()) != null &&
+ ne instanceof MessagingException) {
+ sfe = (MessagingException)ne;
+ if (sfe instanceof SMTPAddressFailedException) {
+ SMTPAddressFailedException ssfe =
+ (SMTPAddressFailedException)sfe;
+ System.out.println("ADDRESS FAILED:");
+ if (verbose)
+ System.out.println(ssfe.toString());
+ System.out.println(" Address: " + ssfe.getAddress());
+ System.out.println(" Command: " + ssfe.getCommand());
+ System.out.println(" RetCode: " + ssfe.getReturnCode());
+ System.out.println(" Response: " + ssfe.getMessage());
+ } else if (sfe instanceof SMTPAddressSucceededException) {
+ System.out.println("ADDRESS SUCCEEDED:");
+ SMTPAddressSucceededException ssfe =
+ (SMTPAddressSucceededException)sfe;
+ if (verbose)
+ System.out.println(ssfe.toString());
+ System.out.println(" Address: " + ssfe.getAddress());
+ System.out.println(" Command: " + ssfe.getCommand());
+ System.out.println(" RetCode: " + ssfe.getReturnCode());
+ System.out.println(" Response: " + ssfe.getMessage());
+ }
+ }
+ } else {
+ System.out.println("Got Exception: " + e);
+ if (verbose)
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * Read the body of the message until EOF.
+ */
+ public static String collect(BufferedReader in) throws IOException {
+ String line;
+ StringBuffer sb = new StringBuffer();
+ while ((line = in.readLine()) != null) {
+ sb.append(line);
+ sb.append("\n");
+ }
+ return sb.toString();
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/transport.java b/src/Java/Jars/javamail-samples/javamail-samples/transport.java
new file mode 100644
index 0000000..16d272e
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/transport.java
@@ -0,0 +1,233 @@
+/*
+ * Copyright (c) 1997-2011 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.util.*;
+import javax.mail.*;
+import javax.mail.internet.*;
+import javax.mail.event.*;
+import javax.activation.*;
+
+/**
+ * transport is a simple program that creates a message, explicitly
+ * retrieves a Transport from the session based on the type of the
+ * address (it's InternetAddress, so SMTP will be used) and sends
+ * the message.
+ *
+ * usage: java transport "toaddr1[, toaddr2]*" from smtphost
+ * true|false
+ * where to and from are the destination and
+ * origin email addresses, respectively, and smtphost
+ * is the hostname of the machine that has the smtp server
+ * running. The to addresses can be either a single email
+ * address or a comma-separated list of email addresses in
+ * quotes, i.e. "joe@machine, jane, max@server.com"
+ * The last parameter either turns on or turns off
+ * debugging during sending.
+ *
+ * @author Max Spivak
+ */
+public class transport implements ConnectionListener, TransportListener {
+ static String msgText = "This is a message body.\nHere's the second line.";
+ static String msgText2 = "\nThis was sent by transport.java demo program.";
+
+ public static void main(String[] args) {
+ Properties props = System.getProperties();
+ // parse the arguments
+ InternetAddress[] addrs = null;
+ InternetAddress from;
+ boolean debug = false;
+ if (args.length != 4) {
+ usage();
+ return;
+ } else {
+ props.put("mail.smtp.host", args[2]);
+ if (args[3].equals("true")) {
+ debug = true;
+ } else if (args[3].equals("false")) {
+ debug = false;
+ } else {
+ usage();
+ return;
+ }
+
+ // parse the destination addresses
+ try {
+ addrs = InternetAddress.parse(args[0], false);
+ from = new InternetAddress(args[1]);
+ } catch (AddressException aex) {
+ System.out.println("Invalid Address");
+ aex.printStackTrace();
+ return;
+ }
+ }
+ // create some properties and get a Session
+ Session session = Session.getInstance(props, null);
+ session.setDebug(debug);
+
+ transport t = new transport();
+ t.go(session, addrs, from);
+ }
+
+ public transport() {}
+
+ public void go(Session session, InternetAddress[] toAddr,
+ InternetAddress from) {
+ Transport trans = null;
+
+ try {
+ // create a message
+ Message msg = new MimeMessage(session);
+ msg.setFrom(from);
+ msg.setRecipients(Message.RecipientType.TO, toAddr);
+ msg.setSubject("JavaMail APIs transport.java Test");
+ msg.setSentDate(new Date()); // Date: header
+ msg.setContent(msgText+msgText2, "text/plain");
+ msg.saveChanges();
+
+ // get the smtp transport for the address
+ trans = session.getTransport(toAddr[0]);
+
+ // register ourselves as listener for ConnectionEvents
+ // and TransportEvents
+ trans.addConnectionListener(this);
+ trans.addTransportListener(this);
+
+ // connect the transport
+ trans.connect();
+
+ // send the message
+ trans.sendMessage(msg, toAddr);
+
+ // give the EventQueue enough time to fire its events
+ try {Thread.sleep(5);}catch(InterruptedException e) {}
+
+ } catch (MessagingException mex) {
+ // give the EventQueue enough time to fire its events
+ try {Thread.sleep(5);}catch(InterruptedException e) {}
+
+ System.out.println("Sending failed with exception:");
+ mex.printStackTrace();
+ System.out.println();
+ Exception ex = mex;
+ do {
+ if (ex instanceof SendFailedException) {
+ SendFailedException sfex = (SendFailedException)ex;
+ Address[] invalid = sfex.getInvalidAddresses();
+ if (invalid != null) {
+ System.out.println(" ** Invalid Addresses");
+ for (int i = 0; i < invalid.length; i++)
+ System.out.println(" " + invalid[i]);
+ }
+ Address[] validUnsent = sfex.getValidUnsentAddresses();
+ if (validUnsent != null) {
+ System.out.println(" ** ValidUnsent Addresses");
+ for (int i = 0; i < validUnsent.length; i++)
+ System.out.println(" "+validUnsent[i]);
+ }
+ Address[] validSent = sfex.getValidSentAddresses();
+ if (validSent != null) {
+ System.out.println(" ** ValidSent Addresses");
+ for (int i = 0; i < validSent.length; i++)
+ System.out.println(" "+validSent[i]);
+ }
+ }
+ System.out.println();
+ if (ex instanceof MessagingException)
+ ex = ((MessagingException)ex).getNextException();
+ else
+ ex = null;
+ } while (ex != null);
+ } finally {
+ try {
+ // close the transport
+ if (trans != null)
+ trans.close();
+ } catch (MessagingException mex) { /* ignore */ }
+ }
+ }
+
+ // implement ConnectionListener interface
+ public void opened(ConnectionEvent e) {
+ System.out.println(">>> ConnectionListener.opened()");
+ }
+ public void disconnected(ConnectionEvent e) {}
+ public void closed(ConnectionEvent e) {
+ System.out.println(">>> ConnectionListener.closed()");
+ }
+
+ // implement TransportListener interface
+ public void messageDelivered(TransportEvent e) {
+ System.out.println(">>> TransportListener.messageDelivered().");
+ System.out.println(" Valid Addresses:");
+ Address[] valid = e.getValidSentAddresses();
+ if (valid != null) {
+ for (int i = 0; i < valid.length; i++)
+ System.out.println(" " + valid[i]);
+ }
+ }
+ public void messageNotDelivered(TransportEvent e) {
+ System.out.println(">>> TransportListener.messageNotDelivered().");
+ System.out.println(" Invalid Addresses:");
+ Address[] invalid = e.getInvalidAddresses();
+ if (invalid != null) {
+ for (int i = 0; i < invalid.length; i++)
+ System.out.println(" " + invalid[i]);
+ }
+ }
+ public void messagePartiallyDelivered(TransportEvent e) {
+ System.out.println(">>> TransportListener.messagePartiallyDelivered().");
+ System.out.println(" Valid Addresses:");
+ Address[] valid = e.getValidSentAddresses();
+ if (valid != null) {
+ for (int i = 0; i < valid.length; i++)
+ System.out.println(" " + valid[i]);
+ }
+ System.out.println(" Valid Unsent Addresses:");
+ Address[] unsent = e.getValidUnsentAddresses();
+ if (unsent != null) {
+ for (int i = 0; i < unsent.length; i++)
+ System.out.println(" " + unsent[i]);
+ }
+ System.out.println(" Invalid Addresses:");
+ Address[] invalid = e.getInvalidAddresses();
+ if (invalid != null) {
+ for (int i = 0; i < invalid.length; i++)
+ System.out.println(" " + invalid[i]);
+ }
+ }
+
+ private static void usage() {
+ System.out.println(
+ "usage: java transport \"[, ]*\" true|false");
+ System.out.println(
+ "example: java transport \"joe@machine, jane\" senderaddr smtphost false");
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/uidmsgshow.java b/src/Java/Jars/javamail-samples/javamail-samples/uidmsgshow.java
new file mode 100644
index 0000000..805f029
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/uidmsgshow.java
@@ -0,0 +1,308 @@
+/*
+ * Copyright (c) 1997-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+import java.util.*;
+import java.io.*;
+import javax.mail.*;
+import javax.mail.internet.*;
+import javax.activation.*;
+
+/*
+ * Demo app that exercises the Message interfaces.
+ * Access message given its UID.
+ * Show information about and contents of messages.
+ *
+ * @author John Mani
+ * @author Bill Shannon
+ */
+
+public class uidmsgshow {
+
+ static String protocol;
+ static String host = null;
+ static String user = null;
+ static String password = null;
+ static String mbox = "INBOX";
+ static String url = null;
+ static boolean verbose = false;
+
+ public static void main(String argv[]) {
+ long uid = -1;
+ int optind;
+
+ for (optind = 0; optind < argv.length; optind++) {
+ if (argv[optind].equals("-T")) {
+ protocol = argv[++optind];
+ } else if (argv[optind].equals("-H")) {
+ host = argv[++optind];
+ } else if (argv[optind].equals("-U")) {
+ user = argv[++optind];
+ } else if (argv[optind].equals("-P")) {
+ password = argv[++optind];
+ } else if (argv[optind].equals("-v")) {
+ verbose = true;
+ } else if (argv[optind].equals("-f")) {
+ mbox = argv[++optind];
+ } else if (argv[optind].equals("-L")) {
+ url = argv[++optind];
+ } else if (argv[optind].equals("--")) {
+ optind++;
+ break;
+ } else if (argv[optind].startsWith("-")) {
+ System.out.println("Usage: uidmsgshow [-L url] [-T protocol] [-H host] [-U user] [-P password] [-f mailbox] [uid] [-v]");
+ System.exit(1);
+ } else {
+ break;
+ }
+ }
+
+ try {
+ if (optind < argv.length)
+ uid = Long.parseLong(argv[optind]);
+
+ // Get a Properties object
+ Properties props = System.getProperties();
+
+ // Get a Session object
+ Session session = Session.getInstance(props, null);
+ // session.setDebug(true);
+
+ // Get a Store object
+ Store store = null;
+ if (url != null) {
+ URLName urln = new URLName(url);
+ store = session.getStore(urln);
+ store.connect();
+ } else {
+ if (protocol != null)
+ store = session.getStore(protocol);
+ else
+ store = session.getStore();
+
+ // Connect
+ if (host != null || user != null || password != null)
+ store.connect(host, user, password);
+ else
+ store.connect();
+ }
+
+
+ // Open the Folder
+
+ Folder folder = store.getDefaultFolder();
+ if (folder == null) {
+ System.out.println("No default folder");
+ System.exit(1);
+ }
+
+ folder = folder.getFolder(mbox);
+ if (!folder.exists()) {
+ System.out.println(mbox + " does not exist");
+ System.exit(1);
+ }
+
+ if (!(folder instanceof UIDFolder)) {
+ System.out.println(
+ "This Provider or this folder does not support UIDs");
+ System.exit(1);
+ }
+
+ UIDFolder ufolder = (UIDFolder)folder;
+
+ folder.open(Folder.READ_WRITE);
+ int totalMessages = folder.getMessageCount();
+
+ if (totalMessages == 0) {
+ System.out.println("Empty folder");
+ folder.close(false);
+ store.close();
+ System.exit(1);
+ }
+
+ if (verbose) {
+ int newMessages = folder.getNewMessageCount();
+ System.out.println("Total messages = " + totalMessages);
+ System.out.println("New messages = " + newMessages);
+ System.out.println("-------------------------------");
+ }
+
+ if (uid == -1) {
+ // Attributes & Flags for ALL messages ..
+ Message[] msgs =
+ ufolder.getMessagesByUID(1, UIDFolder.LASTUID);
+
+ // Use a suitable FetchProfile
+ FetchProfile fp = new FetchProfile();
+ fp.add(FetchProfile.Item.ENVELOPE);
+ fp.add(FetchProfile.Item.FLAGS);
+ fp.add("X-Mailer");
+ folder.fetch(msgs, fp);
+
+ for (int i = 0; i < msgs.length; i++) {
+ System.out.println("--------------------------");
+ System.out.println("MESSAGE UID #" +
+ ufolder.getUID(msgs[i]) + ":");
+ dumpEnvelope(msgs[i]);
+ // dumpPart(msgs[i]);
+ }
+ } else {
+ System.out.println("Getting message UID: " + uid);
+ Message m = ufolder.getMessageByUID(uid);
+ if (m != null)
+ dumpPart(m);
+ else
+ System.out.println(
+ "This Message does not exist on this folder");
+ }
+
+ folder.close(false);
+ store.close();
+ } catch (Exception ex) {
+ System.out.println("Oops, got exception! " + ex.getMessage());
+ ex.printStackTrace();
+ }
+ System.exit(1);
+ }
+
+ public static void dumpPart(Part p) throws Exception {
+ if (p instanceof Message)
+ dumpEnvelope((Message)p);
+
+ /* Dump input stream
+ InputStream is = new BufferedInputStream(p.getInputStream());
+ int c;
+ while ((c = is.read()) != -1)
+ System.out.write(c);
+ */
+
+ System.out.println("CONTENT-TYPE: " + p.getContentType());
+
+ Object o = p.getContent();
+ if (o instanceof String) {
+ System.out.println("This is a String");
+ System.out.println("---------------------------");
+ System.out.println((String)o);
+ } else if (o instanceof Multipart) {
+ System.out.println("This is a Multipart");
+ System.out.println("---------------------------");
+ Multipart mp = (Multipart)o;
+ int count = mp.getCount();
+ for (int i = 0; i < count; i++)
+ dumpPart(mp.getBodyPart(i));
+ } else if (o instanceof Message) {
+ System.out.println("This is a Nested Message");
+ System.out.println("---------------------------");
+ dumpPart((Part)o);
+ } else if (o instanceof InputStream) {
+ System.out.println("This is just an input stream");
+ System.out.println("---------------------------");
+ InputStream is = (InputStream)o;
+ int c;
+ while ((c = is.read()) != -1)
+ System.out.write(c);
+ }
+ }
+
+ public static void dumpEnvelope(Message m) throws Exception {
+ System.out.println("This is the message envelope");
+ System.out.println("---------------------------");
+ Address[] a;
+ // FROM
+ if ((a = m.getFrom()) != null) {
+ for (int j = 0; j < a.length; j++)
+ System.out.println("FROM: " + a[j].toString());
+ }
+
+ // TO
+ if ((a = m.getRecipients(Message.RecipientType.TO)) != null) {
+ for (int j = 0; j < a.length; j++)
+ System.out.println("TO: " + a[j].toString());
+ }
+
+ // SUBJECT
+ System.out.println("SUBJECT: " + m.getSubject());
+
+ // DATE
+ Date d = m.getSentDate();
+ System.out.println("SendDate: " +
+ (d != null ? d.toString() : "UNKNOWN"));
+
+ // SIZE
+ System.out.println("Size: " + m.getSize());
+
+ // FLAGS:
+ Flags flags = m.getFlags();
+ StringBuffer sb = new StringBuffer();
+ Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags
+
+ boolean first = true;
+ for (int i = 0; i < sf.length; i++) {
+ String s;
+ Flags.Flag f = sf[i];
+ if (f == Flags.Flag.ANSWERED)
+ s = "\\Answered";
+ else if (f == Flags.Flag.DELETED)
+ s = "\\Deleted";
+ else if (f == Flags.Flag.DRAFT)
+ s = "\\Draft";
+ else if (f == Flags.Flag.FLAGGED)
+ s = "\\Flagged";
+ else if (f == Flags.Flag.RECENT)
+ s = "\\Recent";
+ else if (f == Flags.Flag.SEEN)
+ s = "\\Seen";
+ else
+ continue; // skip it
+ if (first)
+ first = false;
+ else
+ sb.append(' ');
+ sb.append(s);
+ }
+
+ String[] uf = flags.getUserFlags(); // get the user flag strings
+ for (int i = 0; i < uf.length; i++) {
+ if (first)
+ first = false;
+ else
+ sb.append(' ');
+ sb.append(uf[i]);
+ }
+ System.out.println("FLAGS = " + sb.toString());
+
+ // X-MAILER
+ String[] hdrs = m.getHeader("X-Mailer");
+ if (hdrs != null)
+ System.out.println("X-Mailer: " + hdrs[0]);
+ else
+ System.out.println("X-Mailer NOT available");
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/build.bat b/src/Java/Jars/javamail-samples/javamail-samples/webapp/build.bat
new file mode 100644
index 0000000..b68e59e
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/build.bat
@@ -0,0 +1,57 @@
+@echo off
+REM
+REM Copyright (c) 2010-2011 Oracle and/or its affiliates. All rights reserved.
+REM
+REM Redistribution and use in source and binary forms, with or without
+REM modification, are permitted provided that the following conditions
+REM are met:
+REM
+REM - Redistributions of source code must retain the above copyright
+REM notice, this list of conditions and the following disclaimer.
+REM
+REM - Redistributions in binary form must reproduce the above copyright
+REM notice, this list of conditions and the following disclaimer in the
+REM documentation and/or other materials provided with the distribution.
+REM
+REM - Neither the name of Oracle nor the names of its
+REM contributors may be used to endorse or promote products derived
+REM from this software without specific prior written permission.
+REM
+REM THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+REM IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+REM THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+REM PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+REM CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+REM EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+REM PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+REM PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+REM LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+REM NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+REM SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+REM
+mkdir src\docroot\WEB-INF\classes
+mkdir src\docroot\WEB-INF\classes\demo
+mkdir src\docroot\WEB-INF\lib
+cd src\classes
+echo compiling classes directory
+javac -d ..\docroot\WEB-INF\classes demo\*.java
+cd ..\taglib
+echo compiling lib directory
+javac -classpath "..\docroot\WEB-INF\classes;%CLASSPATH%" demo\*.java
+echo creating tag library archive
+jar cvf ..\docroot\WEB-INF\lib\taglib.jar META-INF demo\*.class
+del demo\*.class
+cd ..\docroot
+echo creating web archive
+jar cvf ..\..\javamail.war index.html *.jsp WEB-INF
+cd WEB-INF\classes\demo
+del *.*
+cd ..
+rmdir demo
+cd ..
+rmdir classes
+cd lib
+del *.*
+cd ..
+rmdir lib
+cd ..\..\..
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/build.sh b/src/Java/Jars/javamail-samples/javamail-samples/webapp/build.sh
new file mode 100644
index 0000000..1030b41
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/build.sh
@@ -0,0 +1,48 @@
+#
+# Copyright (c) 2010-2011 Oracle and/or its affiliates. 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
+# documentation and/or other materials provided with the distribution.
+#
+# - 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.
+#
+
+mkdir src/docroot/WEB-INF/classes
+mkdir src/docroot/WEB-INF/lib
+cd src/classes
+echo "compiling classes directory"
+javac -d ../docroot/WEB-INF/classes demo/*.java
+cd ../taglib
+echo "compiling lib directroy"
+javac -classpath ../docroot/WEB-INF/classes:$CLASSPATH demo/*.java
+echo "creating tag library archive"
+jar cvf ../docroot/WEB-INF/lib/taglib.jar META-INF demo/*.class
+rm demo/*.class
+cd ../docroot
+echo "creating web archive"
+jar cvf ../../javamail.war index.html *.jsp WEB-INF
+rm -r WEB-INF/classes
+rm -r WEB-INF/lib
+cd ../..
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/javamail.war b/src/Java/Jars/javamail-samples/javamail-samples/webapp/javamail.war
new file mode 100644
index 0000000..4ca0997
Binary files /dev/null and b/src/Java/Jars/javamail-samples/javamail-samples/webapp/javamail.war differ
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/classes/demo/AttachmentServlet.java b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/classes/demo/AttachmentServlet.java
new file mode 100644
index 0000000..365ab88
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/classes/demo/AttachmentServlet.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2001-2011 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+package demo;
+
+import java.io.*;
+import javax.mail.*;
+import javax.mail.internet.*;
+import javax.servlet.*;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+/**
+ * This servlet gets the input stream for a given msg part and
+ * pushes it out to the browser with the correct content type.
+ * Used to display attachments and relies on the browser's
+ * content handling capabilities.
+ */
+public class AttachmentServlet extends HttpServlet {
+
+ /**
+ * This method handles the GET requests from the client.
+ */
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException {
+
+ HttpSession session = request.getSession();
+ ServletOutputStream out = response.getOutputStream();
+ int msgNum = Integer.parseInt(request.getParameter("message"));
+ int partNum = Integer.parseInt(request.getParameter("part"));
+ MailUserBean mailuser = (MailUserBean)session.getAttribute("mailuser");
+
+ // check to be sure we're still logged in
+ if (mailuser.isLoggedIn()) {
+ try {
+ Message msg = mailuser.getFolder().getMessage(msgNum);
+
+ Multipart multipart = (Multipart)msg.getContent();
+ Part part = multipart.getBodyPart(partNum);
+
+ String sct = part.getContentType();
+ if (sct == null) {
+ out.println("invalid part");
+ return;
+ }
+ ContentType ct = new ContentType(sct);
+
+ response.setContentType(ct.getBaseType());
+ InputStream is = part.getInputStream();
+ int i;
+ while ((i = is.read()) != -1)
+ out.write(i);
+ out.flush();
+ out.close();
+
+ } catch (MessagingException ex) {
+ throw new ServletException(ex.getMessage());
+ }
+ } else {
+ getServletConfig().getServletContext().
+ getRequestDispatcher("/index.html").
+ forward(request, response);
+ }
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/classes/demo/FilterServlet.java b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/classes/demo/FilterServlet.java
new file mode 100644
index 0000000..5cfe73d
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/classes/demo/FilterServlet.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2001-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+package demo;
+
+import java.io.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+/**
+ * This servlet is used to determine whether the user is logged in before
+ * forwarding the request to the selected URL.
+ */
+public class FilterServlet extends HttpServlet {
+
+ /**
+ * This method handles the "POST" submission from two forms: the
+ * login form and the message compose form.
+ */
+ public void doPost(HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException, ServletException {
+
+ String servletPath = request.getServletPath();
+ servletPath = servletPath.concat(".jsp");
+
+ getServletConfig().getServletContext().
+ getRequestDispatcher("/" + servletPath).forward(request, response);
+ }
+
+ /**
+ * This method handles the GET requests from the client.
+ */
+ public void doGet(HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException, ServletException {
+
+ // check to be sure we're still logged in
+ // before forwarding the request.
+ HttpSession session = request.getSession();
+ MailUserBean mailuser = (MailUserBean)session.getAttribute("mailuser");
+ String servletPath = request.getServletPath();
+ servletPath = servletPath.concat(".jsp");
+
+ if (mailuser.isLoggedIn())
+ getServletConfig().getServletContext().
+ getRequestDispatcher("/" + servletPath).
+ forward(request, response);
+ else
+ getServletConfig().getServletContext().
+ getRequestDispatcher("/index.html").
+ forward(request, response);
+ }
+}
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/classes/demo/MailUserBean.java b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/classes/demo/MailUserBean.java
new file mode 100644
index 0000000..1fcfdd6
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/classes/demo/MailUserBean.java
@@ -0,0 +1,210 @@
+/*
+ * Copyright (c) 2001-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+package demo;
+
+import java.util.*;
+import javax.mail.*;
+import javax.naming.*;
+
+/**
+ * This JavaBean is used to store mail user information.
+ */
+public class MailUserBean {
+ private Folder folder;
+ private String hostname;
+ private String username;
+ private String password;
+ private Session session;
+ private Store store;
+ private URLName url;
+ private String protocol = "imap";
+ private String mbox = "INBOX";
+
+ public MailUserBean(){}
+
+ /**
+ * Returns the javax.mail.Folder object.
+ */
+ public Folder getFolder() {
+ return folder;
+ }
+
+ /**
+ * Returns the number of messages in the folder.
+ */
+ public int getMessageCount() throws MessagingException {
+ return folder.getMessageCount();
+ }
+
+ /**
+ * hostname getter method.
+ */
+ public String getHostname() {
+ return hostname;
+ }
+
+ /**
+ * hostname setter method.
+ */
+ public void setHostname(String hostname) {
+ this.hostname = hostname;
+ }
+
+ /**
+ * username getter method.
+ */
+ public String getUsername() {
+ return username;
+ }
+
+ /**
+ * username setter method.
+ */
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ /**
+ * password getter method.
+ */
+ public String getPassword() {
+ return password;
+ }
+
+ /**
+ * password setter method.
+ */
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ /**
+ * session getter method.
+ */
+ public Session getSession() {
+ return session;
+ }
+
+ /**
+ * session setter method.
+ */
+ public void setSession(Session session) {
+ this.session = session;
+ }
+
+ /**
+ * store getter method.
+ */
+ public Store getStore() {
+ return store;
+ }
+
+ /**
+ * store setter method.
+ */
+ public void setStore(Store store) {
+ this.store = store;
+ }
+
+ /**
+ * url getter method.
+ */
+ public URLName getUrl() {
+ return url;
+ }
+
+ /**
+ * Method for checking if the user is logged in.
+ */
+ public boolean isLoggedIn() {
+ return store.isConnected();
+ }
+
+ /**
+ * Method used to login to the mail host.
+ */
+ public void login() throws Exception {
+ url = new URLName(protocol, getHostname(), -1, mbox,
+ getUsername(), getPassword());
+ /*
+ * First, try to get the session from JNDI,
+ * as would be done under J2EE.
+ */
+ try {
+ InitialContext ic = new InitialContext();
+ Context ctx = (Context)ic.lookup("java:comp/env");
+ session = (Session)ctx.lookup("MySession");
+ } catch (Exception ex) {
+ // ignore it
+ }
+
+ // if JNDI fails, try the old way that should work everywhere
+ if (session == null) {
+ Properties props = null;
+ try {
+ props = System.getProperties();
+ } catch (SecurityException sex) {
+ props = new Properties();
+ }
+ session = Session.getInstance(props, null);
+ }
+ store = session.getStore(url);
+ store.connect();
+ folder = store.getFolder(url);
+
+ folder.open(Folder.READ_WRITE);
+ }
+
+ /**
+ * Method used to login to the mail host.
+ */
+ public void login(String hostname, String username, String password)
+ throws Exception {
+
+ this.hostname = hostname;
+ this.username = username;
+ this.password = password;
+
+ login();
+ }
+
+ /**
+ * Method used to logout from the mail host.
+ */
+ public void logout() throws MessagingException {
+ folder.close(false);
+ store.close();
+ store = null;
+ session = null;
+ }
+}
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/WEB-INF/web.xml b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/WEB-INF/web.xml
new file mode 100644
index 0000000..088ab66
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/WEB-INF/web.xml
@@ -0,0 +1,87 @@
+
+
+
+
+ JspDemo
+ no description
+
+ FilterServlet
+ FilterServlet
+ no description
+ demo.FilterServlet
+
+
+ AttachmentServlet
+ AttachmentServlet
+ no description
+ demo.AttachmentServlet
+
+
+ FilterServlet
+ /compose
+
+
+ FilterServlet
+ /errordetails
+
+
+ FilterServlet
+ /login
+
+
+ FilterServlet
+ /logout
+
+
+ FilterServlet
+ /send
+
+
+ FilterServlet
+ /messageheaders
+
+
+ FilterServlet
+ /messagecontent
+
+
+ AttachmentServlet
+ /attachment
+
+
+ MySession
+ javax.mail.Session
+ Container
+
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/compose.jsp b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/compose.jsp
new file mode 100644
index 0000000..9ba0dc1
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/compose.jsp
@@ -0,0 +1,86 @@
+<%--
+
+ Copyright (c) 2001-2010 Oracle and/or its affiliates. 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
+ documentation and/or other materials provided with the distribution.
+
+ - 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.
+
+--%>
+
+<%@ page language="java" %>
+<%@ page errorPage="errorpage.jsp" %>
+
+
+
+ JavaMail compose
+
+
+
+
+
+
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/errordetails.jsp b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/errordetails.jsp
new file mode 100644
index 0000000..cb1418b
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/errordetails.jsp
@@ -0,0 +1,43 @@
+<%--
+
+ Copyright (c) 2001-2010 Oracle and/or its affiliates. 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
+ documentation and/or other materials provided with the distribution.
+
+ - 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.
+
+--%>
+
+<%@ page isErrorPage="true" %>
+
+
+JavaMail errordetails
+
+
+<%= session.getValue("details") %>
+
+
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/errorpage.jsp b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/errorpage.jsp
new file mode 100644
index 0000000..685b88e
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/errorpage.jsp
@@ -0,0 +1,47 @@
+<%--
+
+ Copyright (c) 2001-2010 Oracle and/or its affiliates. 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
+ documentation and/or other materials provided with the distribution.
+
+ - 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.
+
+--%>
+
+<%@ page isErrorPage="true" %>
+
+
+JavaMail errorpage
+
+
+
+
+
+
+
+
Overview:
+
+
+THIS IS A DEMO!!! Please see the webapp.README.txt
+file for information on how to
+compile and run the web application.
+This demo illustrates the use of JavaMail APIs in a 3-tiered web
+application. It allows the user to login to an
+IMAP store, list all the messages in the INBOX folder, view
+selected messages, compose and send a message, and logout.
+
+
+
Features:
+
+
+
HTML access to your IMAP mailbox
+
Proxy-able anywhere HTTP can be proxied
+
Easy to use
+
Uses web browser's content handling capabilities
+
+
+
Limitations:
+
+
+
Only INBOX support (no user folders)
+
Can't delete, copy, move, print, save, forward, reply to, search in
+ messages --
+ but it could be done
+
Doesn't check for new messages (have to log out and log back it)
+
+
+
+
+
+
+
Feedback to javamail_ww@oracle.com
+
+
+
+
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/login.jsp b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/login.jsp
new file mode 100644
index 0000000..269179a
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/login.jsp
@@ -0,0 +1,56 @@
+<%--
+
+ Copyright (c) 2001-2010 Oracle and/or its affiliates. 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
+ documentation and/or other materials provided with the distribution.
+
+ - 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.
+
+--%>
+
+<%@ page language="java" import="demo.MailUserBean" %>
+<%@ page errorPage="errorpage.jsp" %>
+
+
+
+
+ JavaMail login
+
+
+
+
+<%
+ mailuser.login(request.getParameter("hostname"),
+ request.getParameter("username"),
+ request.getParameter("password"));
+ session.setAttribute("folder", mailuser.getFolder());
+%>
+
+
+
+
+
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/logout.jsp b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/logout.jsp
new file mode 100644
index 0000000..24ba3f5
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/logout.jsp
@@ -0,0 +1,49 @@
+<%--
+
+ Copyright (c) 2001-2010 Oracle and/or its affiliates. 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
+ documentation and/or other materials provided with the distribution.
+
+ - 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.
+
+--%>
+
+<%@ page language="java" import="demo.MailUserBean" %>
+<%@ page errorPage="errorpage.jsp" %>
+
+
+
+
+ JavaMail logout
+
+
+<% mailuser.logout(); %>
+
+
+
Logged out OK
click here to login
+
+
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/messagecontent.jsp b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/messagecontent.jsp
new file mode 100644
index 0000000..a280cd6
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/messagecontent.jsp
@@ -0,0 +1,117 @@
+<%--
+
+ Copyright (c) 2001-2010 Oracle and/or its affiliates. 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
+ documentation and/or other materials provided with the distribution.
+
+ - 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.
+
+--%>
+
+<%@ page language="java" import="demo.MessageInfo, demo.AttachmentInfo" %>
+<%@ page errorPage="errorpage.jsp" %>
+<%@ taglib uri="http://java.sun.com/products/javamail/demo/webapp"
+ prefix="javamail" %>
+
+
+
+
+ JavaMail messagecontent
+
+
+"
+/>
+
+
+
+<% } else { %>
+Filename:
+<%= attachment.getFilename() %>
+
+Description:
+<%= attachment.getDescription() %>
+
+
+Display Attachment
+<% } %>
+
+<% } %>
+
+
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/messageheaders.jsp b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/messageheaders.jsp
new file mode 100644
index 0000000..18332c7
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/messageheaders.jsp
@@ -0,0 +1,103 @@
+<%--
+
+ Copyright (c) 2001-2010 Oracle and/or its affiliates. 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
+ documentation and/or other materials provided with the distribution.
+
+ - 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.
+
+--%>
+
+<%@ page language="java" import="demo.MessageInfo" %>
+<%@ page errorPage="errorpage.jsp" %>
+<%@ taglib uri="http://java.sun.com/products/javamail/demo/webapp"
+ prefix="javamail" %>
+
+
+
+ JavaMail messageheaders
+
+
+
+
+
+
+
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/send.jsp b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/send.jsp
new file mode 100644
index 0000000..186bfe5
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/docroot/send.jsp
@@ -0,0 +1,57 @@
+<%--
+
+ Copyright (c) 2001-2010 Oracle and/or its affiliates. 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
+ documentation and/or other materials provided with the distribution.
+
+ - 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.
+
+--%>
+
+<%@ page language="java" %>
+<%@ page errorPage="errorpage.jsp" %>
+<%@ taglib uri="http://java.sun.com/products/javamail/demo/webapp"
+ prefix="javamail" %>
+
+
+
+ JavaMail send
+
+
+
+"
+ sender="<%= request.getParameter(\"from\") %>"
+ subject="<%= request.getParameter(\"subject\") %>"
+>
+<%= request.getParameter("text") %>
+
+
+
Message sent successfully
+
+
+
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/META-INF/taglib.tld b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/META-INF/taglib.tld
new file mode 100644
index 0000000..2e68f2a
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/META-INF/taglib.tld
@@ -0,0 +1,151 @@
+
+
+
+
+
+ 1.0
+ 1.1
+ javamail
+ http://java.sun.com/products/javamail/demo/webapp
+
+ listattachments
+ demo.ListAttachmentsTag
+ demo.ListAttachmentsTEI
+ JSP
+
+ A listattachments tag
+
+
+ id
+ true
+ true
+
+
+ messageinfo
+ true
+ true
+
+
+
+ listmessages
+ demo.ListMessagesTag
+ demo.ListMessagesTEI
+ JSP
+
+ A listmessages tag
+
+
+ id
+ true
+ true
+
+
+ folder
+ false
+ true
+
+
+ session
+ false
+ true
+
+
+
+ message
+ demo.MessageTag
+ demo.MessageTEI
+ empty
+
+ A message tag
+
+
+ id
+ true
+ true
+
+
+ folder
+ false
+ true
+
+
+ session
+ false
+ true
+
+
+ num
+ true
+ true
+
+
+
+ sendmail
+ demo.SendTag
+ JSP
+
+ A sendmail tag
+
+
+ host
+ false
+ true
+
+
+ recipients
+ true
+ true
+
+
+ sender
+ true
+ true
+
+
+ subject
+ false
+ true
+
+
+
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/AttachmentInfo.java b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/AttachmentInfo.java
new file mode 100644
index 0000000..13b443e
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/AttachmentInfo.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2001-2011 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+package demo;
+
+import java.io.*;
+import java.util.*;
+
+import javax.mail.*;
+import javax.mail.internet.*;
+
+/**
+ * Used to store attachment information.
+ */
+public class AttachmentInfo {
+ private Part part;
+ private int num;
+
+
+ /**
+ * Returns the attachment's content type.
+ */
+ public String getAttachmentType() throws MessagingException {
+ String contentType;
+ if ((contentType = part.getContentType()) == null)
+ return "invalid part";
+ else
+ return contentType;
+ }
+
+ /**
+ * Returns the attachment's content (if it is plain text).
+ */
+ public String getContent() throws IOException, MessagingException {
+ if (hasMimeType("text/plain"))
+ return (String)part.getContent();
+ else
+ return "";
+ }
+
+ /**
+ * Returns the attachment's description.
+ */
+ public String getDescription() throws MessagingException {
+ String description;
+ if ((description = part.getDescription()) != null)
+ return description;
+ else
+ return "";
+ }
+
+ /**
+ * Returns the attachment's filename.
+ */
+ public String getFilename() throws MessagingException {
+ String filename;
+ if ((filename = part.getFileName()) != null)
+ return filename;
+ else
+ return "";
+ }
+
+ /**
+ * Returns the attachment number.
+ */
+ public String getNum() {
+ return (Integer.toString(num));
+ }
+
+ /**
+ * Method for checking if the attachment has a description.
+ */
+ public boolean hasDescription() throws MessagingException {
+ return (part.getDescription() != null);
+ }
+
+ /**
+ * Method for checking if the attachment has a filename.
+ */
+ public boolean hasFilename() throws MessagingException {
+ return (part.getFileName() != null);
+ }
+
+ /**
+ * Method for checking if the attachment has the desired mime type.
+ */
+ public boolean hasMimeType(String mimeType) throws MessagingException {
+ return part.isMimeType(mimeType);
+ }
+
+ /**
+ * Method for checking the content disposition.
+ */
+ public boolean isInline() throws MessagingException {
+ if (part.getDisposition() != null)
+ return part.getDisposition().equals(Part.INLINE);
+ else
+ return true;
+ }
+
+ /**
+ * Method for mapping a message part to this AttachmentInfo class.
+ */
+ public void setPart(int num, Part part)
+ throws MessagingException, ParseException {
+
+ this.part = part;
+ this.num = num;
+ }
+}
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/ListAttachmentsTEI.java b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/ListAttachmentsTEI.java
new file mode 100644
index 0000000..811ae5d
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/ListAttachmentsTEI.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2001-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+package demo;
+
+import javax.servlet.jsp.*;
+import javax.servlet.jsp.tagext.*;
+
+/**
+ * Extra information class to support the scripting variable created by the
+ * ListAttachmentsTag class. The scope of the variable is limited to the body
+ * of the tag.
+ */
+public class ListAttachmentsTEI extends TagExtraInfo {
+
+ public ListAttachmentsTEI() {
+ super();
+ }
+
+ public VariableInfo[] getVariableInfo(TagData data) {
+ VariableInfo info = new VariableInfo(data.getId(),"AttachmentInfo",
+ true, VariableInfo.NESTED);
+ VariableInfo[] varInfo = { info };
+ return varInfo;
+ }
+}
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/ListAttachmentsTag.java b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/ListAttachmentsTag.java
new file mode 100644
index 0000000..18d782d
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/ListAttachmentsTag.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2001-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+package demo;
+
+import java.io.*;
+import java.util.*;
+import javax.mail.*;
+import javax.mail.internet.*;
+import javax.servlet.jsp.*;
+import javax.servlet.jsp.tagext.*;
+
+/**
+ * Custom tag for listing message attachments. The scripting variable is only
+ * within the body of the tag.
+ */
+public class ListAttachmentsTag extends BodyTagSupport {
+ private String messageinfo;
+ private int partNum = 1;
+ private int numParts = 0;
+ private AttachmentInfo attachmentinfo;
+ private MessageInfo messageInfo;
+ private Multipart multipart;
+
+ /**
+ * messageinfo attribute getter method.
+ */
+ public String getMessageinfo() {
+ return messageinfo;
+ }
+
+ /**
+ * messageinfo attribute setter method.
+ */
+ public void setMessageinfo(String messageinfo) {
+ this.messageinfo = messageinfo;
+ }
+
+ /**
+ * Method for processing the start of the tag.
+ */
+ public int doStartTag() throws JspException {
+ messageInfo = (MessageInfo)pageContext.getAttribute(getMessageinfo());
+ attachmentinfo = new AttachmentInfo();
+
+ try {
+ multipart = (Multipart)messageInfo.getMessage().getContent();
+ numParts = multipart.getCount();
+ } catch (Exception ex) {
+ throw new JspException(ex.getMessage());
+ }
+
+ getPart();
+
+ return BodyTag.EVAL_BODY_TAG;
+ }
+
+ /**
+ * Method for processing the body content of the tag.
+ */
+ public int doAfterBody() throws JspException {
+
+ BodyContent body = getBodyContent();
+ try {
+ body.writeOut(getPreviousOut());
+ } catch (IOException e) {
+ throw new JspTagException("IterationTag: " + e.getMessage());
+ }
+
+ // clear up so the next time the body content is empty
+ body.clearBody();
+
+ partNum++;
+ if (partNum < numParts) {
+ getPart();
+ return BodyTag.EVAL_BODY_TAG;
+ } else {
+ return BodyTag.SKIP_BODY;
+ }
+ }
+
+ /**
+ * Helper method for retrieving message parts.
+ */
+ private void getPart() throws JspException {
+ try {
+ attachmentinfo.setPart(partNum, multipart.getBodyPart(partNum));
+ pageContext.setAttribute(getId(), attachmentinfo);
+ } catch (Exception ex) {
+ throw new JspException(ex.getMessage());
+ }
+ }
+}
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/ListMessagesTEI.java b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/ListMessagesTEI.java
new file mode 100644
index 0000000..f0c2fcf
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/ListMessagesTEI.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2001-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+package demo;
+
+import javax.servlet.jsp.*;
+import javax.servlet.jsp.tagext.*;
+
+/**
+ * Extra information class to support the scripting variable created by the
+ * ListMessagesTag class. The scope of the variable is limited to the body
+ * of the tag.
+ */
+public class ListMessagesTEI extends TagExtraInfo {
+
+ public ListMessagesTEI() {
+ super();
+ }
+
+ public VariableInfo[] getVariableInfo(TagData data) {
+ VariableInfo info = new VariableInfo(data.getId(),"MessageInfo",
+ true, VariableInfo.NESTED);
+ VariableInfo[] varInfo = { info };
+ return varInfo;
+ }
+}
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/ListMessagesTag.java b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/ListMessagesTag.java
new file mode 100644
index 0000000..ec0608f
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/ListMessagesTag.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2001-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+package demo;
+
+import java.io.*;
+import java.util.*;
+import javax.mail.*;
+import javax.mail.internet.*;
+import javax.mail.search.*;
+import javax.servlet.jsp.*;
+import javax.servlet.jsp.tagext.*;
+
+/**
+ * Custom tag for listing messages. The scripting variable is only
+ * within the body of the tag.
+ */
+public class ListMessagesTag extends BodyTagSupport {
+ private String folder;
+ private String session;
+ private int msgNum = 0;
+ private int messageCount = 0;
+ private Message message;
+ private Message[] messages;
+ private MessageInfo messageinfo;
+
+ /**
+ * folder attribute getter method.
+ */
+ public String getFolder() {
+ return folder;
+ }
+
+ /**
+ * session attribute getter method.
+ */
+ public String getSession() {
+ return session;
+ }
+
+ /**
+ * folder setter method.
+ */
+ public void setFolder(String folder) {
+ this.folder = folder;
+ }
+
+ /**
+ * session attribute setter method.
+ */
+ public void setSession(String session) {
+ this.session = session;
+ }
+
+ /**
+ * Method for processing the start of the tag.
+ */
+ public int doStartTag() throws JspException {
+ messageinfo = new MessageInfo();
+
+ try {
+ Folder folder = (Folder)pageContext.getAttribute(
+ getFolder(), PageContext.SESSION_SCOPE);
+ FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.DELETED), false);
+ messages = folder.search(ft);
+ messageCount = messages.length;
+ msgNum = 0;
+ } catch (Exception ex) {
+ throw new JspException(ex.getMessage());
+ }
+
+ if (messageCount > 0) {
+ getMessage();
+ return BodyTag.EVAL_BODY_TAG;
+ } else
+ return BodyTag.SKIP_BODY;
+ }
+
+ /**
+ * Method for processing the body content of the tag.
+ */
+ public int doAfterBody() throws JspException {
+
+ BodyContent body = getBodyContent();
+ try {
+ body.writeOut(getPreviousOut());
+ } catch (IOException e) {
+ throw new JspTagException("IterationTag: " + e.getMessage());
+ }
+
+ // clear up so the next time the body content is empty
+ body.clearBody();
+
+ if (msgNum < messageCount) {
+ getMessage();
+ return BodyTag.EVAL_BODY_TAG;
+ } else {
+ return BodyTag.SKIP_BODY;
+ }
+ }
+
+ /**
+ * Helper method for retrieving messages.
+ */
+ private void getMessage() throws JspException {
+ message = messages[msgNum++];
+ messageinfo.setMessage(message);
+ pageContext.setAttribute(getId(), messageinfo);
+ }
+}
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/MessageInfo.java b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/MessageInfo.java
new file mode 100644
index 0000000..a2356eb
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/MessageInfo.java
@@ -0,0 +1,284 @@
+/*
+ * Copyright (c) 2001-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+package demo;
+
+import java.text.*;
+import java.util.*;
+import javax.mail.*;
+import javax.mail.internet.*;
+
+/**
+ * Used to store message information.
+ */
+public class MessageInfo {
+ private Message message;
+
+
+ /**
+ * Returns the bcc field.
+ */
+ public String getBcc() throws MessagingException {
+ return formatAddresses(
+ message.getRecipients(Message.RecipientType.BCC));
+ }
+
+ /**
+ * Returns the body of the message (if it's plain text).
+ */
+ public String getBody() throws MessagingException, java.io.IOException {
+ Object content = message.getContent();
+ if (message.isMimeType("text/plain")) {
+ return (String)content;
+ } else if (message.isMimeType("multipart/alternative")) {
+ Multipart mp = (Multipart)message.getContent();
+ int numParts = mp.getCount();
+ for (int i = 0; i < numParts; ++i) {
+ if (mp.getBodyPart(i).isMimeType("text/plain"))
+ return (String)mp.getBodyPart(i).getContent();
+ }
+ return "";
+ } else if (message.isMimeType("multipart/*")) {
+ Multipart mp = (Multipart)content;
+ if (mp.getBodyPart(0).isMimeType("text/plain"))
+ return (String)mp.getBodyPart(0).getContent();
+ else
+ return "";
+ } else
+ return "";
+ }
+
+ /**
+ * Returns the cc field.
+ */
+ public String getCc() throws MessagingException {
+ return formatAddresses(
+ message.getRecipients(Message.RecipientType.CC));
+ }
+
+ /**
+ * Returns the date the message was sent (or received if the sent date
+ * is null.
+ */
+ public String getDate() throws MessagingException {
+ Date date;
+ SimpleDateFormat df = new SimpleDateFormat("EE M/d/yy");
+ if ((date = message.getSentDate()) != null)
+ return (df.format(date));
+ else if ((date = message.getReceivedDate()) != null)
+ return (df.format(date));
+ else
+ return "";
+ }
+
+ /**
+ * Returns the from field.
+ */
+ public String getFrom() throws MessagingException {
+ return formatAddresses(message.getFrom());
+ }
+
+ /**
+ * Returns the address to reply to.
+ */
+ public String getReplyTo() throws MessagingException {
+ Address[] a = message.getReplyTo();
+ if (a.length > 0)
+ return ((InternetAddress)a[0]).getAddress();
+ else
+ return "";
+ }
+
+ /**
+ * Returns the javax.mail.Message object.
+ */
+ public Message getMessage() {
+ return message;
+ }
+
+ /**
+ * Returns the message number.
+ */
+ public String getNum() {
+ return (Integer.toString(message.getMessageNumber()));
+ }
+
+ /**
+ * Returns the received date field.
+ */
+ public String getReceivedDate() throws MessagingException {
+ if (hasReceivedDate())
+ return (message.getReceivedDate().toString());
+ else
+ return "";
+ }
+
+ /**
+ * Returns the sent date field.
+ */
+ public String getSentDate() throws MessagingException {
+ if (hasSentDate())
+ return (message.getSentDate().toString());
+ else
+ return "";
+ }
+
+ /**
+ * Returns the subject field.
+ */
+ public String getSubject() throws MessagingException {
+ if (hasSubject())
+ return message.getSubject();
+ else
+ return "";
+ }
+
+ /**
+ * Returns the to field.
+ */
+ public String getTo() throws MessagingException {
+ return formatAddresses(
+ message.getRecipients(Message.RecipientType.TO));
+ }
+
+ /**
+ * Method for checking if the message has attachments.
+ */
+ public boolean hasAttachments() throws java.io.IOException,
+ MessagingException {
+ boolean hasAttachments = false;
+ if (message.isMimeType("multipart/*")) {
+ Multipart mp = (Multipart)message.getContent();
+ if (mp.getCount() > 1)
+ hasAttachments = true;
+ }
+
+ return hasAttachments;
+ }
+
+ /**
+ * Method for checking if the message has a bcc field.
+ */
+ public boolean hasBcc() throws MessagingException {
+ return (message.getRecipients(Message.RecipientType.BCC) != null);
+ }
+
+ /**
+ * Method for checking if the message has a cc field.
+ */
+ public boolean hasCc() throws MessagingException {
+ return (message.getRecipients(Message.RecipientType.CC) != null);
+ }
+
+ /**
+ * Method for checking if the message has a date field.
+ */
+ public boolean hasDate() throws MessagingException {
+ return (hasSentDate() || hasReceivedDate());
+ }
+
+ /**
+ * Method for checking if the message has a from field.
+ */
+ public boolean hasFrom() throws MessagingException {
+ return (message.getFrom() != null);
+ }
+
+ /**
+ * Method for checking if the message has the desired mime type.
+ */
+ public boolean hasMimeType(String mimeType) throws MessagingException {
+ return message.isMimeType(mimeType);
+ }
+
+ /**
+ * Method for checking if the message has a received date field.
+ */
+ public boolean hasReceivedDate() throws MessagingException {
+ return (message.getReceivedDate() != null);
+ }
+
+ /**
+ * Method for checking if the message has a sent date field.
+ */
+ public boolean hasSentDate() throws MessagingException {
+ return (message.getSentDate() != null);
+ }
+
+ /**
+ * Method for checking if the message has a subject field.
+ */
+ public boolean hasSubject() throws MessagingException {
+ return (message.getSubject() != null);
+ }
+
+ /**
+ * Method for checking if the message has a to field.
+ */
+ public boolean hasTo() throws MessagingException {
+ return (message.getRecipients(Message.RecipientType.TO) != null);
+ }
+
+ /**
+ * Method for mapping a message to this MessageInfo class.
+ */
+ public void setMessage(Message message) {
+ this.message = message;
+ }
+
+ /**
+ * Utility method for formatting msg header addresses.
+ */
+ private String formatAddresses(Address[] addrs) {
+ if (addrs == null)
+ return "";
+ StringBuffer strBuf = new StringBuffer(getDisplayAddress(addrs[0]));
+ for (int i = 1; i < addrs.length; i++) {
+ strBuf.append(", ").append(getDisplayAddress(addrs[i]));
+ }
+ return strBuf.toString();
+ }
+
+ /**
+ * Utility method which returns a string suitable for msg header display.
+ */
+ private String getDisplayAddress(Address a) {
+ String pers = null;
+ String addr = null;
+ if (a instanceof InternetAddress &&
+ ((pers = ((InternetAddress)a).getPersonal()) != null)) {
+ addr = pers + " "+"<"+((InternetAddress)a).getAddress()+">";
+ } else
+ addr = a.toString();
+ return addr;
+ }
+}
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/MessageTEI.java b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/MessageTEI.java
new file mode 100644
index 0000000..33a3acd
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/MessageTEI.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2001-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+package demo;
+
+import javax.servlet.jsp.*;
+import javax.servlet.jsp.tagext.*;
+
+/**
+ * Extra information class to support the scripting variable created by the
+ * MessagesTag class. The variable exists outside of the tag.
+ *
+ */
+public class MessageTEI extends TagExtraInfo {
+
+ public MessageTEI() {
+ super();
+ }
+
+ public VariableInfo[] getVariableInfo(TagData data) {
+ VariableInfo info = new VariableInfo(data.getId(),"MessageInfo",
+ true, VariableInfo.AT_END);
+ VariableInfo[] varInfo = { info };
+ return varInfo;
+ }
+}
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/MessageTag.java b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/MessageTag.java
new file mode 100644
index 0000000..37f163f
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/MessageTag.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2001-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+package demo;
+
+import java.util.*;
+import javax.mail.*;
+import javax.mail.internet.*;
+import javax.servlet.jsp.*;
+import javax.servlet.jsp.tagext.*;
+
+/**
+ * Custom tag for retrieving a message.
+ */
+public class MessageTag extends TagSupport {
+ private String folder;
+ private String session;
+ private int num = 1;
+
+ /**
+ * folder attribute setter method.
+ */
+ public String getFolder() {
+ return folder;
+ }
+
+ /**
+ * num attribute getter method.
+ */
+ public String getNum() {
+ return Integer.toString(num);
+ }
+
+ /**
+ * session attribute getter method.
+ */
+ public String getSession() {
+ return session;
+ }
+
+ /**
+ * folder setter method.
+ */
+ public void setFolder(String folder) {
+ this.folder = folder;
+ }
+
+ /**
+ * num attribute setter method.
+ */
+ public void setNum(String num) {
+ this.num = Integer.parseInt(num);
+ }
+
+ /**
+ * session attribute setter method.
+ */
+ public void setSession(String session) {
+ this.session = session;
+ }
+
+ /**
+ * Method for processing the start of the tag.
+ */
+ public int doStartTag() throws JspException {
+ MessageInfo messageinfo = new MessageInfo();
+ try {
+ Folder f = (Folder)pageContext.getAttribute(
+ getFolder(), PageContext.SESSION_SCOPE);
+ Message message = f.getMessage(num);
+ messageinfo.setMessage(message);
+ pageContext.setAttribute(getId(), messageinfo);
+ } catch (Exception ex) {
+ throw new JspException(ex.getMessage());
+ }
+
+ return SKIP_BODY;
+ }
+}
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/SendTag.java b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/SendTag.java
new file mode 100644
index 0000000..f436283
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/src/taglib/demo/SendTag.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2001-2010 Oracle and/or its affiliates. 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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - 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.
+ */
+
+package demo;
+
+import java.util.*;
+import java.net.*;
+import javax.mail.*;
+import javax.mail.internet.*;
+import javax.servlet.jsp.*;
+import javax.servlet.jsp.tagext.*;
+
+/**
+ * Custom tag for sending messages.
+ */
+public class SendTag extends BodyTagSupport {
+ private String body;
+ private String cc;
+ private String host;
+ private String recipients;
+ private String sender;
+ private String subject;
+
+ /**
+ * host attribute setter method.
+ */
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ /**
+ * recipient attribute setter method.
+ */
+ public void setRecipients(String recipients) {
+ this.recipients = recipients;
+ }
+
+ /**
+ * sender attribute setter method.
+ */
+ public void setSender(String sender) {
+ this.sender = sender;
+ }
+
+ /**
+ * cc attribute setter method.
+ */
+ public void setCc(String cc) {
+ this.cc = cc;
+ }
+
+ /**
+ * subject attribute setter method.
+ */
+ public void setSubject(String subject) {
+ this.subject = subject;
+ }
+
+ /**
+ * Method for processing the end of the tag.
+ */
+ public int doEndTag() throws JspException {
+ Properties props = System.getProperties();
+
+ try {
+ if (host != null)
+ props.put("mail.smtp.host", host);
+ else if (props.getProperty("mail.smtp.host") == null)
+ props.put("mail.smtp.host", InetAddress.getLocalHost().
+ getHostName());
+ } catch (Exception ex) {
+ throw new JspException(ex.getMessage());
+ }
+ Session session = Session.getDefaultInstance(props, null);
+
+ Message msg = new MimeMessage(session);
+ InternetAddress[] toAddrs = null, ccAddrs = null;
+
+ try {
+ if (recipients != null) {
+ toAddrs = InternetAddress.parse(recipients, false);
+ msg.setRecipients(Message.RecipientType.TO, toAddrs);
+ } else
+ throw new JspException("No recipient address specified");
+
+ if (sender != null)
+ msg.setFrom(new InternetAddress(sender));
+ else
+ throw new JspException("No sender address specified");
+
+ if (cc != null) {
+ ccAddrs = InternetAddress.parse(cc, false);
+ msg.setRecipients(Message.RecipientType.CC, ccAddrs);
+ }
+
+ if (subject != null)
+ msg.setSubject(subject);
+
+ if ((body = getBodyContent().getString()) != null)
+ msg.setText(body);
+ else
+ msg.setText("");
+
+ Transport.send(msg);
+
+ } catch (Exception ex) {
+ throw new JspException(ex.getMessage());
+ }
+
+ return(EVAL_PAGE);
+ }
+}
+
diff --git a/src/Java/Jars/javamail-samples/javamail-samples/webapp/webapp.README.txt b/src/Java/Jars/javamail-samples/javamail-samples/webapp/webapp.README.txt
new file mode 100644
index 0000000..6a90697
--- /dev/null
+++ b/src/Java/Jars/javamail-samples/javamail-samples/webapp/webapp.README.txt
@@ -0,0 +1,189 @@
+This demo illustrates the use of JavaMail APIs in a 3-tiered web
+application. It must be deployed on a web server that supports
+servlet and JSP-based web applications (e.g. Tomcat) using at least
+J2SE 1.3 and Servlet 2.2.
+
+ +-----------+ +-----------+ +-----------+
+ | IMAP | | | | |
+ | Server |<-IMAP->| JavaMail |<-HTTP->| WWW |
+ +-----------+ | Web app |--HTML->| Browser |
+ | SMTP |<-SMTP->| | | |
+ | Server | | | | |
+ +-----------+ +-----------+ +-----------+
+
+
+The JavaMail Web application supports the following functionality:
+ * login to an IMAP server
+ * list all the messages in the INBOX folder
+ * view the selected message
+ * compose and send a message
+
+It is comprised of an HTML document and several Web components
+(servlets, JSP pages and custom tags) and is packaged in a Web
+archive with the following contents:
+
+ index.html
+ login.jsp
+ folders.jsp
+ messageheaders.jsp
+ messagecontent.jsp
+ compose.jsp
+ send.jsp
+ errorpage.jsp
+ errordetails.jsp
+ logout.jsp
+ WEB-INF/
+ WEB-INF/classes/
+ WEB-INF/classes/demo/AttachmentServlet.class
+ WEB-INF/classes/demo/FilterServlet.class
+ WEB-INF/classes/demo/MailUserBean.class
+ WEB-INF/lib/
+ WEB-INF/lib/jtl.jar
+ WEB-INF/web.xml
+
+
+
+
+
+
+
+
+
+
+
+The collection of .html and .jsp files provide the client-side view
+of the JavaMail Web application.
+
+ index.html
+ |
+ login.jsp
+ |
+ folders.jsp
+ |
+ messageheaders.jsp
+ |
+ / \
+ / \
+ compose.jsp messagecontent.jsp
+ |
+ send.jsp
+
+
+The WEB-INF/web.xml file contains the web applications deployment
+descriptor. It is an XML document that contains configuration and
+deployment information for the application.
+
+As per the Servlet specification, the WEB-INF/classes directory
+contains servlet and utility classes used by the web application.
+The FilterServlet acts as the Controller of the JavaMail Web
+application. All requests are mapped to this servlet. It checks
+to see that the user is logged in to the server before forwarding the
+request to the appropriate JSP page. The AttachmentServlet is used
+to render non-text attachments and the MailUserBean is a utility class
+used to maintain information about the mail user.
+
+The WEB-INF/lib directory (also defined in the Servlet specification)
+contains the Java archive file for the javamail custom tag library.
+
+The follow tags are furnished in the javamail tag library:
+
+
+body of the message
+
+
+Description: Used to send messages.
+
+
+
+
+Description: Used to read a single message.
+
+
+
+
+Description: Used to iterate through list of messages. The body of the
+tag is repeated for each message in the list.
+
+
+
+
+
+
+
+
+
+
+
+Building and Packaging the JavaMail Web application
+
+All source for this demo can be found in the following directories:
+ src/classes
+ src/docroot
+ src/taglib
+
+Build scripts (build.sh and build.bat) are provided for building and
+packaging the demo. Before executing the build scripts, be sure that
+the following are in your CLASSPATH:
+ mail.jar the JavaMail jar file
+ activation.jar the JAF jar file
+ servlet.jar the servlet/JSP jar file
+
+The following steps are performed when building and packaging the demo.
+
+1. Create a directory named "src/docroot/WEB-INF/classes/demo".
+
+2. Create a directory named "src/docroot/WEB-INF/lib".
+
+3. Compile the files from the "src/classes/demo" directory and add them
+ to "src/docroot/WEB-INF/classes/demo".
+
+4. Compile the files from the "src/tablib" directory.
+
+5. Create an archive (jtl.jar) of the taglib classes and add it
+ to "src/docroot/WEB-INF/lib".
+
+6. Create a web archive file of the contents of "src/docroot" (and all
+ of its sub-directories).
+
+(For a list of the contents of the resulting web archive,
+ see the beginning of this document.)
+
+
+
+
+
+
+
+
+
+
+
+A note on sending mail
+
+In order to send mail using the JavaMail Web App, it is necessary to identify
+an SMTP host. This can be accomplished in a couple of ways.
+
+1. Use the TOMCAT_OPTS environment variable.
+
+ Add the following to the TOMCAT_OPTS environment variable:
+
+ -Dmail.smtp.host=yourSMTPmailservername
+
+ Restart your web server.
+
+
+2. Modify the send.jsp file and update the javamail.war file:
+
+ Add the following parameter to the tag:
+
+ host="yourSMTPmailservername"
+
+ Repackage the javamail.war file to include the modified send.jsp file.
diff --git a/src/Java/Jars/javax.mail.jar b/src/Java/Jars/javax.mail.jar
new file mode 100644
index 0000000..dd06a6a
Binary files /dev/null and b/src/Java/Jars/javax.mail.jar differ
diff --git a/src/Java/Jars/jsoup.jar b/src/Java/Jars/jsoup.jar
new file mode 100644
index 0000000..75f716b
Binary files /dev/null and b/src/Java/Jars/jsoup.jar differ
diff --git a/src/Java/Jars/jython-standalone-2.7.0.jar b/src/Java/Jars/jython-standalone-2.7.0.jar
new file mode 100644
index 0000000..c494983
Binary files /dev/null and b/src/Java/Jars/jython-standalone-2.7.0.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/LICENSE b/src/Java/Jars/lwjgl_jars/LICENSE
new file mode 100644
index 0000000..a983c18
--- /dev/null
+++ b/src/Java/Jars/lwjgl_jars/LICENSE
@@ -0,0 +1,29 @@
+Copyright (c) 2012-present Lightweight Java Game Library
+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
+ documentation and/or other materials provided with the distribution.
+
+- Neither the name Lightweight Java Game Library 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.
\ No newline at end of file
diff --git a/src/Java/Jars/lwjgl_jars/assimp_license.txt b/src/Java/Jars/lwjgl_jars/assimp_license.txt
new file mode 100644
index 0000000..262606a
--- /dev/null
+++ b/src/Java/Jars/lwjgl_jars/assimp_license.txt
@@ -0,0 +1,78 @@
+Open Asset Import Library (assimp)
+
+Copyright (c) 2006-2016, assimp team
+All rights reserved.
+
+Redistribution and use of this software 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 documentation and/or other
+ materials provided with the distribution.
+
+* Neither the name of the assimp team, nor the names of its
+ contributors may be used to endorse or promote products
+ derived from this software without specific prior
+ written permission of the assimp team.
+
+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 EXCEPTION applies to all files in the ./test/models-nonbsd folder.
+These are 3d models for testing purposes, from various free sources
+on the internet. They are - unless otherwise stated - copyright of
+their respective creators, which may impose additional requirements
+on the use of their work. For any of these models, see
+.source.txt for more legal information. Contact us if you
+are a copyright holder and believe that we credited you inproperly or
+if you don't want your files to appear in the repository.
+
+
+******************************************************************************
+
+Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
+http://code.google.com/p/poly2tri/
+
+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 documentation
+ and/or other materials provided with the distribution.
+* Neither the name of Poly2Tri 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.
diff --git a/src/Java/Jars/lwjgl_jars/bgfx_license.txt b/src/Java/Jars/lwjgl_jars/bgfx_license.txt
new file mode 100644
index 0000000..6877280
--- /dev/null
+++ b/src/Java/Jars/lwjgl_jars/bgfx_license.txt
@@ -0,0 +1,26 @@
+Copyright 2010-2016 Branimir Karadzic. All rights reserved.
+
+https://github.com/bkaradzic/bgfx
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER ``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 COPYRIGHT HOLDER 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.
+
+https://github.com/bkaradzic/bgfx/blob/master/LICENSE
diff --git a/src/Java/Jars/lwjgl_jars/build.txt b/src/Java/Jars/lwjgl_jars/build.txt
new file mode 100644
index 0000000..6c9da3c
--- /dev/null
+++ b/src/Java/Jars/lwjgl_jars/build.txt
@@ -0,0 +1 @@
+LWJGL 3.1.2 build 29
\ No newline at end of file
diff --git a/src/Java/Jars/lwjgl_jars/dyncall_license.txt b/src/Java/Jars/lwjgl_jars/dyncall_license.txt
new file mode 100644
index 0000000..6984164
--- /dev/null
+++ b/src/Java/Jars/lwjgl_jars/dyncall_license.txt
@@ -0,0 +1,14 @@
+Copyright (c) 2007-2015 Daniel Adler ,
+ Tassilo Philipp
+
+Permission to use, copy, modify, and distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
\ No newline at end of file
diff --git a/src/Java/Jars/lwjgl_jars/glfw_license.txt b/src/Java/Jars/lwjgl_jars/glfw_license.txt
new file mode 100644
index 0000000..8a60e1d
--- /dev/null
+++ b/src/Java/Jars/lwjgl_jars/glfw_license.txt
@@ -0,0 +1,21 @@
+Copyright (c) 2002-2006 Marcus Geelnard
+Copyright (c) 2006-2010 Camilla Berglund
+
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any damages
+arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would
+ be appreciated but is not required.
+
+2. Altered source versions must be plainly marked as such, and must not
+ be misrepresented as being the original software.
+
+3. This notice may not be removed or altered from any source
+ distribution.
diff --git a/src/Java/Jars/lwjgl_jars/jemalloc_license.txt b/src/Java/Jars/lwjgl_jars/jemalloc_license.txt
new file mode 100644
index 0000000..bda397d
--- /dev/null
+++ b/src/Java/Jars/lwjgl_jars/jemalloc_license.txt
@@ -0,0 +1,23 @@
+Copyright (C) 2002-2014 Jason Evans .
+All rights reserved.
+Copyright (C) 2007-2012 Mozilla Foundation. All rights reserved.
+Copyright (C) 2009-2014 Facebook, Inc. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+1. Redistributions of source code must retain the above copyright notice(s),
+ this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright notice(s),
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``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 HOLDER(S) 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.
\ No newline at end of file
diff --git a/src/Java/Jars/lwjgl_jars/khronos_license.txt b/src/Java/Jars/lwjgl_jars/khronos_license.txt
new file mode 100644
index 0000000..d7e6e9d
--- /dev/null
+++ b/src/Java/Jars/lwjgl_jars/khronos_license.txt
@@ -0,0 +1,22 @@
+/*
+** Copyright (c) 2013-2014 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
\ No newline at end of file
diff --git a/src/Java/Jars/lwjgl_jars/lmdb_license.txt b/src/Java/Jars/lwjgl_jars/lmdb_license.txt
new file mode 100644
index 0000000..6295703
--- /dev/null
+++ b/src/Java/Jars/lwjgl_jars/lmdb_license.txt
@@ -0,0 +1,47 @@
+The OpenLDAP Public License
+ Version 2.8, 17 August 2003
+
+Redistribution and use of this software and associated documentation
+("Software"), with or without modification, are permitted provided
+that the following conditions are met:
+
+1. Redistributions in source form must retain copyright statements
+ and notices,
+
+2. Redistributions in binary form must reproduce applicable copyright
+ statements and notices, this list of conditions, and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution, and
+
+3. Redistributions must contain a verbatim copy of this document.
+
+The OpenLDAP Foundation may revise this license from time to time.
+Each revision is distinguished by a version number. You may use
+this Software under terms of this license revision or under the
+terms of any subsequent revision of the license.
+
+THIS SOFTWARE IS PROVIDED BY THE OPENLDAP FOUNDATION AND ITS
+CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED 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 OPENLDAP FOUNDATION, ITS CONTRIBUTORS, OR THE AUTHOR(S)
+OR OWNER(S) OF THE SOFTWARE 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.
+
+The names of the authors and copyright holders must not be used in
+advertising or otherwise to promote the sale, use or other dealing
+in this Software without specific, written prior permission. Title
+to copyright in this Software shall at all times remain with copyright
+holders.
+
+OpenLDAP is a registered trademark of the OpenLDAP Foundation.
+
+Copyright 1999-2003 The OpenLDAP Foundation, Redwood City,
+California, USA. All Rights Reserved. Permission to copy and
+distribute verbatim copies of this document is granted.
\ No newline at end of file
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-assimp-natives-linux.jar b/src/Java/Jars/lwjgl_jars/lwjgl-assimp-natives-linux.jar
new file mode 100644
index 0000000..86ae99b
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-assimp-natives-linux.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-assimp-natives-macos.jar b/src/Java/Jars/lwjgl_jars/lwjgl-assimp-natives-macos.jar
new file mode 100644
index 0000000..6f603c3
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-assimp-natives-macos.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-assimp-natives-windows.jar b/src/Java/Jars/lwjgl_jars/lwjgl-assimp-natives-windows.jar
new file mode 100644
index 0000000..6343d03
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-assimp-natives-windows.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-assimp.jar b/src/Java/Jars/lwjgl_jars/lwjgl-assimp.jar
new file mode 100644
index 0000000..226667b
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-assimp.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-bgfx-natives-linux.jar b/src/Java/Jars/lwjgl_jars/lwjgl-bgfx-natives-linux.jar
new file mode 100644
index 0000000..ca9f4b9
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-bgfx-natives-linux.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-bgfx-natives-macos.jar b/src/Java/Jars/lwjgl_jars/lwjgl-bgfx-natives-macos.jar
new file mode 100644
index 0000000..b334d53
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-bgfx-natives-macos.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-bgfx-natives-windows.jar b/src/Java/Jars/lwjgl_jars/lwjgl-bgfx-natives-windows.jar
new file mode 100644
index 0000000..679bc1d
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-bgfx-natives-windows.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-bgfx.jar b/src/Java/Jars/lwjgl_jars/lwjgl-bgfx.jar
new file mode 100644
index 0000000..0ef1619
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-bgfx.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-egl.jar b/src/Java/Jars/lwjgl_jars/lwjgl-egl.jar
new file mode 100644
index 0000000..31a4ec8
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-egl.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-glfw-natives-linux.jar b/src/Java/Jars/lwjgl_jars/lwjgl-glfw-natives-linux.jar
new file mode 100644
index 0000000..7cea641
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-glfw-natives-linux.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-glfw-natives-macos.jar b/src/Java/Jars/lwjgl_jars/lwjgl-glfw-natives-macos.jar
new file mode 100644
index 0000000..01dfb42
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-glfw-natives-macos.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-glfw-natives-windows.jar b/src/Java/Jars/lwjgl_jars/lwjgl-glfw-natives-windows.jar
new file mode 100644
index 0000000..2d46510
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-glfw-natives-windows.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-glfw.jar b/src/Java/Jars/lwjgl_jars/lwjgl-glfw.jar
new file mode 100644
index 0000000..3421cce
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-glfw.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-jawt.jar b/src/Java/Jars/lwjgl_jars/lwjgl-jawt.jar
new file mode 100644
index 0000000..ce40f73
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-jawt.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-jemalloc-natives-linux.jar b/src/Java/Jars/lwjgl_jars/lwjgl-jemalloc-natives-linux.jar
new file mode 100644
index 0000000..7eaf2f5
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-jemalloc-natives-linux.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-jemalloc-natives-macos.jar b/src/Java/Jars/lwjgl_jars/lwjgl-jemalloc-natives-macos.jar
new file mode 100644
index 0000000..c0e58d0
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-jemalloc-natives-macos.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-jemalloc-natives-windows.jar b/src/Java/Jars/lwjgl_jars/lwjgl-jemalloc-natives-windows.jar
new file mode 100644
index 0000000..f904996
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-jemalloc-natives-windows.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-jemalloc.jar b/src/Java/Jars/lwjgl_jars/lwjgl-jemalloc.jar
new file mode 100644
index 0000000..d9d966e
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-jemalloc.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-lmdb-natives-linux.jar b/src/Java/Jars/lwjgl_jars/lwjgl-lmdb-natives-linux.jar
new file mode 100644
index 0000000..b2cbaa4
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-lmdb-natives-linux.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-lmdb-natives-macos.jar b/src/Java/Jars/lwjgl_jars/lwjgl-lmdb-natives-macos.jar
new file mode 100644
index 0000000..2fcc41c
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-lmdb-natives-macos.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-lmdb-natives-windows.jar b/src/Java/Jars/lwjgl_jars/lwjgl-lmdb-natives-windows.jar
new file mode 100644
index 0000000..7d4d89b
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-lmdb-natives-windows.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-lmdb.jar b/src/Java/Jars/lwjgl_jars/lwjgl-lmdb.jar
new file mode 100644
index 0000000..c08c844
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-lmdb.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-nanovg-natives-linux.jar b/src/Java/Jars/lwjgl_jars/lwjgl-nanovg-natives-linux.jar
new file mode 100644
index 0000000..ebcef97
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-nanovg-natives-linux.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-nanovg-natives-macos.jar b/src/Java/Jars/lwjgl_jars/lwjgl-nanovg-natives-macos.jar
new file mode 100644
index 0000000..dd12eca
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-nanovg-natives-macos.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-nanovg-natives-windows.jar b/src/Java/Jars/lwjgl_jars/lwjgl-nanovg-natives-windows.jar
new file mode 100644
index 0000000..67bd1a7
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-nanovg-natives-windows.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-nanovg.jar b/src/Java/Jars/lwjgl_jars/lwjgl-nanovg.jar
new file mode 100644
index 0000000..2487f01
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-nanovg.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-natives-linux.jar b/src/Java/Jars/lwjgl_jars/lwjgl-natives-linux.jar
new file mode 100644
index 0000000..b998a38
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-natives-linux.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-natives-macos.jar b/src/Java/Jars/lwjgl_jars/lwjgl-natives-macos.jar
new file mode 100644
index 0000000..415d254
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-natives-macos.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-natives-windows.jar b/src/Java/Jars/lwjgl_jars/lwjgl-natives-windows.jar
new file mode 100644
index 0000000..82ae549
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-natives-windows.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-nfd-natives-linux.jar b/src/Java/Jars/lwjgl_jars/lwjgl-nfd-natives-linux.jar
new file mode 100644
index 0000000..ac9415c
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-nfd-natives-linux.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-nfd-natives-macos.jar b/src/Java/Jars/lwjgl_jars/lwjgl-nfd-natives-macos.jar
new file mode 100644
index 0000000..8068a98
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-nfd-natives-macos.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-nfd-natives-windows.jar b/src/Java/Jars/lwjgl_jars/lwjgl-nfd-natives-windows.jar
new file mode 100644
index 0000000..30c6b57
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-nfd-natives-windows.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-nfd.jar b/src/Java/Jars/lwjgl_jars/lwjgl-nfd.jar
new file mode 100644
index 0000000..38b7dd8
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-nfd.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-nuklear-natives-linux.jar b/src/Java/Jars/lwjgl_jars/lwjgl-nuklear-natives-linux.jar
new file mode 100644
index 0000000..dabe18c
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-nuklear-natives-linux.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-nuklear-natives-macos.jar b/src/Java/Jars/lwjgl_jars/lwjgl-nuklear-natives-macos.jar
new file mode 100644
index 0000000..8f4167f
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-nuklear-natives-macos.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-nuklear-natives-windows.jar b/src/Java/Jars/lwjgl_jars/lwjgl-nuklear-natives-windows.jar
new file mode 100644
index 0000000..e6ce647
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-nuklear-natives-windows.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-nuklear.jar b/src/Java/Jars/lwjgl_jars/lwjgl-nuklear.jar
new file mode 100644
index 0000000..cf34707
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-nuklear.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-openal-natives-linux.jar b/src/Java/Jars/lwjgl_jars/lwjgl-openal-natives-linux.jar
new file mode 100644
index 0000000..75b863a
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-openal-natives-linux.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-openal-natives-macos.jar b/src/Java/Jars/lwjgl_jars/lwjgl-openal-natives-macos.jar
new file mode 100644
index 0000000..a340ce1
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-openal-natives-macos.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-openal-natives-windows.jar b/src/Java/Jars/lwjgl_jars/lwjgl-openal-natives-windows.jar
new file mode 100644
index 0000000..17c045f
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-openal-natives-windows.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-openal.jar b/src/Java/Jars/lwjgl_jars/lwjgl-openal.jar
new file mode 100644
index 0000000..73999ed
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-openal.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-opencl.jar b/src/Java/Jars/lwjgl_jars/lwjgl-opencl.jar
new file mode 100644
index 0000000..a89a1c5
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-opencl.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-opengl-natives-linux.jar b/src/Java/Jars/lwjgl_jars/lwjgl-opengl-natives-linux.jar
new file mode 100644
index 0000000..7386be1
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-opengl-natives-linux.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-opengl-natives-macos.jar b/src/Java/Jars/lwjgl_jars/lwjgl-opengl-natives-macos.jar
new file mode 100644
index 0000000..52af9f8
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-opengl-natives-macos.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-opengl-natives-windows.jar b/src/Java/Jars/lwjgl_jars/lwjgl-opengl-natives-windows.jar
new file mode 100644
index 0000000..ac20229
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-opengl-natives-windows.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-opengl.jar b/src/Java/Jars/lwjgl_jars/lwjgl-opengl.jar
new file mode 100644
index 0000000..abd341e
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-opengl.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-opengles-natives-linux.jar b/src/Java/Jars/lwjgl_jars/lwjgl-opengles-natives-linux.jar
new file mode 100644
index 0000000..24356d7
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-opengles-natives-linux.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-opengles-natives-macos.jar b/src/Java/Jars/lwjgl_jars/lwjgl-opengles-natives-macos.jar
new file mode 100644
index 0000000..1b403d0
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-opengles-natives-macos.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-opengles-natives-windows.jar b/src/Java/Jars/lwjgl_jars/lwjgl-opengles-natives-windows.jar
new file mode 100644
index 0000000..729b578
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-opengles-natives-windows.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-opengles.jar b/src/Java/Jars/lwjgl_jars/lwjgl-opengles.jar
new file mode 100644
index 0000000..4bb7044
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-opengles.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-openvr-natives-linux.jar b/src/Java/Jars/lwjgl_jars/lwjgl-openvr-natives-linux.jar
new file mode 100644
index 0000000..ce9042b
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-openvr-natives-linux.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-openvr-natives-macos.jar b/src/Java/Jars/lwjgl_jars/lwjgl-openvr-natives-macos.jar
new file mode 100644
index 0000000..7513ba7
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-openvr-natives-macos.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-openvr-natives-windows.jar b/src/Java/Jars/lwjgl_jars/lwjgl-openvr-natives-windows.jar
new file mode 100644
index 0000000..78e9803
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-openvr-natives-windows.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-openvr.jar b/src/Java/Jars/lwjgl_jars/lwjgl-openvr.jar
new file mode 100644
index 0000000..69ec5dc
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-openvr.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-ovr-natives-windows.jar b/src/Java/Jars/lwjgl_jars/lwjgl-ovr-natives-windows.jar
new file mode 100644
index 0000000..542d399
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-ovr-natives-windows.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-ovr.jar b/src/Java/Jars/lwjgl_jars/lwjgl-ovr.jar
new file mode 100644
index 0000000..da8d7d7
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-ovr.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-par-natives-linux.jar b/src/Java/Jars/lwjgl_jars/lwjgl-par-natives-linux.jar
new file mode 100644
index 0000000..a1ccde0
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-par-natives-linux.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-par-natives-macos.jar b/src/Java/Jars/lwjgl_jars/lwjgl-par-natives-macos.jar
new file mode 100644
index 0000000..9bc5e0c
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-par-natives-macos.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-par-natives-windows.jar b/src/Java/Jars/lwjgl_jars/lwjgl-par-natives-windows.jar
new file mode 100644
index 0000000..d995a4e
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-par-natives-windows.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-par.jar b/src/Java/Jars/lwjgl_jars/lwjgl-par.jar
new file mode 100644
index 0000000..13e5cfc
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-par.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-sse-natives-linux.jar b/src/Java/Jars/lwjgl_jars/lwjgl-sse-natives-linux.jar
new file mode 100644
index 0000000..226df24
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-sse-natives-linux.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-sse-natives-macos.jar b/src/Java/Jars/lwjgl_jars/lwjgl-sse-natives-macos.jar
new file mode 100644
index 0000000..4e35f6c
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-sse-natives-macos.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-sse-natives-windows.jar b/src/Java/Jars/lwjgl_jars/lwjgl-sse-natives-windows.jar
new file mode 100644
index 0000000..5d0a1ae
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-sse-natives-windows.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-sse.jar b/src/Java/Jars/lwjgl_jars/lwjgl-sse.jar
new file mode 100644
index 0000000..d466e90
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-sse.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-stb-natives-linux.jar b/src/Java/Jars/lwjgl_jars/lwjgl-stb-natives-linux.jar
new file mode 100644
index 0000000..1a76c0c
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-stb-natives-linux.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-stb-natives-macos.jar b/src/Java/Jars/lwjgl_jars/lwjgl-stb-natives-macos.jar
new file mode 100644
index 0000000..6ef2a2c
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-stb-natives-macos.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-stb-natives-windows.jar b/src/Java/Jars/lwjgl_jars/lwjgl-stb-natives-windows.jar
new file mode 100644
index 0000000..5619e49
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-stb-natives-windows.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-stb.jar b/src/Java/Jars/lwjgl_jars/lwjgl-stb.jar
new file mode 100644
index 0000000..84fd156
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-stb.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-tinyexr-natives-linux.jar b/src/Java/Jars/lwjgl_jars/lwjgl-tinyexr-natives-linux.jar
new file mode 100644
index 0000000..a7f8a9e
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-tinyexr-natives-linux.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-tinyexr-natives-macos.jar b/src/Java/Jars/lwjgl_jars/lwjgl-tinyexr-natives-macos.jar
new file mode 100644
index 0000000..0fa6d04
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-tinyexr-natives-macos.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-tinyexr-natives-windows.jar b/src/Java/Jars/lwjgl_jars/lwjgl-tinyexr-natives-windows.jar
new file mode 100644
index 0000000..a194eac
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-tinyexr-natives-windows.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-tinyexr.jar b/src/Java/Jars/lwjgl_jars/lwjgl-tinyexr.jar
new file mode 100644
index 0000000..87303db
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-tinyexr.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-tinyfd-natives-linux.jar b/src/Java/Jars/lwjgl_jars/lwjgl-tinyfd-natives-linux.jar
new file mode 100644
index 0000000..9aec7d4
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-tinyfd-natives-linux.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-tinyfd-natives-macos.jar b/src/Java/Jars/lwjgl_jars/lwjgl-tinyfd-natives-macos.jar
new file mode 100644
index 0000000..ab8060a
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-tinyfd-natives-macos.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-tinyfd-natives-windows.jar b/src/Java/Jars/lwjgl_jars/lwjgl-tinyfd-natives-windows.jar
new file mode 100644
index 0000000..72ce28b
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-tinyfd-natives-windows.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-tinyfd.jar b/src/Java/Jars/lwjgl_jars/lwjgl-tinyfd.jar
new file mode 100644
index 0000000..394beac
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-tinyfd.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-vulkan.jar b/src/Java/Jars/lwjgl_jars/lwjgl-vulkan.jar
new file mode 100644
index 0000000..03aa655
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-vulkan.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-xxhash-natives-linux.jar b/src/Java/Jars/lwjgl_jars/lwjgl-xxhash-natives-linux.jar
new file mode 100644
index 0000000..cff9b52
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-xxhash-natives-linux.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-xxhash-natives-macos.jar b/src/Java/Jars/lwjgl_jars/lwjgl-xxhash-natives-macos.jar
new file mode 100644
index 0000000..36c8923
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-xxhash-natives-macos.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-xxhash-natives-windows.jar b/src/Java/Jars/lwjgl_jars/lwjgl-xxhash-natives-windows.jar
new file mode 100644
index 0000000..d60cca7
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-xxhash-natives-windows.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-xxhash.jar b/src/Java/Jars/lwjgl_jars/lwjgl-xxhash.jar
new file mode 100644
index 0000000..1e1b02c
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-xxhash.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-yoga-natives-linux.jar b/src/Java/Jars/lwjgl_jars/lwjgl-yoga-natives-linux.jar
new file mode 100644
index 0000000..4c0d089
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-yoga-natives-linux.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-yoga-natives-macos.jar b/src/Java/Jars/lwjgl_jars/lwjgl-yoga-natives-macos.jar
new file mode 100644
index 0000000..9aa137c
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-yoga-natives-macos.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-yoga-natives-windows.jar b/src/Java/Jars/lwjgl_jars/lwjgl-yoga-natives-windows.jar
new file mode 100644
index 0000000..696e885
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-yoga-natives-windows.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl-yoga.jar b/src/Java/Jars/lwjgl_jars/lwjgl-yoga.jar
new file mode 100644
index 0000000..c6683cc
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl-yoga.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/lwjgl.jar b/src/Java/Jars/lwjgl_jars/lwjgl.jar
new file mode 100644
index 0000000..2f201f4
Binary files /dev/null and b/src/Java/Jars/lwjgl_jars/lwjgl.jar differ
diff --git a/src/Java/Jars/lwjgl_jars/nanovg_license.txt b/src/Java/Jars/lwjgl_jars/nanovg_license.txt
new file mode 100644
index 0000000..c9a1534
--- /dev/null
+++ b/src/Java/Jars/lwjgl_jars/nanovg_license.txt
@@ -0,0 +1,18 @@
+Copyright (c) 2013 Mikko Mononen memon@inside.org
+
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any damages
+arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not
+claim that you wrote the original software. If you use this software
+in a product, an acknowledgment in the product documentation would be
+appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be
+misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+
diff --git a/src/Java/Jars/lwjgl_jars/nfd_license.txt b/src/Java/Jars/lwjgl_jars/nfd_license.txt
new file mode 100644
index 0000000..3ab103c
--- /dev/null
+++ b/src/Java/Jars/lwjgl_jars/nfd_license.txt
@@ -0,0 +1,16 @@
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any damages
+arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+
diff --git a/src/Java/Jars/lwjgl_jars/oculus_license.txt b/src/Java/Jars/lwjgl_jars/oculus_license.txt
new file mode 100644
index 0000000..b819ea0
--- /dev/null
+++ b/src/Java/Jars/lwjgl_jars/oculus_license.txt
@@ -0,0 +1,264 @@
+Oculus VR, LLC Software Development Kit License Agreement
+
+Copyright ยฉ 2014 Oculus VR, LLC All rights reserved.
+
+The text of this may be found at: http://www.oculusvr.com/licenses/LICENSE-3.2
+
+Human-Readable Summary*:
+
+You are Free to:
+
+Use, modify, and distribute the Oculus VR Rift SDK in source and binary
+form with your applications/software.
+
+With the Following Restrictions:
+
+You can only distribute or re-distribute the source code to LibOVR in
+whole, not in part.
+
+Modifications to the Oculus VR Rift SDK in source or binary form must
+be shared with Oculus VR.
+
+If your applications cause health and safety issues, you may lose your
+right to use the Oculus VR Rift SDK, including LibOVR.
+
+The Oculus VR Rift SDK may not be used to interface with unapproved commercial
+virtual reality mobile or non-mobile products or hardware.
+
+* - This human-readable Summary is not a license. It is simply a convenient
+reference for understanding the full Oculus VR Rift SDK License Agreement.
+The Summary is written as a user-friendly interface to the full Oculus VR Rift
+SDK License below. This Summary itself has no legal value, and its contents do
+not appear in the actual license.
+
+Full-length Legal Copy:
+
+1. Subject to the terms and conditions of this License Agreement (the "License"),
+Oculus VR, LLC ("Oculus VR") hereby grants to you a perpetual, worldwide,
+non-exclusive, no-charge, royalty-free, sublicenseable copyright license to use,
+reproduce, redistribute (subject to restrictions below), modify, and improve the
+software contained in this Oculus VR Rift Software Development Kit ("RIFT SDK"),
+including, but not limited to, the samples, headers, LibOVR headers, and LibOVR
+source. This license is subject to the following terms and conditions:
+
+1.1. This license includes the non-exclusive license and right to use (i) the RIFT
+SDK to make applications, content, games and demos (collectively and generally
+referred to as "Developer Content") that run on the Oculus VR approved mobile hardware
+and software products ("Oculus Approved Rift Products") and which may incorporate
+the RIFT SDK in whole or in part in binary or object code; and (ii) to use the
+RIFT SDK to create derivative works of the RIFT SDK itself ("RIFT SDK Derivatives"),
+whether in source, binary, or object form, in whole or in part, including third
+party software unless otherwise noted.
+
+1.2. RIFT SDK Derivatives are further defined as source, binary or object code
+derived exclusively from the RIFT SDK by you; provided, however, that RIFT SDK
+Derivatives do not include the Developer Content (engines, utilities, applications,
+content, games or demos) which may be developed using the RIFT SDK. By way of example
+a mobile application or game or demo that is developed using the RIFT SDK would not
+be a RIFT SDK Derivative , nor would a utility or tool set in a pre-existing game
+engine that is adapted to work with the RIFT SDK be a RIFT SDK Derivative.
+By way of example, but not limitation, a RIFT SDK Derivative is or would be: either (i)
+an adaptation of a utility or piece of code from the RIFT SDK to improve efficiency;
+or (ii) an addition of code or improvement to the RIFT SDK that adds functionality.
+
+1.3 For the sake of clarification when you use the RIFT SDK (including RIFT SDK
+Derivatives) in or with Developer Content, you retain all rights to your Developer
+Content, and you have no obligations to share or license Developer Content (including
+your source and object code) to Oculus VR or any third parties; provided, however,
+Oculus VR retains all rights to the RIFT SDK and the RIFT SDK Derivatives that may
+be incorporated into your Developer Content.
+
+1.4 You agree to and you will use the Flash Screen Warning and the Health and
+Safety Warnings (collectively the "Oculus Warnings") and the Oculus VR health and
+safety protocols found in the Oculus Best Practices Guide ("Oculus H&S Protocols"),
+and your use of the Oculus Warnings and the Oculus end user license agreement
+("Oculus EULA") with your Developer Content as provided for in the Oculus Developer
+Center, all of which can be found at the following link:
+https://developer.oculusvr.com/?action=doc.
+
+2. You, the recipient and user of the RIFT SDK, hereby agree and accept that that
+Oculus VR shall own all right, title and interest to the intellectual property
+rights, including, but limited to copyright, trademark and patent rights, to any
+RIFT SDK Derivatives that you may create, and you hereby assign any and all such
+rights to such RIFT SDK Derivatives to Oculus VR, subject to the following.
+
+2.1 We hereby grant to you the a fully paid up, no-charge, royalty-free,
+world-wide, in perpetuity, non-exclusive right and license back to use these RIFT
+SDK Derivatives solely in conjunction with the RIFT SDK (or any components of the
+RIFT SDK) and/or Developer Content on Oculus Rift Products as set forth herein.
+
+2.2 Furthermore, for the sake of clarification, Oculus VR and its assignees and
+licensees shall be free to use such RIFT SDK Derivatives without any approval
+from you and without compensation or attribution to you.
+
+2.3 You also agree upon Oculus VR's request to provide the source and binary code
+of any RIFT SDK Derivatives to Oculus VR. FAILURE TO COMPLY WITH THIS REQUEST
+IS THE BASIS FOR AUTOMATIC TERMINATION OF THIS LICENSE BY OCULUS VR.
+
+3. Subject to the terms and conditions of this License, your license to redistribute
+and sublicense the RIFT SDK and RIFT SDK Derivatives is also expressly made
+subject to the following conditions:
+
+3.1. You may sublicense and redistribute the source, binary, or object code of
+the RIFT SDK in whole or in part by itself for no charge or as part of a for charge
+piece of Developer Content; provided, however, you may only license, sublicense
+or redistribute the source, binary or object code of LibOVR in whole, and you may
+not license, sublicense or redistribute any portion or element of LibOVR separately
+or in part (in either source, binary or object form). If you license, sublicense
+or redistribute RIFT SDK Derivatives in and of themselves (not as a part of a
+piece of Developer Content) then you may only do that solely with and in conjunction
+with either the RIFT SDK or LibOVR. The RIFT SDK (including, but not limited to
+LibOVR), any RIFT SDK Derivatives, and any Developer Content may only be used
+with Oculus Approved Rift Products and may not be used, licensed, or sublicensed
+to interface with mobile software or hardware or other commercial headsets,
+mobile tablets or phones that are not authorized and approved by Oculus VR;
+
+3.2. You must include with all such redistributed or sublicensed RIFT SDK
+or RIFT SDK Derivatives code the following copyright notice:
+"Copyright ยฉ 2014 Oculus VR, LLC. All rights reserved," and include the
+list of conditions contained in this Section 3, including the full text of
+the disclaimer in Section 3.6 below;
+
+3.3. Neither the name of Oculus VR, LLC nor the names of Oculus VR, LLC's
+contributors, licensors, employees, or contractors, may be used to endorse or promote
+products derived from this RIFT SDK without specific prior written permission
+of Oculus VR, LLC;
+
+3.4. You must give any other recipients of the RIFT SDK or any elements thereof,
+including LibOVR or RIFT SDK Derivatives, a copy of this License as such recipients,
+licensees or sublicensees may only use the RIFT SDK or any RIFT SDK Derivatives
+or any elements thereof subject to the terms of this Licence and such recipients,
+licensees or sublicensees agreement and acceptance of this License with Oculus VR
+(which will convey all rights to the recipientsโ or licenseesโ or sublicenseesโ
+RIFT SDK Derivatives to Oculus VR), and you must cause any modified files to
+carry prominent notices stating that you changed the files;
+
+3.5. If the RIFT SDK or a specific element thereof such as LibOVR includes a
+"LICENSE" text file as part of its distribution (the "License Notice"), then
+any RIFT SDK Derivatives that you distribute with the RIFT SDK in whole or in
+part must include a readable copy of such attribution notices as are contained
+within the applicable License Notice file (excluding those notices that do not
+pertain to any part of the RIFT SDK Derivatives), in at least one of the following
+places: within a License Notice text file distributed as part of the RIFT SDK
+Derivatives; within the source form or documentation, if provided along with
+the RIFT SDK Derivatives; or, within a display generated by the RIFT SDK Derivatives,
+if and wherever such third-party notices normally appear. You must also include
+in the License Notice file for all RIFT SDK Derivatives a copy of all notices
+(including any product liability or health and safety notices). The contents
+of the License Notice file are for informational purposes only and do not modify
+the License. You may add your own attribution notices within RIFT SDK Derivatives
+that you distribute, alongside or as an addendum to the License Notice text from
+the RIFT SDK or any part thereof, provided that such additional attribution notices
+cannot be construed as modifying the License.
+
+3.6. THIS RIFT SDK AND ANY COMPONENT THEREOF IS PROVIDED BY OCULUS VR AND
+ITS 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 OCULUS VR AS THE
+COPYRIGHT OWNER OR ITS 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 RIFT
+SDK OR THE RIFT SDK DERIVATIVES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+4. This License does not grant permission to use the trade names, trademarks,
+service marks, or product names of Oculus VR, except as required for reasonable
+and customary use in describing the origin of the RIFT SDK, LibOVR, or any
+element thereof, and reproducing the content of the License Notice file.
+Oculus VR reserves all rights not expressly granted to you under this License.
+
+5. In no event and under no legal theory, whether in tort (including negligence),
+contract, or otherwise, unless required by applicable law (such as
+deliberate and grossly negligent acts) or agreed to in writing, shall Oculus VR
+or any contributor be liable to you or your licensees or sublicensees for
+damages, including any direct, indirect, special, incidental, or consequential
+damages of any character arising as a result of this License or out of the use
+or inability to use the RIFT SDK, LibOVR, any element thereof or any RIFT SDK
+Derivatives (including but not limited to damages for loss of goodwill, work
+stoppage, computer failure or malfunction, or any and all other commercial
+damages or losses), even if you or such contributor has been advised of the
+possibility of such damages.
+
+6. Your acceptance of the terms and conditions of this License in and of
+itself and for all Developer Content created as of March 1, 2014, may be
+evidenced by any of the following: your usage of the RIFT SDK or any element
+thereof, acceptance of the click-through agreement, or opening the packaging
+of the CD-ROM containing the RIFT SDK or any element thereof, including LibOVR.
+As this License is updated for future releases of the RIFT SDK and/or LibOVR,
+you agree to abide by and meet all requirements of future updates of this
+License for those future RIFT SDK releases as evidenced by the same usage of
+the RIFT SDK or any element thereof and the future updates of this License
+will apply for that future Developer Content that may developed for or with
+that future RIFT SDK or any element thereof (i.e., you cannot sidestep out
+of the requirements of future updates of the License by developing against
+an older release of the RIFT SDK or License).
+
+7. Oculus VR reserves the right to terminate this License and all your
+rights hereunder in the event you materially breach this License and fail
+to cure such breach within ten (10) business days after notice of breach
+from Oculus VR.
+
+8. Furthermore, Oculus VR also reserves the right to cancel or terminate
+this License for any of the following reasons upon notice to you, subject
+to the appeal process set forth in Section 14 for a wrongful termination:
+
+ a) Intellectual property infringement by you with Developer Content
+ or RIFT SDK Derivatives created by you that is used with or by the
+ RIFT SDK or any part thereof, or any of the RIFT SDK Derivatives;
+
+ b) Developer Content that violates or infringes upon applicable law;
+
+ c) Health and safety issues associated with your Developer Content;
+
+ d) Failure to comply with or use properly the Oculus Warnings,
+ Oculus H&S Protocols, or Oculus EULA;
+
+ e) Use of the RIFT SDK, RIFT SDK Derivatives or LibOVR with a
+ commercial product other than an Oculus Approved Product; and
+
+ f) Failure to provide required notices or deliver source code
+ and/or binary of RIFT SDK Derivatives as set forth above.
+
+If you believe that you have been wrongfully terminated under this Section 8
+with respect to material breach or with respect to these above conditions,
+you have the right to appeal the termination of this License under Section 14.
+
+9. This License may be amended by Oculus VR on a prospective basis, and your
+usage of the License after such amendments or changes signifies your consent
+to and acceptance of any such amendments or changes on a going forward basis.
+
+10. In the event any provision of this License is determined to be invalid,
+prohibited or unenforceable by a court or other body of competent jurisdiction,
+this License shall be construed as if such invalid, prohibited or unenforceable
+provision has been more narrowly drawn so as not to be invalid, prohibited or
+unenforceable.
+
+11. You may not assign any rights or obligations under this License without
+the advance written consent of Oculus VR, which may be withheld in its sole
+discretion. Oculus VR may assign its rights or obligations under this License
+in its sole discretion.
+
+12. Failure of either party at any time to enforce any of the provisions of
+this License will not be construed as a waiver of such provisions or in any way
+affect the validity of this License or parts thereof.
+
+13. Your remedies under this License shall be limited to the right to collect
+money damages, if any, and you hereby waive your right to injunctive or other
+equitable relief.
+
+14. This License shall be governed by the laws of the State of California,
+without giving effect to choice of law principles. All disputes relating to
+this License shall be resolved by binding non-appearance-based arbitration
+before a neutral arbitrator in Orange County, California. If your License
+has been terminated hereunder by Oculus, you may appeal your termination
+through this arbitration process on an expedited basis with an arbitration
+within thirty days of your giving Oculus VR notice of the appeal. The
+arbitration shall be conducted in accordance with the rules and procedures
+of JAMS then in effect, and the judgment of the arbitrator shall be final
+and capable of entry in any court of competent jurisdiction. You agree
+to submit to the personal jurisdiction of the courts located within Orange
+County, California in connection with any entrance of an arbitratorโs judgment
+or decision or any dispute with respect to the arbitration process or procedure
+or Oculus VRโs exercise of its equitable rights or remedies.
\ No newline at end of file
diff --git a/src/Java/Jars/lwjgl_jars/openal_soft_license.txt b/src/Java/Jars/lwjgl_jars/openal_soft_license.txt
new file mode 100644
index 0000000..5bc8fb2
--- /dev/null
+++ b/src/Java/Jars/lwjgl_jars/openal_soft_license.txt
@@ -0,0 +1,481 @@
+ GNU LIBRARY GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1991 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the library GPL. It is
+ numbered 2 because it goes with version 2 of the ordinary GPL.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Library General Public License, applies to some
+specially designated Free Software Foundation software, and to any
+other libraries whose authors decide to use it. You can use it for
+your libraries, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if
+you distribute copies of the library, or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link a program with the library, you must provide
+complete object files to the recipients so that they can relink them
+with the library, after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ Our method of protecting your rights has two steps: (1) copyright
+the library, and (2) offer you this license which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ Also, for each distributor's protection, we want to make certain
+that everyone understands that there is no warranty for this free
+library. If the library is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original
+version, so that any problems introduced by others will not reflect on
+the original authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that companies distributing free
+software will individually obtain patent licenses, thus in effect
+transforming the program into proprietary software. To prevent this,
+we have made it clear that any patent must be licensed for everyone's
+free use or not licensed at all.
+
+ Most GNU software, including some libraries, is covered by the ordinary
+GNU General Public License, which was designed for utility programs. This
+license, the GNU Library General Public License, applies to certain
+designated libraries. This license is quite different from the ordinary
+one; be sure to read it in full, and don't assume that anything in it is
+the same as in the ordinary license.
+
+ The reason we have a separate public license for some libraries is that
+they blur the distinction we usually make between modifying or adding to a
+program and simply using it. Linking a program with a library, without
+changing the library, is in some sense simply using the library, and is
+analogous to running a utility program or application program. However, in
+a textual and legal sense, the linked executable is a combined work, a
+derivative of the original library, and the ordinary General Public License
+treats it as such.
+
+ Because of this blurred distinction, using the ordinary General
+Public License for libraries did not effectively promote software
+sharing, because most developers did not use the libraries. We
+concluded that weaker conditions might promote sharing better.
+
+ However, unrestricted linking of non-free programs would deprive the
+users of those programs of all benefit from the free status of the
+libraries themselves. This Library General Public License is intended to
+permit developers of non-free programs to use free libraries, while
+preserving your freedom as a user of such programs to change the free
+libraries that are incorporated in them. (We have not seen how to achieve
+this as regards changes in header files, but we have achieved it as regards
+changes in the actual functions of the Library.) The hope is that this
+will lead to faster development of free libraries.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, while the latter only
+works together with the library.
+
+ Note that it is possible for a library to be covered by the ordinary
+General Public License rather than by this special one.
+
+ GNU LIBRARY GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library which
+contains a notice placed by the copyright holder or other authorized
+party saying it may be distributed under the terms of this Library
+General Public License (also called "this License"). Each licensee is
+addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also compile or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ c) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ d) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the source code distributed need not include anything that is normally
+distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Library General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ , 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
diff --git a/src/Java/Jars/lwjgl_jars/openvr_license.txt b/src/Java/Jars/lwjgl_jars/openvr_license.txt
new file mode 100644
index 0000000..ee83337
--- /dev/null
+++ b/src/Java/Jars/lwjgl_jars/openvr_license.txt
@@ -0,0 +1,27 @@
+Copyright (c) 2015, Valve Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+this list of conditions and the following disclaimer in the documentation and/or
+other materials provided with the distribution.
+
+3. Neither the name of the copyright holder 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 HOLDER 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.
diff --git a/src/Java/Jars/lwjgl_jars/tinyexr_license.txt b/src/Java/Jars/lwjgl_jars/tinyexr_license.txt
new file mode 100644
index 0000000..8a6f23c
--- /dev/null
+++ b/src/Java/Jars/lwjgl_jars/tinyexr_license.txt
@@ -0,0 +1,63 @@
+Copyright (c) 2014 - 2016, Syoyo Fujita
+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
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the 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 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.
+*/
+
+// TinyEXR contains some OpenEXR code, which is licensed under ------------
+
+///////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
+// Digital Ltd. LLC
+//
+// 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 documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Industrial Light & Magic 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.
+//
+///////////////////////////////////////////////////////////////////////////
+
+// End of OpenEXR license -------------------------------------------------
\ No newline at end of file
diff --git a/src/Java/Jars/lwjgl_jars/tinyfd_license.txt b/src/Java/Jars/lwjgl_jars/tinyfd_license.txt
new file mode 100644
index 0000000..e3d7205
--- /dev/null
+++ b/src/Java/Jars/lwjgl_jars/tinyfd_license.txt
@@ -0,0 +1,15 @@
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any damages
+arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not
+claim that you wrote the original software. If you use this software
+in a product, an acknowledgment in the product documentation would be
+appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be
+misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
\ No newline at end of file
diff --git a/src/Java/Jars/lwjgl_jars/xxhash_license.txt b/src/Java/Jars/lwjgl_jars/xxhash_license.txt
new file mode 100644
index 0000000..7de801e
--- /dev/null
+++ b/src/Java/Jars/lwjgl_jars/xxhash_license.txt
@@ -0,0 +1,24 @@
+xxHash Library
+Copyright (c) 2012-2014, Yann Collet
+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 documentation and/or
+ other materials provided with the distribution.
+
+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 HOLDER 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.
diff --git a/src/Java/Jars/lwjgl_jars/yoga_license.txt b/src/Java/Jars/lwjgl_jars/yoga_license.txt
new file mode 100644
index 0000000..2b3f0e4
--- /dev/null
+++ b/src/Java/Jars/lwjgl_jars/yoga_license.txt
@@ -0,0 +1,30 @@
+BSD License
+
+For yoga software
+
+Copyright (c) 2014-present, Facebook, Inc. 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 documentation
+ and/or other materials provided with the distribution.
+
+ * Neither the name Facebook 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 HOLDER 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.
diff --git a/src/Java/Resources/buttons-css.css b/src/Java/Resources/buttons-css.css
new file mode 100644
index 0000000..53937f1
--- /dev/null
+++ b/src/Java/Resources/buttons-css.css
@@ -0,0 +1,228 @@
+#green {
+ -fx-background-color:
+ linear-gradient(#f0ff35, #a9ff00),
+ radial-gradient(center 50% -40%, radius 200%, #b8ee36 45%, #80c800 50%);
+ -fx-background-radius: 6, 5;
+ -fx-background-insets: 0, 1;
+ -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.4) , 5, 0.0 , 0 , 1 );
+ -fx-text-fill: #395306;
+}
+#round-red {
+ -fx-background-color: linear-gradient(#ff5400, #be1d00);
+ -fx-background-radius: 30;
+ -fx-background-insets: 0;
+ -fx-text-fill: white;
+}
+#bevel-grey {
+ -fx-background-color:
+ linear-gradient(#f2f2f2, #d6d6d6),
+ linear-gradient(#fcfcfc 0%, #d9d9d9 20%, #d6d6d6 100%),
+ linear-gradient(#dddddd 0%, #f6f6f6 50%);
+ -fx-background-radius: 8,7,6;
+ -fx-background-insets: 0,1,2;
+ -fx-text-fill: black;
+ -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 5, 0.0 , 0 , 1 );
+}
+#glass-grey {
+ -fx-background-color:
+ #c3c4c4,
+ linear-gradient(#d6d6d6 50%, white 100%),
+ radial-gradient(center 50% -40%, radius 200%, #e6e6e6 45%, rgba(230,230,230,0) 50%);
+ -fx-background-radius: 30;
+ -fx-background-insets: 0,1,1;
+ -fx-text-fill: black;
+ -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 3, 0.0 , 0 , 1 );
+}
+#shiny-orange {
+ -fx-background-color:
+ linear-gradient(#ffd65b, #e68400),
+ linear-gradient(#ffef84, #f2ba44),
+ linear-gradient(#ffea6a, #efaa22),
+ linear-gradient(#ffe657 0%, #f8c202 50%, #eea10b 100%),
+ linear-gradient(from 0% 0% to 15% 50%, rgba(255,255,255,0.9), rgba(255,255,255,0));
+ -fx-background-radius: 30;
+ -fx-background-insets: 0,1,2,3,0;
+ -fx-text-fill: #654b00;
+ -fx-font-weight: bold;
+ -fx-font-size: 14px;
+ -fx-padding: 10 20 10 20;
+}
+#dark-blue {
+ -fx-background-color:
+ #090a0c,
+ linear-gradient(#38424b 0%, #1f2429 20%, #191d22 100%),
+ linear-gradient(#20262b, #191d22),
+ radial-gradient(center 50% 0%, radius 100%, rgba(114,131,148,0.9), rgba(255,255,255,0));
+ -fx-background-radius: 5,4,3,5;
+ -fx-background-insets: 0,1,2,0;
+ -fx-text-fill: white;
+ -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 5, 0.0 , 0 , 1 );
+ -fx-font-family: "Arial";
+ -fx-text-fill: linear-gradient(white, #d0d0d0);
+ -fx-font-size: 12px;
+ -fx-padding: 10 20 10 20;
+}
+#dark-blue Text {
+ -fx-effect: dropshadow( one-pass-box , rgba(0,0,0,0.9) , 1, 0.0 , 0 , 1 );
+}
+#record-sales {
+ -fx-padding: 8 15 15 15;
+ -fx-background-insets: 0,0 0 5 0, 0 0 6 0, 0 0 7 0;
+ -fx-background-radius: 8;
+ -fx-background-color:
+ linear-gradient(from 0% 93% to 0% 100%, #a34313 0%, #903b12 100%),
+ #9d4024,
+ #d86e3a,
+ radial-gradient(center 50% 50%, radius 100%, #d86e3a, #c54e2c);
+ -fx-effect: dropshadow( gaussian , rgba(0,0,0,0.75) , 4,0,0,1 );
+ -fx-font-weight: bold;
+ -fx-font-size: 1.1em;
+}
+#record-sales:hover {
+ -fx-background-color:
+ linear-gradient(from 0% 93% to 0% 100%, #a34313 0%, #903b12 100%),
+ #9d4024,
+ #d86e3a,
+ radial-gradient(center 50% 50%, radius 100%, #ea7f4b, #c54e2c);
+}
+#record-sales:pressed {
+ -fx-padding: 10 15 13 15;
+ -fx-background-insets: 2 0 0 0,2 0 3 0, 2 0 4 0, 2 0 5 0;
+}
+#record-sales Text {
+ -fx-fill: white;
+ -fx-effect: dropshadow( gaussian , #a30000 , 0,0,0,2 );
+}
+#rich-blue {
+ -fx-background-color:
+ #000000,
+ linear-gradient(#7ebcea, #2f4b8f),
+ linear-gradient(#426ab7, #263e75),
+ linear-gradient(#395cab, #223768);
+ -fx-background-insets: 0,1,2,3;
+ -fx-background-radius: 3,2,2,2;
+ -fx-padding: 12 30 12 30;
+ -fx-text-fill: white;
+ -fx-font-size: 12px;
+}
+#rich-blue Text {
+ -fx-effect: dropshadow( one-pass-box , rgba(0,0,0,0.8) , 0, 0.0 , 0 , 1);
+}
+#big-yellow {
+ -fx-background-color:
+ #ecebe9,
+ rgba(0,0,0,0.05),
+ linear-gradient(#dcca8a, #c7a740),
+ linear-gradient(#f9f2d6 0%, #f4e5bc 20%, #e6c75d 80%, #e2c045 100%),
+ linear-gradient(#f6ebbe, #e6c34d);
+ -fx-background-insets: 0,9 9 8 9,9,10,11;
+ -fx-background-radius: 50;
+ -fx-padding: 15 30 15 30;
+ -fx-font-family: "Helvetica";
+ -fx-font-size: 18px;
+ -fx-text-fill: #311c09;
+ -fx-effect: innershadow( three-pass-box , rgba(0,0,0,0.1) , 2, 0.0 , 0 , 1);
+}
+#big-yellow Text {
+ -fx-effect: dropshadow( one-pass-box , rgba(255,255,255,0.5) , 0, 0.0 , 0 , 1);
+}
+#iphone-toolbar {
+ -fx-background-color: linear-gradient(#98a8bd 0%, #8195af 25%, #6d86a4 100%);
+}
+#iphone {
+ -fx-background-color:
+ #a6b5c9,
+ linear-gradient(#303842 0%, #3e5577 20%, #375074 100%),
+ linear-gradient(#768aa5 0%, #849cbb 5%, #5877a2 50%, #486a9a 51%, #4a6c9b 100%);
+ -fx-background-insets: 0 0 -1 0,0,1;
+ -fx-background-radius: 5,5,4;
+ -fx-padding: 7 30 7 30;
+ -fx-text-fill: #242d35;
+ -fx-font-family: "Helvetica";
+ -fx-font-size: 12px;
+ -fx-text-fill: white;
+}
+#iphone Text {
+ -fx-effect: dropshadow( one-pass-box , rgba(0,0,0,0.8) , 0, 0.0 , 0 , -1 );
+}
+#ipad-dark-grey {
+ -fx-background-color:
+ linear-gradient(#686868 0%, #232723 25%, #373837 75%, #757575 100%),
+ linear-gradient(#020b02, #3a3a3a),
+ linear-gradient(#9d9e9d 0%, #6b6a6b 20%, #343534 80%, #242424 100%),
+ linear-gradient(#8a8a8a 0%, #6b6a6b 20%, #343534 80%, #262626 100%),
+ linear-gradient(#777777 0%, #606060 50%, #505250 51%, #2a2b2a 100%);
+ -fx-background-insets: 0,1,4,5,6;
+ -fx-background-radius: 9,8,5,4,3;
+ -fx-padding: 15 30 15 30;
+ -fx-font-family: "Helvetica";
+ -fx-font-size: 18px;
+ -fx-font-weight: bold;
+ -fx-text-fill: white;
+ -fx-effect: dropshadow( three-pass-box , rgba(255,255,255,0.2) , 1, 0.0 , 0 , 1);
+}
+#ipad-dark-grey Text {
+ -fx-effect: dropshadow( one-pass-box , black , 0, 0.0 , 0 , -1 );
+}
+#ipad-grey {
+ -fx-background-color:
+ linear-gradient(#686868 0%, #232723 25%, #373837 75%, #757575 100%),
+ linear-gradient(#020b02, #3a3a3a),
+ linear-gradient(#b9b9b9 0%, #c2c2c2 20%, #afafaf 80%, #c8c8c8 100%),
+ linear-gradient(#f5f5f5 0%, #dbdbdb 50%, #cacaca 51%, #d7d7d7 100%);
+ -fx-background-insets: 0,1,4,5;
+ -fx-background-radius: 9,8,5,4;
+ -fx-padding: 15 30 15 30;
+ -fx-font-family: "Helvetica";
+ -fx-font-size: 18px;
+ -fx-font-weight: bold;
+ -fx-text-fill: #333333;
+ -fx-effect: dropshadow( three-pass-box , rgba(255,255,255,0.2) , 1, 0.0 , 0 , 1);
+}
+#ipad-grey Text {
+ -fx-effect: dropshadow( one-pass-box , white , 0, 0.0 , 0 , 1 );
+}
+#lion-default {
+ -fx-background-color:
+ rgba(0,0,0,0.08),
+ linear-gradient(#5a61af, #51536d),
+ linear-gradient(#e4fbff 0%,#cee6fb 10%, #a5d3fb 50%, #88c6fb 51%, #d5faff 100%);
+ -fx-background-insets: 0 0 -1 0,0,1;
+ -fx-background-radius: 5,5,4;
+ -fx-padding: 3 30 3 30;
+ -fx-text-fill: #242d35;
+ -fx-font-size: 14px;
+}
+#lion {
+ -fx-background-color:
+ rgba(0,0,0,0.08),
+ linear-gradient(#9a9a9a, #909090),
+ linear-gradient(white 0%, #f3f3f3 50%, #ececec 51%, #f2f2f2 100%);
+ -fx-background-insets: 0 0 -1 0,0,1;
+ -fx-background-radius: 5,5,4;
+ -fx-padding: 3 30 3 30;
+ -fx-text-fill: #242d35;
+ -fx-font-size: 14px;
+}
+#windows7-default {
+ -fx-background-color:
+ #3c7fb1,
+ linear-gradient(#fafdfe, #e8f5fc),
+ linear-gradient(#eaf6fd 0%, #d9f0fc 49%, #bee6fd 50%, #a7d9f5 100%);
+ -fx-background-insets: 0,1,2;
+ -fx-background-radius: 3,2,1;
+ -fx-padding: 3 30 3 30;
+ -fx-text-fill: black;
+ -fx-font-size: 14px;
+}
+#windows7 {
+ -fx-background-color:
+ #707070,
+ linear-gradient(#fcfcfc, #f3f3f3),
+ linear-gradient(#f2f2f2 0%, #ebebeb 49%, #dddddd 50%, #cfcfcf 100%);
+ -fx-background-insets: 0,1,2;
+ -fx-background-radius: 3,2,1;
+ -fx-padding: 3 30 3 30;
+ -fx-text-fill: black;
+ -fx-font-size: 14px;
+}
diff --git a/src/Java/Scripts/install Dev Pkgs.sh b/src/Java/Scripts/install Dev Pkgs.sh
new file mode 100644
index 0000000..76ba4bb
--- /dev/null
+++ b/src/Java/Scripts/install Dev Pkgs.sh
@@ -0,0 +1,58 @@
+#!/bin/bash
+
+function main() {
+OS=`lsb_release -i | awk '{ print $3 }'`
+
+ if ! [[ "${OS}" == "Ubuntu" ]]; then
+ echo "System isn't Ubuntu.... Exiting."
+ exit;
+ fi
+
+ while [[ $ANSWER != 0 && $ANSWER != 1 &&
+ $ANSWER != 2 && $ANSWER != 3 ]]; do
+ clear;
+ echo "Which language would you like to download?"
+ echo "(0) Python"
+ echo "(1) Java"
+ echo "(2) GTKMM & Glade"
+ echo "(3) C++ & C"
+ read -p "--> : " ANSWER;
+ done
+
+ case $ANSWER in
+ 0) installPython ;;
+ 1) installJava ;;
+ 2) installGTKMM ;;
+ 3) installCPPAndC ;;
+ *) echo "Incorrect input...";;
+ esac
+}
+
+installPython() {
+ sudo apt-get install python;
+}
+
+installJava() {
+
+ DISTRO=`lsb_release -c | awk '{ print $2 }'`
+
+ sudo echo "" >> /etc/apt/sources.list
+ sudo echo "" >> /etc/apt/sources.list
+ sudo echo "#### Oracle Java (JDK) Installer PPA" >> /etc/apt/sources.list
+ sudo echo "" >> /etc/apt/sources.list
+ sudo echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu "${DISTRO}" main" >> /etc/apt/sources.list
+ sudo echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu "\"${DISTRO}"\" main" >> /etc/apt/sources.list
+
+ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
+ sudo apt-get update;
+ sudo apt-get install oracle-java8-installer oracle-java8-set-default;
+}
+
+installGTKMM() {
+ sudo apt-get install libgtkmm-3.0-dev glade;
+}
+
+installCPPAndC() {
+ sudo apt-get install g++ libc-dev-bin;
+}
+main;
\ No newline at end of file
diff --git a/src/Java/Scripts/unix_compile_multi-jar.sh b/src/Java/Scripts/unix_compile_multi-jar.sh
new file mode 100755
index 0000000..475b54e
--- /dev/null
+++ b/src/Java/Scripts/unix_compile_multi-jar.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+function main() {
+ javac -cp .:../bin/resources/jars/* *.java
+ rm ../bin/*.class
+ mv *.class ../bin/
+}
+main;
diff --git a/src/Java/Scripts/unix_compile_select-jars.sh b/src/Java/Scripts/unix_compile_select-jars.sh
new file mode 100755
index 0000000..d64d5b4
--- /dev/null
+++ b/src/Java/Scripts/unix_compile_select-jars.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+# -Xlint:unchecked
+function main() {
+ javac *.java
+ rm ../bin/*.class
+ mv *.class ../bin/
+}
+main;
diff --git a/src/Java/TXTs/Android Phone As Webcam.txt b/src/Java/TXTs/Android Phone As Webcam.txt
new file mode 100644
index 0000000..b16cd0f
--- /dev/null
+++ b/src/Java/TXTs/Android Phone As Webcam.txt
@@ -0,0 +1,43 @@
+---- Desktop Client Side ----
+First: Install v4l2loopback from https://github.com/umlaeute/v4l2loopback
+ # Note: You MUST have installed kernel headers; they MUST match the active kernel version BEFORE
+ * make
+ * make && sudo make install
+
+Second: If you haven't after install done the following, do:
+ sudo modprobe v4l2loopback
+
+Third: Test a loopback device with the following command:
+ * ffmpeg -f x11grab -r 15 -s 1280x720 -i :0.0+0,0 \
+ * -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video0
+ # Note: You MIGHT need to add -vf hflip OR -vf vflip OR both to get the image oriented correctly.
+
+Fourth: Setup server to receive client camera stream from android phone.
+
+Fifth: Pipe the stream to a v4l2loopback device. (Usually /dev/video0)
+
+Sixth: Get Skype, OBS, or other apps to point to the device.
+
+
+[ Client Processing ]
+Remote (Phone)
+v4l2-ctl --set-parm=30;v4l2-ctl --set-fmt-video=width=640,height=480,pixelformat=JPEG --stream-mmap --stream-count=-1 --stream-to=- 2>/dev/null | gst-play-1.0 "fd://0"
+
+
+Local (PC)
+-i needs to point to a stream from the phone...
+mp4 and webm seems like good streaming codecs <-- you know what i mean. =P
+
+
+ffmpeg -re -i https://github.com/STMicroelectronics/meta-st-openstlinux/blob/thud/recipes-samples/demo/demo-launcher/media/ST2297_visionv3.webm?raw=true \
+-vcodec rawvideo -pix_fmt yuv420p -threads 0 \
+-f v4l2 /dev/video0
+
+
+
+
+
+
+---- Android Phone Side ----
+
+Need to make an app....
diff --git a/src/Java/TXTs/Java Cheatsheet of Useful Commands and structures.txt b/src/Java/TXTs/Java Cheatsheet of Useful Commands and structures.txt
new file mode 100644
index 0000000..10b32cc
--- /dev/null
+++ b/src/Java/TXTs/Java Cheatsheet of Useful Commands and structures.txt
@@ -0,0 +1,193 @@
+import javafx.fxml.FXML; // fxml stuff
+import javafx.scene.control.Button; // a button
+import javafx.scene.control.ToggleButton; // a toggl button
+import javafx.scene.layout.AnchorPane; // an anchor pane
+import javafx.scene.layout.VBox; // a virticle box; ie stacking ontop
+import javafx.scene.layout.HBox; // a horizontal box; ie stacking side-to-side
+import javafx.scene.image.Image; // path to an image
+import javafx.scene.image.ImageView; // image window port/view area
+import javafx.scene.control.Label; // a label area for text
+import javafx.scene.control.Tooltip; // tooltips
+import javafx.event.ActionEvent; // for event handling
+import java.io.File; // dealing with files and dirs
+import javafx.scene.input.KeyEvent; // just determins if a key is pressed
+import javafx.scene.input.KeyCode; // Get keys entered
+import javafx.scene.input.MouseEvent; // mouse clicks
+import javafx.scene.control.TextField; // Input field
+import javafx.event.ActionEvent; // fxml event setOnAction
+import javafx.scene.Scene; // the area of the play. ;p
+import javafx.scene.layout.Pane; // like anchor pane but less cool
+import javafx.stage.Stage; // stage windows
+import javafx.stage.StageStyle; // assigning a style of css parts
+import javafx.scene.control.TextArea; // large ammounts of text
+import javafx.scene.control.TreeView; // tree view area
+import javafx.scene.control.TreeItem; // a branch of a tree... kinda....
+import javafx.beans.property.StringProperty; // String stuff
+import javafx.beans.property.SimpleStringProperty; // String stuff
+import javafx.scene.layout.TilePane; // Like gridview but easyer
+import javafx.concurrent.Task; // A thread seperate from javafx's main thread
+import javafx.application.Platform; // Usually IN a task thread but lazy loads stuff
+import java.lang.Runtime; // A process runner
+import javafx.stage.FileChooser; // a file chooser window
+import javafx.stage.DirectoryChooser; // a folder chooser window
+import javafx.scene.input.MouseEvent; // mouse click detection
+import javafx.event.EventHandler; // Event handling
+import javafx.scene.Cursor; // courser stuff
+import java.util.concurrent.atomic.AtomicLong; // gui update timing
+import javafx.application.Platform; // part of application
+import javafx.scene.input.Clipboard; // clipboard mngmnt
+import javafx.scene.input.ClipboardContent; // handles clipboard stuff
+import javafx.scene.control.TablePosition; // handle table positioning stuff
+
+
+
+iconList.length // iconList is an array. this gives its size
+System.getProperty("user.home") // Get user Home dir NOTE: There is NO trailing / or \
+desktopDir.listFiles(); // desktopDir is a File path and listFiles lists the dir contents if any.
+
+
+
+NOTE: private not always needed
+
+
+// draging an item // icon is a vbox element here. Can use other stuff
+ icon.addEventFilter(MouseEvent.MOUSE_PRESSED,
+ new EventHandler() {
+ @Override public void handle(MouseEvent click) {
+ if (click.getClickCount() == 2) {
+ click.consume();
+ try {
+ pb = Runtime.getRuntime().exec("xdg-open " + path);
+ } catch(Throwable imgIOErr) {
+ System.out.println(imgIOErr);
+ }
+ } else {
+ orgSceneX = click.getSceneX();
+ orgSceneY = click.getSceneY();
+ orgTranslateX = desktopArea.getLeftAnchor(icon);
+ orgTranslateY = desktopArea.getTopAnchor(icon);
+ }
+ }
+ });
+
+ icon.addEventFilter(MouseEvent.MOUSE_DRAGGED,
+ new EventHandler() {
+ @Override public void handle(MouseEvent clck) {
+ double offsetX = clck.getSceneX() - orgSceneX;
+ double offsetY = clck.getSceneY() - orgSceneY;
+ double newTranslateX = orgTranslateX + offsetX;
+ double newTranslateY = orgTranslateY + offsetY;
+ desktopArea.setLeftAnchor(icon, newTranslateX);
+ desktopArea.setTopAnchor(icon, newTranslateY);
+ }
+ });
+
+
+
+// mouse event
+ pane.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler() {
+ @Override
+ public void handle(MouseEvent event) {
+ event.consume();
+ try {
+ pb = Runtime.getRuntime().exec("xdg-open " + path);
+ } catch(Throwable imgIOErr) {
+ System.out.println(imgIOErr);
+ }
+ }
+ });
+
+
+
+// Run a system command
+ private Process pb; // Process runner
+ try {
+ pb = Runtime.getRuntime().exec(movieImg);
+ pb.waitFor();
+ } catch(Throwable imgIOErr) {
+ System.out.println(imgIOErr);
+ }
+
+
+
+// Directory chooser
+import javafx.stage.DirectoryChooser;
+
+
+// Key event
+ @FXML void onEnter(KeyEvent event) { // if tied to an fxml file and the controller is called
+ if (event.getCode().equals(KeyCode.ENTER)) { // checks what has been entered then does something.
+ }
+
+
+// Task, a seperate thread
+ Task getDir = new Task() { // getdir is just tags name/caller
+ @Override public Void call() {
+ // enter wahat is to be run
+ return null;
+ }};
+ new Thread(getDir).start();
+
+// Platform lazy loads stuff to javafx thread from a seperate THREAD!!
+// Need to be from a Task thread
+ Platform.runLater(new Runnable() {
+ @Override public void run() {
+ view.setImage(pth);
+ }
+ });
+
+
+
+// Ge images in java
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+ private ImageView imgView;
+
+
+ imgView.setImage(img); // img is likely an Image img = new Image();
+ imgView.setFitWidth(100); // Set width
+ imgView.setFitHeight(100); // Set Height
+
+
+// Set tooltips
+import javafx.scene.control.Tooltip;
+ private Tooltip tooltip;
+
+ tooltip = new Tooltip("What to display on hover");
+ tooltip.minHeight(800);
+ tooltip.minWidth(800);
+ Tooltip.install(icon, tooltip); // icon is the thing we are setting this to.
+ // icon could be a Label, Image, Button, etc.
+ // tooltip is the displayed message/tooltip
+
+
+// anchor pane properties
+import javafx.scene.layout.AnchorPane;
+ // icon is the thing being setup. IE, button, label, etc
+ anchorPane.setLeftAnchor(icon, 100.0); // Must be a double!!
+ anchorPane.setRightAnchor(icon, 100.0);
+ anchorPane.setTopAnchor(icon, 100.0);
+
+
+// Tree view awesomeness!!!
+// This is more a class file but can be converted to non class bits.
+ private TreeItem trunk = new TreeItem ("UMSL HR Site Scan");
+ private TreeItem branch = new TreeItem<> ("------------------------");
+ private TreeItem leaf = new TreeItem ();
+ private TreeView treeOutput = new TreeView (trunk);
+
+ public void setExpandSetting() {
+ trunk.setExpanded(true);
+ }
+
+ public void newBranch(String in) {
+ trunk.getChildren().add(branch);
+ branch = new TreeItem (in);
+ }
+
+ public void addLeaf(String in) {
+ leaf = new TreeItem (in);
+ branch.getChildren().add(leaf);
+ }
+
+ public TreeView getOutputArea() { return treeOutput; }
diff --git a/src/Java/launch.cpp b/src/Java/launch.cpp
new file mode 100644
index 0000000..767d1bc
--- /dev/null
+++ b/src/Java/launch.cpp
@@ -0,0 +1,21 @@
+#include
+#include
+#include
+using namespace std;
+
+
+// This is aparently a jenky way of determining the OS that's running.
+int main() {
+ char* ENVIRONMENT = getenv("windir");
+
+
+ if (ENVIRONMENT != NULL) {
+ chdir("bin\\");
+ system("set JAVA_HOME=\"\" & java -cp '.;jsoup.jar' Main");
+ } else {
+ chdir("bin/");
+ system("export JAVA_HOME='' && java -cp '.:jsoup.jar' Main");
+ }
+
+return 0;
+}
diff --git a/src/PDFs/10 Common Software Architectural Patterns in a Nutshell.pdf b/src/PDFs/10 Common Software Architectural Patterns in a Nutshell.pdf
new file mode 100644
index 0000000..d45f77e
Binary files /dev/null and b/src/PDFs/10 Common Software Architectural Patterns in a Nutshell.pdf differ
diff --git a/src/PDFs/Android Messaging Web App.pdf b/src/PDFs/Android Messaging Web App.pdf
new file mode 100644
index 0000000..56ec0ba
Binary files /dev/null and b/src/PDFs/Android Messaging Web App.pdf differ
diff --git a/src/PDFs/Become A Certificate Authority.pdf b/src/PDFs/Become A Certificate Authority.pdf
new file mode 100644
index 0000000..235f1fb
Binary files /dev/null and b/src/PDFs/Become A Certificate Authority.pdf differ
diff --git a/src/PDFs/DIY - Custom Linux.pdf b/src/PDFs/DIY - Custom Linux.pdf
new file mode 100644
index 0000000..bc7c550
Binary files /dev/null and b/src/PDFs/DIY - Custom Linux.pdf differ
diff --git a/src/PDFs/Debootstraping Mini Root File System.pdf b/src/PDFs/Debootstraping Mini Root File System.pdf
new file mode 100644
index 0000000..a6c4208
Binary files /dev/null and b/src/PDFs/Debootstraping Mini Root File System.pdf differ
diff --git a/src/PDFs/Linux Menu Specifications.pdf b/src/PDFs/Linux Menu Specifications.pdf
new file mode 100644
index 0000000..e7d9d80
Binary files /dev/null and b/src/PDFs/Linux Menu Specifications.pdf differ
diff --git a/src/PDFs/Tools For Building Geospatial Web Applications.pdf b/src/PDFs/Tools For Building Geospatial Web Applications.pdf
new file mode 100644
index 0000000..d7cf785
Binary files /dev/null and b/src/PDFs/Tools For Building Geospatial Web Applications.pdf differ
diff --git a/src/Python/Python Performance Tips/Python Performance Tips.html b/src/Python/Python Performance Tips/Python Performance Tips.html
new file mode 100644
index 0000000..f221d41
--- /dev/null
+++ b/src/Python/Python Performance Tips/Python Performance Tips.html
@@ -0,0 +1,651 @@
+
+
+Python Performance Tips
+
+
+
+
+
+
+
+
+
+
+
+
+
Python Performance Tips
+
+
This page is devoted to various tips and tricks that help improve the
+performance of your Python programs. Wherever the information comes from
+someone else, I've tried to identify the source. Note: I
+originally wrote this in (I think) 1996 and haven't done a lot to keep it
+updated since then. Python has has changed in some significant ways since
+then, which means that some of the orderings will have changed. You should
+always test these tips with your application and the version of Python you
+intend to use and not just blindly accept that one method is faster than
+another.
+
+
Also new since this was originally written are packages like Pyrex, Psyco, Weave, and PyInline, which can dramatically
+improve your application's performance by making it easier to push
+performance-critical code into C or machine language.
+
+
If you have any light to shed on this subject, let me know.
The first step to speeding up your program is learning where the
+bottlenecks lie. It hardly makes sense to optimize code that is never
+executed or that already runs fast. I use two modules to help locate the
+hotspots in my code, profile and trace. In later examples I also use the
+timeit module, which is new in Python 2.3.
The profile
+module is included as a standard module in the Python distribution.
+Using it to profile the execution of a set of functions is quite easy.
+Suppose your main function is called main, takes no arguments
+and you want to execute it under the control of the profile module. In its
+simplest form you just execute
+
+
import profile
+profile.run('main()')
+
+
+
When main() returns, the profile module will print a table
+of function calls and execution times. The output can be tweaked using the
+Stats class included with the module. In Python 2.4 profile will allow the
+time consumed by Python builtins and functions in extension modulesto be
+profiled as well.
New in Python 2.2, the hotshot
+package is intended as a replacement for the profile module. The
+underlying module is written in C, so using hotshot should result in a much
+smaller performance hit, and thus a more accurate idea of how your
+application is performing. There is also a hotshotmain.py
+program in the distributions Tools/scripts directory which
+makes it easy to run your program under hotshot control from the command
+line.
The trace module is a spin-off of the profile module I wrote originally
+to perform some crude statement level test coverage. It's been heavily
+modified by several other people since I released my initial crude effort.
+As of Python 2.0 you should find trace.py in the Tools/scripts directory of
+the Python distribution. Starting with Python 2.3 it's in the standard
+library (the Lib directory). You can copy it to your local bin directory
+and set the execute permission, then execute it directly. It's easy to run
+from the command line to trace execution of whole scripts:
+
+
% trace.py -t spam.py eggs
+
+
+
There's no separate documentation, but you can execute "pydoc trace" to
+view the inline documentation.
+Sorting lists of basic Python objects is generally pretty efficient. The
+sort method for lists takes an optional comparison function as an argument
+that can be used to change the sorting behavior. This is quite convenient,
+though it can really slow down your sorts.
+
+
An alternative way to speed up sorts is to construct a list of tuples
+whose first element is a sort key that will sort properly using the default
+comparison, and whose second element is the original list element. This is
+the so-called Schwartzian
+Transform.
+
+
+Suppose, for example, you have a list of tuples that you want to sort by the
+n-th field of each tuple. The following function will do that.
+
+
def sortby(somelist, n):
+ nlist = [(x[n], x) for x in somelist]
+ nlist.sort()
+ return [val for (key, val) in nlist]
+
+
+
Matching the behavior of the current list sort method (sorting in place)
+is easily achieved as well:
+
+
def sortby_inplace(somelist, n):
+ somelist[:] = [(x[n], x) for x in somelist]
+ somelist.sort()
+ somelist[:] = [val for (key, val) in somelist]
+ return
+
Strings in Python are immutable. This fact frequently sneaks up and
+bites novice Python programmers on the rump. Immutability confers some
+advantages and disadvantages. In the plus column, strings can be used a
+keys in dictionaries and individual copies can be shared among multiple
+variable bindings. (Python automatically shares one- and two-character
+strings.) In the minus column, you can't say something like, "change all
+the 'a's to 'b's" in any given string. Instead, you have to create a new
+string with the desired properties. This continual copying can lead to
+significant inefficiencies in Python programs.
+
+
Avoid this:
+
+
s = ""
+for substring in list:
+ s += substring
+
+
+
Use s = "".join(list) instead. The former is a very common
+and catastrophic mistake when building large strings. Similarly, if you are
+generating bits of a string sequentially instead of:
+
+
s = ""
+for x list:
+ s += some_function(x)
+
+
+
use
+
+
slist = [some_function(elt) for elt in somelist]
+s = "".join(slist)
+
+
+
Avoid:
+
+
out = "<html>" + head + prologue + query + tail + "</html>"
+
+
+
Instead, use
+
+
out = "<html>%s%s%s%s</html>" % (head, prologue, query, tail)
+
+
+
Even better, for readability (this has nothing to do with efficiency
+other than yours as a programmer), use dictionary substitution:
+
+
out = "<html>%(head)s%(prologue)s%(query)s%(tail)s</html>" % locals()
+
+
+
This last two are going to be much faster, especially when piled up over
+many CGI script executions, and easier to modify to boot. In addition, the
+slow way of doing things got slower in Python 2.0 with the addition of rich
+comparisons to the language. It now takes the Python virtual machine a lot
+longer to figure out how to concatenate two strings. (Don't forget that
+Python does all method lookup at runtime.)
Python supports a couple of looping constructs. The for
+statement is most commonly used. It loops over the elements of a sequence,
+assigning each to the loop variable. If the body of your loop is simple,
+the interpreter overhead of the for loop itself can be a
+substantial amount of the overhead. This is where the map
+function is handy. You can think of map as a for
+moved into C code. The only restriction is that the "loop body" of
+map must be a function call.
+
+
Here's a straightforward example. Instead of looping over a list of
+words and converting them to upper case:
+
+
newlist = []
+for word in oldlist:
+ newlist.append(word.upper())
+
+
+
you can use map to push the loop from the interpreter into
+compiled C code:
+
+
newlist = map(str.upper, oldlist)
+
+
+
List comprehensions were added to Python in version 2.0 as well. They
+provide a syntactically more compact way of writing the above for loop:
+
+
newlist = [s.upper() for s in list]
+
+
+
It's generally not any faster than the for loop version, however.
Suppose you can't use map or a list comprehension? You may
+be stuck with the for loop. The for loop example has another inefficiency.
+Both newlist.append and word.upper are function
+references that are reevaluated each time through the loop. The original
+loop can be replaced with:
+
+
upper = str.upper
+newlist = []
+append = newlist.append
+for word in list:
+ append(upper(word))
+
+
+
This technique should be used with caution. It gets more difficult to
+maintain if the loop is large. Unless you are intimately familiar with that
+piece of code you will find yourself scanning up to check the definitions of
+append and upper.
The final speedup available to us for the non-map version
+of the for loop is to use local variables wherever possible.
+If the above loop is cast as a function, append and
+upper become local variables. Python accesses local variables
+much more efficiently than global variables.
+
+
def func():
+ upper = str.upper
+ newlist = []
+ append = newlist.append
+ for word in words:
+ append(upper(word))
+ return newlist
+
+
+
At the time I originally wrote this I was using a 100MHz Pentium running
+BSDI. I got the following times for converting the list of words in
+/usr/share/dict/words (38,470 words at that time) to upper
+case:
+
+
+
+
Version
+
Time (seconds)
+
+
+
+
Basic loop
3.47
+
+
+
+
Eliminate dots
2.45
+
+
+
+
Local variable & no dots
1.79
+
+
+
+
Using map function
0.54
+
+
+
+
Eliminating the loop overhead by using map is often going
+to be the most efficient option. When the complexity of your loop precludes
+its use other techniques are available to speed up your loops, however.
Suppose you are building a dictionary of word frequencies and you've
+already broken your text up into a list of words. You might execute
+something like:
+
+
wdict = {}
+has_key = wdict.has_key
+for word in words:
+ if not has_key(word): wdict[word] = 0
+ wdict[word] = wdict[word] + 1
+
+
+
Except for the first time, each time a word is seen the if
+statement's test fails. If you are counting a large number of words, many
+will probably occur multiple times. In a situation where the initialization
+of a value is only going to occur once and the augmentation of that value
+will occur many times it is cheaper to use a try statement:
It's important to catch the expected KeyError exception, and not have a
+default except clause to avoid trying to recover from an
+exception you really can't handle by the statement(s) in the
+try clause.
+
+
A third alternative became available with the release of Python 2.x.
+Dictionaries now have a get() method which will return a default value if
+the desired key isn't found in the dictionary. This simplifies the loop:
+
+
wdict = {}
+for word in words:
+ wdict[word] = wdict.get(word, 0) + 1
+
+
+
When I originally wrote this section, there were clear situations where
+one of the first two approaches was faster. It seems that all three
+approaches now exhibit similar performance (within about 10% of each other),
+more or less independent of the properties of the list of words.
import statements can be executed just about anywhere.
+It's often useful to place them inside functions to restrict their
+visibility and/or reduce initial startup time. Although Python's
+interpreter is optimized to not import the same module multiple times,
+repeatedly executing an import statement can seriously affect performance in
+some circumstances.
+
+
Consider the following two snippets of code (originally from Greg
+McFarlane, I believe - I found it unattributed in a comp.lang.python/python-list@python.org posting and
+later attributed to him in another source):
+
+
def doit1():
+ import string ###### import statement inside function
+ string.lower('Python')
+
+for num in range(100000):
+ doit1()
+
+
+
or:
+
+
import string ###### import statement outside function
+def doit2():
+ string.lower('Python')
+
+for num in range(100000):
+ doit2()
+
+
+
doit2 will run much faster than doit1, even
+though the reference to the string module is global in doit2.
+Here's a Python interpreter session run using Python 2.3 and the new
+timeit module, which shows how much faster the second is than
+the first:
I found it frustrating that to use map
+to eliminate simple for loops like:
+
+
dict = {}
+nil = []
+for s in list:
+ dict[s] = nil
+
+
+
I had to use a lambda
+form or define a named function
+that would probably negate any speedup I was getting by using
+map in the first place. I decided I needed some functions to
+allow me to set, get or delete dictionary keys and values en masse. I
+proposed a change to Python's dictionary object and used it for awhile.
+However, a more general solution appears in the form of the
+operator module in Python 1.4. Suppose you have a list and you
+want to eliminate its duplicates (ignoring the presence of set objects new
+in Python 2.3). Instead of the code above, you can execute:
Function call overhead in Python is relatively high, especially compared
+with the execution speed of a builtin function. This strongly suggests that
+where appropriate, functions should handle data aggregates. Here's a
+contrived example written in Python.
+
+
import time
+x = 0
+def doit1(i):
+ global x
+ x = x + i
+
+list = range(100000)
+t = time.time()
+for i in list:
+ doit1(i)
+
+print "%.3f" % (time.time()-t)
+
+
+
vs.
+
+
import time
+x = 0
+def doit2(list):
+ global x
+ for i in list:
+ x = x + i
+
+list = range(100000)
+t = time.time()
+doit2(list)
+print "%.3f" % (time.time()-t)
+
+
+
Here's the proof in the pudding using an interactive session:
+
+
>>> t = time.time()
+>>> doit2(list)
+>>> print "%.3f" % (time.time()-t)
+0.204
+>>> t = time.time()
+>>> for i in list:
+... doit1(i)
+...
+>>> print "%.3f" % (time.time()-t)
+0.758
+
+
+
Even written in Python, the second example runs about four times faster
+than the first. Had doit been written in C the difference
+would likely have been even greater (exchanging a Python for
+loop for a C for loop as well as removing most of the function
+calls).
The Python interpreter performs some periodic checks. In particular, it
+decides whether or not to let another thread run and whether or not to run a
+pending call (typically a call established by a signal handler). Most of the
+time there's nothing to do, so performing these checks each pass around the
+interpreter loop can slow things down. There is a function in the
+sys module, setcheckinterval, which you can call
+to tell the interpreter how often to perform these periodic checks. Prior
+to the release of Python 2.3 it defaulted to 10. In 2.3 this was raised to
+100. If you aren't running with threads and you don't expect to be catching
+many signals, setting this to a larger value can improve the interpreter's
+performance, sometimes substantially.
It is also not Perl, Java, C++ or Haskell. Be careful when transferring
+your knowledge of how other languages perform to Python. A simple example
+serves to demonstrate:
+
+
% timeit.py -s 'x = 47' 'x * 2'
+ 1000000 loops, best of 3: 0.574 usec per loop
+ % timeit.py -s 'x = 47' 'x << 1'
+ 1000000 loops, best of 3: 0.524 usec per loop
+ % timeit.py -s 'x = 47' 'x + x'
+ 1000000 loops, best of 3: 0.382 usec per loop
+
+
+
Now consider the similar C programs (only the add version is shown):
+
+
#include <stdio.h>
+
+int
+main (int argc, char **argv) {
+ int i = 47;
+ int loop;
+ for (loop=0; loop<500000000; loop++)
+ i + i;
+}
+
+
+
and the execution times:
+
+
% for prog in mult add shift ; do
+ < for i in 1 2 3 ; do
+ < echo -n "$prog: "
+ < /usr/bin/time ./$prog
+ < done
+ < echo
+ < done
+ mult: 6.12 real 5.64 user 0.01 sys
+ mult: 6.08 real 5.50 user 0.04 sys
+ mult: 6.10 real 5.45 user 0.03 sys
+
+ add: 6.07 real 5.54 user 0.00 sys
+ add: 6.08 real 5.60 user 0.00 sys
+ add: 6.07 real 5.58 user 0.01 sys
+
+ shift: 6.09 real 5.55 user 0.01 sys
+ shift: 6.10 real 5.62 user 0.01 sys
+ shift: 6.06 real 5.50 user 0.01 sys
+
+
+
Note that there is a significant advantage in Python to adding a number
+to itself instead of multiplying it by two or shifting it left by one bit.
+In C on all modern computer architectures, each of the three arithmetic
+operations are translated into a single machine instruction which executes
+in one cycle, so it doesn't really matter which one you choose.
+
+
A common "test" new Python programmers often perform is to translate the
+common Perl idiom
+
+
while (<>) {
+ print;
+ }
+
+
+
into Python code that looks something like
+
+
#!/usr/bin/env python
+
+ import fileinput
+
+ for line in fileinput.input():
+ print line,
+
+
+
and use it to conclude that Python must be much slower than Perl. As others
+have pointed out numerous times, Python is slower than Perl for some things
+and faster for others. Relative performance also often depends on your
+experience with the two languages.