コード例 #1
0
  public void updateFlags(long folderId, long[] messageIds, int flag, boolean value)
      throws PortalException, SystemException {

    Folder folder = FolderLocalServiceUtil.getFolder(folderId);

    Account account = AccountLocalServiceUtil.getAccount(folder.getAccountId());

    for (long messageId : messageIds) {
      MessageLocalServiceUtil.updateFlag(messageId, flag, value);
    }

    if (account.getDraftFolderId() == folderId) {
      _imapAccessor.updateFlags(folderId, messageIds, flag, value, false);
    } else {
      _imapAccessor.updateFlags(folderId, messageIds, flag, value, true);
    }
  }
コード例 #2
0
 public IMAPConnection(Account account, String password) {
   this(
       account.getIncomingHostName(), account.getIncomingPort(),
       account.getIncomingSecure(), account.getOutgoingHostName(),
       account.getOutgoingPort(), account.getOutgoingSecure(),
       account.getLogin(), password);
 }
コード例 #3
0
  public void moveMessages(long folderId, long[] messageIds)
      throws PortalException, SystemException {

    for (long messageId : messageIds) {
      Message message = MessageLocalServiceUtil.getMessage(messageId);

      Account account = AccountLocalServiceUtil.getAccount(message.getAccountId());

      long sourceFolderId = message.getFolderId();

      if ((account.getDraftFolderId() == sourceFolderId)
          || (account.getSentFolderId() == sourceFolderId)) {

        throw new MailException(MailException.FOLDER_INVALID_DESTINATION);
      }

      _imapAccessor.moveMessages(sourceFolderId, folderId, new long[] {messageId}, true);
    }
  }
コード例 #4
0
  public void sendMessage(long accountId, long messageId) throws PortalException, SystemException {

    Account account = AccountLocalServiceUtil.getAccount(accountId);

    Message message = MessageLocalServiceUtil.getMessage(messageId);

    Address[] toAddresses = parseAddresses(message.getTo());
    Address[] ccAddresses = parseAddresses(message.getCc());
    Address[] bccAddresses = parseAddresses(message.getBcc());

    if ((toAddresses.length == 0) && (ccAddresses.length == 0) && (bccAddresses.length == 0)) {

      throw new MailException(MailException.MESSAGE_HAS_NO_RECIPIENTS);
    }

    List<Attachment> attachments = AttachmentLocalServiceUtil.getAttachments(messageId);

    List<MailFile> mailFiles = new ArrayList<MailFile>();

    for (Attachment attachment : attachments) {
      File file = AttachmentLocalServiceUtil.getFile(attachment.getAttachmentId());

      MailFile mailFile = new MailFile(file, attachment.getFileName(), attachment.getSize());

      mailFiles.add(mailFile);
    }

    _imapAccessor.sendMessage(
        account.getPersonalName(),
        account.getAddress(),
        toAddresses,
        ccAddresses,
        bccAddresses,
        message.getSubject(),
        message.getBody(),
        mailFiles);

    MessageLocalServiceUtil.deleteMessage(messageId);
  }
コード例 #5
0
  public Message saveDraft(
      long accountId,
      long messageId,
      String to,
      String cc,
      String bcc,
      String subject,
      String body,
      List<MailFile> mailFiles)
      throws PortalException, SystemException {

    Account account = AccountLocalServiceUtil.getAccount(accountId);

    StringBundler sb = new StringBundler();

    sb.append(user.getFullName());
    sb.append(" <");
    sb.append(account.getAddress());
    sb.append(StringPool.GREATER_THAN);

    String sender = sb.toString();

    Address[] toAddresses = parseAddresses(to);
    Address[] ccAddresses = parseAddresses(cc);
    Address[] bccAddresses = parseAddresses(bcc);

    if ((toAddresses.length == 0) && (ccAddresses.length == 0) && (bccAddresses.length == 0)) {

      throw new MailException(MailException.MESSAGE_HAS_NO_RECIPIENTS);
    }

    Message message = null;

    if (messageId != 0) {
      message =
          MessageLocalServiceUtil.updateMessage(
              messageId,
              account.getDraftFolderId(),
              sender,
              InternetAddressUtil.toString(toAddresses),
              InternetAddressUtil.toString(ccAddresses),
              InternetAddressUtil.toString(bccAddresses),
              null,
              subject,
              body,
              String.valueOf(MailConstants.FLAG_DRAFT),
              0);
    } else {
      message =
          MessageLocalServiceUtil.addMessage(
              user.getUserId(),
              account.getDraftFolderId(),
              sender,
              to,
              cc,
              bcc,
              null,
              subject,
              body,
              String.valueOf(MailConstants.FLAG_DRAFT),
              0);
    }

    if (mailFiles == null) {
      return message;
    }

    for (MailFile mailFile : mailFiles) {
      AttachmentLocalServiceUtil.addAttachment(
          user.getUserId(),
          message.getMessageId(),
          null,
          mailFile.getFileName(),
          mailFile.getSize(),
          mailFile.getFile());
    }

    return message;
  }
コード例 #6
0
  @Override
  protected void doDelete(Object obj) throws Exception {
    SearchContext searchContext = new SearchContext();

    searchContext.setSearchEngineId(getSearchEngineId());

    if (obj instanceof Account) {
      Account account = (Account) obj;

      BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(searchContext);

      booleanQuery.addRequiredTerm(Field.PORTLET_ID, PORTLET_ID);

      booleanQuery.addRequiredTerm("accountId", account.getAccountId());

      Hits hits =
          SearchEngineUtil.search(
              getSearchEngineId(),
              account.getCompanyId(),
              booleanQuery,
              QueryUtil.ALL_POS,
              QueryUtil.ALL_POS);

      for (int i = 0; i < hits.getLength(); i++) {
        Document document = hits.doc(i);

        SearchEngineUtil.deleteDocument(
            getSearchEngineId(), account.getCompanyId(), document.get(Field.UID));
      }
    } else if (obj instanceof Folder) {
      Folder folder = (Folder) obj;

      BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(searchContext);

      booleanQuery.addRequiredTerm(Field.PORTLET_ID, PORTLET_ID);

      booleanQuery.addRequiredTerm("folderId", folder.getFolderId());

      Hits hits =
          SearchEngineUtil.search(
              getSearchEngineId(),
              folder.getCompanyId(),
              booleanQuery,
              QueryUtil.ALL_POS,
              QueryUtil.ALL_POS);

      for (int i = 0; i < hits.getLength(); i++) {
        Document document = hits.doc(i);

        SearchEngineUtil.deleteDocument(
            getSearchEngineId(), folder.getCompanyId(), document.get(Field.UID));
      }
    } else if (obj instanceof Message) {
      Message message = (Message) obj;

      Document document = new DocumentImpl();

      document.addUID(PORTLET_ID, message.getMessageId());

      SearchEngineUtil.deleteDocument(
          getSearchEngineId(), message.getCompanyId(), document.get(Field.UID));
    }
  }