下面列出了怎么用javax.mail.FolderNotFoundException的API类实例代码及写法,或者点击链接到github查看源代码。
private static void onMove(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message) throws JSONException, FolderNotFoundException {
// Move message
DB db = DB.getInstance(context);
// Get arguments
long id = jargs.getLong(0);
boolean seen = jargs.optBoolean(1);
boolean unflag = jargs.optBoolean(3);
// Get target folder
EntityFolder target = db.folder().getFolder(id);
if (target == null)
throw new FolderNotFoundException();
// Move from trash/drafts only
if (!EntityFolder.TRASH.equals(folder.type) &&
!EntityFolder.DRAFTS.equals(folder.type))
throw new IllegalArgumentException("Invalid POP3 folder" +
" source=" + folder.type + " target=" + target.type);
message.folder = target.id;
if (seen)
message.ui_seen = seen;
if (unflag)
message.ui_flagged = false;
message.ui_hide = false;
db.message().updateMessage(message);
}
private static void onRaw(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, IMAPFolder ifolder) throws MessagingException, IOException, JSONException {
// Download raw message
DB db = DB.getInstance(context);
if (message.raw == null || !message.raw) {
IMAPMessage imessage = (IMAPMessage) ifolder.getMessageByUID(message.uid);
if (imessage == null)
throw new MessageRemovedException();
File file = message.getRawFile(context);
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
imessage.writeTo(os);
}
db.message().setMessageRaw(message.id, true);
}
if (jargs.length() > 0) {
// Cross account move
long tid = jargs.getLong(0);
EntityFolder target = db.folder().getFolder(tid);
if (target == null)
throw new FolderNotFoundException();
Log.i(folder.name + " queuing ADD id=" + message.id + ":" + target.id);
EntityOperation operation = new EntityOperation();
operation.account = target.account;
operation.folder = target.id;
operation.message = message.id;
operation.name = EntityOperation.ADD;
operation.args = jargs.toString();
operation.created = new Date().getTime();
operation.id = db.operation().insertOperation(operation);
}
}
void error(Throwable ex) {
if (ex instanceof MessagingException &&
("connection failure".equals(ex.getMessage()) ||
"Not connected".equals(ex.getMessage()) || // POP3
ex.getCause() instanceof SocketException ||
ex.getCause() instanceof ConnectionException))
recoverable = false;
if (ex instanceof ConnectionException)
// failed to create new store connection
// BYE, Socket is closed
recoverable = false;
if (ex instanceof StoreClosedException ||
ex instanceof FolderClosedException ||
ex instanceof FolderNotFoundException)
// Lost folder connection to server
recoverable = false;
if (ex instanceof IllegalStateException && (
"Not connected".equals(ex.getMessage()) ||
"This operation is not allowed on a closed folder".equals(ex.getMessage())))
recoverable = false;
if (ex instanceof OperationCanceledException)
recoverable = false;
thread.interrupt();
yield();
}
@Override
public synchronized void copyMessages(final Message[] msgs, final Folder folder) throws MessagingException {
abortIdle();
checkOpened();
checkExists();
if (msgs == null || folder == null || msgs.length == 0) {
return;
}
if (!folder.exists()) {
throw new FolderNotFoundException(folder.getFullName() + " does not exist", folder);
}
folder.appendMessages(msgs);
}
@Override
protected void checkExists() throws MessagingException {
if (!exists()) {
throw new FolderNotFoundException(this, getFullName() + " not found");
}
}