List of usage examples for javax.mail Store getDefaultFolder
public abstract Folder getDefaultFolder() throws MessagingException;
From source file:edu.stanford.muse.email.MboxEmailStore.java
public Folder openFolderWithoutCount(Store s, String fname) throws MessagingException { if (fname == null) fname = "INBOX"; // ignore the store coming in, we need a new session and store // for each folder Session session = Session.getInstance(mstorProps, null); session.setDebug(DEBUG);//from ww w . j a v a 2 s . c om // Get a Store object Store store = session.getStore(new URLName("mstor:" + fname)); store.connect(); //This is the root folder in the namespace provided //see http://docs.oracle.com/javaee/5/api/javax/mail/Store.html#getDefaultFolder%28%29 Folder folder = store.getDefaultFolder(); if (folder == null) throw new RuntimeException("Invalid folder: " + fname); log.info("Opening folder " + Util.blurPath(fname) + " in r/o mode..."); try { folder.open(Folder.READ_ONLY); } catch (MessagingException me) { folder = null; } return folder; }
From source file:com.jaeksoft.searchlib.crawler.mailbox.crawler.MailboxAbstractCrawler.java
public String check() throws MessagingException, IOException, SearchLibException { Store store = null; StringWriter sw = null;/*from ww w .ja v a 2s . c om*/ PrintWriter pw = null; try { sw = new StringWriter(); pw = new PrintWriter(sw); pw.println(); store = getStore(); connect(store); checkFolder(store.getDefaultFolder(), pw); pw.println("OK"); return sw.toString(); } finally { if (store != null) store.close(); IOUtils.close(pw, sw); } }
From source file:de.saly.elasticsearch.imap.AbstractIMAPRiverUnitTest.java
protected void createInitialIMAPTestdata(final Properties props, final String user, final String password, final int count, final boolean deleteall) throws MessagingException { final Session session = Session.getInstance(props); final Store store = session.getStore(); store.connect(user, password);/*from w w w. j a va2 s . c o m*/ checkStoreForTestConnection(store); final Folder root = store.getDefaultFolder(); final Folder testroot = root.getFolder("ES-IMAP-RIVER-TESTS"); final Folder testrootl2 = testroot.getFolder("Level(2!"); if (deleteall) { deleteMailsFromUserMailbox(props, "INBOX", 0, -1, user, password); if (testroot.exists()) { testroot.delete(true); } final Folder testrootenamed = root.getFolder("renamed_from_ES-IMAP-RIVER-TESTS"); if (testrootenamed.exists()) { testrootenamed.delete(true); } } if (!testroot.exists()) { testroot.create(Folder.HOLDS_FOLDERS & Folder.HOLDS_MESSAGES); testroot.open(Folder.READ_WRITE); testrootl2.create(Folder.HOLDS_FOLDERS & Folder.HOLDS_MESSAGES); testrootl2.open(Folder.READ_WRITE); } final Folder inbox = root.getFolder("INBOX"); inbox.open(Folder.READ_WRITE); final Message[] msgs = new Message[count]; for (int i = 0; i < count; i++) { final MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(EMAIL_TO)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(EMAIL_USER_ADDRESS)); message.setSubject(EMAIL_SUBJECT + "::" + i); message.setText(EMAIL_TEXT + "::" + SID++); message.setSentDate(new Date()); msgs[i] = message; } inbox.appendMessages(msgs); testroot.appendMessages(msgs); testrootl2.appendMessages(msgs); IMAPUtils.close(inbox); IMAPUtils.close(testrootl2); IMAPUtils.close(testroot); IMAPUtils.close(store); }
From source file:com.alvexcore.repo.emails.impl.ExtendedEmailMessage.java
@Override public void fetchFolderList() { try {/*w w w. j a v a 2 s . c o m*/ Store store = connectToStore(); fetchFolderChildren(store.getDefaultFolder(), getEmailConfigNode()); } catch (MessagingException e) { throw new AlfrescoRuntimeException("Folder list fetch failed", e); } }
From source file:com.alvexcore.repo.emails.impl.ExtendedEmailMessage.java
@Override public void fetch() { try {//from ww w .j av a 2s . co m Store store = connectToStore(); fetchFolder((IMAPFolder) store.getDefaultFolder(), new EmailFolderImpl(getEmailConfigNode(), nodeService, contentService), true); store.close(); } catch (MessagingException e) { throw new AlfrescoRuntimeException("Failed to fetch emails", e); } }
From source file:com.naryx.tagfusion.cfm.mail.cfPOP3.java
private Folder openFolder(cfSession _Session, Store popStore) throws cfmRunTimeException { try {/*from w w w.jav a 2s . c o m*/ Folder folder = popStore.getDefaultFolder(); Folder popFolder = folder.getFolder("INBOX"); popFolder.open(Folder.READ_WRITE); return popFolder; } catch (Exception E) { throw newRunTimeException(E.getMessage()); } }
From source file:com.liferay.mail.imap.IMAPAccessor.java
public List<Folder> getFolders() throws MailException { try {//w w w .j a v a 2 s . com 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:org.jasig.portlet.emailpreview.dao.javamail.JavamailAccountDaoImpl.java
private Folder getUserInbox(Session session, String folderName) throws MessagingException { // Assertions. if (session == null) { String msg = "Argument 'session' cannot be null"; throw new IllegalArgumentException(msg); }//from w w w . j ava 2s . co m try { Store store = session.getStore(); store.connect(); if (log.isDebugEnabled()) { log.debug("Mail store connection established to get user inbox"); } // Retrieve user's inbox folder Folder root = store.getDefaultFolder(); Folder inboxFolder = root.getFolder(folderName); return inboxFolder; } catch (AuthenticationFailedException e) { throw new MailAuthenticationException(e); } }
From source file:com.liferay.mail.imap.IMAPAccessor.java
public String[] addFolder(String displayName) throws MailException { try {/*from ww w. j a v a 2 s . c om*/ String fullName = displayName; if (Validator.isNotNull(_account.getFolderPrefix())) { Store store = _imapConnection.getStore(true); Folder jxFolder = store.getDefaultFolder(); fullName = _account.getFolderPrefix() + jxFolder.getSeparator() + displayName; } Folder jxFolder = getFolder(fullName); if (jxFolder.exists()) { throw new MailException(MailException.FOLDER_ALREADY_EXISTS); } else { if (jxFolder.create(Folder.HOLDS_MESSAGES)) { return new String[] { jxFolder.getFullName(), jxFolder.getName() }; } throw new MailException(MailException.FOLDER_CREATE_FAILED); } } catch (MessagingException me) { throw new MailException(me); } }
From source file:com.liferay.mail.imap.IMAPAccessor.java
public String[] renameFolder(long folderId, String newDisplayName) throws PortalException { try {//from www .ja v a 2 s. c om Folder jxFolder = getFolder(folderId); String newFullName = StringPool.BLANK; if (Validator.isNotNull(_account.getFolderPrefix())) { Store store = _imapConnection.getStore(true); Folder defaultJxFolder = store.getDefaultFolder(); newFullName = _account.getFolderPrefix() + defaultJxFolder.getSeparator() + newDisplayName; } if (!jxFolder.exists()) { throw new MailException(MailException.FOLDER_DOES_NOT_EXIST); } if (jxFolder.renameTo(getFolder(newFullName))) { return new String[] { jxFolder.getFullName(), jxFolder.getName() }; } else { throw new MailException(MailException.FOLDER_RENAME_FAILED); } } catch (MessagingException me) { throw new MailException(me); } }