private Folder getRecursiveFolder( String foldername ) throws MessagingException { Folder dfolder; String[] folderparts = foldername.split( "/" ); dfolder = this.getStore().getDefaultFolder(); // Open destination folder for ( int i = 0; i < folderparts.length; i++ ) { dfolder = dfolder.getFolder( folderparts[i] ); } return dfolder; }
Properties props = System.getProperties(); props.setProperty("mail.store.protocol", "imaps"); Session session = Session.getDefaultInstance(props, null); Store store = session.getStore("imaps"); store.connect("imap.gmail.com", "YOURMAILID@gmail.com", "UR_P@ZZWRD"); System.out.println(store); Folder[] f = store.getDefaultFolder().list(); for(Folder fd:f) System.out.println(">> "+fd.getName());
/** * Returns array of all {@link Folder}s as {@code String}s. You can use these names in * {@link #useFolder(String)} method. * * @return array of all {@link Folder}s as {@code String}s. */ public String[] getAllFolders() { final Folder[] folders; try { folders = getService().getDefaultFolder().list("*"); } catch (final MessagingException msgexc) { throw new MailException("Failed to connect to folder", msgexc); } final String[] folderNames = new String[folders.length]; for (int i = 0; i < folders.length; i++) { final Folder folder = folders[i]; folderNames[i] = folder.getFullName(); } return folderNames; }
private void selectFolder( TextVar input ) { if ( connect() ) { try { Folder folder = mailConn.getStore().getDefaultFolder(); SelectFolderDialog s = new SelectFolderDialog( shell, SWT.NONE, folder ); String foldername = s.open(); if ( foldername != null ) { input.setText( foldername ); } } catch ( Exception e ) { // Ignore errors } } }
private void selectFolder( TextVar input ) { if ( connect() ) { try { Folder folder = mailConn.getStore().getDefaultFolder(); SelectFolderDialog s = new SelectFolderDialog( shell, SWT.NONE, folder ); String foldername = s.open(); if ( foldername != null ) { input.setText( foldername ); } } catch ( Exception e ) { // Ignore errors } } }
public Folder openMailFolder( Store store ) throws MessagingException { Folder folder = store.getDefaultFolder(); folder = folder.getFolder( "inbox" ); folder.open( Folder.READ_ONLY ); return folder; }
public Mconn( LogChannelInterface log ) throws KettleException, MessagingException { super( log, MailConnectionMeta.PROTOCOL_IMAP, "junit", 0, "junit", "junit", false, false, "junit" ); store = Mockito.mock( Store.class ); inbox = Mockito.mock( Folder.class ); a = Mockito.mock( Folder.class ); b = Mockito.mock( Folder.class ); c = Mockito.mock( Folder.class ); when( a.getFullName() ).thenReturn( "A" ); when( b.getFullName() ).thenReturn( "B" ); when( c.getFullName() ).thenReturn( "C" ); when( a.exists() ).thenReturn( true ); when( b.exists() ).thenReturn( true ); when( c.exists() ).thenReturn( cCreated ); when( c.create( Mockito.anyInt() ) ).thenAnswer( new Answer<Boolean>() { @Override public Boolean answer( InvocationOnMock invocation ) throws Throwable { Object arg0 = invocation.getArguments()[0]; mode = Integer.class.cast( arg0 ); cCreated = true; return true; } } ); when( inbox.getFolder( "a" ) ).thenReturn( a ); when( a.getFolder( "b" ) ).thenReturn( b ); when( b.getFolder( "c" ) ).thenReturn( c ); when( store.getDefaultFolder() ).thenReturn( inbox ); }
/** * Set destination folder * * @param foldername * destination foldername * @param createFolder * flag create folder if needed * @throws KettleException */ public void setDestinationFolder( String foldername, boolean createFolder ) throws KettleException { try { String[] folderparts = foldername.split( "/" ); Folder f = this.getStore().getDefaultFolder(); // Open destination folder for ( int i = 0; i < folderparts.length; i++ ) { f = f.getFolder( folderparts[i] ); if ( !f.exists() ) { if ( createFolder ) { // Create folder f.create( Folder.HOLDS_MESSAGES ); } else { throw new KettleException( BaseMessages.getString( PKG, "MailConnection.Error.FolderNotFound", foldername ) ); } } } this.destinationIMAPFolder = f; } catch ( Exception e ) { throw new KettleException( e ); } }
/** * Returns all subfolders of the folder folder * * @param folder * target folder * @return sub folders */ public String[] returnAllFolders( String folder ) throws KettleException { Folder dfolder = null; String[] retval = null; try { if ( Utils.isEmpty( folder ) ) { // Default folder dfolder = getStore().getDefaultFolder(); } else { dfolder = getStore().getFolder( folder ); } retval = returnAllFolders( dfolder ); } catch ( Exception e ) { // Ignore errors } finally { try { if ( dfolder != null ) { dfolder.close( false ); } } catch ( Exception e ) { /* Ignore */ } } return retval; }
/** * Return a set of folders representing the <i>personal</i> namespaces * for the current user. A personal namespace is a set of names that * is considered within the personal scope of the authenticated user. * Typically, only the authenticated user has access to mail folders * in their personal namespace. If an INBOX exists for a user, it * must appear within the user's personal namespace. In the * typical case, there should be only one personal namespace for each * user in each Store. <p> * * This implementation returns an array with a single entry containing * the return value of the <code>getDefaultFolder</code> method. * Subclasses should override this method to return appropriate information. * * @return array of Folder objects * @exception IllegalStateException if this Store is not connected. * @exception MessagingException for other failures * @since JavaMail 1.2 */ public Folder[] getPersonalNamespaces() throws MessagingException { return new Folder[] { getDefaultFolder() }; }
/** * Return a set of folders representing the <i>personal</i> namespaces * for the current user. A personal namespace is a set of names that * is considered within the personal scope of the authenticated user. * Typically, only the authenticated user has access to mail folders * in their personal namespace. If an INBOX exists for a user, it * must appear within the user's personal namespace. In the * typical case, there should be only one personal namespace for each * user in each Store. <p> * * This implementation returns an array with a single entry containing * the return value of the <code>getDefaultFolder</code> method. * Subclasses should override this method to return appropriate information. * * @return array of Folder objects * @exception IllegalStateException if this Store is not connected. * @exception MessagingException for other failures * @since JavaMail 1.2 */ public Folder[] getPersonalNamespaces() throws MessagingException { return new Folder[] { getDefaultFolder() }; }
this.folder = this.store.getDefaultFolder(); } else {
/** * Return the root folders of the personal namespace belonging to the current user. * * The default implementation simply returns an array containing the folder returned by {@link #getDefaultFolder()}. * @return the root folders of the user's peronal namespaces * @throws MessagingException if there was a problem accessing the store */ public Folder[] getPersonalNamespaces() throws MessagingException { return new Folder[]{getDefaultFolder()}; }
/** * Return the root folders of the personal namespace belonging to the current user. * * The default implementation simply returns an array containing the folder returned by {@link #getDefaultFolder()}. * @return the root folders of the user's peronal namespaces * @throws MessagingException if there was a problem accessing the store */ public Folder[] getPersonalNamespaces() throws MessagingException { return new Folder[]{getDefaultFolder()}; }
/** * Never return "this" as the parent folder. Somebody not familliar with * POP3 may do something like while(getParent() != null) or something * simmilar which will result in an infinte loop */ public Folder getParent() throws MessagingException { // the default folder returns null. We return the default // folder return store.getDefaultFolder(); }
Session session = Session.getDefaultInstance(System.getProperties(),null); Store store = session.getStore("imaps"); store.connect(this.host, this.userName, this.password); // Get default folder Folder folder = store.getDefaultFolder(); // Get any folder by name Folder[] folderList = folder.list();
//Set the Properties as shown below: Properties properties = new Properties(); this.properties.setProperty("mail.store.protocol", "mstor"); this.properties.setProperty("mstor.mbox.metadataStrategy", "none"); this.properties.setProperty("mstor.mbox.cacheBuffers", "disabled"); this.properties.setProperty("mstor.cache.disabled", "true"); this.properties.setProperty("mstor.mbox.bufferStrategy", "mapped"); this.properties.setProperty("mstor.metadata", "disabled"); //Also mstor count for messages start from 1 and not 0. so change it to 1. Store store = session.getStore(new URLName("mstor:C:/mailbox/MyStore/Inbox")); store.connect(); Folder inbox = store.getDefaultFolder().getFolder("inbox"); inbox.open(Folder.READ_ONLY); Message m = inbox.getMessage(1);
Session session = Session.getDefaultInstance(new Properties()); Store store = session.getStore(new URLName("mstor:c:/mailbox/MyStore")); store.connect(); // read messages from Inbox.. Folder inbox = store.getDefaultFolder().getFolder("Inbox"); inbox.open(Folder.READ_ONLY); Message[] messages = inbox.getMessages();
/** * Establish connection with mail store and return the configured mail folder. * * @param mailParms * @param mailStore * @return the folder specified in configuration * @throws MessagingException */ private Folder retrieveMailFolder(final MailTransportParameters mailParms, final Store mailStore) throws MessagingException { mailStore.connect(mailParms.getReadTestHost(), mailParms.getReadTestPort(), mailParms.getReadTestUserName(), mailParms.getReadTestPassword()); Folder mailFolder = mailStore.getDefaultFolder(); mailFolder = mailFolder.getFolder(mailParms.getReadTestFolder()); return mailFolder; }
protected void fetch(final Pattern unusedPattern, final String unusedFolderName) throws MessagingException, IOException { logger.debug("fetch() - folderName: {}", "INBOX"); final Store store = Session.getInstance(props).getStore(); store.connect(user, password); final Folder folder = store.getDefaultFolder(); try { if (!folder.exists()) { logger.error("Folder {} does not exist on the server", folder.getFullName()); return; } IMAPUtils.open(folder); recurseFolders(folder, null); } finally { IMAPUtils.close(folder); IMAPUtils.close(store); } }