1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.kernel.mail;
21  
22  import java.io.File;
23  import java.io.Serializable;
24  
25  import java.util.ArrayList;
26  import java.util.List;
27  
28  import javax.mail.internet.InternetAddress;
29  
30  /**
31   * <a href="MailMessage.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Brian Wing Shun Chan
34   * @author Neil Griffin
35   * @author Raymond Augé
36   * @author Thiago Moreira
37   *
38   */
39  public class MailMessage implements Serializable {
40  
41      public MailMessage() {
42      }
43  
44      public MailMessage(
45          InternetAddress from, String subject, String body,
46          boolean htmlFormat) {
47  
48          this(from, null, subject, body, htmlFormat);
49      }
50  
51      public MailMessage(
52          InternetAddress from, InternetAddress to, String subject, String body,
53          boolean htmlFormat) {
54  
55          _from = from;
56  
57          if (to != null) {
58              _to = new InternetAddress[] {to};
59          }
60          else {
61              _to = new InternetAddress[0];
62          }
63  
64          _subject = subject;
65          _body = body;
66          _htmlFormat = htmlFormat;
67      }
68  
69      public void addAttachment(File attachment) {
70          if (attachment != null) {
71              _attachments.add(attachment);
72          }
73      }
74  
75      public File[] getAttachments() {
76          return _attachments.toArray(new File[_attachments.size()]);
77      }
78  
79      public InternetAddress[] getBCC() {
80          return _bcc;
81      }
82  
83      public String getBody() {
84          return _body;
85      }
86  
87      public InternetAddress[] getBulkAddresses() {
88          return _bulkAddresses;
89      }
90  
91      public InternetAddress[] getCC() {
92          return _cc;
93      }
94  
95      public InternetAddress getFrom() {
96          return _from;
97      }
98  
99      public boolean getHTMLFormat() {
100         return _htmlFormat;
101     }
102 
103     public String getInReplyTo() {
104         return _inReplyTo;
105     }
106 
107     public String getMessageId() {
108         return _messageId;
109     }
110 
111     public InternetAddress[] getReplyTo() {
112         return _replyTo;
113     }
114 
115     public SMTPAccount getSMTPAccount() {
116         return _smtpAccount;
117     }
118 
119     public String getSubject() {
120         return _subject;
121     }
122 
123     public InternetAddress[] getTo() {
124         return _to;
125     }
126 
127     public boolean isHTMLFormat() {
128         return _htmlFormat;
129     }
130 
131     public void setBCC(InternetAddress bcc) {
132         _bcc = new InternetAddress[] {bcc};
133     }
134 
135     public void setBCC(InternetAddress[] bcc) {
136         _bcc = bcc;
137     }
138 
139     public void setBody(String body) {
140         _body = body;
141     }
142 
143     public void setBulkAddresses(InternetAddress[] bulkAddresses) {
144         _bulkAddresses = bulkAddresses;
145     }
146 
147     public void setCC(InternetAddress cc) {
148         _cc = new InternetAddress[] {cc};
149     }
150 
151     public void setCC(InternetAddress[] cc) {
152         _cc = cc;
153     }
154 
155     public void setFrom(InternetAddress from) {
156         _from = from;
157     }
158 
159     public void setHTMLFormat(boolean htmlFormat) {
160         _htmlFormat = htmlFormat;
161     }
162 
163     public void setInReplyTo(String inReplyTo) {
164         _inReplyTo = inReplyTo;
165     }
166 
167     public void setMessageId(String messageId) {
168         _messageId = messageId;
169     }
170 
171     public void setReplyTo(InternetAddress[] replyTo) {
172         _replyTo = replyTo;
173     }
174 
175     public void setSMTPAccount(SMTPAccount account) {
176         _smtpAccount = account;
177     }
178 
179     public void setSubject(String subject) {
180         _subject = subject;
181     }
182 
183     public void setTo(InternetAddress to) {
184         _to = new InternetAddress[] {to};
185     }
186 
187     public void setTo(InternetAddress[] to) {
188         _to = to;
189     }
190 
191     private InternetAddress _from;
192     private InternetAddress[] _to;
193     private InternetAddress[] _cc;
194     private InternetAddress[] _bcc;
195     private InternetAddress[] _bulkAddresses;
196     private String _subject;
197     private String _body;
198     private boolean _htmlFormat;
199     private InternetAddress[] _replyTo;
200     private String _messageId;
201     private String _inReplyTo;
202     private List<File> _attachments = new ArrayList<File>();
203     private SMTPAccount _smtpAccount;
204 
205 }