Example #1
0
 private boolean hasUIDL() throws IOException {
   if (connection.hasCapability(Pop3Capabilities.UIDL)) {
     return true;
   }
   // Additional check for servers that don't support CAPA
   // (i.e. Hotmail) but do support UIDL.
   try {
     if (connection.getMessageCount() > 0) {
       // Only need to test UIDL on first message
       connection.getMessageUid(1);
     } else {
       connection.getMessageUids();
     }
   } catch (CommandFailedException e) {
     return false;
   }
   return true;
 }
Example #2
0
  private void fetchAndRetainMessages() throws Exception {
    String[] uids = connection.getMessageUids();
    Set<String> existingUids = PopMessage.getMatchingUids(dataSource, uids);
    int count = uids.length - existingUids.size();

    LOG.info("Found %d new message(s) on remote server", count);
    if (count == 0) {
      return; // No new messages
    }
    IOExceptionHandler.getInstance().resetSyncCounter(mbox);
    boolean checkForSelfPopping = true;
    for (int msgno = uids.length; msgno > 0; --msgno) {
      String uid = uids[msgno - 1];

      if (!existingUids.contains(uid)) {
        if (checkForSelfPopping) {
          //  Only check new messages else could match one we previously synced.
          if (poppingSelf(uid)) {
            throw ServiceException.INVALID_REQUEST(
                "User attempted to import messages from his own mailbox", null);
          }
          checkForSelfPopping = false; // Only need to check one message
        }
        LOG.debug("Fetching message with uid %s", uid);
        IOExceptionHandler.getInstance().trackSyncItem(mbox, msgno);
        // Don't allow filtering to a mountpoint when retaining the
        // message.  We don't have a local id, so we can't keep track
        // of it in the data_source_item table.
        try {
          fetchAndAddMessage(msgno, connection.getMessageSize(msgno), uid, false);
        } catch (Exception e) {
          if (IOExceptionHandler.getInstance().isRecoverable(mbox, msgno, "pop sync fail", e)) {
            // skip it; will be retried on every subsequent sync
            continue;
          }
          throw e;
        }
      }
    }
    IOExceptionHandler.getInstance().checkpointIOExceptionRate(mbox);
  }