KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > folder > headercache > CachedHeaderfields


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.mail.folder.headercache;
19
20 import java.awt.Color JavaDoc;
21 import java.util.Date JavaDoc;
22
23 import org.columba.mail.message.ColumbaHeader;
24 import org.columba.mail.message.IColumbaHeader;
25 import org.columba.ristretto.message.Address;
26
27 /**
28  *
29  *
30  * Holds a collection of all cached headerfields, which Columba needs to be able
31  * to quickly show the message summary, etc. to the user.
32  *
33  * @author fdietz
34  */

35 public class CachedHeaderfields {
36
37     // internally used headerfields
38
// these are all boolean values, which are saved using
39
// a single int value
40
public static final String JavaDoc[] INTERNAL_COMPRESSED_HEADERFIELDS = {
41
42     // message flags
43
"columba.flags.seen", "columba.flags.recent",
44             "columba.flags.answered", "columba.flags.flagged",
45             "columba.flags.expunged", "columba.flags.draft",
46             // true, if message has attachments, false otherwise
47
"columba.attachment",
48             // true/false
49
"columba.spam" };
50
51     // this internally used headerfields can be of every basic
52
// type, including String, Integer, Boolean, Date, etc.
53
public static final String JavaDoc[] INTERNAL_HEADERFIELDS = {
54
55     // priority as integer value
56
"columba.priority",
57             // short from, containing only name of person
58
"columba.from",
59             // host from which this message was downloaded
60
"columba.host",
61             // date
62
"columba.date",
63             // size of message
64
"columba.size",
65             // properly decoded subject
66
"columba.subject",
67             // message color
68
"columba.color",
69             // account ID
70
"columba.accountuid",
71             // to
72
"columba.to",
73             // Cc
74
"columba.cc" };
75
76     public static final Class JavaDoc[] INTERNAL_HEADERFIELDS_TYPE = { Integer JavaDoc.class,
77             Address.class, String JavaDoc.class, Date JavaDoc.class, Integer JavaDoc.class,
78             String JavaDoc.class, Color JavaDoc.class, Integer JavaDoc.class, Address.class,
79             String JavaDoc.class };
80
81     // these are cached by default
82
public static final String JavaDoc[] DEFAULT_HEADERFIELDS = { "Subject", "From",
83             "To", "Cc", "Date", "Message-ID", "In-Reply-To", "References",
84             "Content-Type" };
85
86     public static final String JavaDoc[] POP3_HEADERFIELDS = { "Subject", "From",
87             "columba.date", "columba.size",
88             // POP3 message UID
89
"columba.pop3uid",
90             // was this message already fetched from the server?
91
"columba.alreadyfetched" };
92
93     public static final Class JavaDoc[] POP3_HEADERFIELDS_TYPE = { String JavaDoc.class,
94             String JavaDoc.class, Date JavaDoc.class, Integer JavaDoc.class, String JavaDoc.class,
95             Boolean JavaDoc.class };
96
97     /**
98      * No need for creating instances of this class.
99      */

100     private CachedHeaderfields() {
101     }
102
103     /**
104      *
105      * create new header which only contains headerfields needed by Columba
106      * (meaning they also get cached)
107      *
108      * @param h
109      * @return
110      */

111     public static IColumbaHeader stripHeaders(IColumbaHeader h) {
112         //return h;
113
IColumbaHeader strippedHeader = new ColumbaHeader();
114
115         // copy all internally used headerfields
116
for (int i = 0; i < DEFAULT_HEADERFIELDS.length; i++) {
117             if (h.get(DEFAULT_HEADERFIELDS[i]) != null) {
118
119                 strippedHeader.set(DEFAULT_HEADERFIELDS[i], h
120                         .get(DEFAULT_HEADERFIELDS[i]));
121             }
122         }
123
124         for (int i = 0; i < INTERNAL_HEADERFIELDS.length; i++) {
125             if (h.get(INTERNAL_HEADERFIELDS[i]) != null) {
126                 strippedHeader.set(INTERNAL_HEADERFIELDS[i], h
127                         .get(INTERNAL_HEADERFIELDS[i]));
128             }
129         }
130
131         for (int i = 0; i < INTERNAL_COMPRESSED_HEADERFIELDS.length; i++) {
132             if (h.get(INTERNAL_COMPRESSED_HEADERFIELDS[i]) != null) {
133                 strippedHeader.set(INTERNAL_COMPRESSED_HEADERFIELDS[i], h
134                         .get(INTERNAL_COMPRESSED_HEADERFIELDS[i]));
135             }
136         }
137
138         return strippedHeader;
139     }
140
141     public static String JavaDoc[] getDefaultHeaderfields() {
142         String JavaDoc[] result = new String JavaDoc[DEFAULT_HEADERFIELDS.length];
143         System.arraycopy(DEFAULT_HEADERFIELDS,0, result, 0, DEFAULT_HEADERFIELDS.length);
144         return result;
145     }
146 };
Popular Tags