1 19 20 package org.apache.james.imapserver.client.fetch; 21 22 import java.io.IOException ; 23 24 import javax.mail.MessagingException ; 25 import javax.mail.internet.MimeMessage ; 26 27 import org.apache.james.imapserver.util.MessageGenerator; 28 29 public class FetchBody { 30 31 final boolean peek; 32 33 private FetchHeader fetchHeader; 34 35 public FetchBody(boolean peek) { 36 this.peek = peek; 37 } 38 39 public String getCommand() { 40 String result= ""; 41 if (peek) { 42 result += "BODY.PEEK["; 43 } else { 44 result += "BODY["; 45 } 46 if (fetchHeader!=null) { 47 result += fetchHeader.getCommand(); 48 } 49 result += "]"; 50 return result; 51 } 52 53 public String getResult(MimeMessage m) throws IOException , 54 MessagingException { 55 String result = "BODY["; 57 final String data; 58 if (fetchHeader != null) { 59 result += fetchHeader.getCommand(); 60 data = fetchHeader.getData(m); 61 } else { 62 data = getData(m); 63 } 64 result += "] {" + data.length() + "}\r\n" + data; 65 return result; 67 } 68 69 private String getData(MimeMessage m) throws IOException , 70 MessagingException { 71 String data = MessageGenerator.messageContentToString(m); 72 return data; 73 } 74 75 public void setFetchHeader(FetchHeader fetchHeader) { 76 this.fetchHeader = fetchHeader; 77 78 } 79 80 } 81 | Popular Tags |