001: package com.quadcap.pop3.client;
002:
003: /* Copyright 1997 - 2003 Quadcap Software. All rights reserved.
004: *
005: * This software is distributed under the Quadcap Free Software License.
006: * This software may be used or modified for any purpose, personal or
007: * commercial. Open Source redistributions are permitted. Commercial
008: * redistribution of larger works derived from, or works which bundle
009: * this software requires a "Commercial Redistribution License"; see
010: * http://www.quadcap.com/purchase.
011: *
012: * Redistributions qualify as "Open Source" under one of the following terms:
013: *
014: * Redistributions are made at no charge beyond the reasonable cost of
015: * materials and delivery.
016: *
017: * Redistributions are accompanied by a copy of the Source Code or by an
018: * irrevocable offer to provide a copy of the Source Code for up to three
019: * years at the cost of materials and delivery. Such redistributions
020: * must allow further use, modification, and redistribution of the Source
021: * Code under substantially the same terms as this license.
022: *
023: * Redistributions of source code must retain the copyright notices as they
024: * appear in each source code file, these license terms, and the
025: * disclaimer/limitation of liability set forth as paragraph 6 below.
026: *
027: * Redistributions in binary form must reproduce this Copyright Notice,
028: * these license terms, and the disclaimer/limitation of liability set
029: * forth as paragraph 6 below, in the documentation and/or other materials
030: * provided with the distribution.
031: *
032: * The Software is provided on an "AS IS" basis. No warranty is
033: * provided that the Software is free of defects, or fit for a
034: * particular purpose.
035: *
036: * Limitation of Liability. Quadcap Software shall not be liable
037: * for any damages suffered by the Licensee or any third party resulting
038: * from use of the Software.
039: */
040:
041: import java.util.Date;
042:
043: /**
044: * This class holds a single UIDL entry in the Pop3 agent's UIDL map.
045: * Each entry corresponds to a message on the server -- we'll rememember
046: * the date we first saw the message, so we can know when to delete it.
047: *
048: * @author Stan Bailes
049: */
050: public class UidlEntry implements java.io.Serializable {
051: String uidl;
052: int messageNumber;
053: Date firstSeen;
054:
055: transient public boolean markedForDeletion = false;
056:
057: /**
058: * Construct a new UidlEntry from the specified parameters.
059: *
060: * @param uidl the POP3 <b>UIDL</b> string returned from the server.
061: * @param messageNumber the POP# message number returned from the server.
062: * @param firstSeen the date when this message was first seen, usually the
063: * date when the UidlEntry object for that message is first
064: * constructed, i.e. 'now'.
065: */
066: public UidlEntry(String uidl, int messageNumber, Date firstSeen) {
067: this .uidl = uidl;
068: this .messageNumber = messageNumber;
069: this .firstSeen = firstSeen;
070: }
071:
072: public UidlEntry(String s) {
073: int idx = s.indexOf(' ');
074: if (idx < 0) {
075: throw new RuntimeException("Bad UidlEntry string: " + s);
076: }
077: this .uidl = s.substring(0, idx);
078: this .firstSeen = new Date(Long.parseLong(s.substring(idx + 1)));
079: this .messageNumber = -1;
080: }
081:
082: /**
083: * Get the uidl string.
084: *
085: * @return the uidl string for this message.
086: */
087: public String getUidl() {
088: return uidl;
089: }
090:
091: /**
092: * Get the POP3 message number
093: *
094: * @return the POP3 message number, returned e.g. by the LIST command.
095: */
096: public int getMessageNumber() {
097: return messageNumber;
098: }
099:
100: /**
101: * Set the POP3 message number.
102: *
103: * @param num the new POP3 message number. This is set in subsequent
104: * sessions, where a message has the same UIDL, but due to
105: * intervening deletions has a new message number.
106: */
107: public void setMessageNumber(int num) {
108: messageNumber = num;
109: }
110:
111: /**
112: * Get the date this message was first seen.
113: *
114: * @return the first seen date.
115: */
116: public Date getFirstSeen() {
117: return firstSeen;
118: }
119:
120: /**
121: * Return a human-readable version of this UidlEntry object.
122: *
123: * @return a string representing this UidlEntry
124: */
125: public String toString() {
126: return "" + uidl + " " + firstSeen.getTime();
127: }
128: }
|