KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > imapserver > MessageHeader


1 /***********************************************************************
2  * Copyright (c) 2000-2004 The Apache Software Foundation. *
3  * All rights reserved. *
4  * ------------------------------------------------------------------- *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you *
6  * may not use this file except in compliance with the License. You *
7  * may obtain a copy of the License at: *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
14  * implied. See the License for the specific language governing *
15  * permissions and limitations under the License. *
16  ***********************************************************************/

17
18 package org.apache.james.imapserver;
19
20 import java.io.Serializable JavaDoc;
21
22 /**
23  * Class for holding the name-value pairs of an RFC822 or MIME header.
24  * Like javax.mail.Header but serializable
25  *
26  * @version 0.1 on 14 Dec 2000
27  */

28 public class MessageHeader implements Serializable JavaDoc {
29     public static final String JavaDoc CRLF = "\r\n";
30     public static final String JavaDoc CRLFHTAB = "\r\n\t";
31     public static final String JavaDoc CRLFWS = "\r\n ";
32
33     private final String JavaDoc name;
34     private final String JavaDoc value;
35
36     public MessageHeader(String JavaDoc headerLine) {
37         int colon = headerLine.indexOf(":");
38         name = headerLine.substring(0, colon);
39         StringBuffer JavaDoc unwrapped = new StringBuffer JavaDoc(headerLine.length());
40         boolean finished = false;
41         int pos = colon + 1;
42         while (!finished) {
43             int crlf = headerLine.indexOf(CRLF, pos);
44             if (crlf == -1) {
45                 unwrapped.append(headerLine.substring(pos));
46                 finished = true;
47             } else {
48                 unwrapped.append(headerLine.substring(pos, crlf));
49                 unwrapped.append(" ");
50                 pos = crlf +3;
51             }
52         }
53         value = unwrapped.toString();
54     }
55
56     public MessageHeader(String JavaDoc name, String JavaDoc value) {
57         this.name = name;
58         this.value = value;
59     }
60
61     /**
62      * Get the name, aka field name, of this header.
63      *
64      * @return a String
65      */

66     public String JavaDoc getName() {
67         return name;
68     }
69
70     /**
71      * Get the value, aka field value, of this Header
72      *
73      * @return String
74      */

75     public String JavaDoc getValue() {
76         return value;
77     }
78 }
79
80
81
Popular Tags