Exemplo n.º 1
0
  @Override
  protected void doReindex(Object obj) throws Exception {
    Message message = (Message) obj;

    Document document = getDocument(message);

    SearchEngineUtil.updateDocument(getSearchEngineId(), message.getCompanyId(), document);
  }
Exemplo n.º 2
0
  public AttachmentHandler getAttachment(long attachmentId)
      throws IOException, PortalException, SystemException {

    Attachment attachment = AttachmentLocalServiceUtil.getAttachment(attachmentId);

    Message message = MessageLocalServiceUtil.getMessage(attachment.getMessageId());

    if (account.getDraftFolderId() == attachment.getFolderId()) {
      return new DefaultAttachmentHandler(
          AttachmentLocalServiceUtil.getInputStream(attachmentId), null);
    } else {
      return _imapAccessor.getAttachment(
          attachment.getFolderId(), message.getRemoteMessageId(), attachment.getContentPath());
    }
  }
	/**
	 * Adds the message to the database. Also notifies the appropriate model listeners.
	 *
	 * @param message the message
	 * @return the message that was added
	 */
	@Indexable(type = IndexableType.REINDEX)
	@Override
	public Message addMessage(Message message) {
		message.setNew(true);

		return messagePersistence.update(message);
	}
Exemplo n.º 4
0
  public void synchronizeMessage(long messageId) throws PortalException, SystemException {

    Message message = MessageLocalServiceUtil.getMessage(messageId);

    long remoteMessageId = message.getRemoteMessageId();

    if (remoteMessageId == 0) {
      return;
    }

    try {
      _imapAccessor.storeContents(message.getFolderId(), new long[] {message.getRemoteMessageId()});
    } catch (IOException ioe) {
      throw new MailException(ioe);
    }
  }
  public Message updateFlag(long messageId, int flag, boolean value)
      throws PortalException, SystemException {

    String flagString = String.valueOf(flag);

    Message message = messagePersistence.findByPrimaryKey(messageId);

    String flags = message.getFlags();

    if (value && !StringUtil.contains(flags, flagString)) {
      message.setFlags(StringUtil.add(flags, flagString));
    } else if (!value && StringUtil.contains(flags, flagString)) {
      message.setFlags(StringUtil.remove(flags, flagString));
    }

    return messagePersistence.update(message, false);
  }
Exemplo n.º 6
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);
    }
  }
  @Override
  public Message deleteMessage(Message message) throws PortalException, SystemException {

    // Message

    messagePersistence.remove(message);

    // Attachments

    attachmentLocalService.deleteAttachments(message.getCompanyId(), message.getMessageId());

    // Indexer

    Indexer indexer = IndexerRegistryUtil.getIndexer(Message.class);

    indexer.delete(message);

    return message;
  }
  /**
   * Adds the message to the database. Also notifies the appropriate model listeners.
   *
   * @param message the message
   * @return the message that was added
   * @throws SystemException if a system exception occurred
   */
  public Message addMessage(Message message) throws SystemException {
    message.setNew(true);

    message = messagePersistence.update(message, false);

    Indexer indexer = IndexerRegistryUtil.getIndexer(getModelClassName());

    if (indexer != null) {
      try {
        indexer.reindex(message);
      } catch (SearchException se) {
        if (_log.isWarnEnabled()) {
          _log.warn(se, se);
        }
      }
    }

    return message;
  }
  public Message updateContent(long messageId, String body, String flags)
      throws PortalException, SystemException {

    Message message = messagePersistence.findByPrimaryKey(messageId);

    message.setModifiedDate(new Date());
    message.setPreview(getPreview(body));
    message.setBody(getBody(body));
    message.setFlags(flags);
    message.setSize(getSize(messageId, body));

    messagePersistence.update(message, false);

    return message;
  }
Exemplo n.º 10
0
  @Override
  protected Document doGetDocument(Object obj) throws Exception {
    Message message = (Message) obj;

    Document document = getBaseModelDocument(PORTLET_ID, message);

    ExpandoBridge expandoBridge = message.getExpandoBridge();

    document.addText(Field.CONTENT, HtmlUtil.extractText(message.getBody()));
    document.addKeyword(Field.FOLDER_ID, message.getFolderId());
    document.addText(Field.TITLE, message.getSubject());

    document.addKeyword("accountId", message.getAccountId());
    document.addKeyword("remoteMessageId", message.getRemoteMessageId());

    ExpandoBridgeIndexerUtil.addAttributes(document, expandoBridge);

    return document;
  }
Exemplo n.º 11
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);
  }
Exemplo n.º 12
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;
  }
  public Message addMessage(
      long userId,
      long folderId,
      String sender,
      String to,
      String cc,
      String bcc,
      Date sentDate,
      String subject,
      String body,
      String flags,
      long remoteMessageId)
      throws PortalException, SystemException {

    // Message

    User user = userPersistence.findByPrimaryKey(userId);
    Folder folder = folderPersistence.findByPrimaryKey(folderId);
    Date now = new Date();

    long messageId = counterLocalService.increment();

    Message message = messagePersistence.create(messageId);

    message.setCompanyId(user.getCompanyId());
    message.setUserId(user.getUserId());
    message.setUserName(user.getFullName());
    message.setCreateDate(now);
    message.setModifiedDate(now);
    message.setAccountId(folder.getAccountId());
    message.setFolderId(folderId);
    message.setSender(sender);
    message.setTo(to);
    message.setCc(cc);
    message.setBcc(bcc);
    message.setSentDate(sentDate);
    message.setSubject(subject);
    message.setPreview(getPreview(body));
    message.setBody(getBody(body));
    message.setFlags(flags);
    message.setSize(getSize(messageId, body));
    message.setRemoteMessageId(remoteMessageId);

    messagePersistence.update(message, false);

    // Indexer

    Indexer indexer = IndexerRegistryUtil.getIndexer(Message.class);

    indexer.reindex(message);

    return message;
  }
  public Message updateMessage(
      long messageId,
      long folderId,
      String sender,
      String to,
      String cc,
      String bcc,
      Date sentDate,
      String subject,
      String body,
      String flags,
      long remoteMessageId)
      throws PortalException, SystemException {

    // Message

    Message message = messagePersistence.findByPrimaryKey(messageId);

    message.setModifiedDate(new Date());
    message.setFolderId(folderId);
    message.setSender(sender);
    message.setTo(to);
    message.setCc(cc);
    message.setBcc(bcc);
    message.setSentDate(sentDate);
    message.setSubject(subject);
    message.setPreview(getPreview(body));
    message.setBody(getBody(body));
    message.setFlags(flags);
    message.setSize(getSize(messageId, body));
    message.setRemoteMessageId(remoteMessageId);

    messagePersistence.update(message, false);

    // Indexer

    Indexer indexer = IndexerRegistryUtil.getIndexer(Message.class);

    indexer.reindex(message);

    return message;
  }
  /**
   * Adds the message to the database. Also notifies the appropriate model listeners.
   *
   * @param message the message
   * @return the message that was added
   * @throws SystemException if a system exception occurred
   */
  @Indexable(type = IndexableType.REINDEX)
  public Message addMessage(Message message) throws SystemException {
    message.setNew(true);

    return messagePersistence.update(message);
  }
Exemplo n.º 16
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));
    }
  }