X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmircoders%2Fservlet%2FServletModuleOpenIndy.java;h=56a4fdfd027117516a2dd192531237ac714bf4c2;hb=4943e2fa10f39dfec27f22fe2ab4be59586d8e9d;hp=b22ea33e2184af0ef3ef295b5f6fabf4c4952168;hpb=f843cee5a2b61388aa3dc90256b704c78f16e3e6;p=mir.git diff --git a/source/mircoders/servlet/ServletModuleOpenIndy.java b/source/mircoders/servlet/ServletModuleOpenIndy.java index b22ea33e..56a4fdfd 100755 --- a/source/mircoders/servlet/ServletModuleOpenIndy.java +++ b/source/mircoders/servlet/ServletModuleOpenIndy.java @@ -44,6 +44,8 @@ import freemarker.template.*; import com.oreilly.servlet.multipart.*; import com.oreilly.servlet.*; +import org.apache.commons.net.smtp.*; + import org.xml.sax.InputSource; import org.xml.sax.XMLReader; @@ -67,6 +69,7 @@ import mir.entity.*; import mir.storage.*; import mir.media.*; import mir.log.*; +import mir.util.StringRoutines; import mircoders.entity.*; import mircoders.storage.*; @@ -84,7 +87,7 @@ import mircoders.search.*; * open-postings to the newswire * * @author mir-coders group - * @version $Id: ServletModuleOpenIndy.java,v 1.50 2002/12/14 17:36:17 zapata Exp $ + * @version $Id: ServletModuleOpenIndy.java,v 1.53 2003/01/12 22:25:18 john Exp $ * */ @@ -96,6 +99,7 @@ public class ServletModuleOpenIndy extends ServletModule private String postingFormTemplate, postingFormDoneTemplate, postingFormDupeTemplate; private String searchResultsTemplate; + private String prepareMailTemplate,sentMailTemplate; private ModuleContent contentModule; private ModuleComment commentModule; private ModuleImages imageModule; @@ -117,6 +121,8 @@ public class ServletModuleOpenIndy extends ServletModule postingFormDoneTemplate = MirConfig.getProp("ServletModule.OpenIndy.PostingDoneTemplate"); postingFormDupeTemplate = MirConfig.getProp("ServletModule.OpenIndy.PostingDupeTemplate"); searchResultsTemplate = MirConfig.getProp("ServletModule.OpenIndy.SearchResultsTemplate"); + prepareMailTemplate = MirConfig.getProp("ServletModule.OpenIndy.PrepareMailTemplate"); + sentMailTemplate = MirConfig.getProp("ServletModule.OpenIndy.SentMailTemplate"); directOp = MirConfig.getProp("DirectOpenposting").toLowerCase(); passwdProtection = MirConfig.getProp("PasswdProtection").toLowerCase(); mainModule = new ModuleComment(DatabaseComment.getInstance()); @@ -197,6 +203,7 @@ public class ServletModuleOpenIndy extends ServletModule withValues.put(k,StringUtil.removeHTMLTags(v)); } withValues.put("is_published","1"); + withValues.put("to_comment_status","1"); //checking the onetimepasswd if(passwdProtection.equals("yes")){ @@ -261,10 +268,13 @@ public class ServletModuleOpenIndy extends ServletModule } String maxMedia = MirConfig.getProp("ServletModule.OpenIndy.MaxMediaUploadItems"); + String defaultMedia = MirConfig.getProp("ServletModule.OpenIndy.DefaultMediaUploadItems"); String numOfMedia = req.getParameter("medianum"); + if(numOfMedia==null||numOfMedia.equals("")){ - numOfMedia="1"; - } else if(Integer.parseInt(numOfMedia) > Integer.parseInt(maxMedia)) { + numOfMedia=defaultMedia; + } + else if(Integer.parseInt(numOfMedia) > Integer.parseInt(maxMedia)) { numOfMedia = maxMedia; } @@ -352,7 +362,10 @@ public class ServletModuleOpenIndy extends ServletModule if (k.equals("content_data")){ //this doesn't quite work yet, so for now, all html goes //withValues.put(k,StringUtil.approveHTMLTags(v)); - //withValues.put(k,StringUtil.removeHTMLTags(v)); + withValues.put(k,StringUtil.deleteForbiddenTags(v)); + } else if (k.equals("description")) { + String tmp = StringUtil.deleteForbiddenTags(v); + withValues.put(k,StringUtil.deleteHTMLTableTags(tmp)); } else { withValues.put(k,StringUtil.removeHTMLTags(v)); } @@ -417,7 +430,10 @@ public class ServletModuleOpenIndy extends ServletModule throw new ServletModuleException(t.getMessage()); } } - catch (FileHandlerException e) { throw new ServletModuleException("MediaException: "+ e.getMessage());} + catch (FileHandlerException e) { + e.printStackTrace(System.out); + throw new ServletModuleException("MediaException: "+ e.getMessage()); + } catch (IOException e) { throw new ServletModuleException("IOException: "+ e.getMessage());} catch (StorageObjectException e) { throw new ServletModuleException("StorageObjectException" + e.getMessage());} catch (ModuleException e) { throw new ServletModuleException("ModuleException"+e.getMessage());} @@ -425,6 +441,134 @@ public class ServletModuleOpenIndy extends ServletModule deliver(req, res, mergeData, postingFormDoneTemplate); } + /* + * Method for preparing and sending a content as an email message + */ + + public void mail(HttpServletRequest req, HttpServletResponse res) + throws ServletModuleException, ServletModuleUserException { + String aid = req.getParameter("mail_aid"); + if (aid == null){ + throw new ServletModuleUserException("An article id must be specified in requests to email an article. Something therefore went badly wrong...."); + } + + String to = req.getParameter("mail_to"); + String from = req.getParameter("mail_from"); + String from_name = req.getParameter("mail_from_name"); + String comment = req.getParameter("mail_comment"); + String mail_language = req.getParameter("mail_language"); + + SimpleHash mergeData = new SimpleHash(); + + if (to == null || from == null || from_name == null|| to.equals("") || from.equals("") || from_name.equals("") || mail_language == null || mail_language.equals("")){ + + for (Enumeration theParams = req.getParameterNames(); theParams.hasMoreElements() ;) { + String pName=(String)theParams.nextElement(); + if (pName.startsWith("mail_")){ + mergeData.put(pName,new SimpleScalar(req.getParameter(pName))); + } + } + deliver(req,res,mergeData,prepareMailTemplate); + } + else { + //run checks on to and from and mail_language to make sure no monkey business occurring + if (mail_language.indexOf('.') != -1 || mail_language.indexOf('/') != -1 ){ + throw new ServletModuleUserException("Sorry, you've entered an illegal character into the language field. Go back and try again, asshole."); + } + if (to.indexOf('\n') != -1 + || to.indexOf('\r') != -1 + || to.indexOf(',') != -1 + || from.indexOf('\n') != -1 + || from.indexOf('\r') != -1 + || from.indexOf(',') != -1 ){ + throw new ServletModuleUserException("Sorry, you've entered an illegal character into the from or to field. Go back and try again."); + } + EntityContent contentEnt; + try{ + contentEnt = (EntityContent)contentModule.getById(aid); + } + catch (ModuleException e){ + throw new ServletModuleUserException("Couldn't get content for article "+aid); + } + String producerStorageRoot=MirConfig.getProp("Producer.StorageRoot"); + String producerDocRoot=MirConfig.getProp("Producer.DocRoot"); + String publishPath = contentEnt.getValue("publish_path"); + String txtFilePath = producerStorageRoot + producerDocRoot + "/" + mail_language + + publishPath + "/" + aid + ".txt"; + + + File inputFile = new File(txtFilePath); + String content; + + try{ + FileReader in = new FileReader(inputFile); + StringWriter out = new StringWriter(); + int c; + while ((c = in.read()) != -1) + out.write(c); + in.close(); + content= out.toString(); + } + catch (FileNotFoundException e){ + throw new ServletModuleUserException("No text file found in " + txtFilePath); + } + catch (IOException e){ + throw new ServletModuleUserException("Problem reading file in " + txtFilePath); + } + // add some headers + content = "To: " + to + "\nReply-To: "+ from + "\n" + content; + // put in the comment where it should go + if (comment != null) { + String commentTextToInsert = "\n\nAttached comment from " + from_name + ":\n" + comment; + try { + content=StringRoutines.performRegularExpressionReplacement(content,"!COMMENT!",commentTextToInsert); + } + catch (Exception e){ + throw new ServletModuleUserException("Problem doing regular expression replacement " + e.toString()); + } + } + else{ + try { + content=StringRoutines.performRegularExpressionReplacement(content,"!COMMENT!",""); + } + catch (Exception e){ + throw new ServletModuleUserException("Problem doing regular expression replacement " + e.toString()); + } + } + + SMTPClient client=new SMTPClient(); + try { + int reply; + client.connect("localhost"); + System.out.print(client.getReplyString()); + + reply = client.getReplyCode(); + + if(!SMTPReply.isPositiveCompletion(reply)) { + client.disconnect(); + throw new ServletModuleUserException("SMTP server refused connection."); + } + + client.sendSimpleMessage(MirConfig.getProp("ServletModule.OpenIndy.EmailIsFrom"),to,content); + + client.disconnect(); + //mission accomplished + deliver(req,res,mergeData,sentMailTemplate); + + } catch(IOException e) { + if(client.isConnected()) { + try { + client.disconnect(); + } catch(IOException f) { + // do nothing + } + } + throw new ServletModuleUserException(e.toString()); + } + } + } + + /* * Method for querying a lucene index */