View Javadoc
1   /* 
2   Copyright (c) 2010, NHIN Direct Project
3   All rights reserved.
4   
5   Authors:
6      Greg Meyer      gm2552@cerner.com
7    
8   Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
9   
10  Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
11  Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer 
12  in the documentation and/or other materials provided with the distribution.  Neither the name of the The NHIN Direct Project (nhindirect.org). 
13  nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
15  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
16  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
17  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
18  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
19  THE POSSIBILITY OF SUCH DAMAGE.
20  */
21  
22  package org.nhindirect.gateway.smtp.dsn.impl;
23  
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  import org.apache.mailet.Mailet;
28  import org.nhindirect.common.mail.dsn.DSNFailureTextBodyPartGenerator;
29  import org.nhindirect.common.mail.dsn.DSNGenerator;
30  import org.nhindirect.common.mail.dsn.DSNStandard.DSNStatus;
31  import org.nhindirect.common.mail.dsn.impl.DefaultDSNFailureTextBodyPartGenerator;
32  import org.nhindirect.common.mail.dsn.impl.HumanReadableTextAssemblerFactory;
33  import org.nhindirect.common.options.OptionsManager;
34  import org.nhindirect.gateway.GatewayConfiguration;
35  
36  public class FailedDeliveryDSNCreator extends AbstractDSNCreator 
37  {
38  	static
39  	{		
40  		initJVMParams();
41  	}
42  	
43  	private synchronized static void initJVMParams()
44  	{
45  		/*
46  		 * Configuration parameters
47  		 */
48  		final Map<String, String> JVM_PARAMS = new HashMap<String, String>();
49  		JVM_PARAMS.put(FailedDeliveryDSNCreatorOptions.DSN_FAILED_PREFIX, "org.nhindirect.gateway.smtp.dsn.impl.DeliveryFailureDSNFailedPrefix");
50  		JVM_PARAMS.put(FailedDeliveryDSNCreatorOptions.DSN_MTA_NAME, "org.nhindirect.gateway.smtp.dsn.imp.DeliveryFailureDSNMTAName");
51  		JVM_PARAMS.put(FailedDeliveryDSNCreatorOptions.DSN_POSTMASTER, "org.nhindirect.gateway.smtp.dsn.impl.DeliveryFailureDNSPostmaster");
52  		JVM_PARAMS.put(FailedDeliveryDSNCreatorOptions.DSN_FAILED_RECIP_TITLE, "org.nhindirect.gateway.smtp.dsn.impl.DeliveryFailureDSNFaileRecipTitle");
53  		JVM_PARAMS.put(FailedDeliveryDSNCreatorOptions.DSN_FAILED_ERROR_MESSAGE, "org.nhindirect.gateway.smtp.dsn.impl.DeliveryFailureDSNFailedErrorMessage");
54  		JVM_PARAMS.put(FailedDeliveryDSNCreatorOptions.DSN_FAILED_HEADER, "org.nhindirect.gateway.smtp.dsn.impl.DeliveryFailureDSNFailedHeader");
55  		JVM_PARAMS.put(FailedDeliveryDSNCreatorOptions.DSN_FAILED_FOOTER, "org.nhindirect.gateway.smtp.dsn.impl.DeliveryFailureDSNFailedFooter");
56  		
57  		OptionsManager.addInitParameters(JVM_PARAMS);
58  	}
59  	
60  	///CLOVER:OFF
61  	public FailedDeliveryDSNCreator(DSNGenerator generator, String postmasterMailbox, String reportingMta, 
62  			DSNFailureTextBodyPartGenerator textGenerator)
63  	{
64  		this.mailet = null;
65  		this.generator = generator;
66  		this.postmasterMailbox = postmasterMailbox;
67  		this.reportingMta = reportingMta;
68  		this.textGenerator = textGenerator;
69  		this.dsnStatus = DSNStatus.DELIVERY_OTHER;
70  	}
71  	///CLOVER:ON
72  	
73  	public FailedDeliveryDSNCreator(Mailet mailet)
74  	{
75  		this.mailet = mailet;
76  		
77  		this.dsnStatus = DSNStatus.DELIVERY_OTHER;
78  		
79  		generator = new DSNGenerator(GatewayConfiguration.getConfigurationParam(FailedDeliveryDSNCreatorOptions.DSN_FAILED_PREFIX, 
80  				mailet, null, FailedDeliveryDSNCreatorOptions.DEFAULT_PREFIX));
81  		
82  		postmasterMailbox = GatewayConfiguration.getConfigurationParam(FailedDeliveryDSNCreatorOptions.DSN_POSTMASTER, 
83  				mailet, null, FailedDeliveryDSNCreatorOptions.DEFAULT_POSTMASTER);
84  		
85  		reportingMta = GatewayConfiguration.getConfigurationParam(FailedDeliveryDSNCreatorOptions.DSN_MTA_NAME, 
86  				mailet, null, FailedDeliveryDSNCreatorOptions.DEFAULT_MTA_NAME);
87  		
88  		
89  		textGenerator = new DefaultDSNFailureTextBodyPartGenerator(
90  				GatewayConfiguration.getConfigurationParam(FailedDeliveryDSNCreatorOptions.DSN_FAILED_HEADER, 
91  						mailet, null, FailedDeliveryDSNCreatorOptions.DEFAULT_HEADER), 
92  						GatewayConfiguration.getConfigurationParam(FailedDeliveryDSNCreatorOptions.DSN_FAILED_FOOTER, 
93  						mailet, null, FailedDeliveryDSNCreatorOptions.DEFAULT_FOOTER), 
94  						GatewayConfiguration.getConfigurationParam(FailedDeliveryDSNCreatorOptions.DSN_FAILED_RECIP_TITLE, 
95  						mailet, null, FailedDeliveryDSNCreatorOptions.DEFAULT_FAILED_RECIP_TITLE), 
96  						FailedDeliveryDSNCreatorOptions.DEFAULT_ERROR_MESSAGE_TITLE,
97  					GatewayConfiguration.getConfigurationParam(FailedDeliveryDSNCreatorOptions.DSN_FAILED_ERROR_MESSAGE, 
98  								mailet, null, FailedDeliveryDSNCreatorOptions.DEFAULT_ERROR_MESSAGE),
99  			    HumanReadableTextAssemblerFactory.getInstance());
100 	}
101 }