<commit_before>/*---------------------------------------------------------------------------*\
  $Id$
\*---------------------------------------------------------------------------*/

package org.clapper.util.mail;

import java.net.InetAddress;

import java.io.IOException;
import java.io.InputStream;
import java.io.File;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Reader;
import java.io.InputStreamReader;

import java.util.List;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Collection;
import java.util.Iterator;

import java.net.InetAddress;
import java.net.UnknownHostException;

import javax.activation.DataHandler;
import javax.activation.FileTypeMap;
import javax.activation.FileDataSource;

import javax.mail.internet.InternetAddress;
import javax.mail.MessagingException;
import javax.mail.Message;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;

/**
 * <h3>Overview</h3>
 *
 * <p>The <tt>EmailMessage</tt> class is a simplified front-end to a
 * portion of Sun's Java Mail API. It provides an easy-to-use API for
 * composing and sending an email message, including simple single-part and
 * more complicated multipart email messages. Using an
 * <tt>EmailMessage</tt> object, a caller can compose and send a message
 * consisting of an optional text part and zero or more MIME-encoded
 * attachments. The message can have any number of recipients. The
 * recipients can be</p>
 *
 * <ul>
 *   <li> primary ("To:") recipients
 *   <li> "carbon copy" ("Cc:") recipients
 *   <li> blind copy ("Bcc:") recipient
 * </ul>
 *
 * <p>in any combination.</p>
 *
 * <p>Once created and filled, an <tt>EmailMessage</tt> can be sent
 * multiple times, through different SMTP servers if desired. To send
 * an <tt>EmailMessage</tt>, use an <tt>EmailTransport</tt> object.</p>
 *
 * <p>The <tt>EmailMessage</tt> class supports both the MIME
 * "multipart/mixed" and "multipart/alternative" message types. According to
 * {@link <a href="http://www.ietf.org/rfc/rfc1341.txt">RFC 1341</a>},
 * the differences between the two types are as follows:</p>
 *
 * <table border="1">
 *   <tr valign="top">
 *     <td>multipart/mixed</td>
 *     <td>Intended for use when the body parts (i.e., the text and the
 *         attachments) are independent and intended to be displayed serially.
 *         For example, to send a text message with an attached image, you
 *         would use a "multipart/mixed" message.
 *   </tr>
 *
 *   <tr valign="top">
 *     <td>multipart/alternative</td>
 *     <td>Each of the parts (i.e., the main text part and the attachments)
 *         is an alternative version of the same information. The most typical
 *         "multipart/alternative" message contains a plain text part (i.e.,
 *         MIME type "text/plain") and an HTML text part. Both contain the
 *         same text, but the HTML part has a "richer" version of it. The
 *         recipient's mail client should either display the "best" version
 *         of the message, based on the user's environments and
 *         preferences; or, it should offer the user a choice of which part
 *         to view. A mail reader that's capable of displaying HTML might
 *         choose to ignore the plain text part and display only the HTML
 *         attachment; by contrast, a mail reader that cannot render HTML
 *         might choose to display only the plain text part.</td>
 *   </tr>
 * </table>
 *
 * <p>By default, an <tt>EmailMessage</tt> uses the "multipart/mixed"
 * mode. To use "multipart/alternative", use the
 * {@link #setMultipartSubtype(MultipartSubtype) setMultipartSubtype()}
 * method, passing it the constant value
 * {@link #MULTIPART_ALTERNATIVE}. Note: You <b>cannot</b> change the
 * subtype once you've added content to the message.</p>
 *
 * <h3>Examples</h3>
 *
 * <p>The following code builds and sends a message containing a simple
 * "Hello!" text message, with no attachments.
 *
 * <blockquote><pre>
 * </pre></blockquote>
 *
 * <h3>Restrictions</h3>
 *
 * <p>As a simplified front-end, this class does have some restrictions,
 * including the following.</p>
 *
 * <ul>
 *   <li> It cannot currently be used to read incoming email messages
 *        (e.g., from a POP3 or IMAP service).
 *   <li> An <tt>EmailMessage</tt> object cannot be saved to "normal" email
 *        stores, though it can be serialized and unserialized.
 *   <li> It doesn't handle multipart types other than "multipart/mixed"
 *        and "multipart/alternative".
 * </ul>
 *
 * <p>For more complicated email interactions, use the Java Mail API
 * directly.</p>
 *
 * <h3>Third-party Library Requirements</h3>
 *
 * <p><b>Note:</b> This class requires the use of the Java Activation
 * Framework (JAF) classes (package <tt>javax.activation</tt>) and the
 * Java Mail API (package <tt>javax.mail</tt>). It was tested with
 * the following Java Mail API and JAF versions:</p>
 *
 * <ul>
 *   <li>Java Mail API 1.1.2 and Java Activation Framework API 1.0
 *   <li>Java Mail API 1.3.1 and Java Activation Framework API 1.0.2
 * </ul>
 *
 * <p>Both APIs are available from
 * {@link <a href="http://java.sun.com/">java.sun.com</a>}.</p>
 *
 * @version <tt>$Revision$</tt>
 *
 * @see EmailTransport
 * @see SMTPEmailTransport
 * @see <a href="http://java.sun.com/javamail/">The Java Mail API home page</a>
 */
public class EmailMessage
{
    /*----------------------------------------------------------------------*\
                             Public Constants
    \*----------------------------------------------------------------------*/

    /**<commit_msg>Now implements Serializable, as the docs suggest.<commit_after>/*---------------------------------------------------------------------------*\
  $Id$
\*---------------------------------------------------------------------------*/

package org.clapper.util.mail;

import java.net.InetAddress;

import java.io.IOException;
import java.io.Serializable;
import java.io.InputStream;
import java.io.File;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Reader;
import java.io.InputStreamReader;

import java.util.List;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Collection;
import java.util.Iterator;

import java.net.InetAddress;
import java.net.UnknownHostException;

import javax.activation.DataHandler;
import javax.activation.FileTypeMap;
import javax.activation.FileDataSource;

import javax.mail.internet.InternetAddress;
import javax.mail.MessagingException;
import javax.mail.Message;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;

/**
 * <h3>Overview</h3>
 *
 * <p>The <tt>EmailMessage</tt> class is a simplified front-end to a
 * portion of Sun's Java Mail API. It provides an easy-to-use API for
 * composing and sending an email message, including simple single-part and
 * more complicated multipart email messages. Using an
 * <tt>EmailMessage</tt> object, a caller can compose and send a message
 * consisting of an optional text part and zero or more MIME-encoded
 * attachments. The message can have any number of recipients. The
 * recipients can be</p>
 *
 * <ul>
 *   <li> primary ("To:") recipients
 *   <li> "carbon copy" ("Cc:") recipients
 *   <li> blind copy ("Bcc:") recipient
 * </ul>
 *
 * <p>in any combination.</p>
 *
 * <p>Once created and filled, an <tt>EmailMessage</tt> can be sent
 * multiple times, through different SMTP servers if desired. To send
 * an <tt>EmailMessage</tt>, use an <tt>EmailTransport</tt> object.</p>
 *
 * <p>The <tt>EmailMessage</tt> class supports both the MIME
 * "multipart/mixed" and "multipart/alternative" message types. According to
 * {@link <a href="http://www.ietf.org/rfc/rfc1341.txt">RFC 1341</a>},
 * the differences between the two types are as follows:</p>
 *
 * <table border="1">
 *   <tr valign="top">
 *     <td>multipart/mixed</td>
 *     <td>Intended for use when the body parts (i.e., the text and the
 *         attachments) are independent and intended to be displayed serially.
 *         For example, to send a text message with an attached image, you
 *         would use a "multipart/mixed" message.
 *   </tr>
 *
 *   <tr valign="top">
 *     <td>multipart/alternative</td>
 *     <td>Each of the parts (i.e., the main text part and the attachments)
 *         is an alternative version of the same information. The most typical
 *         "multipart/alternative" message contains a plain text part (i.e.,
 *         MIME type "text/plain") and an HTML text part. Both contain the
 *         same text, but the HTML part has a "richer" version of it. The
 *         recipient's mail client should either display the "best" version
 *         of the message, based on the user's environments and
 *         preferences; or, it should offer the user a choice of which part
 *         to view. A mail reader that's capable of displaying HTML might
 *         choose to ignore the plain text part and display only the HTML
 *         attachment; by contrast, a mail reader that cannot render HTML
 *         might choose to display only the plain text part.</td>
 *   </tr>
 * </table>
 *
 * <p>By default, an <tt>EmailMessage</tt> uses the "multipart/mixed"
 * mode. To use "multipart/alternative", use the
 * {@link #setMultipartSubtype(MultipartSubtype) setMultipartSubtype()}
 * method, passing it the constant value
 * {@link #MULTIPART_ALTERNATIVE}. Note: You <b>cannot</b> change the
 * subtype once you've added content to the message.</p>
 *
 * <h3>Examples</h3>
 *
 * <p>The following code builds and sends a message containing a simple
 * "Hello!" text message, with no attachments.
 *
 * <blockquote><pre>
 * </pre></blockquote>
 *
 * <h3>Restrictions</h3>
 *
 * <p>As a simplified front-end, this class does have some restrictions,
 * including the following.</p>
 *
 * <ul>
 *   <li> It cannot currently be used to read incoming email messages
 *        (e.g., from a POP3 or IMAP service).
 *   <li> An <tt>EmailMessage</tt> object cannot be saved to "normal" email
 *        stores, though it can be serialized and unserialized.
 *   <li> It doesn't handle multipart types other than "multipart/mixed"
 *        and "multipart/alternative".
 * </ul>
 *
 * <p>For more complicated email interactions, use the Java Mail API
 * directly.</p>
 *
 * <h3>Third-party Library Requirements</h3>
 *
 * <p><b>Note:</b> This class requires the use of the Java Activation
 * Framework (JAF) classes (package <tt>javax.activation</tt>) and the
 * Java Mail API (package <tt>javax.mail</tt>). It was tested with
 * the following Java Mail API and JAF versions:</p>
 *
 * <ul>
 *   <li>Java Mail API 1.1.2 and Java Activation Framework API 1.0
 *   <li>Java Mail API 1.3.1 and Java Activation Framework API 1.0.2
 * </ul>
 *
 * <p>Both APIs are available from
 * {@link <a href="http://java.sun.com/">java.sun.com</a>}.</p>
 *
 * @version <tt>$Revision$</tt>
 *
 * @see EmailTransport
 * @see SMTPEmailTransport
 * @see <a href="http://java.sun.com/javamail/">The Java Mail API home page</a>
 */
public class EmailMessage implements Serializable
{
    /*----------------------------------------------------------------------*\
                             Public Constants
    \*----------------------------------------------------------------------*/

    /**
{'fraction_non_alphanumeric': 0.1643353642838754, 'fraction_numerical': 0.0049772590749163305, 'mean_word_length': 2.810987573577502, 'pattern_counts': {'":': 0, '<': 183, '<?xml version=': 0, '>': 183, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1074102', 'n_tokens_mistral': 3450, 'n_tokens_neox': 3324, 'n_words': 1206}