001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.mail;
016    
017    import java.io.File;
018    import java.io.Serializable;
019    
020    import java.util.ArrayList;
021    import java.util.List;
022    
023    import javax.mail.internet.InternetAddress;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     * @author Neil Griffin
028     * @author Raymond Augé
029     * @author Thiago Moreira
030     */
031    public class MailMessage implements Serializable {
032    
033            public MailMessage() {
034            }
035    
036            public MailMessage(
037                    InternetAddress from, String subject, String body,
038                    boolean htmlFormat) {
039    
040                    this(from, null, subject, body, htmlFormat);
041            }
042    
043            public MailMessage(
044                    InternetAddress from, InternetAddress to, String subject, String body,
045                    boolean htmlFormat) {
046    
047                    _from = from;
048    
049                    if (to != null) {
050                            _to = new InternetAddress[] {to};
051                    }
052                    else {
053                            _to = new InternetAddress[0];
054                    }
055    
056                    _subject = subject;
057                    _body = body;
058                    _htmlFormat = htmlFormat;
059            }
060    
061            public void addAttachment(File attachment) {
062                    if (attachment != null) {
063                            _attachments.add(attachment);
064                    }
065            }
066    
067            public File[] getAttachments() {
068                    return _attachments.toArray(new File[_attachments.size()]);
069            }
070    
071            public InternetAddress[] getBCC() {
072                    return _bcc;
073            }
074    
075            public String getBody() {
076                    return _body;
077            }
078    
079            public InternetAddress[] getBulkAddresses() {
080                    return _bulkAddresses;
081            }
082    
083            public InternetAddress[] getCC() {
084                    return _cc;
085            }
086    
087            public InternetAddress getFrom() {
088                    return _from;
089            }
090    
091            public boolean getHTMLFormat() {
092                    return _htmlFormat;
093            }
094    
095            public String getInReplyTo() {
096                    return _inReplyTo;
097            }
098    
099            public String getMessageId() {
100                    return _messageId;
101            }
102    
103            public InternetAddress[] getReplyTo() {
104                    return _replyTo;
105            }
106    
107            public SMTPAccount getSMTPAccount() {
108                    return _smtpAccount;
109            }
110    
111            public String getSubject() {
112                    return _subject;
113            }
114    
115            public InternetAddress[] getTo() {
116                    return _to;
117            }
118    
119            public boolean isHTMLFormat() {
120                    return _htmlFormat;
121            }
122    
123            public void setBCC(InternetAddress bcc) {
124                    _bcc = new InternetAddress[] {bcc};
125            }
126    
127            public void setBCC(InternetAddress[] bcc) {
128                    _bcc = bcc;
129            }
130    
131            public void setBody(String body) {
132                    _body = body;
133            }
134    
135            public void setBulkAddresses(InternetAddress[] bulkAddresses) {
136                    _bulkAddresses = bulkAddresses;
137            }
138    
139            public void setCC(InternetAddress cc) {
140                    _cc = new InternetAddress[] {cc};
141            }
142    
143            public void setCC(InternetAddress[] cc) {
144                    _cc = cc;
145            }
146    
147            public void setFrom(InternetAddress from) {
148                    _from = from;
149            }
150    
151            public void setHTMLFormat(boolean htmlFormat) {
152                    _htmlFormat = htmlFormat;
153            }
154    
155            public void setInReplyTo(String inReplyTo) {
156                    _inReplyTo = inReplyTo;
157            }
158    
159            public void setMessageId(String messageId) {
160                    _messageId = messageId;
161            }
162    
163            public void setReplyTo(InternetAddress[] replyTo) {
164                    _replyTo = replyTo;
165            }
166    
167            public void setSMTPAccount(SMTPAccount account) {
168                    _smtpAccount = account;
169            }
170    
171            public void setSubject(String subject) {
172                    _subject = subject;
173            }
174    
175            public void setTo(InternetAddress to) {
176                    _to = new InternetAddress[] {to};
177            }
178    
179            public void setTo(InternetAddress[] to) {
180                    _to = to;
181            }
182    
183            private InternetAddress _from;
184            private InternetAddress[] _to;
185            private InternetAddress[] _cc;
186            private InternetAddress[] _bcc;
187            private InternetAddress[] _bulkAddresses;
188            private String _subject;
189            private String _body;
190            private boolean _htmlFormat;
191            private InternetAddress[] _replyTo;
192            private String _messageId;
193            private String _inReplyTo;
194            private List<File> _attachments = new ArrayList<File>();
195            private SMTPAccount _smtpAccount;
196    
197    }