public void messagesRemoved(MessageCountEvent event) {
   if (logger.isDebugEnabled()) {
     Message messages[] = event.getMessages();
     for (int i = 0; i < messages.length; i++) {
       try {
         logger.debug("Message removed: " + messages[i].getSubject());
       } catch (MessagingException ignore) {
         logger.debug("ignoring exception: " + ignore.getMessage());
       }
     }
   }
 }
예제 #2
0
        public void messagesAdded(MessageCountEvent e) {
          try {
            // I don't think it matters where we put the new messages, but for the sanity of users
            // who don't sort, and because it's the cheapest option, we'll bung them at the end.
            Message[] newMessages = e.getMessages();

            // Work out where the new items will appear.
            final int firstNewRow = messages.size();
            final int lastNewRow = firstNewRow + newMessages.length - 1;

            // Actually insert the new items, and notify the listeners.
            messages.addAll(Arrays.asList(newMessages));
            fireTableRowsInserted(firstNewRow, lastNewRow);
          } catch (Exception ex) {
            ex.printStackTrace();
          }
        }
  public void messagesAdded(MessageCountEvent event) {
    try {
      Message messages[] = event.getMessages();
      List<Message> processedMessages = new ArrayList<Message>();
      if (messages != null) {
        MuleMessage message = null;
        for (int i = 0; i < messages.length; i++) {
          if (getLifecycleState().isStopping() || getLifecycleState().isStopped()) {
            break;
          }
          try {
            if (!messages[i].getFlags().contains(Flags.Flag.DELETED)
                && !messages[i].getFlags().contains(Flags.Flag.SEEN)) {
              try {
                MimeMessage mimeMessage = new MimeMessage((MimeMessage) messages[i]);
                storeMessage(mimeMessage);
                message = createMuleMessage(mimeMessage, endpoint.getEncoding());

                if (castConnector().isDeleteReadMessages()) {
                  if (moveToFolder != null) {
                    folder.copyMessages(new Message[] {messages[i]}, moveToFolder);
                  }
                  // Mark as deleted
                  messages[i].setFlag(Flags.Flag.DELETED, true);
                } else {
                  if (this.getEndpoint().getFilter() != null
                      && this.getEndpoint().getFilter().accept(message)) {
                    Flags.Flag flag = castConnector().getDefaultProcessMessageAction();
                    if (flag != null) {
                      if (flag == Flags.Flag.DELETED && moveToFolder != null) {
                        folder.copyMessages(new Message[] {messages[i]}, moveToFolder);
                      }
                      messages[i].setFlag(flag, true);
                    }
                  } else {
                    messages[i].setFlag(Flags.Flag.SEEN, true);
                    processedMessages.add(messages[i]);
                  }
                }
                routeMessage(message);
              } catch (org.mule.api.MessagingException e) {
                // Already handled by TransactionTemplate
              } catch (Exception e) {
                connector.getMuleContext().getExceptionListener().handleException(e);
                throw e;
              }
            }
          } catch (MuleException e) {
            throw e;
          } catch (Exception e) {
            Exception forwarded;

            if (message != null) {
              forwarded =
                  new org.mule.api.MessagingException(EmailMessages.routingError(), message, e);
            } else {
              forwarded = new ReceiveException(endpoint, -1, e);
            }
            throw forwarded;
          }
        }
        // Copy processed messages that have not been deleted (the deleted were already moved)
        if (moveToFolder != null) {
          folder.copyMessages(
              processedMessages.toArray(new Message[processedMessages.size()]), moveToFolder);
        }
      }
    } catch (Exception e) {
      // Throw a runtime exception because the javax.mail API does not allow a checked exception on
      // this method.
      throw new MuleRuntimeException(e);
    }
  }
예제 #4
0
 public void messagesRemoved(MessageCountEvent e) {
   // We'll have removed messages from the table before we remove them from the server.
   // If another client is accessing the mailbox concurrently, though, messages might
   // disappear under us.
   removeMessages(e.getMessages());
 }