public void notifyMessageFetched(Message message, String folderName, long accountId) throws MessagingException { Folder folder = Folder.getFolderByName(accountId, folderName, application.getDBHelper()); long folderId; if (folder == null) { Folder notesFolder = Folder.getFolderByName( accountId, ImapConsts.IMAP__INOTES_FOLDER, application.getDBHelper()); folderId = notesFolder == null ? Folder.ALL_FOLDER_ID : notesFolder.id; } else { folderId = folder.id; } Note note = MessageCompose.notesFromMessage(message); note.accountId = accountId; note.folderId = folderId; Note noteLocal = getRelativeNoteLocal(note); if (noteLocal == null) { Log.i(TAG, "add a remote note to local:" + note.sid); note.status = Status.SYNC_DONE; Note.createNote(note, application.getDBHelper()); if (TextUtils.isEmpty(note.id)) { throw new MessagingException("create note failed.." + note.sid); } } else { Log.i(TAG, "update a remote note to local:" + note.sid); Boolean result = doDiff(note, noteLocal); note.status = result ? Status.SYNC_UPDATE : Status.SYNC_DONE; if (!Note.updateNotesWithoutModifyDate(note, accountId, application.getDBHelper())) { throw new MessagingException("update note failed.." + note.sid); } } }