Ejemplo n.º 1
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;
  }
Ejemplo n.º 2
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);
  }