Exemplo n.º 1
0
 private void connect() throws ServiceException {
   if (!connection.isClosed()) return;
   try {
     connection.connect();
     try {
       connection.login(dataSource.getDecryptedPassword());
     } catch (CommandFailedException e) {
       throw new LoginException(e.getError());
     }
   } catch (Exception e) {
     connection.close();
     throw ServiceException.FAILURE("Unable to connect to POP3 server: " + dataSource, e);
   }
 }
Exemplo n.º 2
0
 private void fetchAndAddMessage(int msgno, int size, String uid, boolean allowFilterToMountpoint)
     throws ServiceException, IOException {
   ContentInputStream cis = null;
   MessageContent mc = null;
   checkIsEnabled();
   try {
     cis = connection.getMessage(msgno);
     mc = MessageContent.read(cis, size);
     ParsedMessage pm = mc.getParsedMessage(null, indexAttachments);
     if (pm == null) {
       LOG.warn("Empty message body for UID %d. Must be ignored.", uid);
       return;
     }
     Message msg = null;
     // bug 47796: Set received date to sent date if available otherwise use current time
     try {
       Date sentDate = pm.getMimeMessage().getSentDate();
       if (sentDate == null) {
         LOG.warn(
             "null sent date; probably due to parse error. Date header value: [%s]",
             pm.getMimeMessage().getHeader("Date", null));
       }
       pm.setReceivedDate(sentDate != null ? sentDate.getTime() : System.currentTimeMillis());
     } catch (MessagingException e) {
       LOG.warn(
           "unable to get sent date from parsed message due to exception, must use current time",
           e);
       pm.setReceivedDate(System.currentTimeMillis());
     }
     DeliveryContext dc = mc.getDeliveryContext();
     if (isOffline()) {
       msg = addMessage(null, pm, size, dataSource.getFolderId(), Flag.BITMASK_UNREAD, dc);
     } else {
       Integer localId =
           getFirstLocalId(
               RuleManager.applyRulesToIncomingMessage(
                   null,
                   mbox,
                   pm,
                   size,
                   dataSource.getEmailAddress(),
                   dc,
                   dataSource.getFolderId(),
                   true,
                   allowFilterToMountpoint));
       if (localId != null) {
         msg = mbox.getMessageById(null, localId);
       }
     }
     if (msg != null && uid != null) {
       PopMessage msgTracker = new PopMessage(dataSource, msg.getId(), uid);
       msgTracker.add();
     }
   } catch (CommandFailedException e) {
     LOG.warn("Error fetching message number %d: %s", msgno, e.getMessage());
   } finally {
     if (cis != null) {
       try {
         cis.close();
       } catch (ParseException pe) {
         LOG.error(
             "ParseException while closing ContentInputStream. Assuming cis is effectively closed",
             pe);
       }
     }
     if (mc != null) {
       mc.cleanup();
     }
   }
 }