001: /*
002: * $Id: MailContext.java,v 1.42 2005/10/18 22:28:55 js143762 Exp $
003: * Copyright 2002 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and iPlanet
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */
014:
015: package com.sun.portal.wireless.taglibs.mail;
016:
017: import java.util.*;
018: import java.util.logging.Logger;
019: import java.util.logging.Level;
020: import java.text.*;
021: import java.net.*;
022: import java.io.*;
023:
024: import javax.servlet.*;
025: import javax.servlet.http.*;
026: import javax.servlet.jsp.*;
027:
028: import javax.mail.*;
029: import javax.mail.internet.*;
030: import javax.mail.search.*;
031:
032: import com.iplanet.sso.*;
033: import com.iplanet.services.cdm.*;
034: import com.iplanet.am.util.*;
035: import com.iplanet.am.sdk.AMException;
036: import com.iplanet.am.sdk.AMStoreConnection;
037: import com.iplanet.am.sdk.AMUser;
038:
039: import com.sun.ssoadapter.*;
040: import com.sun.ssoadapter.impl.JavaMailSSOAdapter;
041:
042: import com.sun.ssoadapter.config.*;
043: import com.sun.ssoadapter.config.PSClientAwareContextFactory;
044: import com.sun.ssoadapter.config.ClientAwareUserContext;
045:
046: import com.sun.mobile.util.*;
047: import com.sun.portal.wireless.util.*;
048:
049: import com.sun.portal.wireless.taglibs.base.*;
050: import com.sun.portal.wireless.taglibs.util.Catalog;
051: import com.sun.portal.log.common.PortalLogger;
052:
053: /**
054: * MailContext - track state across requests.
055: *
056: * This class implements a simple context mechanism
057: * that may be used for tracking user state across
058: * multiple requests.
059: *
060: * @version 1.0
061: * @see ContextCache
062: */
063:
064: public class MailContext extends Context {
065: private static Logger logger = PortalLogger
066: .getLogger(MailContext.class);
067:
068: public static final String CONTEXT_CLASS_NAME = "com.sun.portal.wireless.taglibs.mail.MailContext";
069:
070: public static final String CONTEXT_CACHE_CLASS_NAME = "com.sun.portal.wireless.taglibs.mail.MailContextCache";
071:
072: public static final String CONTEXT_TYPE = "mailcontext";
073:
074: public static final String SSO_CONFIG_TYPE = "MAIL-TYPE";
075:
076: private JavaMailSSOAdapter mailSSOAdapter;
077: private javax.mail.Session mailSession;
078: private Store mailStore = null;
079: private FolderBean currentFolder = null;
080: private Folder INBOX;
081:
082: private String fromAddress = null;
083:
084: private MsgBean currentMsg = null;
085: private int currentMsgIdx = 0;
086:
087: private boolean doMsgInclude = false;
088: private boolean includeSig = true;
089: private boolean saveSent = false;
090: private ViewBean allView = null;
091: private ViewBean currentView = null;
092:
093: private FolderBean[] folders = null;
094: private MsgBean[] messages = null;
095: private LineBean[] lines = null;
096:
097: protected Vector views = null;
098:
099: private int lineLength = 0;
100:
101: // PROTECTED member variables: available to subclasses (e.g. MailPrefsContext)
102:
103: protected ConfigurationFactory mailAppConfigFactory = null;
104: protected ConfigurationFactory ruleFactory = null;
105: protected ConfigurationFactory viewFactory = null;
106:
107: protected Configuration mailAppConfig = null;
108: protected Vector popConfigs = null;
109:
110: protected Vector presetMessages = null;
111:
112: /**
113: * Initialize a context with the specified session.
114: *
115: * <p>For the time being, the user's "from address" is
116: * computed in the following fashion:
117: * <ol>
118: * <li>If mail app preference "fromAddress" is set, use that as the "from address", otherwise...
119: * <li>Determine email username. If "imap uid" is set, use that, else use SSOToken principal.
120: * <li>If the resulting username has a "@" character in it, use that as the "from address",
121: * otherwise...
122: * <li>Determine mail domain. If the org level attr "sunMobileAppMailDefaultMailDomain" is
123: * is set, use that, else, if the sso adapter property "smtpServer" is set, use that, else,
124: * use the imap host name.
125: * <li>Combine the resulting user and mail domain names to form a "from address".
126: * </ol>
127: *
128: * @param session Context belongs to this session.
129: * @exception Exception
130: */
131: public void init(HttpServletRequest request, SSOToken session,
132: SSOAdapter ssoAdapter) throws Exception {
133: super .init(request, session,
134: AppConfigConstants.MAIL_APP_SERVICE_NAME, ssoAdapter);
135:
136: initMail(session, request);
137: initConfigs(request);
138: initViewCollection(request);
139:
140: String tmp;
141:
142: //
143: // TODO: This whole bit of logic should be replaced by some sort of
144: // pluggable implementation.
145: //
146: fromAddress = mailAppConfig.getProperty("fromAddress");
147: if (fromAddress == null || fromAddress.length() == 0) {
148: Properties ssoProperties = ssoAdapter.getProperties();
149: String user = ssoProperties.getProperty("uid");
150: if (user == null || user.length() == 0) {
151: try {
152: HashMap authServiceMap = new HashMap();
153: authServiceMap.put("serviceName",
154: "iPlanetAMAuthService");
155: PSClientAwareContextFactory authSvcContextFactory = PSClientAwareContextFactory
156: .getInstance();
157: ClientAwareUserContext authSvcContext = authSvcContextFactory
158: .getClientAwareUserContext(new SSOAdapterSession(
159: request));
160: String uidAttr = authSvcContext.getStringAttribute(
161: authServiceMap,
162: "iplanet-am-auth-user-naming-attr");
163: user = authSvcContext.getStringAttribute(
164: authServiceMap, uidAttr);
165: //AMStoreConnection amsc = new AMStoreConnection(session);
166: //AMUser auser = amsc.getUser(session.getPrincipal().getName());
167: //user = auser.getStringAttribute("uid");
168: } catch (Exception e) {
169: logger.log(Level.FINER, "PSMA_CSPWTM0009");
170: }
171: }
172: if (user == null || user.length() == 0) {
173: fromAddress = "";
174: } else if (user.indexOf('@') >= 0) {
175: fromAddress = user;
176: } else {
177: String mailDomain = getAttributeString("sunMobileAppMailDefaultMailDomain");
178: if (mailDomain == null || mailDomain.length() == 0) {
179: mailDomain = ssoProperties
180: .getProperty("smtpServer");
181: }
182: if (mailDomain == null || mailDomain.length() == 0) {
183: mailDomain = ssoProperties.getProperty("host");
184: }
185: fromAddress = user + "@" + mailDomain;
186: }
187: }
188:
189: String lineLengthString;
190: try {
191: lineLengthString = ClientsManager.getInstance(
192: getClientType()).getProperty("lineLength");
193: if (lineLengthString != null)
194: lineLength = Integer.parseInt(lineLengthString);
195: } catch (Exception ee) {
196: }
197:
198: tmp = mailAppConfig.getProperty("sentFolderCopy");
199: if (tmp != null) {
200: Boolean b = new Boolean(tmp);
201: saveSent = b.booleanValue();
202: }
203: }
204:
205: /**
206: * Returns a MailContext for this session.
207: *
208: * @param request
209: * @param pageContext
210: */
211: public static MailContext getContext(PageContext pageContext)
212: throws Exception {
213: return (MailContext) Context.getContext(pageContext,
214: CONTEXT_CLASS_NAME, CONTEXT_CACHE_CLASS_NAME,
215: CONTEXT_TYPE);
216: }
217:
218: public int getLineLength() {
219: return lineLength;
220: }
221:
222: public int getInboxNumMsgs() throws MessagingException {
223: int msgCount = INBOX.getMessageCount();
224: if (msgCount < 0) {
225: INBOX.open(Folder.READ_ONLY);
226: msgCount = INBOX.getMessageCount();
227: INBOX.close(false);
228: }
229: return msgCount;
230: }
231:
232: public int getInboxNumUnreadMsgs() throws MessagingException {
233: int unreadCount = INBOX.getUnreadMessageCount();
234: if (unreadCount < 0) {
235: INBOX.open(Folder.READ_ONLY);
236: unreadCount = INBOX.getUnreadMessageCount();
237: INBOX.close(false);
238: }
239: return unreadCount;
240: }
241:
242: public int getInboxNumUnreadAddrToMeMsgs()
243: throws MessagingException {
244: boolean InboxWasAlreadyOpen = true;
245:
246: int unreadCount = INBOX.getUnreadMessageCount();
247: if ((unreadCount < 0) || (!INBOX.isOpen())) {
248: InboxWasAlreadyOpen = false;
249: INBOX.open(Folder.READ_ONLY);
250:
251: unreadCount = INBOX.getUnreadMessageCount();
252: }
253:
254: if (unreadCount > 0) {
255: FlagTerm unseen = new FlagTerm(new Flags(Flags.Flag.SEEN),
256: false);
257: HeaderTerm to = new HeaderTerm("To", fromAddress);
258: SearchTerm term = new AndTerm(unseen, to);
259:
260: Message[] msgs = INBOX.search(term);
261: unreadCount = (msgs != null) ? msgs.length : 0;
262: }
263:
264: if (!InboxWasAlreadyOpen) {
265: INBOX.close(false);
266: }
267:
268: return unreadCount;
269: }
270:
271: public int getInboxNumNewMsgs() throws MessagingException {
272: int newCount = INBOX.getNewMessageCount();
273: if (newCount < 0) {
274: INBOX.open(Folder.READ_ONLY);
275: newCount = INBOX.getNewMessageCount();
276: INBOX.close(false);
277: }
278: return newCount;
279: }
280:
281: public int getNumMsgs() throws MessagingException {
282: if (messages != null) {
283: return messages.length;
284: } else {
285: Folder f = currentFolder.getFolder();
286: return f.getMessageCount();
287: }
288: }
289:
290: public int getNumUnreadMsgs() throws MessagingException {
291: Folder f = currentFolder.getFolder();
292: return f.getUnreadMessageCount();
293: }
294:
295: public int getNumUnreadAddrToMeMsgs() throws MessagingException {
296: Folder folder = currentFolder.getFolder();
297:
298: int unreadCount = folder.getUnreadMessageCount();
299: if (unreadCount > 0) {
300: FlagTerm unseen = new FlagTerm(new Flags(Flags.Flag.SEEN),
301: false);
302: HeaderTerm to = new HeaderTerm("To", fromAddress);
303: SearchTerm term = new AndTerm(unseen, to);
304:
305: Message[] msgs = folder.search(term);
306: unreadCount = (msgs != null) ? msgs.length : 0;
307: }
308:
309: if (unreadCount < 0) {
310: unreadCount = 0;
311: }
312:
313: return unreadCount;
314: }
315:
316: public int getNumNewMsgs() throws MessagingException {
317: Folder f = currentFolder.getFolder();
318: return f.getNewMessageCount();
319: }
320:
321: public Folder getInbox() {
322: return INBOX;
323: }
324:
325: public FolderBean getCurrentFolder() {
326: return currentFolder;
327: }
328:
329: public void setCurrentFolder(FolderBean folder) {
330: currentFolder = folder;
331: }
332:
333: public MsgBean getMsg() {
334: return currentMsg;
335: }
336:
337: public void setMsg(MsgBean m) {
338: currentMsg = m;
339: }
340:
341: public int getMsgIdx() {
342: return currentMsgIdx;
343: }
344:
345: public void setMsgIdx(int idx) {
346: currentMsgIdx = idx;
347: }
348:
349: public String getFrom() {
350: return fromAddress;
351: }
352:
353: /**
354: * @return textEncoding is used to encode MIME header to be
355: * in 7 bit ASCII such as B or Q as per RFC 2047
356: */
357: public String getTextEncoding() {
358: Catalog rb = new Catalog("mail", getLocale());
359: return rb.getMsg("textEncoding");
360: }
361:
362: public String getCharset() {
363:
364: String charset = super .getCharset();
365:
366: Set attributeSet;
367: try {
368:
369: attributeSet = getAttributeSet("sunMobileAppMailOutboundMailCharset");
370: if (attributeSet == null) {
371: return charset;
372: }
373:
374: Iterator attrIterator = attributeSet.iterator();
375:
376: while (attrIterator.hasNext()) {
377: String attribute = (String) attrIterator.next();
378: if (attribute.toUpperCase().startsWith(
379: charset.toUpperCase())) {
380: int i = attribute.indexOf('=');
381: if (i > 0) {
382: return attribute.substring(i + 1);
383: } else {
384: return charset;
385: }
386: }
387: }
388: } catch (Exception e) {
389: logger.log(Level.FINER, "PSMA_CSPWTM0010");
390: }
391:
392: return charset;
393: }
394:
395: public Store getMailStore() {
396: return mailStore;
397: }
398:
399: public javax.mail.Session getMailSession() {
400: try {
401: return mailSSOAdapter.getSession();
402: } catch (Exception e) {
403: return null;
404: }
405: }
406:
407: public String getSignature() {
408: return getAttributeString("sunMobileAppMailSignature", "");
409: }
410:
411: public boolean saveSentMail() {
412: return saveSent;
413: }
414:
415: public boolean includeMsg() {
416: return doMsgInclude;
417: }
418:
419: public void setDoMsgInclude(String flag) {
420: Boolean b = new Boolean(flag);
421: doMsgInclude = b.booleanValue();
422: }
423:
424: public boolean includeSig() {
425: return includeSig;
426: }
427:
428: public void setIncludeSig(String flag) {
429: Boolean b = new Boolean(flag);
430: includeSig = b.booleanValue();
431: }
432:
433: // determines if there is a message following the
434: // current selected message.
435: //
436: // array is 0 to (n-1) where n = messages.length
437: //
438: public boolean isAtmsgend() {
439: if (currentMsgIdx + 1 >= messages.length) {
440: return true;
441: }
442: return false;
443: }
444:
445: // determines if there is a message proceeding the
446: // current selected message.
447: //
448: // array is 0 to (n-1) where n = messages.length
449: //
450: public boolean isAtmsgstart() {
451: if (currentMsgIdx - 1 < 0) {
452: return true;
453: }
454: return false;
455: }
456:
457: public int getNextmsgidx() {
458: if (!isAtmsgend()) {
459: return currentMsgIdx + 1;
460: }
461: return messages.length - 1;
462: }
463:
464: public int getPrevmsgidx() {
465: if (!isAtmsgstart()) {
466: return currentMsgIdx - 1;
467: }
468: return 0;
469: }
470:
471: /**
472: * Check if the preset messages list is empty
473: *
474: * @return boolean
475: */
476: public boolean isPresetEmpty() {
477: if (presetMessages != null && presetMessages.size() > 0) {
478: return false;
479: } else {
480: return true;
481: }
482: }
483:
484: /**
485: * Get the preset messages vector
486: *
487: * @return Vector
488: */
489: public Vector getPresetMessages() {
490: return presetMessages;
491: }
492:
493: /**
494: * Get the preset messages from user's and profile and encapsulate
495: * them in PresetMsg beans.
496: *
497: * @return boolean indicates whether preset messages fetch successed
498: */
499: public boolean doPresetMessagesFetch() {
500:
501: // Collection of preset messages to return
502: Vector presetMsgList = new Vector();
503:
504: // Read the predefined message list from the Profile
505: Set msgSetTmp = getAttributeSet("sunMobileAppMailPredefinedReplies");
506: TreeSet msgSet = new TreeSet(msgSetTmp);
507: if (msgSet == null) {
508: // Note: done this way to maintain compat
509: // w/ earlier implementation.
510: //
511: // Shouldn't set this.presetMessages?
512: // Should return false?
513: this .presetMessages = presetMsgList;
514: return true;
515: }
516:
517: Iterator msgIterator = msgSet.iterator();
518:
519: for (int i = 1; msgIterator.hasNext(); i++) {
520:
521: // The predefined messages property in profile is in the form
522: // of a name-value pair, like -'preset1|Hi'.
523: // Get the value
524:
525: String nameValue = (String) msgIterator.next();
526: int delimiter = nameValue.indexOf('=');
527: if (delimiter != -1) {
528: String presetIdx = "preset" + i;
529: String key = nameValue.substring(0, delimiter);
530: String value = nameValue.substring(delimiter + 1,
531: nameValue.length());
532: if (key.equals(presetIdx)) {
533: if ((value != null) && (!value.equals(""))) {
534: presetMsgList.add(new PresetMsg(value, i));
535: }
536: } else {
537: logger
538: .log(Level.FINE, "PSMA_CSPWTM0011",
539: presetIdx);
540: }
541: } else {
542: logger.log(Level.FINE, "PSMA_CSPWTM0012");
543: }
544:
545: }
546: this .presetMessages = presetMsgList;
547: return true;
548: }
549:
550: /**
551: * Check if pop3 configuration list is empty
552: *
553: * @return boolean
554: */
555: public boolean isPopEmpty() {
556: if (popConfigs != null) {
557: for (int i = 0; i < popConfigs.size(); i++) {
558: if (((ConfigBean) popConfigs.elementAt(i))
559: .getProtocol().equals("pop3"))
560: return false;
561: }
562: }
563:
564: return true;
565: }
566:
567: /**
568: * Get the popConfigs vector
569: *
570: * @return Vector
571: */
572: public Vector getConfigsCollection() {
573: return popConfigs;
574: }
575:
576: protected void initViewCollection(HttpServletRequest request) {
577:
578: Set viewClients = getAttributeSet("sunMobileAppMailViewClients");
579: allView = new AllView(0);
580:
581: if (viewClients != null && viewClients.size() > 0) {
582:
583: int len = viewClients.size();
584: views = new Vector(); // create ViewBean collection
585: views.add(allView); // Assign first allView
586:
587: viewFactory = ConfigurationFactory.getInstance(
588: AppConfigConstants.MAIL_APP_SERVICE_NAME,
589: AppConfigConstants.MAIL_APP_VIEW_LIST);
590:
591: ruleFactory = ConfigurationFactory.getInstance(
592: AppConfigConstants.MAIL_APP_SERVICE_NAME,
593: AppConfigConstants.MAIL_APP_RULE_LIST);
594:
595: String[] tmp = new String[len];
596: viewClients.toArray(tmp);
597: Configuration conf = null;
598:
599: for (int i = 0; i < len; i++) {
600: try {
601: // Strip off client from rule name
602: int k = tmp[i].indexOf("|");
603: tmp[i] = tmp[i].substring(k + 1);
604: conf = viewFactory.readConfiguration(tmp[i], false,
605: new SSOAdapterSession(request));
606: views.add(new ViewBean(conf, ruleFactory, request,
607: i + 1));
608: } catch (Exception e) {
609: logger.log(Level.FINE, "PSMA_CSPWTM0013", e);
610:
611: // Error processing user views, so skipping them and just
612: // setting the default
613: views = new Vector();
614: views.add(allView);
615: return;
616: }
617: }
618: } else {
619: // We have no user defined views for this client
620: views = new Vector();
621: views.add(allView);
622: }
623: }
624:
625: public int getNumOfViews() {
626: return views.size();
627: }
628:
629: public Vector getViewCollection() {
630: return views;
631: }
632:
633: public ViewBean getCurrentViewBean() {
634: if (currentView == null) {
635: return allView;
636: }
637: return currentView;
638: }
639:
640: public void setCurrentView(String idx) {
641: int index = -1;
642: index = Integer.parseInt(idx);
643:
644: ViewBean current = allView;
645: if (views != null) {
646: if (index >= 0 && index < views.size()) {
647: current = (ViewBean) views.elementAt(index);
648: }
649: }
650: currentView = current;
651:
652: }
653:
654: /**
655: * Set current view to one of the default:
656: * <ul>
657: * <li>read
658: * <li>unread
659: * <li>unreadAddrToMe - unread and addressed to me
660: * </ul>
661: *
662: * @param Default view name
663: */
664: public void setDefaultView(String str) {
665: // Default to allView
666: ViewBean view = allView;
667:
668: Flags flags = new Flags(Flags.Flag.SEEN);
669: SearchTerm term = null;
670:
671: if (str.equals("read")) {
672: // Read messages
673: term = new FlagTerm(flags, true);
674:
675: } else if (str.equals("unread")) {
676: // Unread messages
677: term = new FlagTerm(flags, false);
678:
679: } else if (str.equals("unreadAddrToMe")) {
680: // Unread and addressed to me
681: term = new HeaderTerm("To", fromAddress);
682: FlagTerm ft = new FlagTerm(flags, false);
683:
684: term = new AndTerm(ft, term);
685: } else {
686: // no change to current view
687: return;
688: }
689:
690: if (term != null) {
691: try {
692: view = new ViewBean(term);
693: } catch (Exception e) {
694: logger.log(Level.FINE, "PSMA_CSPWTM0014", e);
695: return;
696: }
697:
698: }
699:
700: currentView = view;
701: }
702:
703: // #### Collection methods ######################################
704: //
705: public FolderBean[] getFoldersCollection() {
706: return folders;
707: }
708:
709: public void setFoldersCollection(FolderBean[] folders) {
710: this .folders = folders;
711: }
712:
713: public MsgBean[] getMsgsCollection() {
714: return messages;
715: }
716:
717: public void setMsgsCollection(MsgBean[] msgs) {
718: messages = msgs;
719: }
720:
721: public LineBean[] getLinesCollection() {
722: return lines;
723: }
724:
725: public void setLinesCollection(LineBean[] vlines) {
726: lines = vlines;
727: }
728:
729: // #### Private Class methods ######################################
730: //
731:
732: private void initMail(SSOToken session, HttpServletRequest request)
733: throws Exception {
734:
735: mailSSOAdapter = (JavaMailSSOAdapter) ssoAdapter;
736: mailStore = (Store) ssoAdapter.getConnection();
737: currentFolder = new FolderBean(mailStore.getFolder("INBOX"));
738: INBOX = mailStore.getFolder("INBOX");
739:
740: }
741:
742: // Get all the configurations
743: protected void initConfigs(HttpServletRequest request)
744: throws Exception {
745:
746: mailAppConfigFactory = ConfigurationFactory.getInstance(
747: SSOAdapterPrivate.SSO_SERVICE_NAME,
748: SSOAdapterPrivate.SSO_ATTR_CONFIGURATIONS_NAME,
749: SSOAdapterPrivate.SSO_ATTR_TEMPLATES_NAME);
750:
751: //
752: // TODO: This is bogus. We should only be collecting POP configurations here and the "config" tag
753: // be changed to something like the "popcollectionsconfig" tag...
754: //
755: Enumeration configEnum = mailAppConfigFactory
756: .getConfigurationNames(new SSOAdapterSession(request));
757: if (configEnum != null) {
758: popConfigs = new Vector();
759: int index = 0;
760:
761: // iterate through each configuration and add it to the ConfigBean list
762: while (configEnum.hasMoreElements()) {
763: String configName = (String) configEnum.nextElement();
764: Configuration configProps = mailAppConfigFactory
765: .readConfiguration(configName, true,
766: new SSOAdapterSession(request));
767:
768: if (configProps != null
769: && configProps.getConfigurationDescription() != null
770: && configProps
771: .getConfigurationDescription()
772: .equals(
773: AppConfigConstants.POP_COLLECTIONS_TEMPLATE_NAME)) {
774:
775: popConfigs.add(new ConfigBean(configName,
776: configProps.getProperty("protocol"),
777: index++));
778: }
779:
780: }
781: }
782:
783: //
784: // Read "per-account" application preferences...
785: //
786: mailAppConfigFactory = ConfigurationFactory.getInstance(
787: AppConfigConstants.MAIL_APP_SERVICE_NAME,
788: AppConfigConstants.MAIL_APP_ATTR_CONFIGURATIONS_NAME,
789: AppConfigConstants.MAIL_APP_ATTR_TEMPLATES_NAME);
790:
791: try {
792: String configName = ssoAdapter.getName();
793: mailAppConfig = mailAppConfigFactory.readConfiguration(
794: configName, true, new SSOAdapterSession(request));
795: if (mailAppConfig == null) {
796: int i = configName.indexOf('_');
797: if (i >= 0) {
798: mailAppConfig = mailAppConfigFactory
799: .readConfiguration(configName.substring(0,
800: i), true, new SSOAdapterSession(
801: request));
802: }
803: if (mailAppConfig == null) {
804: mailAppConfig = new Configuration();
805: }
806: }
807: } catch (Exception e) {
808: mailAppConfig = new Configuration();
809: }
810: }
811:
812: /**
813: * Handle SessionChanged events from the Portal Session.
814: * Cleanup the context when the session goes invalid.
815: *
816: * @param se session change event
817: */
818: public void ssoTokenChanged(SSOTokenEvent evt) {
819: try {
820: int evtType = evt.getType();
821:
822: if (evtType != evt.SSO_TOKEN_DESTROY
823: && evtType != evt.SSO_TOKEN_IDLE_TIMEOUT
824: && evtType != evt.SSO_TOKEN_MAX_TIMEOUT) {
825: return;
826: }
827:
828: if (currentFolder != null)
829: currentFolder.getFolder().close(true);
830: if (mailStore != null)
831: mailStore.close();
832:
833: } catch (Exception e) {
834: }
835:
836: super .ssoTokenChanged(evt);
837: }
838:
839: public void closeConnection() {
840: try {
841: if (currentFolder != null)
842: currentFolder.getFolder().close(true);
843: if (mailStore != null)
844: mailStore.close();
845: super .closeConnection();
846: } catch (Exception e) {
847: }
848: }
849:
850: }
|