KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > protomatter > syslog > MailMessage


1 package com.protomatter.syslog;
2
3 /**
4  * {{{ The Protomatter Software License, Version 1.0
5  * derived from The Apache Software License, Version 1.1
6  *
7  * Copyright (c) 1998-2002 Nate Sammons. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution,
22  * if any, must include the following acknowledgment:
23  * "This product includes software developed for the
24  * Protomatter Software Project
25  * (http://protomatter.sourceforge.net/)."
26  * Alternately, this acknowledgment may appear in the software itself,
27  * if and wherever such third-party acknowledgments normally appear.
28  *
29  * 4. The names "Protomatter" and "Protomatter Software Project" must
30  * not be used to endorse or promote products derived from this
31  * software without prior written permission. For written
32  * permission, please contact support@protomatter.com.
33  *
34  * 5. Products derived from this software may not be called "Protomatter",
35  * nor may "Protomatter" appear in their name, without prior written
36  * permission of the Protomatter Software Project
37  * (support@protomatter.com).
38  *
39  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
40  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
41  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42  * DISCLAIMED. IN NO EVENT SHALL THE PROTOMATTER SOFTWARE PROJECT OR
43  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
46  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
47  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
48  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
49  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE. }}}
51  */

52
53 import java.io.*;
54 import java.util.*;
55 import com.protomatter.util.*;
56
57 /**
58  * A simple mail message object.
59  */

60 class MailMessage
61 implements java.io.Serializable JavaDoc
62 {
63   private String JavaDoc subject = null;
64   private Vector to = null;
65   private Vector cc = null;
66   private Vector bcc = null;
67   private String JavaDoc fromAddress = null;
68   private String JavaDoc fromName = null;
69
70   private String JavaDoc bodyString = null;
71   private MIMEMessage bodyMime = null;
72
73   /**
74    * Create a new, empty mail message.
75    */

76   public MailMessage()
77   {
78     super();
79   }
80
81   /**
82    * Set the list of addresses this message is to.
83    */

84   public void setTo(Vector to)
85   {
86     this.to = to;
87   }
88   /**
89    * Get the list of addresses this message is to.
90    */

91   public Vector getTo()
92   {
93     return (this.to == null) ? new Vector() : this.to;
94   }
95
96
97   /**
98    * Set the list of addresses this message
99    * is carbon-copied to.
100    */

101   public void setCC(Vector cc)
102   {
103     this.cc = cc;
104   }
105   /**
106    * Get the list of addresses this message
107    * is carbon-copied to.
108    */

109   public Vector getCC()
110   {
111     return (this.cc == null) ? new Vector() : this.cc;
112   }
113
114
115   /**
116    * Set the list of addresses this message
117    * is blind carbon-copied to.
118    */

119   public void setBCC(Vector bcc)
120   {
121     this.bcc = bcc;
122   }
123   /**
124    * Get the list of addresses this message
125    * is blind carbon-copied to.
126    */

127   public Vector getBCC()
128   {
129     return (this.bcc == null) ? new Vector() : this.bcc;
130   }
131
132
133   /**
134    * Set the from address for this message.
135    */

136   public void setFromAddress(String JavaDoc from)
137   {
138     this.fromAddress = from;
139   }
140   /**
141    * Get the from address for this message.
142    */

143   public String JavaDoc getFromAddress()
144   {
145     return this.fromAddress;
146   }
147
148
149   /**
150    * Set the from name for this message.
151    */

152   public void setFromName(String JavaDoc from)
153   {
154     this.fromName = from;
155   }
156   /**
157    * Get the from name for this message.
158    */

159   public String JavaDoc getFromName()
160   {
161     return this.fromName;
162   }
163
164
165   /**
166    * Set the subject of the message.
167    */

168   public void setSubject(String JavaDoc subject)
169   {
170     this.subject = subject;
171   }
172   /**
173    * Get the subject of the message.
174    */

175   public String JavaDoc getSubject()
176   {
177     return this.subject;
178   }
179
180   /**
181    * Set the body of the message.
182    */

183   public void setBody(String JavaDoc body)
184   {
185     this.bodyString = body;
186     this.bodyMime = null;
187   }
188   /**
189    * Set the body of the message.
190    */

191   public void setBody(MIMEMessage body)
192   {
193     this.bodyMime = body;
194     this.bodyString = null;
195   }
196   /**
197    * Get the body of the message.
198    */

199   public Object JavaDoc getBody()
200   {
201     return (this.bodyString != null)
202       ? (Object JavaDoc)this.bodyString : (Object JavaDoc)this.bodyMime;
203   }
204
205   public String JavaDoc toString()
206   {
207     StringBuffer JavaDoc b = new StringBuffer JavaDoc();
208
209     b.append("To: ");
210     Enumeration e = getTo().elements();
211     while (e.hasMoreElements())
212     {
213       b.append((String JavaDoc)e.nextElement());
214       if (e.hasMoreElements())
215         b.append(", ");
216     }
217     b.append("\n\r");
218
219
220     b.append("From: ");
221     b.append(getFromName());
222     b.append(" <");
223     b.append(getFromAddress());
224     b.append(">\n\r");
225
226
227     e = getCC().elements();
228     if (e.hasMoreElements())
229     {
230       b.append("CC: ");
231       while (e.hasMoreElements())
232       {
233         b.append((String JavaDoc)e.nextElement());
234         if (e.hasMoreElements())
235           b.append(", ");
236       }
237       b.append("\n\r");
238     }
239
240
241     e = getBCC().elements();
242     if (e.hasMoreElements())
243     {
244       b.append("BCC: ");
245       while (e.hasMoreElements())
246       {
247         b.append((String JavaDoc)e.nextElement());
248         if (e.hasMoreElements())
249           b.append(", ");
250       }
251       b.append("\n\r");
252     }
253
254
255     b.append("Subject: ");
256     b.append(getSubject());
257     b.append("\n\r");
258
259     b.append("\n\r");
260     b.append(getBody());
261
262     return b.toString();
263   }
264 }
265
Popular Tags