1 Reply Latest reply: May 20, 2014 12:00 PM by 1db718d0-ae55-4573-9690-fc6165e53123 RSS

    issue with MessageCountListener

    1db718d0-ae55-4573-9690-fc6165e53123

      Hi

      Iam writing below code to get notified whenever the new mail arrives to my inbox.

      first i've sent an email to this email then iam getting subject of the email only once as per the code.

      If iam sending again one more email then iam getting subject of the second email twicce and if iam sending again one more email then iam getting subject of third email thrice.

      But if iam just printing a debug message(the commented line) with out accessing email, then it is printing only once if i send email first time, second time, ...

      so issue is happening only when accessing email in messagesAdded() method. the event is firing for two times, three times...

      Tried with inbox.idle(), inbox.idle(false) and inbox.idle(true). Can i get any help on this.

       

       

                  while(true){

                      inbox.addMessageCountListener(new MessageCountListener(){

                         

                          @Override

                          public void messagesAdded(MessageCountEvent event){

       

       

                              Message[] msgs = event.getMessages();

                              for(Message msg:msgs){

                                  try {

                                      //System.out.println("fired");

                                      System.out.println(msg.getSubject());

                                  } catch (MessagingException ex) {

                                      Logger.getLogger(JavaApplication2.class.getName()).log(Level.SEVERE, null, ex);

                                  }

       

       

                              }

                              }

       

       

                          @Override

                          public void messagesRemoved(MessageCountEvent mce) {

                              throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

                          }

                         

                      });

        inbox.idle(true);

       

       

                  }

       

      Thanks

      Satya