1 32 33 package scioworks.imap.presentation.imapWeb; 34 35 import java.util.Vector ; 36 import java.net.URLEncoder ; 37 38 import javax.mail.*; 39 import javax.mail.internet.*; 40 import javax.activation.*; 41 42 import org.w3c.dom.*; 43 import org.w3c.dom.html.*; 44 45 import com.lutris.appserver.server.httpPresentation.*; 46 47 import scioworks.imap.presentation.base.*; 48 import scioworks.imap.presentation.imapWeb.*; 49 import scioworks.imap.spec.beans.*; 50 import scioworks.imap.spec.ImapWebException; 51 import scioworks.imap.spec.util.*; 52 53 public class mail_list extends BasePO { 54 55 public String handleDefault() throws HttpPresentationException { 56 57 58 String fFolder = super.getStringParameter(PARAM_folder); 60 61 if (fFolder.equals("")) { 63 fFolder = "INBOX"; 64 } 65 66 mail_listHTML page = (mail_listHTML)m_comms.xmlcFactory.create(mail_listHTML.class); 67 68 HTMLInputElement msgidEle = page.getElementMsgid(); 69 HTMLElement fromEle = page.getElementFrom(); 70 HTMLElement subjectEle = page.getElementSubject(); 71 HTMLElement dateEle = page.getElementDate(); 72 HTMLElement sizeEle = page.getElementSize(); 73 74 HTMLTableRowElement emailListRow = page.getElementEmailListRow(); 76 Node emailListTable = emailListRow.getParentNode(); 77 78 HTMLAnchorElement emailLink = page.getElementEmailLink(); 80 String currLink = emailLink.getHref() + "?" + 81 PARAM_folder + "=" + URLEncoder.encode(fFolder) + "&" + 82 PARAM_msgid + "="; 83 84 86 IWMessage iwMsg = IWMessageFactory.getIWMessage("scioworks.imap.business.beans.IWMessageImpl"); 87 88 try { 89 Vector targetFolders = iwMsg.getFolderNames(super.getImapWebSessionData().getImapStore(), 90 fFolder); 91 targetFolders.insertElementAt("-- Choose Folder --", 0); 92 super.processSelectList(page, page.getElementTargetFolder(), 93 targetFolders, targetFolders, "-1"); 94 95 100 } catch(NullPointerException ex) { 101 return ((mail_listHTML)m_comms.xmlcFactory.create(mail_listHTML.class)).toDocument(); 102 } catch (ImapWebException e) { 103 return super.showErrorPage(MSG_OPERATION_FAILED, e.getMessage(), "", ""); 104 } 105 msgidEle.removeAttribute("id"); 107 fromEle.removeAttribute("id"); 108 subjectEle.removeAttribute("id"); 109 dateEle.removeAttribute("id"); 110 sizeEle.removeAttribute("id"); 111 emailListRow.removeAttribute("id"); 112 emailLink.removeAttribute("id"); 113 114 page.getElementFolder().setValue(fFolder); 116 117 try { 118 Folder folder = super.getImapWebSessionData().getImapStore().getFolder(fFolder); 119 120 UIDFolder ufolder = (UIDFolder) folder; 121 122 folder.open(Folder.READ_ONLY); 124 125 Message[] messages = folder.getMessages(); 127 128 long uid; 129 String personalName; 130 131 for (int i=0; i<messages.length; i++) { 132 133 uid = ufolder.getUID(messages[i]); 135 136 msgidEle.setValue(Long.toString(uid)); 138 139 personalName = ((InternetAddress)messages[i].getFrom()[0]).getPersonal(); 141 if (personalName == null) { 142 page.setTextFrom((messages[i].getFrom()[0]).toString()); 143 } else { 144 page.setTextFrom(personalName); 145 } 146 147 149 150 151 page.setTextDate(TextUtil.singleton().dateFormat(messages[i].getSentDate())); 152 153 page.setTextSize(TextUtil.singleton().verboseFilesize(messages[i].getSize())); 155 156 MessagingUtil messagingUtil = MessagingUtilFactory.getMessagingUtil("scioworks.imap.business.util.MessagingUtilImpl"); 158 159 page.setTextSubject(messagingUtil.formatSubject(messages[i].getSubject())); 160 161 emailLink.setHref(currLink+uid); 163 164 emailListTable.appendChild(emailListRow.cloneNode(true)); 165 } 166 167 folder.close(false); 169 170 } catch (MessagingException e) { 171 super.showErrorPage("Error getting messages", e.getMessage(), "", ""); 172 173 } finally { 174 emailListTable.removeChild(emailListRow); 175 } 176 177 return page.toDocument(); 178 } 179 } | Popular Tags |