/** * Create a new IMAPMessage object to represent the given message number. * Subclasses of IMAPFolder may override this method to create a * subclass of IMAPMessage. * * @param msgnum the message sequence number * @return the new IMAPMessage object * @since JavaMail 1.4.6 */ protected IMAPMessage newIMAPMessage(int msgnum) { return new IMAPMessage(this, msgnum); }
/** * Package private constructor. <p> * * Note that nested messages have no containing folder, nor * a message number. */ IMAPNestedMessage(IMAPMessage m, BODYSTRUCTURE b, ENVELOPE e, String sid) { super(m._getSession()); msg = m; bs = b; envelope = e; sectionId = sid; setPeek(m.getPeek()); }
/** * Get the desired Recipient type. */ public Address[] getRecipients(Message.RecipientType type) throws MessagingException { checkExpunged(); if (bodyLoaded) return super.getRecipients(type); loadEnvelope(); if (type == Message.RecipientType.TO) return aaclone(envelope.to); else if (type == Message.RecipientType.CC) return aaclone(envelope.cc); else if (type == Message.RecipientType.BCC) return aaclone(envelope.bcc); else return super.getRecipients(type); }
/** * Get the received date (INTERNALDATE). */ public Date getReceivedDate() throws MessagingException { checkExpunged(); if (receivedDate == null) loadEnvelope(); // have to go to the server for this if (receivedDate == null) return null; else return new Date(receivedDate.getTime()); }
/** * Get matching headers. */ @SuppressWarnings("unchecked") public Enumeration<Header> getMatchingHeaders(String[] names) throws MessagingException { checkExpunged(); loadHeaders(); return super.getMatchingHeaders(names); }
/** * Get the ReplyTo addresses. */ public Address[] getReplyTo() throws MessagingException { checkExpunged(); if (bodyLoaded) return super.getReplyTo(); loadEnvelope(); /* * The IMAP spec requires that the Reply-To field never be * null, but at least Exchange 2007 fails to fill it in in * some cases. Use the same fallback strategy used by * MimeMessage. */ if (envelope.replyTo == null || envelope.replyTo.length == 0) return getFrom(); return aaclone(envelope.replyTo); }
/** * Set/Unset the given flags in this message. */ public synchronized void setFlags(Flags flag, boolean set) throws MessagingException { // Acquire MessageCacheLock, to freeze seqnum. synchronized(getMessageCacheLock()) { try { IMAPProtocol p = getProtocol(); checkExpunged(); // Insure that this message is not expunged p.storeFlags(getSequenceNumber(), flag, set); } catch (ConnectionException cex) { throw new FolderClosedException(folder, cex.getMessage()); } catch (ProtocolException pex) { throw new MessagingException(pex.getMessage(), pex); } } }
@Override protected InputStream getContentStream() throws MessagingException { InputStream is = null; boolean pk = message.getPeek(); // acquire outside of message cache lock synchronized(message.getMessageCacheLock()) { try { IMAPProtocol p = message.getProtocol(); message.checkExpunged(); if (p.isREV1() && (message.getFetchBlockSize() != -1)) return new IMAPInputStream(message, sectionId, message.ignoreBodyStructureSize() ? -1 : bs.size, pk); int seqnum = message.getSequenceNumber(); BODY b; if (pk) } catch (ConnectionException cex) { throw new FolderClosedException( message.getFolder(), cex.getMessage()); } catch (ProtocolException pex) { throw new MessagingException(pex.getMessage(), pex); message.forceCheckExpunged(); // may throw MessageRemovedException
if (uid != null && msg.getUID() != uid.uid) { msg.setUID(uid.uid); if (uidTable == null) uidTable = new Hashtable<>(); if (modseq != null && msg._getModSeq() != modseq.modseq) { msg.setModSeq(modseq.modseq); msg._setFlags(flags); // assume flags changed notify = true; msg.handleExtensionFetchItems(fr.getExtensionItems());
checkExpunged(); if (isHeaderLoaded(name)) // already loaded ? return headers.getHeader(name); synchronized(getMessageCacheLock()) { try { IMAPProtocol p = getProtocol(); checkExpunged(); BODY b = p.peekBody(getSequenceNumber(), toSection("HEADER.FIELDS (" + name + ")") ); if (b != null) is = b.getByteArrayInputStream(); } else { RFC822DATA rd = p.fetchRFC822(getSequenceNumber(), "HEADER.LINES (" + name + ")"); if (rd != null) throw new FolderClosedException(folder, cex.getMessage()); } catch (ProtocolException pex) { forceCheckExpunged(); throw new MessagingException(pex.getMessage(), pex); setHeaderLoaded(name); // Mark this header as loaded
boolean pk = getPeek(); // get before acquiring message cache lock synchronized(getMessageCacheLock()) { try { IMAPProtocol p = getProtocol(); checkExpunged(); // insure this message is not expunged if (p.isREV1() && (getFetchBlockSize() != -1)) // IMAP4rev1 return new IMAPInputStream(this, sectionId, -1, pk); BODY b; if (pk) b = p.peekBody(getSequenceNumber(), sectionId); else b = p.fetchBody(getSequenceNumber(), sectionId); if (b != null) is = b.getByteArrayInputStream(); } else { RFC822DATA rd = p.fetchRFC822(getSequenceNumber(), null); if (rd != null) is = rd.getByteArrayInputStream(); throw new FolderClosedException(folder, cex.getMessage()); } catch (ProtocolException pex) { forceCheckExpunged(); throw new MessagingException(pex.getMessage(), pex); forceCheckExpunged(); // may throw MessageRemovedException
/** * Normally the SEEN flag will have been set by now, but if not, * force it to be set (as long as the folder isn't open read-only * and we're not peeking). * And of course, if there's no folder (e.g., a nested message) * don't do anything. */ private void checkSeen() { if (peek) // if we're peeking, don't set the SEEN flag return; try { Folder f = msg.getFolder(); if (f != null && f.getMode() != Folder.READ_ONLY && !msg.isSet(Flags.Flag.SEEN)) msg.setFlag(Flags.Flag.SEEN, true); } catch (MessagingException ex) { // ignore it } } }
IMAPMessage msg = new IMAPMessage(this, ++total, ++realTotal); msgs[i] = msg; messageCache.addElement(msg); msg.setExpunged(true); // mark this message expunged. for (int i = msg.getMessageNumber(); i < total; i++) { if (m.isExpunged()) // an expunged message, skip continue; m.setSequenceNumber(m.getSequenceNumber() - 1); IMAPMessage msg = getMessageBySeqNumber(f.getNumber()); if (msg != null) { // should always be true msg._setFlags(flags); notifyMessageChangedListeners( MessageChangedEvent.FLAGS_CHANGED, msg);
/** * Get the named header. */ public String getHeader(String name, String delimiter) throws MessagingException { checkExpunged(); // force the header to be loaded by invoking getHeader(name) if (getHeader(name) == null) return null; return headers.getHeader(name, delimiter); }
/** * Do a NOOP to force any untagged EXPUNGE responses * and then check if this message is expunged. */ private void forceCheckExpunged() throws MessageRemovedIOException, FolderClosedIOException { synchronized (msg.getMessageCacheLock()) { try { msg.getProtocol().noop(); } catch (ConnectionException cex) { throw new FolderClosedIOException(msg.getFolder(), cex.getMessage()); } catch (FolderClosedException fex) { throw new FolderClosedIOException(fex.getFolder(), fex.getMessage()); } catch (ProtocolException pex) { // ignore it } } if (msg.isExpunged()) throw new MessageRemovedIOException(); }
/** * Get the Content-Disposition. */ @Override public String getDisposition() throws MessagingException { checkExpunged(); if (bodyLoaded) return super.getDisposition(); loadBODYSTRUCTURE(); return bs.disposition; }
/** * Get the Flags for this message. */ public synchronized Flags getFlags() throws MessagingException { checkExpunged(); loadFlags(); return super.getFlags(); }
/** * Do a NOOP to force any untagged EXPUNGE responses * and then check if this message is expunged. * * @exception MessageRemovedException if the message has been removed * @exception FolderClosedException if the folder has been closed */ protected void forceCheckExpunged() throws MessageRemovedException, FolderClosedException { synchronized (getMessageCacheLock()) { try { getProtocol().noop(); } catch (ConnectionException cex) { throw new FolderClosedException(folder, cex.getMessage()); } catch (ProtocolException pex) { // ignore it } } if (expunged) throw new MessageRemovedException(); }
@Override protected int getFetchBlockSize() { return msg.getFetchBlockSize(); }
/** * Get the message object for the indicated message number. * If the message object hasn't been created, create it. */ public IMAPMessage getMessage(int msgnum) { // check range if (msgnum < 1 || msgnum > size) throw new ArrayIndexOutOfBoundsException( "message number (" + msgnum + ") out of bounds (" + size + ")"); IMAPMessage msg = messages[msgnum-1]; if (msg == null) { if (debug) out.println("DEBUG IMAP MC: create message number " + msgnum); msg = new IMAPMessage(folder, msgnum); messages[msgnum-1] = msg; // mark message expunged if no seqnum if (seqnumOf(msgnum) <= 0) { if (debug) out.println("DEBUG IMAP MC: it's expunged!"); msg.setExpunged(true); } } return msg; }