📄 dsnbounce.java
字号:
/*********************************************************************** * Copyright (c) 2000-2004 The Apache Software Foundation. * * All rights reserved. * * ------------------------------------------------------------------- * * Licensed under the Apache License, Version 2.0 (the "License"); you * * may not use this file except in compliance with the License. You * * may obtain a copy of the License at: * * * * http://www.apache.org/licenses/LICENSE-2.0 * * * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS, * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * * implied. See the License for the specific language governing * * permissions and limitations under the License. * ***********************************************************************/package org.apache.james.transport.mailets;import java.io.PrintWriter;import java.io.StringWriter;import java.net.ConnectException;import java.net.InetAddress;import java.net.SocketException;import java.net.UnknownHostException;import java.util.Collection;import java.util.Date;import java.util.HashSet;import java.util.Iterator;import javax.mail.MessagingException;import javax.mail.SendFailedException;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 javax.activation.CommandMap;import javax.activation.MailcapCommandMap;import org.apache.james.core.MailImpl;import org.apache.mailet.Mail;import org.apache.mailet.MailAddress;import org.apache.james.util.RFC2822Headers;import org.apache.james.util.RFC822DateFormat;import org.apache.james.Constants;import org.apache.james.util.mail.MimeMultipartReport;import org.apache.oro.text.regex.MalformedPatternException;import org.apache.oro.text.regex.Pattern;import org.apache.oro.text.regex.Perl5Compiler;import org.apache.oro.text.regex.Perl5Matcher;import org.apache.oro.text.regex.MatchResult;/** * * <P>Generates a Delivery Status Notification (DSN) * Note that this is different than a mail-client's * reply, which would use the Reply-To or From header.</P> * <P>Bounced messages are attached in their entirety (headers and * content) and the resulting MIME part type is "message/rfc822".<BR> * The reverse-path and the Return-Path header of the response is set to "null" ("<>"), * meaning that no reply should be sent.</P> * <P>A sender of the notification message can optionally be specified. * If one is not specified, the postmaster's address will be used.<BR> * <P>Supports the <CODE>passThrough</CODE> init parameter (true if missing).</P> * * <P>Sample configuration:</P> * <PRE><CODE> * <mailet match="All" class="DSNBounce"> * <sender><I>an address or postmaster or sender or unaltered, default=postmaster</I></sender> * <prefix><I>optional subject prefix prepended to the original message</I></prefix> * <attachment><I>message or none, default=message</I></attachment> * <messageString><I>the message sent in the bounce, the first occurrence of the pattern [machine] is replaced with the name of the executing machine, default=Hi. This is the James mail server at [machine] ... </I></messageString> * <passThrough><I>true or false, default=true</I></passThrough> * <debug><I>true or false, default=false</I></debug> * </mailet> * </CODE></PRE> * * @see org.apache.james.transport.mailets.AbstractNotify */public class DSNBounce extends AbstractNotify { /** * Constants and getters for RFC 3463 Enhanced Mail System Status Codes * * I suggest do extract this inner class for future use in the smtp-handler * */ public static class DSNStatus { // status code classes /** * Success */ public static final int SUCCESS = 2; /** * Persistent Transient Failure */ public static final int TRANSIENT = 4; /** * Permanent Failure */ public static final int PERMANENT = 5; // subjects and details /** * Other or Undefined Status */ public static final int UNDEFINED = 0; /** * Other undefined status */ public static final String UNDEFINED_STATUS = "0.0"; /** * Addressing Status */ public static final int ADDRESS = 1; /** * Other address status */ public static final String ADDRESS_OTHER = "1.0"; /** * Bad destination mailbox address */ public static final String ADDRESS_MAILBOX = "1.1"; /** * Bad destination system address */ public static final String ADDRESS_SYSTEM = "1.2"; /** * Bad destination mailbox address syntax */ public static final String ADDRESS_SYNTAX = "1.3"; /** * Destination mailbox address ambiguous */ public static final String ADDRESS_AMBIGUOUS = "1.4"; /** * Destination Address valid */ public static final String ADDRESS_VALID = "1.5"; /** * Destimation mailbox has moved, no forwarding address */ public static final String ADDRESS_MOVED = "1.6"; /** * Bad sender's mailbox address syntax */ public static final String ADDRESS_SYNTAX_SENDER = "1.7"; /** * Bad sender's system address */ public static final String ADDRESS_SYSTEM_SENDER = "1.8"; /** * Mailbox Status */ public static final int MAILBOX = 2; /** * Other or Undefined Mailbox Status */ public static final String MAILBOX_OTHER = "2.0"; /** * Mailbox disabled, not accepting messages */ public static final String MAILBOX_DISABLED = "2.1"; /** * Mailbox full */ public static final String MAILBOX_FULL = "2.2"; /** * Message length exceeds administrative limit */ public static final String MAILBOX_MSG_TOO_BIG = "2.3"; /** * Mailing list expansion problem */ public static final String MAILBOX_LIST_EXPANSION = "2.4"; /** * Mail System Status */ public static final int SYSTEM = 3; /** * Other or undefined mail system status */ public static final String SYSTEM_OTHER = "3.0"; /** * Mail system full */ public static final String SYSTEM_FULL = "3.1"; /** * System not accepting messages */ public static final String SYSTEM_NOT_ACCEPTING = "3.2"; /** * System not capable of selected features */ public static final String SYSTEM_NOT_CAPABLE = "3.3"; /** * Message too big for system */ public static final String SYSTEM_MSG_TOO_BIG = "3.4"; /** * System incorrectly configured */ public static final String SYSTEM_CFG_ERROR = "3.5"; /** * Network and Routing Status */ public static final int NETWORK = 4; /** * Other or undefined network or routing status */ public static final String NETWORK_OTHER = "4.0"; /** * No answer form host */ public static final String NETWORK_NO_ANSWER = "4.1"; /** * Bad Connection */ public static final String NETWORK_CONNECTION = "4.2"; /** * Directory server failure */ public static final String NETWORK_DIR_SERVER = "4.3"; /** * Unable to route */ public static final String NETWORK_ROUTE = "4.4"; /** * Mail system congestion */ public static final String NETWORK_CONGESTION = "4.5"; /** * Routing loop detected */ public static final String NETWORK_LOOP = "4.6"; /** * Delivery time expired */ public static final String NETWORK_EXPIRED = "4.7"; /** * Mail Delivery Protocol Status */ public static final int DELIVERY = 5; /** * Other or undefined (SMTP) protocol status */ public static final String DELIVERY_OTHER = "5.0"; /** * Invalid command */ public static final String DELIVERY_INVALID_CMD = "5.1"; /** * Syntax error */ public static final String DELIVERY_SYNTAX = "5.2"; /** * Too many recipients */ public static final String DELIVERY_TOO_MANY_REC = "5.3"; /** * Invalid command arguments */ public static final String DELIVERY_INVALID_ARG = "5.4"; /** * Wrong protocol version */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -