KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SnowMailClient > model > PreviewHeader


1 package SnowMailClient.model;
2
3 import SnowMailClient.model.accounts.MailAccount;
4 import SnowMailClient.utils.MailMessageUtils;
5 import snow.concurrent.*;
6 import java.util.concurrent.*;
7 import java.util.Date JavaDoc;
8
9 /**
10     Special: In the preview mode, only headers are downloaded from the server
11     the associated mailAccount is stored as reference.
12     TODO: preview n first lines...
13
14     The folowing keys are always present: date,from,to,subject
15     they ca be directly retrieved for exmample :
16
17        getEntryValue("subject", "<NO SUBJECT FIELD>");
18 */

19 public final class PreviewHeader extends Header
20 {
21   final private MailAccount account;
22   final private String JavaDoc uidl;
23   final private String JavaDoc size;
24   final private long intSize;
25
26   public enum State { MessageNotDownloaded, DownloadingMessage, MessageDownloaded,
27                       DownloadInterrupted, DownloadError, Deleted, Deleting }
28   public State state = State.MessageNotDownloaded;
29   public Throwable JavaDoc error = null;
30   public long alreadyDownloadedSize = 0;
31   //to manual specify to keep on server
32
public boolean forceKeep = false;
33   public boolean forceDelete = false;
34
35   public InterruptableTask downloadTask = null;
36
37   public PreviewHeader(MailAccount account, String JavaDoc uidl, long intSize)
38   {
39      this.account = account;
40      this.uidl = uidl;
41      this.size = MailMessageUtils.formatSize(intSize);
42      this.intSize = intSize;
43   }
44
45
46   public final MailAccount getAccount() { return account; }
47   public final String JavaDoc getSize() { return size; }
48   public final long getSizeInBytes() { return intSize; }
49   public final String JavaDoc getUIDL() { return uidl; }
50
51   /** -1 if not parsed successfully
52   */

53   public long getParsedDate()
54   {
55      try
56      {
57        Date JavaDoc d = MailMessageUtils.parseDateFromString( getEntryValue("date", "?") );
58        if(d==null) return -1;
59        return d.getTime();
60      }
61      catch(Exception JavaDoc e)
62      {
63        String JavaDoc de = getEntryValue("date", null);
64        if(de!=null)
65        {
66          System.out.println("Invalid date in header : "+de);
67        }
68        return -1;
69      }
70   }
71
72 } // PreviewHeader
Popular Tags