001 /* 002 * Copyright 2010 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package com.hs.mail.imap.message; 017 018 import javax.mail.FetchProfile; 019 020 /** 021 * 022 * @author Won Chul Doh 023 * @since Jan 29, 2010 024 * 025 */ 026 public class BodyFetchItem extends FetchProfile.Item { 027 028 public static final int HEADER_FIELDS_NOT = 0; 029 public static final int HEADER_FIELDS = 1; 030 public static final int HEADER = 2; 031 /** 032 * Text body of the message, omitting the [RFC-2822] header 033 */ 034 public static final int TEXT = 3; 035 /** 036 * [RFC-2045] header for the part 037 */ 038 public static final int MIME = 4; 039 /** 040 * Entire message including the header 041 */ 042 public static final int CONTENT = 5; 043 044 private String name; 045 private boolean peek; // BODY.PEEK when fetching contents? 046 private int sectionType = CONTENT; 047 private String[] headers; 048 private int[] path; 049 private long firstOctet = -1; 050 private long numberOfOctets = -1; 051 052 public BodyFetchItem(String name, boolean peek) { 053 super(name); 054 setName(name); 055 this.setPeek(peek); 056 } 057 058 public BodyFetchItem(String name, boolean peek, int sectionType) { 059 this(name, peek); 060 setSectionType(sectionType); 061 } 062 063 public String getName() { 064 return name; 065 } 066 067 public void setName(String name) { 068 this.name = name; 069 } 070 071 public void setPeek(boolean peek) { 072 this.peek = peek; 073 } 074 075 public boolean isPeek() { 076 return peek; 077 } 078 079 public void setSectionType(int sectionType) { 080 this.sectionType = sectionType; 081 } 082 083 public int getSectionType() { 084 return sectionType; 085 } 086 087 public void setHeaders(String[] headers) { 088 this.headers = headers; 089 } 090 091 public String[] getHeaders() { 092 return headers; 093 } 094 095 private void ensureSpaceForOneInPath() { 096 if (path == null) { 097 path = new int[1]; 098 } else { 099 int length = path.length; 100 int[] newPath = new int[length + 1]; 101 System.arraycopy(path, 0, newPath, 0, length); 102 path = newPath; 103 } 104 } 105 106 public void addPath(int part) { 107 ensureSpaceForOneInPath(); 108 path[path.length - 1] = part; 109 } 110 111 public int[] getPath() { 112 return path; 113 } 114 115 public void setFirstOctet(long firstOctet) { 116 this.firstOctet = firstOctet; 117 } 118 119 public long getFirstOctet() { 120 return firstOctet; 121 } 122 123 public void setNumberOfOctets(long numberOfOctets) { 124 this.numberOfOctets = numberOfOctets; 125 } 126 127 public long getNumberOfOctets() { 128 return numberOfOctets; 129 } 130 131 }