Exemple #1
0
 private void refreshFolder(Account account, String folderName) {
   // There has to be a cheaper way to get at the localFolder object than this
   Folder localFolder = null;
   try {
     if (account != null && folderName != null) {
       if (!account.isAvailable(FolderList.this)) {
         Log.i(K9.LOG_TAG, "not refreshing folder of unavailable account");
         return;
       }
       localFolder = account.getLocalStore().getFolder(folderName);
       int unreadMessageCount = localFolder.getUnreadMessageCount();
       FolderInfoHolder folderHolder = getFolder(folderName);
       if (folderHolder != null) {
         folderHolder.populate(context, localFolder, mAccount, unreadMessageCount);
         mHandler.dataChanged();
       }
     }
   } catch (Exception e) {
     Log.e(K9.LOG_TAG, "Exception while populating folder", e);
   } finally {
     if (localFolder != null) {
       localFolder.close();
     }
   }
 }
 @Override
 public Folder getFolder(String name) {
   Folder folder = mFolders.get(name);
   if (folder == null) {
     folder = new Pop3Folder(name);
     mFolders.put(folder.getName(), folder);
   }
   return folder;
 }
Exemple #3
0
  @Override
  public int delete(Uri uri, String selection, String[] selectionArgs) {
    if (K9.app == null) {
      return 0;
    }

    if (K9.DEBUG) {
      Log.v(K9.LOG_TAG, "MessageProvider/delete: " + uri);
    }

    // Note: can only delete a message

    List<String> segments = null;
    int accountId = -1;
    String folderName = null;
    String msgUid = null;

    segments = uri.getPathSegments();
    accountId = Integer.parseInt(segments.get(1));
    folderName = segments.get(2);
    msgUid = segments.get(3);

    // get account
    Account myAccount = null;
    for (Account account : Preferences.getPreferences(getContext()).getAccounts()) {
      if (account.getAccountNumber() == accountId) {
        myAccount = account;
        if (!account.isAvailable(getContext())) {
          Log.w(K9.LOG_TAG, "not deleting messages because account is unavailable at the moment");
          return 0;
        }
      }
    }

    // get localstore parameter
    Message msg = null;
    try {
      Folder lf = LocalStore.getLocalInstance(myAccount, K9.app).getFolder(folderName);
      int msgCount = lf.getMessageCount();
      if (K9.DEBUG) {
        Log.d(K9.LOG_TAG, "folder msg count = " + msgCount);
      }
      msg = lf.getMessage(msgUid);
    } catch (MessagingException e) {
      Log.e(K9.LOG_TAG, "Unable to retrieve message", e);
    }

    // launch command to delete the message
    if ((myAccount != null) && (msg != null)) {
      MessagingController.getInstance(K9.app).deleteMessages(new Message[] {msg}, null);
    }

    // FIXME return the actual number of deleted messages
    return 0;
  }
Exemple #4
0
    @Override
    public void listLocalMessagesAddMessages(
        final Account account, final String folderName, final List<Message> messages) {
      // cache fields into local variables for faster access on JVM without JIT
      final MessageHelper helper = mMessageHelper;
      final List<MessageInfoHolder> holders = mHolders;

      final Context context = getContext();

      for (final Message message : messages) {
        final MessageInfoHolder messageInfoHolder = new MessageInfoHolder();
        final Folder messageFolder = message.getFolder();
        final Account messageAccount = messageFolder.getAccount();

        helper.populate(
            messageInfoHolder,
            message,
            new FolderInfoHolder(context, messageFolder, messageAccount),
            messageAccount);

        holders.add(messageInfoHolder);
      }
    }
Exemple #5
0
 @Override
 public Map<String, String> copyMessages(List<? extends Message> messages, Folder folder)
     throws MessagingException {
   moveOrCopyMessages(messages, folder.getName(), false);
   return null;
 }
Exemple #6
0
          @Override
          public void listFolders(Account account, Folder[] folders) {
            if (account.equals(mAccount)) {

              List<FolderInfoHolder> newFolders = new LinkedList<FolderInfoHolder>();
              List<FolderInfoHolder> topFolders = new LinkedList<FolderInfoHolder>();

              Account.FolderMode aMode = account.getFolderDisplayMode();
              Preferences prefs =
                  Preferences.getPreferences(getApplication().getApplicationContext());
              for (Folder folder : folders) {
                try {
                  folder.refresh(prefs);

                  Folder.FolderClass fMode = folder.getDisplayClass();

                  if ((aMode == Account.FolderMode.FIRST_CLASS
                          && fMode != Folder.FolderClass.FIRST_CLASS)
                      || (aMode == Account.FolderMode.FIRST_AND_SECOND_CLASS
                          && fMode != Folder.FolderClass.FIRST_CLASS
                          && fMode != Folder.FolderClass.SECOND_CLASS)
                      || (aMode == Account.FolderMode.NOT_SECOND_CLASS
                          && fMode == Folder.FolderClass.SECOND_CLASS)) {
                    continue;
                  }
                } catch (MessagingException me) {
                  Log.e(
                      K9.LOG_TAG,
                      "Couldn't get prefs to check for displayability of folder "
                          + folder.getName(),
                      me);
                }

                FolderInfoHolder holder = null;

                int folderIndex = getFolderIndex(folder.getName());
                if (folderIndex >= 0) {
                  holder = (FolderInfoHolder) getItem(folderIndex);
                }
                int unreadMessageCount = 0;
                try {
                  unreadMessageCount = folder.getUnreadMessageCount();
                } catch (Exception e) {
                  Log.e(
                      K9.LOG_TAG,
                      "Unable to get unreadMessageCount for "
                          + mAccount.getDescription()
                          + ":"
                          + folder.getName());
                }

                if (holder == null) {
                  holder = new FolderInfoHolder(context, folder, mAccount, unreadMessageCount);
                } else {
                  holder.populate(context, folder, mAccount, unreadMessageCount);
                }
                if (folder.isInTopGroup()) {
                  topFolders.add(holder);
                } else {
                  newFolders.add(holder);
                }
              }
              Collections.sort(newFolders);
              Collections.sort(topFolders);
              topFolders.addAll(newFolders);
              mHandler.newFolders(topFolders);
            }
            super.listFolders(account, folders);
          }
Exemple #7
0
        @Override
        public void listFolders(Account account, Folder[] folders) {
          if (!account.equals(mAccount)) {
            return;
          }
          Account.FolderMode aMode = mMode;
          Preferences prefs = Preferences.getPreferences(getApplication().getApplicationContext());
          ArrayList<String> localFolders = new ArrayList<String>();

          for (Folder folder : folders) {
            String name = folder.getName();

            // Inbox needs to be compared case-insensitively
            if (mHideCurrentFolder
                && (name.equals(mFolder)
                    || (mAccount.getInboxFolderName().equalsIgnoreCase(mFolder)
                        && mAccount.getInboxFolderName().equalsIgnoreCase(name)))) {
              continue;
            }
            try {
              folder.refresh(prefs);
              Folder.FolderClass fMode = folder.getDisplayClass();

              if ((aMode == Account.FolderMode.FIRST_CLASS
                      && fMode != Folder.FolderClass.FIRST_CLASS)
                  || (aMode == Account.FolderMode.FIRST_AND_SECOND_CLASS
                      && fMode != Folder.FolderClass.FIRST_CLASS
                      && fMode != Folder.FolderClass.SECOND_CLASS)
                  || (aMode == Account.FolderMode.NOT_SECOND_CLASS
                      && fMode == Folder.FolderClass.SECOND_CLASS)) {
                continue;
              }
            } catch (MessagingException me) {
              Log.e(
                  K9.LOG_TAG,
                  "Couldn't get prefs to check for displayability of folder " + folder.getName(),
                  me);
            }

            localFolders.add(folder.getName());
          }

          if (mShowOptionNone) {
            localFolders.add(K9.FOLDER_NONE);
          }

          Collections.sort(
              localFolders,
              new Comparator<String>() {
                @Override
                public int compare(String aName, String bName) {
                  if (K9.FOLDER_NONE.equalsIgnoreCase(aName)) {
                    return -1;
                  }
                  if (K9.FOLDER_NONE.equalsIgnoreCase(bName)) {
                    return 1;
                  }
                  if (mAccount.getInboxFolderName().equalsIgnoreCase(aName)) {
                    return -1;
                  }
                  if (mAccount.getInboxFolderName().equalsIgnoreCase(bName)) {
                    return 1;
                  }

                  return aName.compareToIgnoreCase(bName);
                }
              });
          int selectedFolder = -1;

          /*
           * We're not allowed to change the adapter from a background thread, so we collect the
           * folder names and update the adapter in the UI thread (see finally block).
           */
          final List<String> folderList = new ArrayList<String>();
          try {
            int position = 0;
            for (String name : localFolders) {
              if (mAccount.getInboxFolderName().equalsIgnoreCase(name)) {
                folderList.add(getString(R.string.special_mailbox_name_inbox));
                mHeldInbox = name;
              } else if (!K9.ERROR_FOLDER_NAME.equals(name)
                  && !account.getOutboxFolderName().equals(name)) {
                folderList.add(name);
              }

              if (mSelectFolder != null) {
                /*
                 * Never select EXTRA_CUR_FOLDER (mFolder) if EXTRA_SEL_FOLDER
                 * (mSelectedFolder) was provided.
                 */

                if (name.equals(mSelectFolder)) {
                  selectedFolder = position;
                }
              } else if (name.equals(mFolder)
                  || (mAccount.getInboxFolderName().equalsIgnoreCase(mFolder)
                      && mAccount.getInboxFolderName().equalsIgnoreCase(name))) {
                selectedFolder = position;
              }
              position++;
            }
          } finally {
            runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    // Now we're in the UI-thread, we can safely change the contents of the adapter.
                    mAdapter.clear();
                    for (String folderName : folderList) {
                      mAdapter.add(folderName);
                    }

                    mAdapter.notifyDataSetChanged();

                    /*
                     * Only enable the text filter after the list has been
                     * populated to avoid possible race conditions because our
                     * FolderListFilter isn't really thread-safe.
                     */
                    getListView().setTextFilterEnabled(true);
                  }
                });
          }

          if (selectedFolder != -1) {
            mHandler.setSelectedFolder(selectedFolder);
          }
        }