Java Code Examples for javax.mail.Folder#getFullName()

The following examples show how to use javax.mail.Folder#getFullName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StoreDeleter.java    From mnIMAPSync with Apache License 2.0 6 votes vote down vote up
private void deleteTargetFolder(Folder folder) throws MessagingException {
    final String targetFolderName = folder.getFullName();
    final String sourceFolderName = targetToSourceFolderName(targetFolderName, sourceIndex, targetIndex);
    //Delete folder
    if (!sourceIndex.containsFolder(sourceFolderName)) {
        //Delete recursively
        targetStore.getFolder(targetFolderName).delete(true);
        incrementFoldersDeletedCount();
    }
    //Folder recursion. Get all children
    if ((folder.getType() & Folder.HOLDS_FOLDERS) == Folder.HOLDS_FOLDERS) {
        for (Folder child : folder.list()) {
            deleteTargetFolder(child);
        }
    }
}
 
Example 2
Source File: StoreCopier.java    From mnIMAPSync with Apache License 2.0 6 votes vote down vote up
/**
 * Create folders in the target server recursively from the source.
 *
 * It also indexes the source store folders if we want to delete target folders that no longer
 * exist
 */
private void copySourceFolder(Folder folder) throws MessagingException {
    final String sourceFolderName = folder.getFullName();
    final String targetFolderName = sourceFolderNameToTarget(sourceFolderName, sourceIndex,
        targetIndex);
    //Index for delete after copy (if necessary)
    if (sourceIndex != null) {
        sourceIndex.addFolder(sourceFolderName);
    }
    //Copy folder
    if (!targetIndex.containsFolder(targetFolderName)) {
        if (!targetStore.getFolder(targetFolderName).create(folder.getType())) {
            throw new MessagingException(String.format(
                    "Couldn't create folder: %s in target server.", sourceFolderName));
        }
        incrementFoldersCopiedCount();
    } else {
        incrementFoldersSkippedCount();
    }
    //Folder recursion. Get all children
    if ((folder.getType() & Folder.HOLDS_FOLDERS) == Folder.HOLDS_FOLDERS) {
        for (Folder child : folder.list()) {
            copySourceFolder(child);
        }
    }
}
 
Example 3
Source File: EmailService.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
List<EntityFolder> getFolders() throws MessagingException {
    List<EntityFolder> folders = new ArrayList<>();

    for (Folder ifolder : getStore().getDefaultFolder().list("*")) {
        String fullName = ifolder.getFullName();
        String[] attrs = ((IMAPFolder) ifolder).getAttributes();
        String type = EntityFolder.getType(attrs, fullName, true);
        Log.i(fullName + " attrs=" + TextUtils.join(" ", attrs) + " type=" + type);

        if (type != null)
            folders.add(new EntityFolder(fullName, type));
    }

    EntityFolder.guessTypes(folders, getStore().getDefaultFolder().getSeparator());

    boolean inbox = false;
    boolean drafts = false;
    for (EntityFolder folder : folders)
        if (EntityFolder.INBOX.equals(folder.type))
            inbox = true;
        else if (EntityFolder.DRAFTS.equals(folder.type))
            drafts = true;

    if (!inbox || !drafts)
        return null;

    return folders;
}
 
Example 4
Source File: IMAPMockFolder.java    From javamail-mock2 with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 5
Source File: StoreCrawler.java    From mnIMAPSync with Apache License 2.0 5 votes vote down vote up
private static void crawlFolders(Store store, Index index, Folder folder,
    ExecutorService service) throws MessagingException {
  if (folder != null) {
    final String folderName = folder.getFullName();
    index.addFolder(folderName);
    if ((folder.getType() & Folder.HOLDS_MESSAGES) == Folder.HOLDS_MESSAGES) {
      folder.open(Folder.READ_ONLY);
      if (folder.getMode() != Folder.READ_ONLY) {
        folder.expunge();
      }
      final int messageCount = folder.getMessageCount();
      folder.close(false);
      int pos = 1;
      while (pos + MNIMAPSync.BATCH_SIZE <= messageCount) {
        service.execute(new FolderCrawler(store, folderName, pos,
            pos + MNIMAPSync.BATCH_SIZE, index));
        pos = pos + MNIMAPSync.BATCH_SIZE;
      }
      service.execute(new FolderCrawler(store, folderName, pos, messageCount, index));
    }
    //Folder recursion. Get all children
    if ((folder.getType() & Folder.HOLDS_FOLDERS) == Folder.HOLDS_FOLDERS) {
      for (Folder child : folder.list()) {
        crawlFolders(store, index, child, service);
      }
    }
  }
}
 
Example 6
Source File: StoreDeleter.java    From mnIMAPSync with Apache License 2.0 5 votes vote down vote up
private void deleteTargetMessages(Folder targetFolder) throws MessagingException {
    if (targetFolder != null) {
        final String targetFolderName = targetFolder.getFullName();
        final String sourceFolderName = targetToSourceFolderName(targetFolderName, sourceIndex, targetIndex);
        if ((targetFolder.getType() & Folder.HOLDS_MESSAGES) == Folder.HOLDS_MESSAGES) {
            targetFolder.open(Folder.READ_WRITE);
            if (targetFolder.getMode() != Folder.READ_ONLY) {
                targetFolder.expunge();
            }
            final int messageCount = targetFolder.getMessageCount();
            targetFolder.close(false);
            int pos = 1;
            while (pos + MNIMAPSync.BATCH_SIZE <= messageCount) {
                service.execute(
                        new MessageDeleter(this, targetFolderName, pos,
                                pos + MNIMAPSync.BATCH_SIZE, false, sourceIndex.
                                getFolderMessages(sourceFolderName)));
                pos = pos + MNIMAPSync.BATCH_SIZE;
            }
            service.execute(new MessageDeleter(this, targetFolderName,
                    pos, messageCount, true, sourceIndex.getFolderMessages(sourceFolderName)));
        }
        //Folder recursion. Get all children
        if ((targetFolder.getType() & Folder.HOLDS_FOLDERS) == Folder.HOLDS_FOLDERS) {
            for (Folder child : targetFolder.list()) {
                deleteTargetMessages(child);
            }
        }
    }
}