Package javax.mail

Examples of javax.mail.Folder


    }

    HeadersHelper oHlpr = new HeadersHelper();
    String [] aMsgsXml = null;

    Folder oFldr = getFolder(sFolderName);

  oFldr.open (Folder.READ_ONLY);

  int iDeleted = 0;
  int iTotalCount = oFldr.getMessageCount();

  if (iTotalCount>0) {

      if (DebugFile.trace) DebugFile.writeln("Folder.getMessages("+String.valueOf(iTotalCount)+")");

      Message[] aMsgsObj = oFldr.getMessages();

      FetchProfile oFtchPrfl = new FetchProfile();
      oFtchPrfl.add(FetchProfile.Item.ENVELOPE);
      oFtchPrfl.add(FetchProfile.Item.CONTENT_INFO);
      oFtchPrfl.add(FetchProfile.Item.FLAGS);
      oFtchPrfl.add("X-Priority");
      oFtchPrfl.add("X-Spam-Flag");

      if (DebugFile.trace) {
        DebugFile.writeln("Folder.fetch(Message[], ENVELOPE & CONTENT_INFO & FLAGS)");
        oChMeter.start();
      }

      oFldr.fetch(aMsgsObj, oFtchPrfl);
     
      if (DebugFile.trace) {
        DebugFile.writeln(String.valueOf(iTotalCount)+" headers fetched in "+String.valueOf(oChMeter.stop()/1000l)+" seconds");
        oChMeter.start();
      }
       
      aMsgsXml = new String[iTotalCount];
      for (int m=0; m<iTotalCount; m++) {
        if (aMsgsObj[m].isSet(Flags.Flag.DELETED)) {
          iDeleted++;
        } else {
          oHlpr.setMessage((MimeMessage) aMsgsObj[m]);
          aMsgsXml[m-iDeleted] = oHlpr.toXML();
        } // fi
      } // next (m)
     
      aMsgsObj = null;

    if (iDeleted>0) aMsgsXml = Arrays.copyOfRange(aMsgsXml, 0, iTotalCount-iDeleted);

      if (DebugFile.trace) {
        DebugFile.writeln(String.valueOf(iTotalCount-iDeleted)+" messages to XML in "+String.valueOf(oChMeter.stop())+" ms");
      }

  } // fi (iTotalCount>0)
  oFldr.close(false);

    if (DebugFile.trace) {
      DebugFile.decIdent();
      if (null==aMsgsXml)
        DebugFile.writeln("End SessionHandler.listFolderMessages() : 0");
View Full Code Here


    }

    HeadersHelper oHlpr = new HeadersHelper();
    String [] aMsgsXml = null;

    Folder oFldr = getFolder(sFolderName);

  oFldr.open (Folder.READ_ONLY);

  int iTotalCount = oFldr.getMessageCount();

    if (DebugFile.trace) DebugFile.writeln(String.valueOf(iTotalCount)+" messages found at "+sFolderName);

  if (iTotalCount>0) {
    LinkedList<String> oList = new LinkedList<String>();
    int iLowerBound = iTotalCount-iMaxMsgs;
    if (iLowerBound<0) iLowerBound = 0;
    for (int m=iTotalCount-1; m>=iLowerBound && oList.size()<iMaxMsgs; m--) {
      if (DebugFile.trace) DebugFile.writeln("getting message "+String.valueOf(m));
      try {
        Message oMsgObj = oFldr.getMessage(m);

          if (!oMsgObj.isSet(Flags.Flag.DELETED) && !oMsgObj.isSet(Flags.Flag.ANSWERED)) {
            String sSpamFlag = ((MimeMessage) oMsgObj).getHeader("X-Spam-Flag","");
            if (sSpamFlag==null) sSpamFlag = "";
            if (!sSpamFlag.equalsIgnoreCase("YES")) {
              oHlpr.setMessage((MimeMessage) oMsgObj);
              String sMsgXML = oHlpr.toXML();
          oList.add(sMsgXML);
            }
          } // fi
      } catch (ArrayIndexOutOfBoundsException aiob) {
      if (DebugFile.trace) DebugFile.writeln("Folder.getMessage("+String.valueOf(m)+") ArrayIndexOutOfBoundsException");
      }
    } // next (m)
    if (oList.size()>0) {
      aMsgsXml = new String [oList.size()];
      aMsgsXml = oList.toArray(aMsgsXml);
    }
  } // fi (iTotalCount>0)
    oFldr.close(false);

    if (DebugFile.trace) {
      DebugFile.decIdent();
      if (null==aMsgsXml)
        DebugFile.writeln("End SessionHandler.listFolderMessages() : 0");
View Full Code Here

   public EmailData[] readInbox(boolean clear) throws XmlBlasterException {
      // if (isShutdown()) Does it recover automatically after a shutdown?
      // throw new XmlBlasterException(glob, ErrorCode.INTERNAL_ILLEGALSTATE,
      // Pop3Driver.class.getName(), "The plugin is shutdown");
      Store store = null;
      Folder inbox = null;
      try {
         store = getStore();
         Folder root = store.getDefaultFolder();
         inbox = root.getFolder(POP3_FOLDER);
         inbox.open(Folder.READ_WRITE);
         Message[] msgs = inbox.getMessages();
         if (msgs == null)
            msgs = new Message[0];
View Full Code Here

               });
            }
            store.connect();
         }

         Folder folder = store.getDefaultFolder();
         if (folder == null) {
            System.out.println("No default folder");
            System.exit(1);
         }

         folder = folder.getFolder(mbox);
         if (folder == null) {
            System.out.println("Invalid folder");
            System.exit(1);
         }

         // try to open read/write and if that fails try read-only
         try {
            folder.open(Folder.READ_WRITE);
         } catch (MessagingException ex) {
            folder.open(Folder.READ_ONLY);
         }
         int totalMessages = folder.getMessageCount();

         if (totalMessages == 0) {
            System.out.println("Empty folder");
            folder.close(false);
            store.close();
            System.exit(1);
         }

         if (verbose) {
            int newMessages = folder.getNewMessageCount();
            System.out.println("Total messages = " + totalMessages);
            System.out.println("New messages = " + newMessages);
            System.out.println("===============================");
         }

         // Attributes & Flags for all messages ..
         Message[] msgs = folder.getMessages();

         // Use a suitable FetchProfile
         FetchProfile fp = new FetchProfile();
         fp.add(FetchProfile.Item.ENVELOPE);
         fp.add(FetchProfile.Item.FLAGS);
         fp.add("X-Mailer");
         folder.fetch(msgs, fp);

         for (int i = 0; i < msgs.length; i++) {
            int level = 0;
            System.out.println("\n=========MESSAGE #" + (i + 1) + ":=================");
            dumpEnvelope(msgs[i], level);
            level = dumpPart(msgs[i], level);
         }

         folder.close(false);
         store.close();
      } catch (Exception ex) {
         System.out.println("Oops, got exception! " + ex.getMessage());
         ex.printStackTrace();
         System.exit(1);
View Full Code Here

     * this is our main program.
     */
    public boolean spooler_process() throws Exception {

      boolean expunge    = false; // delete marked messages
        Folder folder     = null;
        Message[] messages   = {};
        SOSMimeMessage sosMimeMessage = null;

        try {

            this.getLogger().debug3("Calling " + SOSClassUtil.getMethodName());

            receiver = new SOSMailReceiver(receiverHost, receiverPort, pop3_user,
                    pop3_password);

            receiver.setLogger(this.getLogger());

            receiver.connect(protocol);

            folder = receiver.openFolder("INBOX", receiver.READ_WRITE);

            // processed bounced emails selected??
            if (this.isHandleBouncedMessagesOnly())
                messages = folder.search(getBounceSerachTerm());
            else
                messages = folder.getMessages();

            getLogger().debug5("total found messages: " + messages.length);

            for (int i = 0; i < messages.length; i++) {
                sosMimeMessage = new SOSMimeMessage(messages[i], this
View Full Code Here

      receiver.connect(mailServerType);
      if (mailServerTimeout > 0) {
        receiver.setTimeout(mailServerTimeout);
      }
      sosLogger.debug3("reading " + mailMessageFolder);
      Folder folder = receiver.openFolder(mailMessageFolder, receiver.READ_WRITE);
      int max = folder.getMessageCount();
      if (fromMail > max) {
        sosLogger.debug3("all messages found.");
        return null;
      }
      SubjectTerm term = null;
      Message[] msgs = null;
      Message[] msgs2 = null;
      sosLogger.debug3(max - fromMail + 1 + " messages left.");
      term = new SubjectTerm(mailSubjectFilter);
      msgs = folder.getMessages(fromMail, min(max, fromMail + nextMail));
      sosLogger.debug3(msgs.length + " messages found.");
      if (!mailSubjectFilter.equals("")) {
        sosLogger.debug3("looking for " + mailSubjectFilter);
        msgs2 = folder.search(term, msgs);
        sosLogger.debug3(msgs2.length + " messages found with " + mailSubjectFilter);
      }
      else {
        msgs2 = msgs;
        sosLogger.debug3(msgs2.length + " messages found");
View Full Code Here

        }
    }

    private boolean importEmail(Store store){
        try{
            Folder folder = null;
            //get the folder of inbox
            folder = store.getDefaultFolder();
            if (folder == null) {
                return false;
            }
            //if it's inbox
            folder = folder.getFolder("INBOX");
            if (folder == null) {
                return false;
            }
            folder.open(Folder.READ_ONLY);
            //get mail list
            Message[] msgs = folder.getMessages();
            Progress.switchToDeterminate(progress, msgs.length);
            Progress.setDisplayName(progress, "Download "+msgs.length+" emails");
            //show progress bar
//            showProgressBar(msgs.length);
            int index = 0;
            for (Message msg : msgs) {
                index ++;
//                setProgressBar(index);
                filterOneEmail(msg);
                Progress.progress(progress);
            }
            folder.close(false);
            store.close();
        } catch (NoSuchProviderException ex) {
            Exceptions.printStackTrace(ex);
            return false;
        } catch (MessagingException ex) {
View Full Code Here

            fail("Expected exception due to invalid type -12345");
        } catch (IllegalArgumentException e) {
        }
    }
    private void doEventTests(int type) {
        Folder folder = TestData.getTestFolder();
        MessageCountEvent event =
            new MessageCountEvent(folder, type, false, null);
        assertEquals(folder, event.getSource());
        assertEquals(type, event.getType());
        MessageCountListenerTest listener = new MessageCountListenerTest();
View Full Code Here

        doEventTests(TransportEvent.MESSAGE_DELIVERED);
        doEventTests(TransportEvent.MESSAGE_PARTIALLY_DELIVERED);
        doEventTests(TransportEvent.MESSAGE_NOT_DELIVERED);
    }
    private void doEventTests(int type) throws AddressException {
        Folder folder = TestData.getTestFolder();
        Message message = TestData.getMessage();
        Transport transport = TestData.getTestTransport();
        Address[] sent = new Address[] { new InternetAddress("alex@here.com")};
        Address[] empty = new Address[0];
        TransportEvent event =
View Full Code Here

        // connect to mailbox
        Mailbox.clearAll();
        JavaMailSender sender = new DefaultJavaMailSender();
        Store store = sender.getSession().getStore("pop3");
        store.connect("localhost", 25, "bill", "secret");
        Folder folder = store.getFolder("INBOX");
        folder.open(Folder.READ_WRITE);
        folder.expunge();

        // inserts 1 new message
        Message[] messages = new Message[1];
        messages[0] = new MimeMessage(sender.getSession());
        messages[0].setSubject("TestSubject");
        messages[0].setText("TestText");

        folder.appendMessages(messages);
        folder.close(true);
    }
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.