📄 sendservlet.java
字号:
/*
* @(#)SendServlet.java
*
* Copyright (C) 2006 Sergey Bredikhin
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package olivax.webmail;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import oliva.mail.MessageNotFound;
public class SendServlet extends HttpServlet {
static final long serialVersionUID = 1675075694621323211L;
public SendServlet() {
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = null;
try {
request.setCharacterEncoding(Context.clntCp);
response.setContentType("text/html; charset=" + Context.clntCp);
out = response.getWriter();
HttpSession session = request.getSession();
Context myContext = (Context) session.getAttribute("myContext");
if(myContext == null) {
myContext = new Context();
session.setAttribute("myContext", myContext);
}
myContext.loadSettings(request);
// Get parameters
String action = request.getParameter("action");
boolean isNotify = false;
if(action != null && action.equalsIgnoreCase("notify"))
isNotify = true;
boolean delayedMesage = myContext._delayed_message;
if(myContext.isLoggedIn())
delayedMesage = false;
else if (!delayedMesage || isNotify) {
Context.forward(this, request, response, "/logon");
}
boolean messageLost = false;
String sentTo = null;
if(isNotify) {
int msgno = Integer.parseInt(request.getParameter("msgno"));
String msguid = request.getParameter("msguid");
if(msguid == null) msguid = "";
String strPartNo = request.getParameter("partno");
int partno = -1;
if(strPartNo != null)
partno = Integer.parseInt(strPartNo);
try {
sentTo = myContext.mailBean.sendNotifyResponse(msgno,
msguid, partno, request.getParameter("cp"),
myContext.getI18nString("_str_notify_subj"),
myContext.getI18nString("_str_notify_text"))[0].toString();
} catch (MessageNotFound mnf) {
messageLost = true;
}
} else {
// request.setCharacterEncoding(Context.clntCp);
try {
sentTo = myContext.sendMessageFormData(request, delayedMesage);
} catch (MessageNotFound mnf) {
messageLost = true;
}
}
if(sentTo != null) {
sentTo = oliva.mail.MailUtils.replaceMailto(sentTo, " ").replaceAll("<", "<").replaceAll(">", ">");
} else
sentTo = "";
if(!myContext.isLoggedIn()) {
Context.forward(this, request, response, "/logon");
}
// Main page
StringBuffer sb = new StringBuffer();
sb.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\r\n");
sb.append("<html>\r\n");
sb.append("<head>\r\n");
sb.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=").append(Context.clntCp).append("\">\r\n");
// sb.append("<meta http-equiv=\"Content-Language\" content=\"ru-RU\">\r\n");
sb.append("<meta HTTP-EQUIV=\"PRAGMA\" content=\"NO-CACHE\">\r\n");
sb.append("<title>\r\n");
sb.append(myContext.getI18nString("_str_sent_title")).append("\r\n");
sb.append("</title>\r\n");
sb.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"./oliva.css\">\r\n");
sb.append("</head>\r\n");
sb.append("<body link=\"#000033\" alink=\"#000033\" vlink=\"#000033\">\r\n");
out.print(sb.toString());
//Logo
WebPage webPage = new WebPage();
webPage.addPane(myContext.getWebLogo());
//Title
WebPane webPane = new WebPane();
webPane.setColor(WebPane.COLOR_CCCCCC);
webPane.setWidth("100%");
webPane.setHeight("35");
webPane.setContent("<font size=\"3\" face=\"arial, tahoma, verdana\"><strong>" +
myContext.getI18nString("_str_sent_title") + "</strong></font>");
webPage.addPaneToSameRow(webPane);
//Sublogo
webPane = new WebPane();
webPane.setColor(WebPane.COLOR_CCFF99);
webPane.setWidth("20%");
webPane.setHeight("35");
webPane.setContent("<font size=\"4\" color=\"#999966\" face=\"arial, tahoma, verdana\"><strong><i>"
+ myContext.getSenderDomain() + "</i></strong></font>");
webPage.addPaneToSameRow(webPane);
// Menu
sb = new StringBuffer();
sb.append("<font size=\"2\">\r\n");
sb.append("<a href=\"./list\">").append(myContext.getI18nString("_str_inbox"))
.append("</a> \r\n");
sb.append("<a href=\"javascript:{history.back();}\">")
.append(myContext.getI18nString("_str_compose")).append("</a> \r\n");
sb.append("<a href=\"./logon?action=logout\">").append(myContext.getI18nString("_str_exit")).append("</a> \r\n");
sb.append("</font>\r\n");
WebPane menuPane = new WebPane();
menuPane.setColor(WebPane.COLOR_CCCC99);
menuPane.setContent(sb.toString());
webPage.addPane(menuPane);
// Main pane
sb = new StringBuffer();
sb.append("<font size=\"2\">\r\n");
if(messageLost) {
sb.append("<strong>").append(myContext.getI18nString("_str_msg_lost"))
.append("</strong>\r\n");
} else {
if (isNotify) {
sb.append(myContext.getI18nString("_str_sent_notify"))
.append("\r\n");
} else {
sb.append(myContext.getI18nString("_str_sent_for"))
.append("\r\n");
}
sb.append("<br><strong>").append(sentTo)
.append("</strong><br>").append(myContext.getI18nString("_str_sent_sent"))
.append("\r\n");
}
sb.append("</font>\r\n");
webPane = new WebPane();
webPane.setColor(WebPane.COLOR_9999CC);
webPane.setHeight("200");
webPane.setContent(sb.toString());
webPage.addPane(webPane);
//Menu
webPage.addPane(menuPane);
webPage.show(out);
sb = new StringBuffer();
sb.append("</body>\r\n");
sb.append("</html>\r\n");
out.print(sb.toString());
out.flush();
out.close();
} catch (Exception e) {
try {
Context.sendErrorRedirect(this, request, response, "/error", e);
} catch (Exception exc) {
exc.printStackTrace();
}
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -