List of usage examples for javax.mail Folder list
public Folder[] list() throws MessagingException
From source file:populate.java
private static void copy(Folder src, Folder dst) throws MessagingException { System.out.println("Populating " + dst.getFullName()); Folder ddst = dst;//from w w w . j a v a 2 s . c o m Folder[] srcFolders = null; if ((src.getType() & Folder.HOLDS_FOLDERS) != 0) srcFolders = src.list(); boolean srcHasChildren = srcFolders != null && srcFolders.length > 0; if (!dst.exists()) { // Create it. boolean dstHoldsOnlyFolders = false; if (!dst.create(src.getType())) { // might not be able to create a folder that holds both if (!dst.create(srcHasChildren ? Folder.HOLDS_FOLDERS : Folder.HOLDS_MESSAGES)) { // might only be able to create one type (Gmail) if (!dst.create(Folder.HOLDS_MESSAGES)) { System.out.println("couldn't create " + dst.getFullName()); return; } } dstHoldsOnlyFolders = srcHasChildren; } // Copy over any messges from src to dst if ((src.getType() & Folder.HOLDS_MESSAGES) != 0) { src.open(Folder.READ_ONLY); if (dstHoldsOnlyFolders) { if (src.getMessageCount() > 0) { System.out.println("Unable to copy messages from " + src.getFullName() + " to " + dst.getFullName() + " because destination holds only folders"); } } else copyMessages(src, dst); src.close(false); } } else { System.out.println(dst.getFullName() + " already exists"); // Copy over any messges from src to dst if (force && (src.getType() & Folder.HOLDS_MESSAGES) != 0) { src.open(Folder.READ_ONLY); copyMessages(src, dst); src.close(false); } } // Copy over subfolders if (srcHasChildren) { for (int i = 0; i < srcFolders.length; i++) { // skip special directories? if (skipSpecial) { if (srcFolders[i].getName().equals("SCCS") || srcFolders[i].getName().equals("Drafts") || srcFolders[i].getName().equals("Trash") || srcFolders[i].getName().equals("Shared Folders")) continue; } copy(srcFolders[i], dst.getFolder(srcFolders[i].getName())); } } }
From source file:populate.java
private static void copy(Folder src, Folder dst) throws MessagingException { System.out.println("Populating " + dst.getFullName()); Folder ddst = dst;/* w w w. java2s . c om*/ Folder[] srcFolders = null; if ((src.getType() & Folder.HOLDS_FOLDERS) != 0) srcFolders = src.list(); boolean srcHasChildren = srcFolders != null && srcFolders.length > 0; if (!dst.exists()) { // Create it. boolean dstHoldsOnlyFolders = false; try { if (!dst.create(src.getType())) { System.out.println("couldn't create " + dst.getFullName()); return; } } catch (MessagingException mex) { // might not be able to create a folder that holds both if (src.getType() != (Folder.HOLDS_MESSAGES | Folder.HOLDS_FOLDERS)) throw mex; if (!dst.create(srcHasChildren ? Folder.HOLDS_FOLDERS : Folder.HOLDS_MESSAGES)) { System.out.println("couldn't create " + dst.getFullName()); return; } dstHoldsOnlyFolders = srcHasChildren; } // Copy over any messges from src to dst if ((src.getType() & Folder.HOLDS_MESSAGES) != 0) { src.open(Folder.READ_ONLY); if (dstHoldsOnlyFolders) { if (src.getMessageCount() > 0) { System.out.println("Unable to copy messages from " + src.getFullName() + " to " + dst.getFullName() + " because destination holds only folders"); } } else copyMessages(src, dst); src.close(false); } } else { System.out.println(dst.getFullName() + " already exists"); // Copy over any messges from src to dst if (force && (src.getType() & Folder.HOLDS_MESSAGES) != 0) { src.open(Folder.READ_ONLY); copyMessages(src, dst); src.close(false); } } // Copy over subfolders if (srcHasChildren) { for (int i = 0; i < srcFolders.length; i++) { // skip special directories? if (skipSpecial) { if (srcFolders[i].getName().equals("SCCS") || srcFolders[i].getName().equals("Drafts") || srcFolders[i].getName().equals("Trash") || srcFolders[i].getName().equals("Shared Folders")) continue; } copy(srcFolders[i], dst.getFolder(srcFolders[i].getName())); } } }
From source file:com.treesbearfruit.icloudnotes.NotesSaver.java
public NotesSaver(String username, String password, String j, String wheretosave) throws Exception { // Get system properties Properties props = System.getProperties(); Session session = Session.getDefaultInstance(props); // Get the store Store store = session.getStore("imaps"); String noteFolderLabel = ""; if (j.toLowerCase().equals("apple")) { noteFolderLabel = "Notes"; store.connect("imap.mail.me.com", username, password); // username without @icloud.com } else if (j.toLowerCase().equals("google")) { noteFolderLabel = "Notes"; store.connect("imap.gmail.com", username, password); } else {/*w w w .ja va 2 s . c o m*/ throw new Exception("Notesprovider not implemented!"); } String timestamp = new java.text.SimpleDateFormat("dd_MM_yyyy_hh_mm_ss").format(new Date()); String backup_directory = wheretosave + (wheretosave.endsWith(File.separator) ? "" : File.separator) + noteFolderLabel + "_" + timestamp + File.separator; // saves main folder save(store, backup_directory, noteFolderLabel); // folder..s Folder mainnotefolder = store.getFolder(noteFolderLabel); System.out.println("found " + mainnotefolder.list().length + " note folders"); Folder[] f = mainnotefolder.list(); for (Folder fd : f) { String backup_directory_i = backup_directory + fd.getName(); save(store, backup_directory_i, noteFolderLabel + "/" + fd.getName()); } // Close connection store.close(); }
From source file:com.jaeksoft.searchlib.crawler.mailbox.crawler.MailboxAbstractCrawler.java
private void readHoldsFolder(Folder folder) throws MessagingException, IOException, SearchLibException { Folder[] folders = folder.list(); if (folders == null) return;//ww w . j a v a 2 s .c o m for (Folder f : folders) readFolder(f); }
From source file:com.alvexcore.repo.emails.impl.ExtendedEmailMessage.java
protected void fetchFolderChildren(Folder folder, NodeRef repoFolder) throws MessagingException { for (Folder f : folder.list()) { Map<QName, Serializable> props = new HashMap<QName, Serializable>(); props.put(AlvexContentModel.PROP_EMAIL_FOLDER_FETCH_ACTIVE, true); props.put(ContentModel.PROP_NAME, f.getName()); NodeRef newNode = nodeService.createNode(repoFolder, ContentModel.ASSOC_CONTAINS, QName.createQName(AlvexContentModel.ALVEXEM_MODEL_URI, f.getName()), AlvexContentModel.TYPE_EMAIL_FOLDER, props).getChildRef(); fetchFolderChildren(f, newNode); }//from ww w .ja v a 2 s .c o m }
From source file:folderlist.java
static void dumpFolder(Folder folder, boolean recurse, String tab) throws Exception { System.out.println(tab + "Name: " + folder.getName()); System.out.println(tab + "Full Name: " + folder.getFullName()); System.out.println(tab + "URL: " + folder.getURLName()); if (verbose) { if (!folder.isSubscribed()) System.out.println(tab + "Not Subscribed"); if ((folder.getType() & Folder.HOLDS_MESSAGES) != 0) { if (folder.hasNewMessages()) System.out.println(tab + "Has New Messages"); System.out.println(tab + "Total Messages: " + folder.getMessageCount()); System.out.println(tab + "New Messages: " + folder.getNewMessageCount()); System.out.println(tab + "Unread Messages: " + folder.getUnreadMessageCount()); }// ww w . j a v a 2s. c o m if ((folder.getType() & Folder.HOLDS_FOLDERS) != 0) System.out.println(tab + "Is Directory"); /* * Demonstrate use of IMAP folder attributes * returned by the IMAP LIST response. */ if (folder instanceof IMAPFolder) { IMAPFolder f = (IMAPFolder) folder; String[] attrs = f.getAttributes(); if (attrs != null && attrs.length > 0) { System.out.println(tab + "IMAP Attributes:"); for (int i = 0; i < attrs.length; i++) System.out.println(tab + " " + attrs[i]); } } } System.out.println(); if ((folder.getType() & Folder.HOLDS_FOLDERS) != 0) { if (recurse) { Folder[] f = folder.list(); for (int i = 0; i < f.length; i++) dumpFolder(f[i], recurse, tab + " "); } } }
From source file:MainClass.java
static void dumpFolder(Folder folder, boolean recurse, String tab) throws Exception { System.out.println(tab + "Name: " + folder.getName()); System.out.println(tab + "Full Name: " + folder.getFullName()); System.out.println(tab + "URL: " + folder.getURLName()); if (verbose) { if (!folder.isSubscribed()) System.out.println(tab + "Not Subscribed"); if ((folder.getType() & Folder.HOLDS_MESSAGES) != 0) { if (folder.hasNewMessages()) System.out.println(tab + "Has New Messages"); System.out.println(tab + "Total Messages: " + folder.getMessageCount()); System.out.println(tab + "New Messages: " + folder.getNewMessageCount()); System.out.println(tab + "Unread Messages: " + folder.getUnreadMessageCount()); }// ww w . j a va 2s . c o m if ((folder.getType() & Folder.HOLDS_FOLDERS) != 0) System.out.println(tab + "Is Directory"); /* * Demonstrate use of IMAP folder attributes returned by the IMAP LIST * response. */ if (folder instanceof IMAPFolder) { IMAPFolder f = (IMAPFolder) folder; String[] attrs = f.getAttributes(); if (attrs != null && attrs.length > 0) { System.out.println(tab + "IMAP Attributes:"); for (int i = 0; i < attrs.length; i++) System.out.println(tab + " " + attrs[i]); } } } System.out.println(); if ((folder.getType() & Folder.HOLDS_FOLDERS) != 0) { if (recurse) { Folder[] f = folder.list(); for (int i = 0; i < f.length; i++) dumpFolder(f[i], recurse, tab + " "); } } }
From source file:com.jaeksoft.searchlib.crawler.mailbox.crawler.MailboxAbstractCrawler.java
protected void checkFolder(Folder folder, PrintWriter pw) throws MessagingException, IOException, SearchLibException { if (folder == null) return;/* w w w.j av a 2s.com*/ if ((folder.getType() & Folder.HOLDS_MESSAGES) != 0) { folder.open(Folder.READ_ONLY); try { pw.print("Folder "); pw.print(folder.getName()); pw.print(": "); pw.print(folder.getMessageCount()); pw.println(" msgs(s)."); } finally { folder.close(false); } } if ((folder.getType() & Folder.HOLDS_FOLDERS) != 0) { Folder[] folders = folder.list(); if (folders != null) for (Folder f : folders) checkFolder(f, pw); } }
From source file:com.liferay.mail.imap.IMAPAccessor.java
public List<Folder> getFolders() throws MailException { try {//from w ww. ja v a 2 s . c o m List<Folder> jxFolders = new ArrayList<>(); Store store = _imapConnection.getStore(true); Folder jxFolder = store.getDefaultFolder(); getFolders(jxFolders, jxFolder.list()); return jxFolders; } catch (MessagingException me) { throw new MailException(me); } }
From source file:com.sonicle.webtop.mail.MailAccount.java
public boolean deleteFolder(Folder folder) throws MessagingException { for (Folder subfolder : folder.list()) { deleteFolder(subfolder);//from www.ja va 2 s . c om } try { folder.close(false); } catch (Throwable exc) { } boolean retval = folder.delete(true); if (retval) { destroyFolderCache(folder.getFullName()); } return retval; }