예제 #1
0
 public void doDispose() {
   initialised.set(false);
   // close and expunge deleted messages
   try {
     if (folder != null) {
       folder.close(true);
     }
   } catch (MessagingException e) {
     logger.error("Failed to close pop3 inbox: " + e.getMessage(), e);
   }
 }
예제 #2
0
  protected void initialise(UMOEndpointURI endpoint) throws MessagingException {
    if (!initialised.get()) {
      String inbox = null;
      if (connector.getProtocol().equals("imap") && endpoint.getParams().get("folder") != null) {
        inbox = (String) endpoint.getParams().get("folder");
      } else {
        inbox = Pop3Connector.MAILBOX;
      }

      URLName url =
          new URLName(
              endpoint.getScheme(),
              endpoint.getHost(),
              endpoint.getPort(),
              inbox,
              endpoint.getUsername(),
              endpoint.getPassword());

      session = MailUtils.createMailSession(url);
      session.setDebug(logger.isDebugEnabled());

      Store store = session.getStore(url);
      store.connect();
      folder = store.getFolder(inbox);
      if (!folder.isOpen()) {
        try {
          // Depending on Server implementation it's not always
          // necessary
          // to open the folder to check it
          // Opening folders can be exprensive!
          // folder.open(Folder.READ_ONLY);
          folder.open(Folder.READ_WRITE);
        } catch (MessagingException e) {
          logger.warn("Failed to open folder: " + folder.getFullName(), e);
        }
      }
    }
  }