01: /*
02: * MessageTag
03: * @(#)MessageTag.java 1.2 03/28/01 Sun Microsystems
04: *
05: * Copyright 2000 Sun Microsystems, Inc. All rights reserved.
06: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
07: */
08:
09: package com.sun.portal.wireless.taglibs.mail;
10:
11: import javax.mail.*;
12: import javax.mail.internet.*;
13: import javax.mail.search.*;
14:
15: import com.sun.portal.wireless.taglibs.base.*;
16:
17: /**
18: *
19: * @version 1.0
20: * @see com.sun.portal.wireless.taglibs.base.BeanTag
21: */
22:
23: public class MessageTag extends BeanTag {
24:
25: String msgid = null;
26: String index = null;
27:
28: public Object newBean() throws Exception {
29: MailContext mc = MailContext.getContext(pageContext);
30: javax.mail.Session mailsession = mc.getMailSession();
31: MsgBean mb = new MsgBean(mailsession, mc.getCharset(), mc
32: .getFrom(), mc.getTimeZone());
33: mb.setTextEncoding(mc.getTextEncoding());
34: return mb;
35: }
36:
37: public void setMsgid(String msgid) {
38: this .msgid = evalAttribute(msgid);
39: }
40:
41: public void setIndex(String index) {
42: this .index = evalAttribute(index);
43: }
44:
45: public Object findBean() throws Exception {
46: MailContext mc = MailContext.getContext(pageContext);
47: MsgBean bean;
48:
49: if (msgid != null) {
50: int idx = 0;
51: idx = Integer.parseInt(msgid);
52:
53: Folder folder = mc.getCurrentFolder().getFolder();
54: Message msg = folder.getMessage(idx);
55:
56: bean = new MsgBean(msg, mc.getFrom(), mc.getTimeZone());
57:
58: if (id != null) {
59: pageContext.setAttribute(id, bean);
60: }
61:
62: return bean;
63: }
64:
65: if (index != null) {
66: int idx = 0;
67: idx = Integer.parseInt(index);
68:
69: MsgBean[] msgs = mc.getMsgsCollection();
70: bean = msgs[idx];
71:
72: if (id != null) {
73: pageContext.setAttribute(id, bean);
74: }
75:
76: return bean;
77: }
78:
79: return super.findBean();
80: }
81: }
|