⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pdasendservlet.java

📁 一个简单的java邮件系统
💻 JAVA
字号:
/*
 * @(#)PdaSendServlet.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 PdaSendServlet extends HttpServlet {

	static final long serialVersionUID = 1675075694621323211L;	
	
	public PdaSendServlet() {
	}

	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, "/pda_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.sendMessage(request, delayedMesage);
				  } catch (MessageNotFound mnf) {
					  messageLost = true;
				  }
			  }
			  if(sentTo != null) {
				sentTo = oliva.mail.MailUtils.replaceMailto(sentTo, " ").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
			  } else
				  sentTo = "";
			  if(!myContext.isLoggedIn()) {
				  Context.forward(this, request, response, "/pda_logon");  
			  }
			  
			  myContext.setNoCache(response);

			    PdaPage pdaPage = new PdaPage();
			    pdaPage.setTitle(myContext.getI18nString("_str_sent_title"));
			    
			    //Logo		    		    
			    pdaPage.addPane(myContext.getPdaLogo());
			    
			    //Title
			    PdaPane pdaPane = new PdaPane();
			    pdaPane.setColor(PdaPane.COLOR_CCCCCC);
			    pdaPane.setHeight("20");
			    pdaPane.setContent("<font size=\"3\" face=\"arial, tahoma, verdana\"><strong>" +
			    		myContext.getI18nString("_str_sent_title") + "</strong></font>");
			    pdaPage.addPane(pdaPane);		    
			    
			    //Menu
			    StringBuffer sb = new StringBuffer();
			    sb.append("<font size=\"3\">");
				sb.append("<a href=\"./pda_compose\">").append(myContext.getI18nString("_str_compose")).append("</a>&nbsp; &nbsp;");
				sb.append("<a href=\"./pda_list\">").append(myContext.getI18nString("_str_inbox")).append("</a>&nbsp; &nbsp;");						
				sb.append("<a href=\"./pda_logon?action=logout\">").append(myContext.getI18nString("_str_exit")).append("</a>&nbsp; &nbsp;");			
			    sb.append("</font>");
			    
			    PdaPane menuPane = new PdaPane();
			    menuPane.setColor(PdaPane.COLOR_FFFFFF);
			    menuPane.setContent(sb.toString());
			    pdaPage.addPane(menuPane);		    		    			  
			  	
			// Main pane
			sb = new StringBuffer();			    
			sb.append("<font size=\"3\">\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");			

		    pdaPane = new PdaPane();
		    pdaPane.setColor(PdaPane.COLOR_FFFFFF);
		    pdaPane.setContent(sb.toString());
		    pdaPage.addPane(pdaPane);		    		    

		    //Menu
		    pdaPage.addPane(menuPane);
		    
		    //Sublogo
		    pdaPane = new PdaPane();
		    pdaPane.setColor(PdaPane.COLOR_CCFF99);
		    pdaPane.setHeight("20");
		    pdaPane.setContent("<font size=\"3\" color=\"#999966\" face=\"arial, tahoma, verdana\"><strong><i>"
		    		+ myContext.getSenderDomain() + "</i></strong></font>");
		    pdaPage.addPane(pdaPane);		    		    		    
		    
		    pdaPage.show(out);

		    out.flush();
		    out.close();	    		    			
		} catch (Exception e) {
			try {
				Context.sendErrorRedirect(this, request, response, "/pda_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 + -