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

The following examples show how to use javax.mail.Folder#getMode() . 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: SyncUtils.java    From ImapNote2 with GNU General Public License v3.0 6 votes vote down vote up
public static void GetNotes(Account account, Folder notesFolder, Context ctx, NotesDb storedNotes) throws MessagingException, IOException{
  Long UIDM;
  Message notesMessage;
  File directory = new File (ctx.getFilesDir() + "/" + account.name);
  if (notesFolder.isOpen()) {
    if ((notesFolder.getMode() & Folder.READ_ONLY) != 0)
      notesFolder.open(Folder.READ_ONLY);
  } else {
    notesFolder.open(Folder.READ_ONLY);
  }
  UIDValidity = GetUIDValidity(account, ctx);
  SetUIDValidity(account, UIDValidity, ctx);
  Message[] notesMessages = notesFolder.getMessages();
  //Log.d(TAG,"number of messages in folder="+(notesMessages.length));
  for(int index=notesMessages.length-1; index>=0; index--) {
      notesMessage = notesMessages[index];
      // write every message in files/{accountname} directory
      // filename is the original message uid
      UIDM=((IMAPFolder)notesFolder).getUID(notesMessage);
      String suid = UIDM.toString();
      File outfile = new File (directory, suid);
      GetOneNote(outfile, notesMessage, storedNotes, account.name, suid, true);
  }
}
 
Example 2
Source File: SyncUtils.java    From ImapNote2 with GNU General Public License v3.0 5 votes vote down vote up
public static void DeleteNote(Folder notesFolder, int numMessage) throws MessagingException, IOException {
  notesFolder = store.getFolder(sfolder);
  if (notesFolder.isOpen()) {
    if ((notesFolder.getMode() & Folder.READ_WRITE) != 0)
      notesFolder.open(Folder.READ_WRITE);
  } else {
    notesFolder.open(Folder.READ_WRITE);
  }
  
  //Log.d(TAG,"UID to remove:"+numMessage);
  Message[] msgs = {((IMAPFolder)notesFolder).getMessageByUID(numMessage)};
  notesFolder.setFlags(msgs, new Flags(Flags.Flag.DELETED), true);
  ((IMAPFolder)notesFolder).expunge(msgs);
}
 
Example 3
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 4
Source File: MessageDeleter.java    From mnIMAPSync with Apache License 2.0 5 votes vote down vote up
public void run() {
    long deleted = 0L;
    long skipped = 0L;
    try {
        final Folder targetFolder = storeDeleter.getTargetStore().getFolder(targetFolderName);
        //Opens a new connection per Thread
        targetFolder.open(Folder.READ_WRITE);
        final Message[] targetMessages = targetFolder.getMessages(start, end);
        targetFolder.fetch(targetMessages, MessageId.addHeaders(new FetchProfile()));
        for (Message message : targetMessages) {
            try {
                final MessageId id = new MessageId(message);
                if (!sourceFolderMessages.contains(id)) {
                    message.setFlag(Flags.Flag.DELETED, true);
                    deleted++;
                } else {
                    skipped++;
                }
            } catch (MessageId.MessageIdException ex) {
                //Usually messages that ran into this exception are spammy, so we skip them.
                skipped++;
            }
        }
        //Close folder and expunge flagged messages
        //Expunge only if folder is read write
        if (targetFolder.getMode() == Folder.READ_ONLY) {
            targetFolder.close(false);
        } else {
            targetFolder.close(expunge);
        }
    } catch (MessagingException messagingException) {
        Logger.getLogger(Index.class.getName()).log(Level.SEVERE, null, messagingException);
    }
    storeDeleter.updatedMessagesDeletedCount(deleted);
    storeDeleter.updateMessagesSkippedCount(skipped);
}
 
Example 5
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);
            }
        }
    }
}