2
* Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
8
* - Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
11
* - Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
15
* - Neither the name of Sun Microsystems nor the names of its
16
* contributors may be used to endorse or promote products derived
17
* from this software without specific prior written permission.
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
import javax.mail.internet.*;
38
import javax.mail.search.*;
39
import javax.servlet.jsp.*;
40
import javax.servlet.jsp.tagext.*;
43
* Custom tag for listing messages. The scripting variable is only
44
* within the body of the tag.
46
public class ListMessagesTag extends BodyTagSupport {
47
private String folder;
48
private String session;
49
private int msgNum = 0;
50
private int messageCount = 0;
51
private Message message;
52
private Message[] messages;
53
private MessageInfo messageinfo;
56
* folder attribute getter method.
58
public String getFolder() {
63
* session attribute getter method.
65
public String getSession() {
70
* folder setter method.
72
public void setFolder(String folder) {
77
* session attribute setter method.
79
public void setSession(String session) {
80
this.session = session;
84
* Method for processing the start of the tag.
86
public int doStartTag() throws JspException {
87
messageinfo = new MessageInfo();
90
Folder folder = (Folder)pageContext.getAttribute(
91
getFolder(), PageContext.SESSION_SCOPE);
92
FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.DELETED), false);
93
messages = folder.search(ft);
94
messageCount = messages.length;
96
} catch (Exception ex) {
97
throw new JspException(ex.getMessage());
100
if (messageCount > 0) {
102
return BodyTag.EVAL_BODY_TAG;
104
return BodyTag.SKIP_BODY;
108
* Method for processing the body content of the tag.
110
public int doAfterBody() throws JspException {
112
BodyContent body = getBodyContent();
114
body.writeOut(getPreviousOut());
115
} catch (IOException e) {
116
throw new JspTagException("IterationTag: " + e.getMessage());
119
// clear up so the next time the body content is empty
122
if (msgNum < messageCount) {
124
return BodyTag.EVAL_BODY_TAG;
126
return BodyTag.SKIP_BODY;
131
* Helper method for retrieving messages.
133
private void getMessage() throws JspException {
134
message = messages[msgNum++];
135
messageinfo.setMessage(message);
136
pageContext.setAttribute(getId(), messageinfo);