KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > imapserver > client > fetch > FetchHeader


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

19
20 package org.apache.james.imapserver.client.fetch;
21
22 import java.util.Enumeration JavaDoc;
23
24 import javax.mail.MessagingException JavaDoc;
25 import javax.mail.internet.MimeMessage JavaDoc;
26
27 public class FetchHeader {
28
29     private String JavaDoc[] fields;
30
31     public String JavaDoc getCommand() {
32         if (fields == null) {
33             return "HEADER";
34         } else {
35             return "HEADER.FIELDS ("+getFormattedFieldList()+")";
36         }
37     }
38
39     private String JavaDoc getFormattedFieldList() {
40         String JavaDoc result ="";
41         for (int i = 0; i < fields.length; i++) {
42             result +=" "+fields[i];
43             
44         }
45         if (result.length()>0) {
46             result=result.substring(1);
47         }
48         return result;
49     }
50
51     public String JavaDoc getData(MimeMessage JavaDoc m) throws MessagingException JavaDoc {
52         String JavaDoc result = "";
53         final Enumeration JavaDoc e;
54         if (fields==null) {
55         e= m.getAllHeaderLines();
56         } else {
57             e = m.getMatchingHeaderLines(fields);
58         }
59         while (e.hasMoreElements()) {
60             String JavaDoc line = (String JavaDoc) e.nextElement();
61             result += line + "\r\n";
62         }
63         result += "\r\n"; // TODO Should this be counted for size?
64
return result;
65     }
66
67     public void setFields(String JavaDoc[] fields) {
68         this.fields = fields;
69
70     }
71
72 }
73
Popular Tags