<commit_before>/*
 * Copyright (C) The Apache Software Foundation. All rights reserved.
 *
 * This software is published under the terms of the Apache Software License
 * version 1.1, a copy of which has been included with this distribution in
 * the LICENSE file.
 */
package org.apache.james.transport.mailets;

import java.io.PrintWriter;
import java.io.StringWriter;

import java.util.Collection;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.StringTokenizer;

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

import org.apache.james.util.RFC822DateFormat;

import org.apache.mailet.GenericMailet;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;


/**
*<P>A mailet providing configurable redirection services<BR>
*This mailet can produce listserver, forward and notify behaviour, with the original
*message intact, attached, appended or left out altogether.<BR>
*This built in functionality is controlled by the configuration as laid out below.</P>
*<P>However it is also designed to be easily subclassed to make authoring redirection
*mailets simple. <BR>
*By extending it and overriding one or more of these methods new behaviour can
*be quickly created without the author having to address any other issue than
*the relevant one:</P>
*<UL>
*<LI>attachError() , should error messages be appended to the message</LI>
*<LI>getAttachementType(), what should be attached to the message</LI>
*<LI>getInLineType(), what should be included in the message</LI>
*<LI>getMessage(), The text of the message itself</LI>
*<LI>getRecipients(), the recipients the mail is sent to</LI>
*<LI>getReplyTo(), where replys to this message will be sent</LI>
*<LI>getSender(), who the mail is from</LI>
*<LI>getSubjectPrefix(), a prefix to be added to the message subject</LI>
*<LI>getTo(), a list of people to whom the mail is *apparently* sent</LI>
*<LI>getPassThrough(), should this mailet GHOST the original message.</LI>
*<LI>isStatic(), should this mailet run the get methods for every mail, or just
*once. </LI>
*</UL>
*<P>The configuration parameters are:</P>
*<TABLE width="75%" border="0" cellspacing="2" cellpadding="2">
*<TR>
*<TD width="20%">&lt;recipients&gt;</TD>
*<TD width="80%">A comma delimited list of email addresses for recipients of
*this message, it will use the &quot;to&quot; list if not specified. These
*addresses will only appear in the To: header if no &quot;to&quot; list is
*supplied.</TD>
*</TR>
*<TR>
*<TD width="20%">&lt;to&gt;</TD>
*<TD width="80%">A comma delimited list of addresses to appear in the To: header,
*the email will only be delivered to these addresses if they are in the recipients
*list.<BR>
*The recipients list will be used if this is not supplied</TD>
*</TR>
*<TR>
*<TD width="20%">&lt;sender&gt;</TD>
*<TD width="80%">A single email address to appear in the From: header <BR>
*It can include constants &quot;sender&quot; and &quot;postmaster&quot;</TD>
*</TR>
*<TR>
*<TD width="20%">&lt;message&gt;</TD>
*<TD width="80%">A text message to be the body of the email. Can be omitted.</TD>
*</TR>
*<TR>
*<TD width="20%">&lt;inline&gt;</TD>
*<TD width="80%">
*<P>One of the following items:</P>
*<UL>
*<LI>unaltered &nbsp;&nbsp;&nbsp;&nbsp;The original message is the new
* message, for forwarding/aliasing</LI>
*<LI>heads&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The
* headers of the original message are appended to the message</LI>
*<LI>body&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The
* body of the original is appended to the new message</LI>
*<LI>all&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Both
* headers and body are appended</LI>
*<LI>none&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Neither
* body nor headers are appended</LI>
*</UL>
*</TD>
*</TR>
*<TR>
*<TD width="20%">&lt;attachment&gt;</TD>
*<TD width="80%">
*<P>One of the following items:</P>
*<UL>
*<LI>heads&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The headers of the original
* are attached as text</LI>
*<LI>body&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The body of the original
* is attached as text</LI>
*<LI>all&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Both
* headers and body are attached as a single text file</LI>
*<LI>none&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Nothing is attached</LI>
*<LI>message &nbsp;The original message is attached as type message/rfc822,
* this means that it can, in many cases, be opened, resent, fw'd, replied
* to etc by email client software.</LI>
*</UL>
*</TD>
*</TR>
*<TR>
*<TD width="20%">&lt;passThrough&gt;</TD>
*<TD width="80%">TRUE or FALSE, if true the original message continues in the
*mailet processor after this mailet is finished. False causes the original
*to be stopped.</TD>
*</TR>
*<TR>
*<TD width="20%">&lt;attachError&gt;</TD>
*<TD width="80%">TRUE or FALSE, if true any error message available to the
*mailet is appended to the message body (except in the case of inline ==
*unaltered)</TD>
*</TR>
*<TR>
*<TD width="20%">&lt;replyto&gt;</TD>
*<TD width="80%">A single email address to appear in the Rely-To: header, can
*also be &quot;sender&quot; or &quot;postmaster&quot;, this header is not
*set if this is omited.</TD>
*</TR>
*<TR>
*<TD width="20%">&lt;prefix&gt;</TD>
*<TD width="80%">An optional subject prefix prepended to the original message
+*subject, for example:<BR>
+*Undeliverable mail: </TD>
*</TR>
*<TR>
*<TD width="20%">&lt;static&gt;</TD>
*<TD width="80%">
*<P>TRUE or FALSE, if this is true it hints to the mailet that none of the
*parameters are set dynamically, and therefore they can be set once in
*the init method.<BR>
*False tells the mailet to call all the &quot;getters&quot; for every mail
*processed.</P>
*<P>This defaults to false.<BR>
*It should be TRUE in all cases, except where one of the getter methods
*has been overriden to provide dynamic values, such as a listserve which
*might override getRecipients() to get a list from a users repository.</P>
*</TD><commit_msg>Fix to the previous bugfix.  Removing extra leading '+'s<commit_after>/*
 * Copyright (C) The Apache Software Foundation. All rights reserved.
 *
 * This software is published under the terms of the Apache Software License
 * version 1.1, a copy of which has been included with this distribution in
 * the LICENSE file.
 */
package org.apache.james.transport.mailets;

import java.io.PrintWriter;
import java.io.StringWriter;

import java.util.Collection;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.StringTokenizer;

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

import org.apache.james.util.RFC822DateFormat;

import org.apache.mailet.GenericMailet;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;


/**
*<P>A mailet providing configurable redirection services<BR>
*This mailet can produce listserver, forward and notify behaviour, with the original
*message intact, attached, appended or left out altogether.<BR>
*This built in functionality is controlled by the configuration as laid out below.</P>
*<P>However it is also designed to be easily subclassed to make authoring redirection
*mailets simple. <BR>
*By extending it and overriding one or more of these methods new behaviour can
*be quickly created without the author having to address any other issue than
*the relevant one:</P>
*<UL>
*<LI>attachError() , should error messages be appended to the message</LI>
*<LI>getAttachementType(), what should be attached to the message</LI>
*<LI>getInLineType(), what should be included in the message</LI>
*<LI>getMessage(), The text of the message itself</LI>
*<LI>getRecipients(), the recipients the mail is sent to</LI>
*<LI>getReplyTo(), where replys to this message will be sent</LI>
*<LI>getSender(), who the mail is from</LI>
*<LI>getSubjectPrefix(), a prefix to be added to the message subject</LI>
*<LI>getTo(), a list of people to whom the mail is *apparently* sent</LI>
*<LI>getPassThrough(), should this mailet GHOST the original message.</LI>
*<LI>isStatic(), should this mailet run the get methods for every mail, or just
*once. </LI>
*</UL>
*<P>The configuration parameters are:</P>
*<TABLE width="75%" border="0" cellspacing="2" cellpadding="2">
*<TR>
*<TD width="20%">&lt;recipients&gt;</TD>
*<TD width="80%">A comma delimited list of email addresses for recipients of
*this message, it will use the &quot;to&quot; list if not specified. These
*addresses will only appear in the To: header if no &quot;to&quot; list is
*supplied.</TD>
*</TR>
*<TR>
*<TD width="20%">&lt;to&gt;</TD>
*<TD width="80%">A comma delimited list of addresses to appear in the To: header,
*the email will only be delivered to these addresses if they are in the recipients
*list.<BR>
*The recipients list will be used if this is not supplied</TD>
*</TR>
*<TR>
*<TD width="20%">&lt;sender&gt;</TD>
*<TD width="80%">A single email address to appear in the From: header <BR>
*It can include constants &quot;sender&quot; and &quot;postmaster&quot;</TD>
*</TR>
*<TR>
*<TD width="20%">&lt;message&gt;</TD>
*<TD width="80%">A text message to be the body of the email. Can be omitted.</TD>
*</TR>
*<TR>
*<TD width="20%">&lt;inline&gt;</TD>
*<TD width="80%">
*<P>One of the following items:</P>
*<UL>
*<LI>unaltered &nbsp;&nbsp;&nbsp;&nbsp;The original message is the new
* message, for forwarding/aliasing</LI>
*<LI>heads&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The
* headers of the original message are appended to the message</LI>
*<LI>body&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The
* body of the original is appended to the new message</LI>
*<LI>all&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Both
* headers and body are appended</LI>
*<LI>none&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Neither
* body nor headers are appended</LI>
*</UL>
*</TD>
*</TR>
*<TR>
*<TD width="20%">&lt;attachment&gt;</TD>
*<TD width="80%">
*<P>One of the following items:</P>
*<UL>
*<LI>heads&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The headers of the original
* are attached as text</LI>
*<LI>body&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The body of the original
* is attached as text</LI>
*<LI>all&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Both
* headers and body are attached as a single text file</LI>
*<LI>none&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Nothing is attached</LI>
*<LI>message &nbsp;The original message is attached as type message/rfc822,
* this means that it can, in many cases, be opened, resent, fw'd, replied
* to etc by email client software.</LI>
*</UL>
*</TD>
*</TR>
*<TR>
*<TD width="20%">&lt;passThrough&gt;</TD>
*<TD width="80%">TRUE or FALSE, if true the original message continues in the
*mailet processor after this mailet is finished. False causes the original
*to be stopped.</TD>
*</TR>
*<TR>
*<TD width="20%">&lt;attachError&gt;</TD>
*<TD width="80%">TRUE or FALSE, if true any error message available to the
*mailet is appended to the message body (except in the case of inline ==
*unaltered)</TD>
*</TR>
*<TR>
*<TD width="20%">&lt;replyto&gt;</TD>
*<TD width="80%">A single email address to appear in the Rely-To: header, can
*also be &quot;sender&quot; or &quot;postmaster&quot;, this header is not
*set if this is omited.</TD>
*</TR>
*<TR>
*<TD width="20%">&lt;prefix&gt;</TD>
*<TD width="80%">An optional subject prefix prepended to the original message
*subject, for example:<BR>
*Undeliverable mail: </TD>
*</TR>
*<TR>
*<TD width="20%">&lt;static&gt;</TD>
*<TD width="80%">
*<P>TRUE or FALSE, if this is true it hints to the mailet that none of the
*parameters are set dynamically, and therefore they can be set once in
*the init method.<BR>
*False tells the mailet to call all the &quot;getters&quot; for every mail
*processed.</P>
*<P>This defaults to false.<BR>
*It should be TRUE in all cases, except where one of the getter methods
*has been overriden to provide dynamic values, such as a listserve which
*might override getRecipients() to get a list from a users repository.</P>
*</TD>
{'fraction_non_alphanumeric': 0.15617808110467424, 'fraction_numerical': 0.009046901039600031, 'mean_word_length': 5.943250688705234, 'pattern_counts': {'":': 0, '<': 275, '<?xml version=': 0, '>': 275, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5393126', 'n_tokens_mistral': 4224, 'n_tokens_neox': 4093, 'n_words': 1469}