001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.mail.folder.headercache;
019:
020: import java.awt.Color;
021: import java.util.Date;
022:
023: import org.columba.mail.message.ColumbaHeader;
024: import org.columba.mail.message.IColumbaHeader;
025: import org.columba.ristretto.message.Address;
026:
027: /**
028: *
029: *
030: * Holds a collection of all cached headerfields, which Columba needs to be able
031: * to quickly show the message summary, etc. to the user.
032: *
033: * @author fdietz
034: */
035: public class CachedHeaderfields {
036:
037: // internally used headerfields
038: // these are all boolean values, which are saved using
039: // a single int value
040: public static final String[] INTERNAL_COMPRESSED_HEADERFIELDS = {
041:
042: // message flags
043: "columba.flags.seen", "columba.flags.recent",
044: "columba.flags.answered", "columba.flags.flagged",
045: "columba.flags.expunged", "columba.flags.draft",
046: // true, if message has attachments, false otherwise
047: "columba.attachment",
048: // true/false
049: "columba.spam" };
050:
051: // this internally used headerfields can be of every basic
052: // type, including String, Integer, Boolean, Date, etc.
053: public static final String[] INTERNAL_HEADERFIELDS = {
054:
055: // priority as integer value
056: "columba.priority",
057: // short from, containing only name of person
058: "columba.from",
059: // host from which this message was downloaded
060: "columba.host",
061: // date
062: "columba.date",
063: // size of message
064: "columba.size",
065: // properly decoded subject
066: "columba.subject",
067: // message color
068: "columba.color",
069: // account ID
070: "columba.accountuid",
071: // to
072: "columba.to",
073: // Cc
074: "columba.cc" };
075:
076: public static final Class[] INTERNAL_HEADERFIELDS_TYPE = {
077: Integer.class, Address.class, String.class, Date.class,
078: Integer.class, String.class, Color.class, Integer.class,
079: Address.class, String.class };
080:
081: // these are cached by default
082: public static final String[] DEFAULT_HEADERFIELDS = { "Subject",
083: "From", "To", "Cc", "Date", "Message-ID", "In-Reply-To",
084: "References", "Content-Type" };
085:
086: public static final String[] POP3_HEADERFIELDS = { "Subject",
087: "From", "columba.date", "columba.size",
088: // POP3 message UID
089: "columba.pop3uid",
090: // was this message already fetched from the server?
091: "columba.alreadyfetched" };
092:
093: public static final Class[] POP3_HEADERFIELDS_TYPE = {
094: String.class, String.class, Date.class, Integer.class,
095: String.class, Boolean.class };
096:
097: /**
098: * No need for creating instances of this class.
099: */
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],
134: h.get(INTERNAL_COMPRESSED_HEADERFIELDS[i]));
135: }
136: }
137:
138: return strippedHeader;
139: }
140:
141: public static String[] getDefaultHeaderfields() {
142: String[] result = new String[DEFAULT_HEADERFIELDS.length];
143: System.arraycopy(DEFAULT_HEADERFIELDS, 0, result, 0,
144: DEFAULT_HEADERFIELDS.length);
145: return result;
146: }
147: };
|