FileAttacher.java
上传用户:huihesys
上传日期:2007-01-04
资源大小:3877k
文件大小:4k
- /* CVS ID: $Id: FileAttacher.java,v 1.2 2000/04/06 08:02:02 wastl Exp $ */
- import net.wastl.webmail.ui.html.*;
- import net.wastl.webmail.ui.xml.*;
- import net.wastl.webmail.server.*;
- import net.wastl.webmail.server.http.*;
- import java.util.*;
- import java.text.*;
- import java.io.*;
- import javax.mail.*;
- import net.wastl.webmail.misc.*;
- /**
- * FileAttacher.java
- *
- * Created: Tue Sep 7 16:45:21 1999
- *
- * Copyright (C) 1999-2000 Sebastian Schaffert
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- /**
- * This plugin shows the Form for attaching files to a message as well as does
- * the actual attaching to a WebMailSession
- *
- * provides: attach
- * requires: composer
- *
- * @author Sebastian Schaffert
- * @version
- */
- public class FileAttacher implements URLHandler, Plugin {
-
- public static final String VERSION="1.00";
- public static final String URL="/compose/attach";
-
- Storage store;
- public FileAttacher() {
-
- }
- public void register(WebMailServer parent) {
- parent.getURLHandler().registerHandler(URL,this);
- this.store=parent.getStorage();
- parent.getConfigScheme().configRegisterStringKey("MAX ATTACH SIZE","1000000","Maximum size of attachments in bytes");
- }
- public String getName() {
- return "FileAttacher";
- }
- public String getDescription() {
- return "This URL-Handler handles file attachments for the Composer.";
- }
- public String getVersion() {
- return VERSION;
- }
- public String getURL() {
- return URL;
- }
-
- public HTMLDocument handleURL(String suburl, HTTPSession sess, HTTPRequestHeader head) throws WebMailException {
- if(sess == null) {
- throw new WebMailException("No session was given. If you feel this is incorrect, please contact your system administrator");
- }
- WebMailSession session=(WebMailSession)sess;
- UserData user=session.getUser();
- if(head.isContentSet("ADD")) {
- try {
- /* Read the file from the HTTP Header and store it in the user's session */
- ByteStore bs=(ByteStore)head.getObjContent("FILE");
- String description="";
- if(head.isContentSet("DESCRIPTION")) {
- description=new String(((ByteStore)head.getObjContent("DESCRIPTION")).getBytes());
- }
- //System.err.println("Description: "+description);
- if(bs!=null && bs.getSize() >0 ) {
- session.addWorkAttachment(bs.getName(),bs,description);
- }
- } catch(Exception e) {
- e.printStackTrace();
- throw new DocumentNotFoundException("Could not attach file. (Reason: "+e.getMessage()+")");
- }
- } else if(head.isContentSet("DELETE") && head.isContentSet("ATTACHMENTS")) {
- System.err.println("Removing "+head.getContent("ATTACHMENTS"));
- session.removeWorkAttachment(head.getContent("ATTACHMENTS"));
- }
-
- return new XHTMLDocument(session.getModel(),
- store.getStylesheet("compose_attach.xsl",
- user.getPreferredLocale(),user.getTheme()));
- }
- public String provides() {
- return "attach";
- }
- public String requires() {
- return "composer";
- }
- } // FileAttacher