private void writeHeaderInfoToOut( EmailHeader tmp, PrintWriter out, HttpServletRequest request, FolderDbObject myFolder) { String subject = tmp.getSubject(); if (null == subject || 0 == subject.length()) subject = getText(request, "no.subject"); String from = tmp.getFromShown(); if (null == from || 0 == from.length()) from = getText(request, "unknown.sender"); String priority = org.claros.commons.mail.models.EmailPriority.toStringValue(tmp.getPriority()); short sensitivity = tmp.getSensitivity(); out.print( "<p " + ((tmp.isMultipart()) ? " class='attach' " : "") + "id='mail" + tmp.getMessageId() + "' " + ((tmp.getUnread().booleanValue()) ? "style='font-weight:bold;'" : "") + ">" + "<span class='flag' onclick='mailListClick(event, this, false, true);'> </span>"); out.print( "<span class='attributes' onclick='mailListClick(event, this, true, false);'><img alt='' src='images/priority-" + priority.toLowerCase() + ".gif' align='absmiddle'><img alt='' src='images/sensitivity-" + sensitivity + ".gif' align='absmiddle'></span>"); if (myFolder .getFolderType() .equals(org.claros.intouch.common.utility.Constants.FOLDER_TYPE_SENT)) { out.print( "<span class='from' onclick='mailListClick(event, this, true, false);'>" + org.claros.commons.utility.Utility.convertTRCharsToHtmlSafe( Utility.htmlCheck(sbjTrim(tmp.getToShown()))) + "</span>"); } else { out.print( "<span class='from' onclick='mailListClick(event, this, true, false);'>" + org.claros.commons.utility.Utility.convertTRCharsToHtmlSafe( Utility.htmlCheck(sbjTrim(from))) + "</span>"); } out.print( "<span class='subject' onclick='mailListClick(event, this, true, false);' title=\"" + org.claros.commons.utility.Utility.convertTRCharsToHtmlSafe( Utility.htmlCheck(subject)) + "\">" + org.claros.commons.utility.Utility.convertTRCharsToHtmlSafe( Utility.htmlCheck(sbjTrim(subject))) + "</span>" + "<span class='date' onclick='mailListClick(event, this, true, false);'>" + Utility.htmlCheck(tmp.getDateShown()) + "</span>" + "<span class='size' onclick='mailListClick(event, this, true, false);'>" + Utility.htmlCheck(tmp.getSizeShown()) + "</span>" + "<span class='attach' onclick='mailListClick(event, this, true, false);'> </span>" + "</p>"); }
/** * The doPost method of the servlet. <br> * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setHeader("Expires", "-1"); response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-control", "no-cache"); response.setHeader("Content-Type", "text/xml; charset=utf-8"); PrintWriter out = response.getWriter(); out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); out.write("<data>"); out.print("<events>"); try { String sEventId = request.getParameter("eventId"); AuthProfile auth = getAuthProfile(request); CalendarObject tmp = CalendarDBController.getEventById(auth, new Long(sEventId)); Calendar cal = Calendar.getInstance(); Calendar calTmp = Calendar.getInstance(); cal.setTimeInMillis(tmp.getRecordDate().getTime()); DecimalFormat df = new DecimalFormat("00"); out.print("<event>"); out.print("<id>" + tmp.getId() + " </id>"); out.print("<year>" + cal.get(Calendar.YEAR) + " </year>"); out.print("<month>" + df.format((cal.get(Calendar.MONTH) + 1)) + " </month>"); out.print("<day>" + df.format(cal.get(Calendar.DATE)) + " </day>"); out.print( "<begin>" + df.format(cal.get(Calendar.HOUR_OF_DAY)) + ":" + df.format(cal.get(Calendar.MINUTE)) + " </begin>"); calTmp.setTimeInMillis(tmp.getEndDate().getTime()); out.print( "<end>" + df.format(calTmp.get(Calendar.HOUR_OF_DAY)) + ":" + df.format(calTmp.get(Calendar.MINUTE)) + " </end>"); out.print("<color>" + tmp.getColor() + " </color>"); out.print( "<description>" + Utility.htmlSpecialChars(tmp.getDescription()) + " </description>"); out.print( "<hasReminder>" + (tmp.getReminderDays() != null && tmp.getReminderDays().equals("-1") ? "false" : "true") + " </hasReminder>"); out.print("<repeatType>" + tmp.getRepeatType() + " </repeatType>"); out.print("<location>" + tmp.getLocation() + " </location>"); out.print("<reminderDays>" + tmp.getReminderDays() + " </reminderDays>"); out.print("<reminderMethod>" + tmp.getReminderMethod() + " </reminderMethod>"); out.print("</event>"); out.print("</events>"); out.print("<result>0</result>"); out.write("</data>"); } catch (Exception e) { out.print("</events>"); out.print("<result>1</result>"); out.write("</data>"); } }
/** * Fetches all e-mail headers from the server, with appropriate fields already set. * * @param handler * @return ArrayList of MessageHeaders * @throws ConnectionException */ public ArrayList fetchAllHeaders() throws SystemException, ConnectionException { ArrayList headers = new ArrayList(); Folder fold = null; try { fold = getFolder(); EmailHeader header = null; Message[] msgs = fold.getMessages(); FetchProfile fp = new FetchProfile(); fp.add(FetchProfile.Item.ENVELOPE); fp.add(FetchProfile.Item.FLAGS); fp.add(FetchProfile.Item.CONTENT_INFO); fp.add("Size"); fp.add("Date"); fp.add("Disposition-Notification-To"); fp.add("X-Priority"); fp.add("X-MSMail-Priority"); fp.add("Sensitivity"); fold.fetch(msgs, fp); Message msg = null; for (int i = 0; i < msgs.length; i++) { try { header = new EmailHeader(); msg = msgs[i]; header.setMultipart((msg.isMimeType("multipart/*")) ? true : false); header.setMessageId(i + 1); header.setFrom(msg.getFrom()); header.setTo(msg.getRecipients(Message.RecipientType.TO)); header.setCc(msg.getRecipients(Message.RecipientType.CC)); header.setBcc(msg.getRecipients(Message.RecipientType.BCC)); header.setDate(msg.getSentDate()); header.setReplyTo(msg.getReplyTo()); header.setSize(msg.getSize()); header.setSubject(org.claros.commons.utility.Utility.updateTRChars(msg.getSubject())); // now set the human readables. header.setDateShown(Formatter.formatDate(header.getDate(), "dd.MM.yyyy HH:mm")); header.setFromShown( org.claros.commons.utility.Utility.updateTRChars( Utility.addressArrToStringShort(header.getFrom()))); header.setToShown(Utility.addressArrToStringShort(header.getTo())); header.setCcShown(Utility.addressArrToStringShort(header.getCc())); header.setSizeShown(Utility.sizeToHumanReadable(header.getSize())); org.claros.commons.mail.parser.MessageParser.setHeaders(msg, header); boolean deleted = false; if (profile.getProtocol().equals(Constants.IMAP)) { Flags.Flag flags[] = msg.getFlags().getSystemFlags(); if (flags != null) { Flags.Flag flag = null; for (int m = 0; m < flags.length; m++) { flag = flags[m]; if (flag.equals(Flags.Flag.SEEN)) { header.setUnread(new Boolean(false)); } if (flag.equals(Flags.Flag.DELETED)) { deleted = true; } } } } if (header.getUnread() == null) { header.setUnread(new Boolean(true)); } // it is time to add it to the arraylist if (!deleted) { headers.add(header); } } catch (MessagingException e1) { log.error( "Could not parse headers of e-mail. Message might be defuncted or illegal formatted.", e1); } } } catch (MessagingException e) { log.error("Could not fetch message headers. Is mbox connection still alive???", e); // throw new ConnectionException(e); } catch (Exception e) { log.error("Could not fetch message headers. Is mbox connection still alive???", e); // throw new ConnectionException(e); } return headers; }