📄 composeservlet.java
字号:
/*
* @(#)ComposeServlet.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.common.OlivaUtils;
import oliva.mail.MailUtils;
import oliva.mail.SimpleMessage;
public class ComposeServlet extends HttpServlet {
static final long serialVersionUID = 1675075694621323211L;
public ComposeServlet() {
}
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);
}
if(!myContext.isLoggedIn()) {
Context.forward(this, request, response, "/logon");
}
myContext.setNoCache(response);
//Get parameters
String action = request.getParameter("action");
String msgno = request.getParameter("msgno");
String msguid = request.getParameter("msguid");
String strPartNo = request.getParameter("partno");
int partno = -1;
if(strPartNo != null)
partno = Integer.parseInt(strPartNo);
String cp = request.getParameter("cp");
SimpleMessage msg = null;
boolean isReply = false;
boolean isDelayed = false;
String fwdNo = null;
String newTo = null;
boolean initialLost = false;
if(action != null) {
if(msgno != null) {
int iMsgNo = Integer.parseInt(msgno);
if(action.equalsIgnoreCase("reply")) {
if(partno == -1) {
msg = myContext.mailBean.getReplyMessage(iMsgNo, msguid, cp, true);
} else {
msg = null;
oliva.mail.Message message = myContext.getMessage(iMsgNo, msguid, null);
if (message != null) {
msg = myContext.mailBean.getReplyMessage(message.getRfc822Part(partno).apiMessage, cp, true);
}
}
if(msg != null) {
msg.From = oliva.mail.MailUtils.getHtmlAddressList(msg.From, null);
msg.ReplyTo = oliva.mail.MailUtils.getHtmlAddressList(msg.ReplyTo, null);
msg.To = oliva.mail.MailUtils.getHtmlAddressList(msg.To, null);
msg.Cc = oliva.mail.MailUtils.getHtmlAddressList(msg.Cc, null);
if(msg.text != null) {
java.lang.StringBuffer sb = new java.lang.StringBuffer();
sb.append("\n\n\n-----Original Message-----\nFrom: " + msg.From +
"\nSent: " + oliva.common.OlivaUtils.getDateString(msg.sentDate, myContext.lang, myContext.getI18nString("_settings.dateFormat")) +
"\nTo: " + msg.To);
if(msg.Cc.length() != 0)
sb.append("\nCc: " + msg.Cc);
sb.append("\nSubject: " + msg.Subject + "\n\n");
sb.append(msg.text);
msg.text = sb.toString();
}
msg.Subject = MailUtils.getPrefixedSubject(msg.Subject, "Re");
isReply = true;
} else
initialLost = true;
}
if(action.equalsIgnoreCase("forward")) {
if(partno == -1) {
msg = myContext.mailBean.getReplyMessage(iMsgNo, msguid, cp, false);
} else {
msg = null;
oliva.mail.Message message = myContext.getMessage(iMsgNo, msguid, null);
if(message != null) {
msg = myContext.mailBean.getReplyMessage(message.getRfc822Part(partno).apiMessage, cp, false);
}
}
if(msg != null) {
msg.Subject = MailUtils.getPrefixedSubject(msg.Subject, "Fwd");
fwdNo = String.valueOf(iMsgNo);
} else
initialLost = true;
}
}
if(action.equalsIgnoreCase("new")) {
newTo = request.getParameter("to");
if(newTo != null)
newTo = oliva.common.OlivaUtils.getStringInternals(newTo, Context.clntCp);
}
if(action.equalsIgnoreCase("delayed")) {
msg = myContext.getDelayedMessage();
if(msg != null) {
isDelayed = true;
myContext.emptyDelayedMessage();
}
}
}
if(newTo == null) newTo = "";
// 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_compose_title")).append("\r\n");
sb.append("</title>\r\n");
sb.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"./oliva.css\">\r\n");
sb.append("<script type=\"text/javascript\">\r\n");
sb.append("<!--\r\n");
sb.append("var i = 0\r\n");
sb.append("function moreFiles() {\r\n");
sb.append(" if(i > 10)\r\n");
sb.append(" return false;\r\n");
sb.append(" var td = document.getElementById(\"td1\");\r\n");
sb.append(" var k = 4;\r\n");
sb.append(" if(i < 4) k = 2;\r\n");
sb.append(" if(i < 2) k = 1;\r\n");
sb.append(" for(var j = 1; j <= k; j ++) {\r\n");
sb.append(" var div = document.createElement(\"div\");\r\n");
sb.append(" div.innerHTML = \"<input type=\\\"file\\\" size=\\\"40\\\" name=\\\"attachment\" + ++i + \"\\\"/><br/>\"\r\n");
sb.append(" td.appendChild(div);\r\n");
sb.append(" }\r\n");
sb.append(" return true;\r\n");
sb.append("}\r\n\r\n");
sb.append("function openWnd(url,wnd_name,width,height) {\r\n");
sb.append(" var save = window.open(url,wnd_name,'width='+width+',height='+height+',status=yes,menubar=no,resizable=yes,scrollbars=yes,left='+String((screen.width-width)/2)+',top='+String((screen.height-height)/2));\r\n");
sb.append("}\r\n");
sb.append("// -->\r\n");
sb.append("</script>\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 = 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_compose_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=\"javascript:{history.back();}\">")
.append(myContext.getI18nString("_str_back")).append("</a> \r\n");
if(myContext._storage_enabled) {
sb.append("<a href=\"./addr_form?action=search\">")
.append(myContext.getI18nString("_str_addr_list_link"))
.append("</a> \r\n");
}
sb.append("<a href=\"./list\">")
.append(myContext.getI18nString("_str_inbox")).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);
//Hint
sb = new StringBuffer();
if (initialLost) {
sb.append("<font size=\"2\" color=\"#cc0000\" face=\"Arial, Verdana, Tahoma\"><strong>")
.append(myContext.getI18nString("_str_msg_lost"))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -