001    /**
002     * Copyright (c) 2000-2011 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 com.liferay.mail.model.Attachment;
018    
019    import java.io.File;
020    import java.io.Serializable;
021    
022    import java.util.ArrayList;
023    import java.util.List;
024    
025    import javax.mail.internet.InternetAddress;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     * @author Neil Griffin
030     * @author Raymond Augé
031     * @author Thiago Moreira
032     */
033    public class MailMessage implements Serializable {
034    
035            public MailMessage() {
036            }
037    
038            public MailMessage(
039                    InternetAddress from, String subject, String body,
040                    boolean htmlFormat) {
041    
042                    this(from, null, subject, body, htmlFormat);
043            }
044    
045            public MailMessage(
046                    InternetAddress from, InternetAddress to, String subject, String body,
047                    boolean htmlFormat) {
048    
049                    _from = from;
050    
051                    if (to != null) {
052                            _to = new InternetAddress[] {to};
053                    }
054                    else {
055                            _to = new InternetAddress[0];
056                    }
057    
058                    _subject = subject;
059                    _body = body;
060                    _htmlFormat = htmlFormat;
061            }
062    
063            public void addAttachment(File file) {
064                    addAttachment(file, null);
065            }
066    
067            public void addAttachment(File file, String fileName) {
068                    if (file != null) {
069                            Attachment attachment = new Attachment(file, fileName);
070    
071                            _attachments.add(attachment);
072                    }
073            }
074    
075            public List<Attachment> getAttachments() {
076                    return _attachments;
077            }
078    
079            public InternetAddress[] getBCC() {
080                    return _bcc;
081            }
082    
083            public String getBody() {
084                    return _body;
085            }
086    
087            public InternetAddress[] getBulkAddresses() {
088                    return _bulkAddresses;
089            }
090    
091            public InternetAddress[] getCC() {
092                    return _cc;
093            }
094    
095            public InternetAddress getFrom() {
096                    return _from;
097            }
098    
099            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<Attachment> _attachments = new ArrayList<Attachment>();
203            private SMTPAccount _smtpAccount;
204    
205    }