KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quadcap > pop3 > client > UidlEntry


1 package com.quadcap.pop3.client;
2
3 /* Copyright 1997 - 2003 Quadcap Software. All rights reserved.
4  *
5  * This software is distributed under the Quadcap Free Software License.
6  * This software may be used or modified for any purpose, personal or
7  * commercial. Open Source redistributions are permitted. Commercial
8  * redistribution of larger works derived from, or works which bundle
9  * this software requires a "Commercial Redistribution License"; see
10  * http://www.quadcap.com/purchase.
11  *
12  * Redistributions qualify as "Open Source" under one of the following terms:
13  *
14  * Redistributions are made at no charge beyond the reasonable cost of
15  * materials and delivery.
16  *
17  * Redistributions are accompanied by a copy of the Source Code or by an
18  * irrevocable offer to provide a copy of the Source Code for up to three
19  * years at the cost of materials and delivery. Such redistributions
20  * must allow further use, modification, and redistribution of the Source
21  * Code under substantially the same terms as this license.
22  *
23  * Redistributions of source code must retain the copyright notices as they
24  * appear in each source code file, these license terms, and the
25  * disclaimer/limitation of liability set forth as paragraph 6 below.
26  *
27  * Redistributions in binary form must reproduce this Copyright Notice,
28  * these license terms, and the disclaimer/limitation of liability set
29  * forth as paragraph 6 below, in the documentation and/or other materials
30  * provided with the distribution.
31  *
32  * The Software is provided on an "AS IS" basis. No warranty is
33  * provided that the Software is free of defects, or fit for a
34  * particular purpose.
35  *
36  * Limitation of Liability. Quadcap Software shall not be liable
37  * for any damages suffered by the Licensee or any third party resulting
38  * from use of the Software.
39  */

40
41 import java.util.Date JavaDoc;
42
43 /**
44  * This class holds a single UIDL entry in the Pop3 agent's UIDL map.
45  * Each entry corresponds to a message on the server -- we'll rememember
46  * the date we first saw the message, so we can know when to delete it.
47  *
48  * @author Stan Bailes
49  */

50 public class UidlEntry implements java.io.Serializable JavaDoc {
51     String JavaDoc uidl;
52     int messageNumber;
53     Date JavaDoc firstSeen;
54     
55     transient public boolean markedForDeletion = false;
56
57     /**
58      * Construct a new UidlEntry from the specified parameters.
59      *
60      * @param uidl the POP3 <b>UIDL</b> string returned from the server.
61      * @param messageNumber the POP# message number returned from the server.
62      * @param firstSeen the date when this message was first seen, usually the
63      * date when the UidlEntry object for that message is first
64      * constructed, i.e. 'now'.
65      */

66     public UidlEntry(String JavaDoc uidl, int messageNumber, Date JavaDoc firstSeen) {
67     this.uidl = uidl;
68     this.messageNumber = messageNumber;
69     this.firstSeen = firstSeen;
70     }
71
72     public UidlEntry(String JavaDoc s) {
73     int idx = s.indexOf(' ');
74     if (idx < 0) {
75         throw new RuntimeException JavaDoc("Bad UidlEntry string: " + s);
76     }
77     this.uidl = s.substring(0, idx);
78     this.firstSeen = new Date JavaDoc(Long.parseLong(s.substring(idx+1)));
79     this.messageNumber = -1;
80     }
81
82     /**
83      * Get the uidl string.
84      *
85      * @return the uidl string for this message.
86      */

87     public String JavaDoc getUidl() { return uidl; }
88     
89
90     /**
91      * Get the POP3 message number
92      *
93      * @return the POP3 message number, returned e.g. by the LIST command.
94      */

95     public int getMessageNumber() { return messageNumber; }
96
97     /**
98      * Set the POP3 message number.
99      *
100      * @param num the new POP3 message number. This is set in subsequent
101      * sessions, where a message has the same UIDL, but due to
102      * intervening deletions has a new message number.
103      */

104     public void setMessageNumber(int num) { messageNumber = num; }
105
106     /**
107      * Get the date this message was first seen.
108      *
109      * @return the first seen date.
110      */

111     public Date JavaDoc getFirstSeen() { return firstSeen; }
112
113     /**
114      * Return a human-readable version of this UidlEntry object.
115      *
116      * @return a string representing this UidlEntry
117      */

118     public String JavaDoc toString() {
119     return "" + uidl + " " + firstSeen.getTime();
120     }
121 }
122
Popular Tags