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"))); }
@Override HTTPResponse makeWebPageGet(URI uri, HTTPRequest req, ToadletContext ctx, PageNode page) { HTMLNode pageNode = page.outer; HTMLNode contentNode = page.content; HTMLNode container = contentNode.addChild("div", "class", "container"); // Add the list of folders HTMLNode folderList = container.addChild("div", "class", "folderlist"); String identity = loginManager.getSession(ctx).getUserID(); FreemailAccount account = accountManager.getAccount(identity); MessageBank topLevelMessageBank = account.getMessageBank(); addMessageBank(folderList, topLevelMessageBank, "inbox"); // Add the message String folderName = req.getParam("folder", "inbox"); MessageBank messageBank = MessageBankTools.getMessageBank(account, folderName); int messageUid; try { messageUid = Integer.parseInt(req.getParam("uid")); } catch (NumberFormatException e) { Logger.error(this, "Got invalid uid: " + req.getParam("uid")); messageUid = 0; } MailMessage msg = MessageBankTools.getMessage(messageBank, messageUid); if (msg == null) { /* FIXME: L10n */ HTMLNode infobox = addErrorbox(container, "Message doesn't exist"); infobox.addChild("p", "The message you requested doesn't exist"); return new GenericHTMLResponse(ctx, 200, "OK", pageNode.generate()); } HTMLNode messageNode = container.addChild("div", "class", "message"); addMessageButtons(ctx, messageNode, folderName, messageUid); addMessageHeaders(messageNode, msg); addMessageContents(messageNode, msg); // Mark message as read if (!msg.flags.get("\\seen")) { msg.flags.set("\\seen", true); msg.storeFlags(); } return new GenericHTMLResponse(ctx, 200, "OK", pageNode.generate()); }