View Javadoc

1   /*
2    * This file is part of Domingo
3    * an Open Source Java-API to Lotus Notes/Domino
4    * hosted at http://domingo.sourceforge.net
5    *
6    * Copyright (c) 2003-2007 Beck et al. projects GmbH Munich, Germany (http://www.bea.de)
7    *
8    * This library is free software; you can redistribute it and/or
9    * modify it under the terms of the GNU Lesser General Public
10   * License as published by the Free Software Foundation; either
11   * version 2.1 of the License, or (at your option) any later version.
12   *
13   * This library is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   * Lesser General Public License for more details.
17   *
18   * You should have received a copy of the GNU Lesser General Public
19   * License along with this library; if not, write to the Free Software
20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21   */
22  
23  package de.bea.domingo.groupware;
24  
25  import java.io.InvalidObjectException;
26  import java.io.ObjectStreamException;
27  import java.util.ArrayList;
28  import java.util.Calendar;
29  import java.util.Collection;
30  import java.util.HashMap;
31  import java.util.HashSet;
32  import java.util.List;
33  import java.util.Map;
34  import java.util.Set;
35  
36  import de.bea.domingo.map.BaseInstance;
37  
38  /***
39   * Represents a Notes mail document.
40   *
41   * @author <a href=mailto:kriede@users.sourceforge.net>Kurt Riede</a>
42   */
43  public final class Email extends BaseInstance {
44  
45      /***
46       * Represents all possible values for the importance.
47       */
48      public static final class Importance {
49  
50          /*** Represents a low importance. */
51          public static final Importance LOW = new Importance((byte) 3, "low");
52  
53          /*** Represents a normal importance. */
54          public static final Importance NORMAL = new Importance((byte) 2, "normal");
55  
56          /*** Represents a high importance. */
57          public static final Importance HIGH = new Importance((byte) 1, "high");
58  
59          private byte fValue;
60  
61          private transient final String fName;
62  
63          private Importance(final byte i, final String name) {
64              fValue = i;
65              fName = name;
66          }
67  
68          /***
69           * {@inheritDoc}
70           * @see java.lang.Object#toString()
71           */
72          public String toString() {
73              return fName;
74          }
75  
76          private Object readResolve() throws ObjectStreamException {
77              if (fValue == 1) {
78                  return HIGH;
79              }
80              if (fValue == 2) {
81                  return NORMAL;
82              }
83              if (fValue == 3) {
84                  return LOW;
85              }
86              throw new InvalidObjectException("Attempt to resolve unknown importance: " + fValue);
87          }
88      }
89  
90      /***
91       * Represents all possible values for the priority.
92       */
93      public static final class Priority {
94  
95          /*** Represents a low priority. */
96          public static final Priority LOW = new Priority((byte) 3, "low");
97  
98          /*** Represents a normal priority. */
99          public static final Priority NORMAL = new Priority((byte) 2, "normal");
100 
101         /*** Represents a high priority. */
102         public static final Priority HIGH = new Priority((byte) 1, "high");
103 
104         private byte fValue;
105 
106         private transient final String fName;
107 
108         private Priority(final byte i, final String name) {
109             fValue = i;
110             fName = name;
111         }
112 
113         /***
114          * {@inheritDoc}
115          * @see java.lang.Object#toString()
116          */
117         public String toString() {
118             return fName;
119         }
120 
121         private Object readResolve() throws ObjectStreamException {
122             if (fValue == 1) {
123                 return HIGH;
124             }
125             if (fValue == 2) {
126                 return LOW;
127             }
128             if (fValue == 3) {
129                 return NORMAL;
130             }
131             throw new InvalidObjectException("Attempt to resolve unknown priority: " + fValue);
132         }
133     }
134 
135     /*** Subject. */
136     private String fSubject;
137 
138     /*** Sender name. */
139     private String fFrom;
140 
141     /*** Reply-to name. */
142     private String fReplyTo;
143 
144     /*** Principal name. */
145     private String fPrincipal;
146 
147     /*** Required invitees (List of Strings). */
148     private List fRecipients = new ArrayList();
149 
150     /*** Optional invitees (List of Strings). */
151     private List fCc = new ArrayList();
152 
153     /*** Optional informed persons (List of Strings). */
154     private List fBcc = new ArrayList();
155 
156     /*** List of other header attributes. */
157     private Map fHeaders = new HashMap();
158 
159     /*** The body of the email as text. */
160     private String fBody;
161 
162     /*** List of category strings. */
163     private Set fCategories = new HashSet();
164 
165     /*** Priority of the email, defaults to {@link Priority#NORMAL}. */
166     private Priority fPriority = Priority.NORMAL;
167 
168     /*** Importance of the message, defaults to {@link Importance#NORMAL}. */
169     private Importance fImportance = Importance.NORMAL;
170 
171     /*** Date e-mail was delivered. */
172     private Calendar fDeliveredDate;
173 
174     /*** If the mail should be saved after send. */
175     private boolean fSaveOnSend = true;
176 
177     /***
178      * Constructor.
179      */
180     public Email() {
181         super();
182     }
183 
184     /***
185      * Constructor.
186      *
187      * @param memo another memo for copying data from.
188      */
189     public Email(final Email memo) {
190         super(memo);
191     }
192 
193     /***
194      * @return Returns the subject.
195      */
196     public String getSubject() {
197         return fSubject;
198     }
199 
200     /***
201      * @param subject The subject to set
202      */
203     public void setSubject(final String subject) {
204         this.fSubject = subject;
205     }
206 
207     /***
208      * Returns the list of blind copy recipients.
209      *
210      * @return list of blind copy recipients
211      */
212     public List getBcc() {
213         return fBcc;
214     }
215 
216     /***
217      * Sets the list of blind copy recipients to a list of names. All previously
218      * existing names are removed.
219      *
220      * @param bcc list of names
221      */
222     public void setBcc(final Collection bcc) {
223         fBcc.clear();
224         fBcc.addAll(bcc);
225     }
226 
227     /***
228      * Sets the list of blind copy recipients to a list of names. All previously
229      * existing names are removed.
230      *
231      * @param bcc list of names
232      */
233     public void setBcc(final List bcc) {
234         fBcc.clear();
235         fBcc.addAll(bcc);
236     }
237 
238     /***
239      * Sets the list of blind copy recipients to a single name. All previously
240      * existing names are removed.
241      *
242      * @param bcc The sendTo to set.
243      */
244     public void setBcc(final String bcc) {
245         fBcc.clear();
246         fBcc.add(bcc);
247     }
248 
249     /***
250      * Adds a name to the list of the blind copy recipients.
251      *
252      * @param bcc The sendTo to set.
253      */
254     public void addBcc(final String bcc) {
255         fBcc.add(bcc);
256     }
257 
258     /***
259      * Adds list of names to the list of the blind copy recipients.
260      *
261      * @param bcc The sendTo to set.
262      */
263     public void addBcc(final List bcc) {
264         fBcc.addAll(bcc);
265     }
266 
267     /***
268      * @return Returns the recipients.
269      */
270     public List getRecipients() {
271         return fRecipients;
272     }
273 
274     /***
275      * @param recipients The recipients to set.
276      */
277     public void setRecipients(final Collection recipients) {
278         fRecipients.clear();
279         fRecipients.add(recipients);
280     }
281 
282     /***
283      * @param recipients The recipients to set.
284      */
285     public void setRecipients(final List recipients) {
286         fRecipients.clear();
287         fRecipients.add(recipients);
288     }
289 
290     /***
291      * Sets the list of recipients to a single name. All previously
292      * existing names are removed.
293      *
294      * @param recipients The recipients to set.
295      */
296     public void setRecipient(final String recipients) {
297         fRecipients.clear();
298         fRecipients.add(recipients);
299     }
300 
301     /***
302      * @param recipient The recipient to set.
303      */
304     public void addRecipient(final String recipient) {
305         fRecipients.add(recipient);
306     }
307 
308     /***
309      * @return Returns the sopyTo.
310      */
311     public List getCc() {
312         return fCc;
313     }
314 
315     /***
316      * @param copyTo The copyTo to set.
317      */
318     public void setCc(final Collection copyTo) {
319         fCc.clear();
320         fCc.addAll(copyTo);
321     }
322 
323     /***
324      * @param copyTo The copyTo to set.
325      */
326     public void setCc(final List copyTo) {
327         fCc.clear();
328         fCc.addAll(copyTo);
329     }
330 
331     /***
332      * @param sendTo The sendTo to set.
333      */
334     public void addCc(final String sendTo) {
335         fCc.add(sendTo);
336     }
337 
338     /***
339      * @param sendTo The sendTo to set.
340      */
341     public void addCc(final List sendTo) {
342         fCc.addAll(sendTo);
343     }
344 
345     /***
346      * @return Returns the from.
347      */
348     public String getFrom() {
349         return fFrom;
350     }
351 
352     /***
353      * @param from The from to set.
354      */
355     public void setFrom(final String from) {
356         fFrom = from;
357     }
358 
359     /***
360      * @return Returns the principal.
361      */
362     public String getPrincipal() {
363         return fPrincipal;
364     }
365 
366     /***
367      * @param principal The principal to set.
368      */
369     public void setPrincipal(final String principal) {
370         fPrincipal = principal;
371     }
372 
373     /***
374      * @return Returns the replyTo.
375      */
376     public String getReplyTo() {
377         return fReplyTo;
378     }
379 
380     /***
381      * @param replyTo The replyTo to set.
382      */
383     public void setReplyTo(final String replyTo) {
384         fReplyTo = replyTo;
385     }
386 
387     /***
388      * Returns the body of the email as an unformatted string.
389      *
390      * @return unformatted body
391      */
392     public String getBody() {
393         return fBody;
394     }
395 
396     /***
397      * Sets the body of the email as an unformatted string.
398      *
399      * @param body unformatted body
400      */
401     public void setBody(final String body) {
402         fBody = body;
403     }
404 
405     /***
406      * Adds a new header attribute.
407      *
408      * @param name the name of the attribute
409      * @param value the value of the attribute
410      */
411     public void addHeader(final String name, final String value) {
412         fHeaders.put(name, value);
413     }
414 
415     /***
416      * Removes a header attribute.
417      *
418      * @param name the name of the attribute
419      */
420     public void removeHeader(final String name) {
421         fHeaders.remove(name);
422     }
423 
424     /***
425      * Returns the set of all header names.
426      *
427      * @return set of all header names
428      */
429     public Set getAllHeaderNames() {
430         return fHeaders.keySet();
431     }
432 
433     /***
434      * Returns the value of a given named header attribute.
435      *
436      * @param name the name of the attribute
437      */
438     public void getHeader(final String name) {
439         fHeaders.get(name);
440     }
441 
442     /***
443      * Returns the map of all header attribute.
444      *
445      * @return map of header attributes
446      */
447     public Map getHeaders() {
448         return fHeaders;
449     }
450 
451     /***
452      * Clears all other header information.
453      */
454     public void clearHeaders() {
455         fHeaders.clear();
456     }
457 
458     /***
459      * Checks if a header attribute exists.
460      *
461      * @param name name of the attribute to check
462      * @return <code>true</code> if the attribute exists, else
463      *         <code>false</code>
464      */
465     public boolean containsHeader(final Object name) {
466         return fHeaders.containsKey(name);
467     }
468 
469     /***
470      * Returns a set of the names of all available header attributes..
471      *
472      * @return set of header attribute names
473      */
474     public Set headerNames() {
475         return fHeaders.keySet();
476     }
477 
478     /***
479      * Adds all given attributes to the set of headers.
480      *
481      * @param map of attributes to add
482      */
483     public void addHeaders(final Map map) {
484         fHeaders.putAll(map);
485     }
486 
487     /***
488      * Adds a collection of categories.
489      *
490      * @param categories the categories to add
491      */
492     public void addCategories(final Collection categories) {
493         fCategories.addAll(categories);
494     }
495 
496     /***
497      * Adds a single category.
498      *
499      * @param category the category to add
500      */
501     public void addCategories(final String category) {
502         fCategories.add(category);
503     }
504 
505     /***
506      * Sets the set of categories.
507      *
508      * @param categories the categories to set
509      */
510     public void setCategories(final Set categories) {
511         fCategories = categories;
512     }
513 
514     /***
515      * Returns an iterator over all categories.
516      *
517      * @return iterator over all categories.
518      */
519     public Set getCategories() {
520         return fCategories;
521     }
522 
523     /***
524      * Returns the importance.
525      *
526      * @return importance
527      */
528     public Importance getImportance() {
529         return fImportance;
530     }
531 
532     /***
533      * Sets the importance.
534      *
535      * @param importance importance
536      */
537     public void setImportance(final Importance importance) {
538         fImportance = importance;
539     }
540 
541     /***
542      * Returns the priority.
543      *
544      * @return priority
545      */
546     public Priority getPriority() {
547         return fPriority;
548     }
549 
550     /***
551      * Sets the priority.
552      *
553      * @param priority priority
554      */
555     public void setPriority(final Priority priority) {
556         fPriority = priority;
557     }
558 
559     /***
560      * Get the Delivery Date/Time.
561      *
562      * @return date message was delivered.
563      */
564     public Calendar getDeliveredDate() {
565         return fDeliveredDate;
566     }
567 
568     /***
569      * Set the Delivery Date/Time.
570      *
571      * @param deliveredDate date email was delivered.
572      */
573     public void setDeliveredDate(final Calendar deliveredDate) {
574         fDeliveredDate = deliveredDate;
575     }
576 
577     /***
578      * Returns if the mail should be saved after send or not.
579      *
580      * @return <code>true</code> if the mail should be saved after send, else <code>false</code>
581      */
582     public boolean getSaveOnSend() {
583         return fSaveOnSend;
584     }
585 
586     /***
587      * Sets if the mail should be saved after send or not.
588      * <p>The default value is <code>true</code>.</p>
589      *
590      * @param saveOnSend <code>true</code> if the mail should be saved after send, else <code>false</code>
591      */
592     public void setSaveOnSend(final boolean saveOnSend) {
593         fSaveOnSend = saveOnSend;
594     }
595 }