Package javax.mail

Examples of javax.mail.Folder


    if (myStore == null) {
      openStore ();
    }
    if (myStore != null) {
      // open folder
      Folder folder = null;
      try {
        folder = parentFolder.getFolder (name);
        folder.open (mode);

        //myLog.debug ("Total Messages = {}", folder.getMessageCount ());
        //myLog.debug ("New Messages = {}", folder.getNewMessageCount ());
      }
      catch (MessagingException exc) {
View Full Code Here


      Folder[] folders = store.getPersonalNamespaces();
      System.out.println("Folders:");
      for (Folder folder : folders) {
        System.out.println("- " + folder.getName() + "  //  " + folder.getFullName());
      }
      Folder folder = store.getFolder("INBOX");
      System.out.println("Folder (Name, FullName):" + folder.getName() + ", " + folder.getFullName());
      folder.open(Folder.READ_ONLY);
      // folder.getUnreadMessageCount();
      Message messages[] = folder.getMessages();
      System.out.println(messages.length + " Messages.");
      System.out.println("");
      int k = messages.length > 8 ? 8 : messages.length;
      for (int i = 0; i < messages.length; i++) {
        // Nur ein paar anlisten.
        if (i == k) {
          i = messages.length - k / 2;
        }
        Message message = messages[i];
        System.out.println(i + ": " + message.getFrom()[0] + "  -  \"" + message.getSubject() + "\"");
        Object content = message.getContent();
        System.out.println("Content-Klasse: " + content.getClass().toString() + " / Content-Type: "
            + message.getContentType());
        @SuppressWarnings("unchecked")
        Enumeration<Header> s = message.getAllHeaders();
        while (s.hasMoreElements()) {
          Header h = s.nextElement();
          System.out.println("H: " + h.getName() + " := " + h.getValue());
        }
        System.out.println(" ");
        if (content instanceof String) {
          System.out.println("String-CONTENT ::: " + (String) content);
        }
        else {
          System.out.println("NO String-CONTENT ::: " + content.getClass());
        }
      }
      folder.close(false);
      store.close();
    }
    catch (MessagingException exception) {
      throw new RuntimeException(exception);
    }
View Full Code Here

            log("Connecting to IMAP server @ " + this.host);
            st.connect(this.host, this.user, this.pass);

            log("Attempting to open default folder");
            Folder f = st.getFolder("inbox");

            f.open(Folder.READ_WRITE);

            log("Downloading message list from folder");
            this.message = f.getMessages();

            int i = 0;

            log("Starting XML generation");
            this.contentHandler.startDocument();
View Full Code Here

        boolean found = false;
        Session session = Session.getDefaultInstance(System.getProperties());
        Store store = session.getStore("pop3");
        store.connect(pop3Host, pop3Port, mailAddress, mailPassword);

        Folder inbox = store.getFolder("INBOX");
        assertNotNull(inbox);
        inbox.open(Folder.READ_WRITE);

        Message[] messages = inbox.getMessages();
        for (int i = 0; i < messages.length; i++) {
            if (sender.equals(messages[i].getFrom()[0].toString()) && subject.equals(messages[i].getSubject())) {
                found = true;
                messages[i].setFlag(Flag.DELETED, true);
            }
        }

        inbox.close(true);
        store.close();
        return found;
    }
View Full Code Here

    this.marshaler = marshaler;
  }

  public void poll() throws Exception {
    Store store = null;
    Folder folder = null;
    try {
      session.setDebug(isDebug());
      store = session.getStore((mailBox.equals("INBOX")) ? "pop3"
          : "imap");
      store.connect(hostName, userName, password);
      folder = store.getFolder(mailBox);
      if (folder == null || !folder.exists()) {
        throw new Exception("Folder not found or invalid: " + mailBox);
      }
      folder.open(Folder.READ_WRITE);
      int msgCount = Math.min(folder.getMessageCount(),maxFetchSize);
      DeliveryChannel channel = getDeliveryChannel();
      MessageExchangeFactory mef = getExchangeFactory();
        for(int i=1; i <= msgCount;i++) {
          MimeMessage mailMsg = (MimeMessage) folder.getMessage(i);
          InOnly io = mef.createInOnlyExchange();
          NormalizedMessage normalizedMessage = io.createMessage();
          this.marshaler.prepareExchange(io,normalizedMessage,mailMsg);
          io.setInMessage(normalizedMessage);
          channel.send(io);
            mailMsg.setFlag(Flags.Flag.DELETED,true);
        }
    } finally {
      try {
        if (folder != null) {
          folder.close(true);
        }
        if (store != null) {
          store.close();
        }
      } catch (Exception ignored) {}
View Full Code Here

        boolean found = false;
        Session session = Session.getDefaultInstance(System.getProperties());
        Store store = session.getStore("pop3");
        store.connect(pop3Host, pop3Port, mailAddress, mailPassword);

        Folder inbox = store.getFolder("INBOX");
        assertNotNull(inbox);
        inbox.open(Folder.READ_WRITE);

        Message[] messages = inbox.getMessages();
        for (int i = 0; i < messages.length; i++) {
            if (sender.equals(messages[i].getFrom()[0].toString()) && subject.equals(messages[i].getSubject())) {
                found = true;
                messages[i].setFlag(Flag.DELETED, true);
            }
        }
        inbox.close(true);
        store.close();
        return found;
    }
View Full Code Here

            });

            store = session.getStore();
            store.connect();

            Folder root = store.getDefaultFolder();

            inbox = root.getFolder("inbox");
        } catch (NoSuchProviderException e) {
            throw new AxisFault(e);
        } catch (MessagingException e) {
            throw new AxisFault(e);
        }
View Full Code Here

        Store store = session.getStore();

        store.connect();

        Folder root = store.getDefaultFolder();
        Folder inbox = root.getFolder("inbox");

        inbox.open(Folder.READ_WRITE);

        Message[] msgs = inbox.getMessages();

        numMessages = msgs.length;

        if ((msgs.length == 0) && show) {
            log.info("No messages in inbox");
        }

        for (int i = 0; i < msgs.length; i++) {
            MimeMessage msg = (MimeMessage) msgs[i];

            if (show) {
                log.info("    From: " + msg.getFrom()[0]);
                log.info(" Subject: " + msg.getSubject());
                log.info(" Content: " + msg.getContent());
            }

            if (clear) {
                msg.setFlag(Flags.Flag.DELETED, true);
            }
        }

        inbox.close(true);
        store.close();

        return numMessages;
    }
View Full Code Here

        // Get an email message store, and connect to it
        final Store store = getStore(session, info.getType());
        store.connect(server, port, info.getUsername(), info.getPassword());

        // Try to get the default folder
        Folder folder = store.getDefaultFolder();
        if (folder == null) {
            throw new MessagingException("No default folder");
        }

        // ...and its INBOX
        folder = folder.getFolder("INBOX");
        if (folder == null) {
            throw new MessagingException("No INBOX");
        }

        // Open the folder with r/w-access
        folder.open(Folder.READ_WRITE);
        return folder;
    }
View Full Code Here

        return fPropertyType;
    }

    public void doExecute() {
        final EmailConfigInfo configInfo = (EmailConfigInfo) getContext().get("EmailConfigInfo");
        Folder folder = null;
        try {
            folder = getHelper().getInboxFolder(configInfo);
            setWebtestProperty(getProperty(), processContent(folder), getPropertyType());
        }
        catch (final MessagingException e) {
View Full Code Here

TOP

Related Classes of javax.mail.Folder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.