checkOpened(); // insure that folder is open synchronized(messageCacheLock) { if (uidTable == null) uidTable = new Hashtable<Long, IMAPMessage>(); long[] ua = getProtocol().fetchSequenceNumbers(start, end); Message m = uidTable.get(Long.valueOf(ua[i])); if (m != null) // found it ma.add(m); throw new FolderClosedException(this, cex.getMessage()); } catch (ProtocolException pex) { throw new MessagingException(pex.getMessage(), pex);
is = ((MimeMessage)part).getContentStream(); else throw new MessagingException("Unknown part"); return is; } catch (FolderClosedException fex) { throw new FolderClosedIOException(fex.getFolder(), fex.getMessage()); } catch (MessagingException mex) { IOException ioex = new IOException(mex.getMessage()); ioex.initCause(mex); throw ioex;
/** * 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(); }
"Message does not belong to this folder"); checkOpened(); // insure that folder is open throw new MessagingException("message is not an IMAPMessage"); IMAPMessage m = (IMAPMessage)message; IMAPProtocol p = getProtocol(); UID u = p.fetchUID(m.getSequenceNumber()); uidTable = new Hashtable<Long, IMAPMessage>(); uidTable.put(Long.valueOf(uid), m); throw new FolderClosedException(this, cex.getMessage()); } catch (ProtocolException pex) { throw new MessagingException(pex.getMessage(), pex);
checkOpened(); // insure folder is open m = uidTable.get(l); if (m != null) // found it return m; } else uidTable = new Hashtable<Long, IMAPMessage>(); getProtocol().fetchSequenceNumber(uid); m = uidTable.get(l); if (m != null) // found it return m; throw new FolderClosedException(this, cex.getMessage()); } catch (ProtocolException pex) { throw new MessagingException(pex.getMessage(), pex);
checkOpened(); // insure that folder is open synchronized(messageCacheLock) { if (uidTable == null) uidTable = new Hashtable(); UID[] ua = getProtocol().fetchSequenceNumbers(start, end); m = getMessageBySeqNumber(ua[i].seqnum); m.setUID(ua[i].uid); msgs[i] = m; uidTable.put(new Long(ua[i].uid), m); throw new FolderClosedException(this, cex.getMessage()); } catch (ProtocolException pex) { throw new MessagingException(pex.getMessage(), pex);
checkOpened(); fetch(msgs, fp); doExpungeNotification = false; // We do this ourselves later try { IMAPProtocol p = getProtocol(); if (msgs != null) p.uidexpunge(Utility.toUIDSet(msgs)); else p.expunge(); } catch (CommandFailedException cfx) { "Cannot expunge READ_ONLY folder: " + fullName); else throw new MessagingException(cfx.getMessage(), cfx); } catch (ConnectionException cex) { throw new FolderClosedException(this, cex.getMessage()); } catch (ProtocolException pex) { throw new MessagingException(pex.getMessage(), pex); } finally { doExpungeNotification = true; uidTable.remove(Long.valueOf(uid));
if (p.isREV1()) { BODY b = p.peekBody(getSequenceNumber(), toSection("HEADER")); if (b != null) is = b.getByteArrayInputStream(); } else { RFC822DATA rd = p.fetchRFC822(getSequenceNumber(), "HEADER"); if (rd != null) throw new FolderClosedException(folder, cex.getMessage()); } catch (ProtocolException pex) { forceCheckExpunged(); throw new MessagingException(pex.getMessage(), pex); throw new MessagingException("Cannot load header"); headers = new InternetHeaders(is); headersLoaded = true;
/** * Fetch the header of the message and the first <code>n</code> lines * of the raw content of the message. The headers and data are * available in the returned InputStream. * * @param n number of lines of content to fetch * @return InputStream containing the message headers and n content lines * @exception MessagingException for failures */ public InputStream top(int n) throws MessagingException { try { synchronized (this) { return folder.getProtocol().top(msgnum, n); } } catch (EOFException eex) { folder.close(false); throw new FolderClosedException(folder, eex.toString()); } catch (IOException ex) { throw new MessagingException("error getting size", ex); } }
return headers.getHeader(name); if (p.isREV1()) { BODY b = p.peekBody(getSequenceNumber(), toSection("HEADER.FIELDS (" + name + ")") ); 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); headers = new InternetHeaders(); headers.load(is); // load this header into the Headers object.
try { hdrSize = hdrs.available(); headers = new InternetHeaders(hdrs); } finally { hdrs.close(); throw new FolderClosedException(folder, eex.toString()); } catch (IOException ex) { throw new MessagingException("error loading POP3 headers", ex);
headers = new InternetHeaders(); if (p.isREV1()) { int seqnum = message.getSequenceNumber(); BODY b = p.peekBody(seqnum, sectionId + ".MIME"); throw new MessagingException("Failed to fetch headers"); throw new MessagingException("Failed to fetch headers"); headers.load(bis); headers.addHeader("Content-Type", type); headers.addHeader("Content-Transfer-Encoding", bs.encoding); throw new FolderClosedException( message.getFolder(), cex.getMessage()); } catch (ProtocolException pex) { throw new MessagingException(pex.getMessage(), pex);
/** * Get the deleted message count. */ public synchronized int getDeletedMessageCount() throws MessagingException { if (!opened) { checkExists(); // no way to do this on closed folders return -1; } // if opened, issue server-side search for messages that do // have the DELETED flag. Flags f = new Flags(); f.add(Flags.Flag.DELETED); try { synchronized(messageCacheLock) { int[] matches = getProtocol().search(new FlagTerm(f, true)); return matches.length; // NOTE: 'matches' is never null } } catch (ConnectionException cex) { throw new FolderClosedException(this, cex.getMessage()); } catch (ProtocolException pex) { // Shouldn't happen throw new MessagingException(pex.getMessage(), pex); } }
checkOpened(); int[] matches = getProtocol().search(term); if (matches != null) matchMsgs = getMessagesBySeqNumbers(matches); return super.search(term); } catch (ConnectionException cex) { throw new FolderClosedException(this, cex.getMessage()); } catch (ProtocolException pex) { throw new MessagingException(pex.getMessage(), pex);
long start, long end, long modseq) throws MessagingException { checkOpened(); // insure that folder is open IMAPProtocol p = getProtocol(); if (!p.hasCapability("CONDSTORE")) throw new BadCommandException("CONDSTORE not supported"); int[] nums = p.uidfetchChangedSince(start, end, modseq); return getMessagesBySeqNumbers(nums); throw new FolderClosedException(this, cex.getMessage()); } catch (ProtocolException pex) { throw new MessagingException(pex.getMessage(), pex);
/** * Set the specified flags for the given array of messages. */ public synchronized void setFlags(Message[] msgs, Flags flag, boolean value) throws MessagingException { checkOpened(); checkFlags(flag); // validate flags if (msgs.length == 0) // boundary condition return; synchronized(messageCacheLock) { try { IMAPProtocol p = getProtocol(); MessageSet[] ms = Utility.toMessageSetSorted(msgs, null); if (ms == null) throw new MessageRemovedException( "Messages have been removed"); p.storeFlags(ms, flag, value); } catch (ConnectionException cex) { throw new FolderClosedException(this, cex.getMessage()); } catch (ProtocolException pex) { throw new MessagingException(pex.getMessage(), pex); } } }
checkOpened(); int[] matches = getProtocol().sort(term, sterm); if (matches != null) matchMsgs = getMessagesBySeqNumbers(matches); throw new MessagingException(cfx.getMessage(), cfx); } catch (SearchException sex) { throw new MessagingException(sex.getMessage(), sex); } catch (ConnectionException cex) { throw new FolderClosedException(this, cex.getMessage()); } catch (ProtocolException pex) { throw new MessagingException(pex.getMessage(), pex);
/** * 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); } } }
protected void checkRange(int msgno) throws MessagingException { if (msgno < 1) // message-numbers start at 1 throw new IndexOutOfBoundsException("message number < 1"); if (msgno <= total) return; // Out of range, let's ping the server and see if // the server has more messages for us. synchronized(messageCacheLock) { // Acquire lock try { keepConnectionAlive(false); } catch (ConnectionException cex) { // Oops, lost connection throw new FolderClosedException(this, cex.getMessage()); } catch (ProtocolException pex) { throw new MessagingException(pex.getMessage(), pex); } } // Release lock if (msgno > total) // Still out of range ? Throw up ... throw new IndexOutOfBoundsException(msgno + " > " + total); }
private synchronized void loadFlags() throws MessagingException { if (flags != null) return; // Acquire MessageCacheLock, to freeze seqnum. synchronized(getMessageCacheLock()) { try { IMAPProtocol p = getProtocol(); // This message could be expunged when we were waiting // to acquire the lock ... checkExpunged(); flags = p.fetchFlags(getSequenceNumber()); // make sure flags is always set, even if server is broken if (flags == null) flags = new Flags(); } catch (ConnectionException cex) { throw new FolderClosedException(folder, cex.getMessage()); } catch (ProtocolException pex) { forceCheckExpunged(); throw new MessagingException(pex.getMessage(), pex); } } // Release MessageCacheLock }