1 19 20 package org.apache.james.imapserver.client.fetch; 21 22 import java.util.Enumeration ; 23 24 import javax.mail.MessagingException ; 25 import javax.mail.internet.MimeMessage ; 26 27 public class FetchHeader { 28 29 private String [] fields; 30 31 public String getCommand() { 32 if (fields == null) { 33 return "HEADER"; 34 } else { 35 return "HEADER.FIELDS ("+getFormattedFieldList()+")"; 36 } 37 } 38 39 private String getFormattedFieldList() { 40 String 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 getData(MimeMessage m) throws MessagingException { 52 String result = ""; 53 final Enumeration e; 54 if (fields==null) { 55 e= m.getAllHeaderLines(); 56 } else { 57 e = m.getMatchingHeaderLines(fields); 58 } 59 while (e.hasMoreElements()) { 60 String line = (String ) e.nextElement(); 61 result += line + "\r\n"; 62 } 63 result += "\r\n"; return result; 65 } 66 67 public void setFields(String [] fields) { 68 this.fields = fields; 69 70 } 71 72 } 73 | Popular Tags |