1 22 23 package gnu.mail.providers.mbox; 24 25 import java.io.*; 26 import java.util.*; 27 import javax.activation.DataHandler ; 28 import javax.mail.*; 29 import javax.mail.internet.*; 30 31 37 public class MboxMessage 38 extends MimeMessage 39 { 40 41 45 protected static final String STATUS = "Status"; 46 47 51 protected String fromLine; 52 53 57 protected MboxMessage(MboxFolder folder, 58 String fromLine, 59 InputStream in, 60 int msgnum) 61 throws MessagingException 62 { 63 super(folder, in, msgnum); 64 this.fromLine = fromLine; 65 readStatusHeader(); 66 } 67 68 73 protected MboxMessage(MboxFolder folder, 74 MimeMessage message, 75 int msgnum) 76 throws MessagingException 77 { 78 super(message); 79 this.folder = folder; 80 this.msgnum = msgnum; 81 readStatusHeader(); 82 } 83 84 87 protected void setExpunged(boolean expunged) 88 { 89 super.setExpunged(expunged); 90 } 91 92 95 public void setFrom(Address address) 96 throws MessagingException 97 { 98 throw new IllegalWriteException("MboxMessage is read-only"); 99 } 100 101 104 public void addFrom(Address[] address) 105 throws MessagingException 106 { 107 throw new IllegalWriteException("MboxMessage is read-only"); 108 } 109 110 113 public void setRecipients(Message.RecipientType recipienttype, 114 Address[] addresses) 115 throws MessagingException 116 { 117 throw new IllegalWriteException("MboxMessage is read-only"); 118 } 119 120 123 public void addRecipients(Message.RecipientType recipienttype, 124 Address[] addresses) 125 throws MessagingException 126 { 127 throw new IllegalWriteException("MboxMessage is read-only"); 128 } 129 130 133 public void setReplyTo(Address[] addresses) 134 throws MessagingException 135 { 136 throw new IllegalWriteException("MboxMessage is read-only"); 137 } 138 139 142 public void setSubject(String subject, String charset) 143 throws MessagingException 144 { 145 throw new IllegalWriteException("MboxMessage is read-only"); 146 } 147 148 151 public void setSentDate(Date date) 152 throws MessagingException 153 { 154 throw new IllegalWriteException("MboxMessage is read-only"); 155 } 156 157 160 public void setDisposition(String disposition) 161 throws MessagingException 162 { 163 throw new IllegalWriteException("MboxMessage is read-only"); 164 } 165 166 169 public void setContentID(String cid) 170 throws MessagingException 171 { 172 throw new IllegalWriteException("MboxMessage is read-only"); 173 } 174 175 178 public void setContentMD5(String md5) 179 throws MessagingException 180 { 181 throw new IllegalWriteException("MboxMessage is read-only"); 182 } 183 184 187 public void setDescription(String description, String charset) 188 throws MessagingException 189 { 190 throw new IllegalWriteException("MboxMessage is read-only"); 191 } 192 193 196 public void setDataHandler(DataHandler datahandler) 197 throws MessagingException 198 { 199 throw new IllegalWriteException("MboxMessage is read-only"); 200 } 201 202 205 public synchronized void setFlags(Flags flag, boolean set) 206 throws MessagingException 207 { 208 if (set) 209 flags.add(flag); 210 else 211 flags.remove(flag); 212 } 213 214 217 protected void updateHeaders() 218 throws MessagingException 219 { 220 super.updateHeaders(); 221 222 String old = getHeader(STATUS, "\n"); 223 StringBuffer buffer = new StringBuffer (); 224 boolean seen = flags.contains(Flags.Flag.SEEN); 225 boolean recent = flags.contains(Flags.Flag.RECENT); 226 boolean answered = flags.contains(Flags.Flag.ANSWERED); 227 boolean deleted = flags.contains(Flags.Flag.DELETED); 228 if (seen) 229 buffer.append('R'); 230 if (!recent) 231 buffer.append('O'); 232 if (answered) 233 buffer.append('A'); 234 if (deleted) 235 buffer.append('D'); 236 String status = buffer.toString(); 237 if (!(status.equals(old))) 238 setHeader(STATUS, status); 239 } 240 241 242 245 private void readStatusHeader() 246 throws MessagingException 247 { 248 String [] currentStatus = this.getHeader(STATUS); 249 if (currentStatus != null && currentStatus.length > 0) 250 { 251 flags = new Flags(); 252 if (currentStatus[0].indexOf('R') >= 0) 253 flags.add(Flags.Flag.SEEN); 254 if (currentStatus[0].indexOf('O') < 0) 255 flags.add(Flags.Flag.RECENT); 256 if (currentStatus[0].indexOf('A') >= 0) 257 flags.add(Flags.Flag.ANSWERED); 258 if (currentStatus[0].indexOf('D') >= 0) 259 flags.add(Flags.Flag.DELETED); 260 } 261 } 262 263 265 public boolean equals(Object other) 266 { 267 if (other instanceof MimeMessage) 268 { 269 MimeMessage message = (MimeMessage)other; 270 return (message.getFolder()==getFolder() && 271 message.getMessageNumber()==getMessageNumber()); 272 } 273 return false; 274 } 275 276 } 277 | Popular Tags |