001    /**
002     * Copyright (c) 2000-2012 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.FileAttachment;
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, InternetAddress to, String subject, String body,
040                    boolean htmlFormat) {
041    
042                    _from = from;
043    
044                    if (to != null) {
045                            _to = new InternetAddress[] {to};
046                    }
047                    else {
048                            _to = new InternetAddress[0];
049                    }
050    
051                    _subject = subject;
052                    _body = body;
053                    _htmlFormat = htmlFormat;
054            }
055    
056            public MailMessage(
057                    InternetAddress from, String subject, String body,
058                    boolean htmlFormat) {
059    
060                    this(from, null, subject, body, htmlFormat);
061            }
062    
063            public void addFileAttachment(File file) {
064                    addFileAttachment(file, null);
065            }
066    
067            public void addFileAttachment(File file, String fileName) {
068                    if (file == null) {
069                            return;
070                    }
071    
072                    FileAttachment fileAttachment = new FileAttachment(file, fileName);
073    
074                    _fileAttachments.add(fileAttachment);
075            }
076    
077            public InternetAddress[] getBCC() {
078                    return _bcc;
079            }
080    
081            public String getBody() {
082                    return _body;
083            }
084    
085            public InternetAddress[] getBulkAddresses() {
086                    return _bulkAddresses;
087            }
088    
089            public InternetAddress[] getCC() {
090                    return _cc;
091            }
092    
093            public List<FileAttachment> getFileAttachments() {
094                    return _fileAttachments;
095            }
096    
097            public InternetAddress getFrom() {
098                    return _from;
099            }
100    
101            public boolean getHTMLFormat() {
102                    return _htmlFormat;
103            }
104    
105            public String getInReplyTo() {
106                    return _inReplyTo;
107            }
108    
109            public String getMessageId() {
110                    return _messageId;
111            }
112    
113            public InternetAddress[] getReplyTo() {
114                    return _replyTo;
115            }
116    
117            public SMTPAccount getSMTPAccount() {
118                    return _smtpAccount;
119            }
120    
121            public String getSubject() {
122                    return _subject;
123            }
124    
125            public InternetAddress[] getTo() {
126                    return _to;
127            }
128    
129            public boolean isHTMLFormat() {
130                    return _htmlFormat;
131            }
132    
133            public void setBCC(InternetAddress bcc) {
134                    _bcc = new InternetAddress[] {bcc};
135            }
136    
137            public void setBCC(InternetAddress[] bcc) {
138                    _bcc = bcc;
139            }
140    
141            public void setBody(String body) {
142                    _body = body;
143            }
144    
145            public void setBulkAddresses(InternetAddress[] bulkAddresses) {
146                    _bulkAddresses = bulkAddresses;
147            }
148    
149            public void setCC(InternetAddress cc) {
150                    _cc = new InternetAddress[] {cc};
151            }
152    
153            public void setCC(InternetAddress[] cc) {
154                    _cc = cc;
155            }
156    
157            public void setFrom(InternetAddress from) {
158                    _from = from;
159            }
160    
161            public void setHTMLFormat(boolean htmlFormat) {
162                    _htmlFormat = htmlFormat;
163            }
164    
165            public void setInReplyTo(String inReplyTo) {
166                    _inReplyTo = inReplyTo;
167            }
168    
169            public void setMessageId(String messageId) {
170                    _messageId = messageId;
171            }
172    
173            public void setReplyTo(InternetAddress[] replyTo) {
174                    _replyTo = replyTo;
175            }
176    
177            public void setSMTPAccount(SMTPAccount account) {
178                    _smtpAccount = account;
179            }
180    
181            public void setSubject(String subject) {
182                    _subject = subject;
183            }
184    
185            public void setTo(InternetAddress to) {
186                    _to = new InternetAddress[] {to};
187            }
188    
189            public void setTo(InternetAddress[] to) {
190                    _to = to;
191            }
192    
193            private InternetAddress[] _bcc;
194            private String _body;
195            private InternetAddress[] _bulkAddresses;
196            private InternetAddress[] _cc;
197            private List<FileAttachment> _fileAttachments =
198                    new ArrayList<FileAttachment>();
199            private InternetAddress _from;
200            private boolean _htmlFormat;
201            private String _inReplyTo;
202            private String _messageId;
203            private InternetAddress[] _replyTo;
204            private SMTPAccount _smtpAccount;
205            private String _subject;
206            private InternetAddress[] _to;
207    
208    }