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);
      }
    }
  }
 private void doFetchRemoteMessagesLite(long accountId) throws AuthenticationFailedException {
   List<Folder> localFolders =
       Folder.getAllFoldersChangedByAccountId(accountId, application.getDBHelper());
   for (Folder folder : localFolders) {
     handleServerFolderChange(folder);
   }
 }
  private void doFetchRemoteMessages(long accountId) throws AuthenticationFailedException {

    imapStoreClient.fetchNewFolder(accountId);

    List<Folder> localFolders =
        Folder.getAllFoldersByAccountId(accountId, null, null, null, application.getDBHelper());

    for (Folder folder : localFolders) {
      handleServerFolderChange(folder);
    }
    Log.i(TAG, "doFetchRemoteMessages() end");
  }
  private void doDeleteNotes(long accountId) throws MessagingException {
    Log.i(TAG, "doDeleteNotes() begin");
    MimeMessage msg;
    List<MimeMessage> pendingDeleteMessages = new ArrayList<MimeMessage>();
    HashMap<Long, List<Note>> folderId2NotesMap =
        buildLocalChangedFolder2NotesMap(
            Note.getLocalDeletedNotes(accountId, application.getDBHelper()));

    if (folderId2NotesMap.size() == 0) {
      Log.i(TAG, "doDeleteNotes() end... no deleted notes");
      return;
    }
    try {
      for (long folderId : folderId2NotesMap.keySet()) {
        for (Note note : folderId2NotesMap.get(folderId)) {
          msg = MessageCompose.messageFromDeletedNotes(note);
          if (loginUser != null) {
            msg.setFrom(new Address(loginUser));
          }
          msg.getMessageId();
          pendingDeleteMessages.add(msg);
        }
        Message[] delMessages =
            (Message[]) pendingDeleteMessages.toArray(new Message[pendingDeleteMessages.size()]);
        if (delMessages.length > 0) {
          if (folderId == Folder.ALL_FOLDER_ID) {
            imapStoreClient.deleteNote(delMessages, ImapConsts.IMAP__INOTES_FOLDER);
          } else {
            Folder folder = Folder.getFolderById(folderId, accountId, application.getDBHelper());
            imapStoreClient.deleteNote(delMessages, folder.name);
          }
          pendingDeleteMessages.clear();
        }
        // TODO 感觉可能有点危险,确保删除都是成功的
        for (Note note : folderId2NotesMap.get(folderId)) {
          Note.deleteNoteByIdForever(note.id, accountId, application.getDBHelper());
        }
      }
    } catch (MessagingException e) {
      Log.e(TAG, " ", e);
      throw new MessagingException(e.getLocalizedMessage());
    }
    Log.i(TAG, "doDeleteNotes() end");
  }
  private void doAddNotes(long accountId) throws MessagingException {
    Log.i(TAG, "doAddNotes() begin");
    MimeMessage msg;
    List<MimeMessage> pendingComposeMessages = new ArrayList<MimeMessage>();
    HashMap<Long, List<Note>> folderIdNotesMap =
        buildLocalChangedFolder2NotesMap(
            Note.getLocalAddedNotes(accountId, application.getDBHelper()));
    if (folderIdNotesMap.size() == 0) {
      Log.i(TAG, "doAddNotes() end ..no added notes");
      return;
    }
    try {

      for (long folderId : folderIdNotesMap.keySet()) {
        for (Note note : folderIdNotesMap.get(folderId)) {
          msg = MessageCompose.messageFromNotes(note, application);
          if (loginUser != null) {
            msg.setFrom(new Address(loginUser));
          }
          pendingComposeMessages.add(msg);
        }
        if (pendingComposeMessages.size() > 0) {
          if (folderId == Folder.ALL_FOLDER_ID) {
            imapStoreClient.createNotes(pendingComposeMessages, ImapConsts.IMAP__INOTES_FOLDER);
          } else {
            Folder folder = Folder.getFolderById(folderId, accountId, application.getDBHelper());
            imapStoreClient.createNotes(
                pendingComposeMessages,
                folder == null ? ImapConsts.IMAP__INOTES_FOLDER : folder.name);
          }
          pendingComposeMessages.clear();
        }
      }

      handleRemoteUidNullErro(accountId);

    } catch (MessagingException e) {
      Log.e(TAG, " ", e);
      throw new MessagingException(e.getLocalizedMessage());
    }
    Log.i(TAG, "doAddNotes() end");
  }