KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > mail > javamail > MimeMailMessage


1 /*
2  * Copyright 2002-2005 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 java.util.Date JavaDoc;
20
21 import javax.mail.MessagingException JavaDoc;
22 import javax.mail.internet.MimeMessage JavaDoc;
23
24 import org.springframework.mail.MailMessage;
25 import org.springframework.mail.MailParseException;
26
27 /**
28  * Implementation of the MailMessage interface for a JavaMail MIME message,
29  * to let message population code interact with a simple message or a MIME
30  * message through a common interface.
31  *
32  * <p>Uses a MimeMessageHelper underneath. Can either be created with a
33  * MimeMessageHelper instance or with a JavaMail MimeMessage instance.
34  *
35  * @author Juergen Hoeller
36  * @since 1.1.5
37  * @see MimeMessageHelper
38  * @see javax.mail.internet.MimeMessage
39  */

40 public class MimeMailMessage implements MailMessage {
41
42     private final MimeMessageHelper helper;
43
44
45     /**
46      * Create a new MimeMailMessage based on the given MimeMessageHelper.
47      * @param mimeMessageHelper the MimeMessageHelper
48      */

49     public MimeMailMessage(MimeMessageHelper mimeMessageHelper) {
50         this.helper = mimeMessageHelper;
51     }
52
53     /**
54      * Create a new MimeMailMessage based on the given JavaMail MimeMessage.
55      * @param mimeMessage the JavaMail MimeMessage
56      */

57     public MimeMailMessage(MimeMessage JavaDoc mimeMessage) {
58         this.helper = new MimeMessageHelper(mimeMessage);
59     }
60
61     /**
62      * Return the MimeMessageHelper that this MimeMailMessage is based on.
63      */

64     public final MimeMessageHelper getMimeMessageHelper() {
65         return this.helper;
66     }
67
68     /**
69      * Return the JavaMail MimeMessage that this MimeMailMessage is based on.
70      */

71     public final MimeMessage JavaDoc getMimeMessage() {
72         return this.helper.getMimeMessage();
73     }
74
75
76     public void setFrom(String JavaDoc from) throws MailParseException {
77         try {
78             this.helper.setFrom(from);
79         }
80         catch (MessagingException JavaDoc ex) {
81             throw new MailParseException(ex);
82         }
83     }
84
85     public void setReplyTo(String JavaDoc replyTo) throws MailParseException {
86         try {
87             this.helper.setReplyTo(replyTo);
88         }
89         catch (MessagingException JavaDoc ex) {
90             throw new MailParseException(ex);
91         }
92     }
93
94     public void setTo(String JavaDoc to) throws MailParseException {
95         try {
96             this.helper.setTo(to);
97         }
98         catch (MessagingException JavaDoc ex) {
99             throw new MailParseException(ex);
100         }
101     }
102
103     public void setTo(String JavaDoc[] to) throws MailParseException {
104         try {
105             this.helper.setTo(to);
106         }
107         catch (MessagingException JavaDoc ex) {
108             throw new MailParseException(ex);
109         }
110     }
111
112     public void setCc(String JavaDoc cc) throws MailParseException {
113         try {
114             this.helper.setCc(cc);
115         }
116         catch (MessagingException JavaDoc ex) {
117             throw new MailParseException(ex);
118         }
119     }
120
121     public void setCc(String JavaDoc[] cc) throws MailParseException {
122         try {
123             this.helper.setCc(cc);
124         }
125         catch (MessagingException JavaDoc ex) {
126             throw new MailParseException(ex);
127         }
128     }
129
130     public void setBcc(String JavaDoc bcc) throws MailParseException {
131         try {
132             this.helper.setBcc(bcc);
133         }
134         catch (MessagingException JavaDoc ex) {
135             throw new MailParseException(ex);
136         }
137     }
138
139     public void setBcc(String JavaDoc[] bcc) throws MailParseException {
140         try {
141             this.helper.setBcc(bcc);
142         }
143         catch (MessagingException JavaDoc ex) {
144             throw new MailParseException(ex);
145         }
146     }
147
148     public void setSentDate(Date JavaDoc sentDate) throws MailParseException {
149         try {
150             this.helper.setSentDate(sentDate);
151         }
152         catch (MessagingException JavaDoc ex) {
153             throw new MailParseException(ex);
154         }
155     }
156
157     public void setSubject(String JavaDoc subject) throws MailParseException {
158         try {
159             this.helper.setSubject(subject);
160         }
161         catch (MessagingException JavaDoc ex) {
162             throw new MailParseException(ex);
163         }
164     }
165
166     public void setText(String JavaDoc text) throws MailParseException {
167         try {
168             this.helper.setText(text);
169         }
170         catch (MessagingException JavaDoc ex) {
171             throw new MailParseException(ex);
172         }
173     }
174
175 }
176
Popular Tags