javax.mail.Store.getDefaultFolder()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(365)

本文整理了Java中javax.mail.Store.getDefaultFolder()方法的一些代码示例,展示了Store.getDefaultFolder()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Store.getDefaultFolder()方法的具体详情如下:
包路径:javax.mail.Store
类名称:Store
方法名:getDefaultFolder

Store.getDefaultFolder介绍

[英]Returns a Folder object that represents the 'root' of the default namespace presented to the user by the Store.
[中]返回一个文件夹对象,该对象表示存储提供给用户的默认命名空间的“根”。

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

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;
}

代码示例来源:origin: stackoverflow.com

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());

代码示例来源:origin: oblac/jodd

/**
 * 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;
}

代码示例来源:origin: pentaho/pentaho-kettle

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
  }
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

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
  }
 }
}

代码示例来源:origin: apache/usergrid

public Folder openMailFolder( Store store ) throws MessagingException {
  Folder folder = store.getDefaultFolder();
  folder = folder.getFolder( "inbox" );
  folder.open( Folder.READ_ONLY );
  return folder;
}

代码示例来源:origin: pentaho/pentaho-kettle

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 );
}

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * 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 );
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * 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;
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * 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() };
}

代码示例来源:origin: com.sun.mail/javax.mail

/**
 * 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() };
}

代码示例来源:origin: pentaho/pentaho-kettle

this.folder = this.store.getDefaultFolder();
} else {

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.4_spec

/**
 * 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()};
}

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.3.1_spec

/**
 * 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()};
}

代码示例来源:origin: org.apache.geronimo.javamail/geronimo-javamail_1.4_provider

/**
 * 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(); 
}

代码示例来源:origin: stackoverflow.com

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();

代码示例来源:origin: stackoverflow.com

//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);

代码示例来源:origin: stackoverflow.com

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();

代码示例来源:origin: OpenNMS/opennms

/**
 * 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;
}

代码示例来源:origin: salyh/elasticsearch-imap

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);
  }
}

相关文章