View Javadoc
1   /*
2    * Copyright 2002-2012 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.mail.javamail;
18  
19  import javax.activation.FileTypeMap;
20  import javax.mail.Session;
21  import javax.mail.internet.MimeMessage;
22  
23  /**
24   * Special subclass of the standard JavaMail {@link MimeMessage}, carrying a
25   * default encoding to be used when populating the message and a default Java
26   * Activation {@link FileTypeMap} to be used for resolving attachment types.
27   *
28   * <p>Created by {@link JavaMailSenderImpl} in case of a specified default encoding
29   * and/or default FileTypeMap. Autodetected by {@link MimeMessageHelper}, which
30   * will use the carried encoding and FileTypeMap unless explicitly overridden.
31   *
32   * @author Juergen Hoeller
33   * @since 1.2
34   * @see JavaMailSenderImpl#createMimeMessage()
35   * @see MimeMessageHelper#getDefaultEncoding(javax.mail.internet.MimeMessage)
36   * @see MimeMessageHelper#getDefaultFileTypeMap(javax.mail.internet.MimeMessage)
37   */
38  class SmartMimeMessage extends MimeMessage {
39  
40  	private final String defaultEncoding;
41  
42  	private final FileTypeMap defaultFileTypeMap;
43  
44  
45  	/**
46  	 * Create a new SmartMimeMessage.
47  	 * @param session the JavaMail Session to create the message for
48  	 * @param defaultEncoding the default encoding, or {@code null} if none
49  	 * @param defaultFileTypeMap the default FileTypeMap, or {@code null} if none
50  	 */
51  	public SmartMimeMessage(Session session, String defaultEncoding, FileTypeMap defaultFileTypeMap) {
52  		super(session);
53  		this.defaultEncoding = defaultEncoding;
54  		this.defaultFileTypeMap = defaultFileTypeMap;
55  	}
56  
57  
58  	/**
59  	 * Return the default encoding of this message, or {@code null} if none.
60  	 */
61  	public final String getDefaultEncoding() {
62  		return this.defaultEncoding;
63  	}
64  
65  	/**
66  	 * Return the default FileTypeMap of this message, or {@code null} if none.
67  	 */
68  	public final FileTypeMap getDefaultFileTypeMap() {
69  		return this.defaultFileTypeMap;
70  	}
71  
72  }