예제 #1
0
 private void checkCurrentFolder(Folder folder) {
   Preconditions.checkState(
       folder.equals(currentFolder),
       "You must have opened folder %s"
           + " before attempting to read from it (%s is currently open).",
       folder.getName(),
       (currentFolder == null ? "No folder" : currentFolder.getName()));
 }
  public static void main(String[] args) throws Throwable {
    String mailbox = null;
    boolean DEBUG = false;

    for (int i = 0; i < args.length; i++) {
      if (args[i].equals("-debug")) {
        DEBUG = true;

      } else if (mailbox == null) {
        mailbox = args[i];

      } else {
        usage("Spurious command line: " + args);
      }
    }

    if (mailbox == null) {
      usage("Missing mailbox");
    }

    // Get a connection to the mail server
    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);
    session.setDebug(DEBUG);

    Provider[] providers = session.getProviders();
    for (int i = 0; i < providers.length; i++) {
      Provider provider = providers[i];
      out.println(provider);
    }

    Store store = session.getStore("imap");
    Folder folder = store.getFolder(mailbox);
    Message[] messages = folder.getMessages();
    out.println("Folder " + folder.getName() + " with " + messages.length + " messages");
    for (int i = 0; i < messages.length; i++) {
      Message message = messages[i];
      out.println("  " + i + ": " + message.getSubject());
    }

    out.println("");
  }
예제 #3
0
 public int compare(Folder o1, Folder o2) {
   return o1.getName().compareToIgnoreCase(o2.getName());
 }