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