1 39 40 package demo; 41 42 import java.io.*; 43 import java.util.*; 44 45 import javax.mail.*; 46 import javax.mail.internet.*; 47 import javax.servlet.*; 48 import javax.servlet.http.*; 49 50 53 public class AttachmentInfo { 54 private Part part; 55 private int num; 56 57 58 61 public String getAttachmentType() throws MessagingException { 62 String contentType; 63 if ((contentType = part.getContentType()) == null) 64 return "invalid part"; 65 else 66 return contentType; 67 } 68 69 72 public String getContent() throws java.io.IOException , MessagingException { 73 if (hasMimeType("text/plain")) 74 return (String )part.getContent(); 75 else 76 return ""; 77 } 78 79 82 public String getDescription() throws MessagingException { 83 String description; 84 if ((description = part.getDescription()) != null) 85 return description; 86 else 87 return ""; 88 } 89 90 93 public String getFilename() throws MessagingException { 94 String filename; 95 if ((filename = part.getFileName()) != null) 96 return filename; 97 else 98 return ""; 99 } 100 101 104 public String getNum() { 105 return (Integer.toString(num)); 106 } 107 108 111 public boolean hasDescription() throws MessagingException { 112 return (part.getDescription() != null); 113 } 114 115 118 public boolean hasFilename() throws MessagingException { 119 return (part.getFileName() != null); 120 } 121 122 125 public boolean hasMimeType(String mimeType) throws MessagingException { 126 return part.isMimeType(mimeType); 127 } 128 129 132 public boolean isInline() throws MessagingException { 133 if (part.getDisposition() != null) 134 return part.getDisposition().equals(Part.INLINE); 135 else 136 return true; 137 } 138 139 142 public void setPart(int num, Part part) 143 throws MessagingException, ParseException { 144 145 this.part = part; 146 this.num = num; 147 } 148 } 149 150 | Popular Tags |