public class WebmailIntroTag extends TagSupport {
@Override
public int doStartTag() throws JspException {
HttpSession session = this.pageContext.getSession();
IWebMailManager webmailManager = (IWebMailManager) ApsWebApplicationUtils.getBean(JpwebmailSystemConstants.WEBMAIL_MANAGER, pageContext);
Store store = null;
WebMailIntroInfo info = new WebMailIntroInfo();
try {
UserDetails currentUser = (UserDetails) session.getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
if (currentUser.getUsername().equals(SystemConstants.GUEST_USER_NAME)) return super.doStartTag();
if (currentUser.getUsername().equals(SystemConstants.ADMIN_USER_NAME) && !this.isCheckAdmin()) return super.doStartTag();
store = webmailManager.initInboxConnection(currentUser.getUsername(), currentUser.getPassword());
} catch (Throwable t) {
webmailManager.closeConnection(store);
this.pageContext.setAttribute(this.getVar(), info);
ApsSystemUtils.logThrowable(t, this, "doStartTag");
return super.doStartTag();
}
try {
Folder inboxFolder = store.getFolder("INBOX");
info.setExistMailbox(true);
info.setMessageCount(inboxFolder.getMessageCount());
info.setNewMessageCount(inboxFolder.getNewMessageCount());
info.setUnreadMessageCount(inboxFolder.getUnreadMessageCount());
this.pageContext.setAttribute(this.getVar(), info);
} catch (Throwable t) {
ApsSystemUtils.logThrowable(t, this, "doStartTag");
throw new JspException("Errore inizializzazione tag", t);
} finally {
webmailManager.closeConnection(store);
}
return super.doStartTag();
}