1 32 33 package scioworks.imap.presentation.imapWeb; 34 35 import java.io.*; 36 import java.net.URLEncoder ; 37 import java.util.Vector ; 38 39 import javax.mail.*; 40 import javax.mail.internet.*; 41 import javax.activation.*; 42 43 import org.w3c.dom.*; 44 import org.w3c.dom.html.*; 45 46 import com.lutris.appserver.server.httpPresentation.*; 47 48 import scioworks.imap.presentation.base.*; 49 import scioworks.imap.presentation.imapWeb.*; 50 import scioworks.imap.spec.beans.*; 51 import scioworks.imap.spec.ImapWebException; 52 import scioworks.imap.spec.util.*; 53 54 public class view_mail extends BasePO { 55 56 public String handleDefault() throws HttpPresentationException { 57 58 String fFolder = super.getStringParameter(PARAM_folder); 59 long fMsgid = super.getLongParameter(PARAM_msgid); 60 61 try { 62 63 64 65 IWMessage iwMsg = IWMessageFactory.getIWMessage("scioworks.imap.business.beans.IWMessageImpl"); 66 67 Message msg = iwMsg.getMessage(super.getImapWebSessionData().getImapStore(), 68 fFolder, fMsgid); 69 view_mailHTML page = (view_mailHTML)m_comms.xmlcFactory.create(view_mailHTML.class); 71 72 73 ((HTMLInputElement) page.getElementFolder1()).setValue(fFolder); 75 ((HTMLInputElement) page.getElementMsgid1()).setValue(Long.toString(fMsgid)); 76 77 ((HTMLInputElement) page.getElementFolder2()).setValue(fFolder); 78 ((HTMLInputElement) page.getElementMsgid2()).setValue(Long.toString(fMsgid)); 79 80 ((HTMLInputElement) page.getElementFolder3()).setValue(fFolder); 81 ((HTMLInputElement) page.getElementMsgid3()).setValue(Long.toString(fMsgid)); 82 83 Vector targetFolders = iwMsg.getFolderNames(super.getImapWebSessionData().getImapStore(), 85 fFolder); 86 targetFolders.insertElementAt("-- Choose Folder --", 0); 87 super.processSelectList(page, page.getElementTargetFolder(), 88 targetFolders, targetFolders, "-1"); 89 90 page.getElementDate().removeAttribute("id"); 91 page.getElementTo().removeAttribute("id"); 92 page.getElementFrom().removeAttribute("id"); 93 page.getElementSubject().removeAttribute("id"); 94 page.getElementEmailText().removeAttribute("id"); 95 96 Node messageRow = page.getElementMessageRow(); 98 Node messageRowParent = messageRow.getParentNode(); 99 100 page.setTextDate(msg.getSentDate().toString()); 102 page.setTextTo(InternetAddress.toString(msg.getAllRecipients())); 103 104 MessagingUtil messagingUtil = MessagingUtilFactory.getMessagingUtil("scioworks.imap.business.util.MessagingUtilImpl"); 105 106 page.setTextSubject(messagingUtil.formatSubject(msg.getSubject())); 107 page.setTextFrom(msg.getFrom()[0].toString()); 108 page.setTextEmailText(messagingUtil.formatBodyText(iwMsg.getMessageBody(msg))); 109 110 messageRowParent.appendChild(messageRow.cloneNode(true)); 111 112 HTMLElement filenameEle = page.getElementFilename(); 114 HTMLAnchorElement downloadLinkEle = page.getElementDownloadLink(); 115 116 filenameEle.removeAttribute("id"); 117 downloadLinkEle.removeAttribute("id"); 118 119 HTMLTableRowElement attachmentListRow = page.getElementAttachmentListRow(); 121 Node attachmentListTable = attachmentListRow.getParentNode(); 122 123 String currLink = downloadLinkEle.getHref() + "?" + 124 PARAM_event + "=" + EVENT_downloadAttachment + "&" + 125 PARAM_folder + "=" + URLEncoder.encode(fFolder) + "&" + 126 PARAM_msgid + "=" + Long.toString(fMsgid) + "&" + 127 PARAM_part + "=" ; 128 129 if (msg.isMimeType("multipart/*")) { 130 Multipart mp = (Multipart)msg.getContent(); 131 for (int i=1; i<mp.getCount(); i++) { 132 processEmail(page, mp.getBodyPart(i), currLink+Integer.toString(i)); 133 } 134 attachmentListTable.removeChild(attachmentListRow); 135 } else { 136 super.removeElement(page, (Element)attachmentListTable); 137 } 138 139 messageRowParent.removeChild(messageRow); 140 141 return page.toDocument(); 142 143 } catch(NullPointerException ex) { 144 148 return ((view_mailHTML)m_comms.xmlcFactory.create(view_mailHTML.class)).toDocument(); 149 150 151 } catch (ImapWebException e) { 152 return super.showErrorPage("Error getting message", e.getMessage(), "", ""); 153 154 } catch (MessagingException e) { 155 e.printStackTrace(); 156 return super.showErrorPage("Error getting messages", e.getMessage(), "", ""); 157 158 } catch (IOException e) { 159 e.printStackTrace(); 160 return super.showErrorPage("Error getting message", e.getMessage(), "", ""); 161 } 162 } 163 164 public void processEmail(view_mailHTML page, Part part, String partId) 165 throws HttpPresentationException, MessagingException, IOException, ImapWebException { 166 167 if (part.isMimeType("multipart/*")) { 168 169 Multipart mp = ((Multipart) part.getContent()); 170 int count = mp.getCount(); 171 for (int i = 1; i<mp.getCount(); i++) { 172 processEmail(page, mp.getBodyPart(i), partId + "." + i); 173 } 174 175 } else if (part.isMimeType("message/rfc822")) { 176 177 178 Node messageRow = page.getElementMessageRow(); 180 Node messageRowParent = messageRow.getParentNode(); 181 182 Message msg = (Message) part.getContent(); 183 page.setTextDate(msg.getSentDate().toString()); 184 page.setTextTo(InternetAddress.toString(msg.getAllRecipients())); 185 MessagingUtil messagingUtil = MessagingUtilFactory.getMessagingUtil("scioworks.imap.business.util.MessagingUtilImpl"); 186 187 page.setTextSubject(messagingUtil.formatSubject(msg.getSubject())); 188 page.setTextFrom(msg.getFrom()[0].toString()); 189 190 IWMessage iwMsg = IWMessageFactory.getIWMessage("scioworks.imap.business.beans.IWMessageImpl"); 191 192 page.setTextEmailText(messagingUtil.formatBodyText(iwMsg.getMessageBody(msg))); 193 194 messageRowParent.appendChild(messageRow.cloneNode(true)); 195 196 if (msg.isMimeType("multipart/*")) { 197 Multipart mp = (Multipart)msg.getContent(); 198 for (int i=1; i<mp.getCount(); i++) { 199 processEmail(page, mp.getBodyPart(i), partId + "." + i); 200 } 201 } 202 203 } else { 204 HTMLElement filenameEle = page.getElementFilename(); 206 HTMLAnchorElement downloadLinkEle = page.getElementDownloadLink(); 207 208 HTMLTableRowElement attachmentListRow = page.getElementAttachmentListRow(); 210 Node attachmentListTable = attachmentListRow.getParentNode(); 211 212 page.setTextFilename(part.getFileName()); 213 downloadLinkEle.setHref(partId); 214 215 attachmentListTable.appendChild(attachmentListRow.cloneNode(true)); 216 217 } 218 } 219 220 } | Popular Tags |