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