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 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());
    }
  }
  @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;
  }