Ejemplo n.º 1
0
  private void addMessageHeaders(HTMLNode messageNode, MailMessage message) {
    HTMLNode headerBox = messageNode.addChild("div", "class", "message-headers");

    try {
      message.readHeaders();
    } catch (IOException e) {
      /* FIXME: L10n */
      Logger.error(this, "Caugth IOException reading headers for " + message);
      headerBox.addChild("p", "There was a problem reading the message headers");
      return;
    }

    HTMLNode fromPara = headerBox.addChild("p");
    fromPara.addChild("strong", "From:");
    try {
      String from = MailMessage.decodeHeader(message.getFirstHeader("from"));
      if (from == null) {
        from = FreemailL10n.getString("Freemail.MessageToadlet.fromMissing");
      }

      fromPara.addChild("#", " " + from);
    } catch (UnsupportedEncodingException e1) {
      fromPara.addChild("#", " " + message.getFirstHeader("from"));
    }

    for (String header : new String[] {"To", "CC", "BCC"}) {
      for (String recipient : message.getHeadersByName(header)) {
        HTMLNode toPara = headerBox.addChild("p");
        toPara.addChild("strong", header + ":");
        try {
          toPara.addChild("#", " " + MailMessage.decodeHeader(recipient));
        } catch (UnsupportedEncodingException e) {
          toPara.addChild("#", " " + recipient);
        }
      }
    }

    HTMLNode subjectPara = headerBox.addChild("p");
    subjectPara.addChild("strong", "Subject:");

    String subject;
    try {
      subject = message.getSubject();
    } catch (UnsupportedEncodingException e) {
      subject = message.getFirstHeader("subject");
    }
    if ((subject == null) || (subject.equals(""))) {
      subject = FreemailL10n.getString("Freemail.Web.Common.defaultSubject");
    }
    subjectPara.addChild("#", " " + subject);

    HTMLNode datePara = headerBox.addChild("p");
    datePara.addChild("strong", FreemailL10n.getString("Freemail.MessageToadlet.date"));
    datePara.addChild(
        "#",
        " "
            + getMessageDateAsString(
                message, FreemailL10n.getString("Freemail.MessageToadlet.dateMissing")));
  }