Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java: How to print the namespaces supported by a store

Java: How to print the namespaces supported by a store
{filelink=1027}

import java.util.Properties;
import javax.mail.Folder;
import javax.mail.FolderNotFoundException;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.URLName;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
public class JavaMail_Namespace
{
  public static void main(String argv[]) {
    try {
     final String username="myUsername";
     final String password="password-***";
    URLName rep_Serveur = new URLName("pop3://test@pop.gmail.com/Inbox");
    // Login with username and password
    Session session = Session.getDefaultInstance(new Properties(),
    	 new Authenticator()
    	 {
    	 	  public PasswordAuthentication getPasswordAuthentication()
    	 	  	     {
                  return new PasswordAuthentication(username, password);
                     }
    	 }
    	 	);
      Store store = session.getStore(rep_Serveur);
      store.connect();
      get_Info("Personal", store.getPersonalNamespaces());
      get_Info("User " , store.getUserNamespaces(username));
      get_Info("Shared", store.getSharedNamespaces());
      store.close();
    } catch (Exception ex)
    {
      System.out.println("Exception " + ex.getMessage());
      ex.printStackTrace();
    }
    System.exit(0);
  }
  private static void get_Info(String name, Folder[] folders) throws MessagingException {
    System.out.println(" Namespace "+ name +":" );
    if (folders == null || folders.length == 0) {
      System.out.println("  ");
      return;
    }
    for (int i = 0; i ";
      try {
        System.out.println("  " + fn + ", delimiter " + folders[i].getSeparator() + "");
        Folder[] fl = folders[i].list();
        if (fl.length > 0) {
          System.out.println("Subfolders:");
          for (int j = 0; j < fl.length; j++)
            System.out.println("    " + fl[j].getFullName());
        }
      } catch (FolderNotFoundException ex) {
      }
    }
  }
}

Users who found this page were searching for:

  • python attaching files to an email
  • python iterating through passwords
  • form["user"].value python

No comments yet.

Leave a Comment