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