001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.tag; 020 021import javax.servlet.jsp.tagext.Tag; 022 023import lucee.runtime.exp.ApplicationException; 024import lucee.runtime.exp.PageException; 025import lucee.runtime.ext.tag.BodyTagImpl; 026 027/** 028* Specifies one part of a multipart e-mail message. Can only be used in the cfmail tag. 029* You can use more than one cfmailpart tag within a cfmail tag 030* 031* 032* 033**/ 034public final class MailPart extends BodyTagImpl { 035 036 lucee.runtime.net.mail.MailPart part=new lucee.runtime.net.mail.MailPart(); 037 038 @Override 039 public void release() { 040 super.release(); 041 part=new lucee.runtime.net.mail.MailPart(); 042 } 043 044 /** 045 * @param type The type to set. 046 * @throws ApplicationException 047 */ 048 public void setType(String type) throws ApplicationException { 049 part.setType(type); 050 } 051 052 053 /** 054 * @param charset The charset to set. 055 */ 056 public void setCharset(String charset) { 057 part.setCharset(charset); 058 } 059 060 /** 061 * @param wraptext The wraptext to set. 062 */ 063 public void setWraptext(double wraptext) { 064 part.setWraptext((int)wraptext); 065 } 066 067 @Override 068 public int doStartTag() { 069 070 return EVAL_BODY_BUFFERED; 071 } 072 073 @Override 074 public void doInitBody() { 075 076 } 077 078 @Override 079 public int doAfterBody() { 080 part.setBody(bodyContent.getString()); 081 return SKIP_BODY; 082 } 083 084 @Override 085 public int doEndTag() throws PageException { 086 087 getMail().addPart(part); 088 /*String type = part.getType(); 089 if(StringUtil.isEmpty(part.getCharset())) part.setCharset(mail.getCharset()); 090 if(type!=null && (type.equals("text/plain") || type.equals("plain") || type.equals("text"))){ 091 part.isPlain(true); 092 mail.setBodyPart(part); 093 } 094 else if(type!=null && (type.equals("text/html") || type.equals("html") || type.equals("htm"))){ 095 part.isHTML(true); 096 mail.setBodyPart(part); 097 } 098 else { 099 100 getMail().setParam(type, null, "susi", part.getBody(), "inline", null); 101 }*/ 102 // throw new ApplicationException("attribute type of tag mailpart has an invalid values","valid values are [plain,text,html] but value is now ["+type+"]"); 103 104 105 106 return EVAL_PAGE; 107 } 108 109 110 111 private Mail getMail() throws ApplicationException { 112 Tag parent=getParent(); 113 while(parent!=null && !(parent instanceof Mail)) { 114 parent=parent.getParent(); 115 } 116 if(parent instanceof Mail)return (Mail) parent; 117 throw new ApplicationException("Wrong Context, tag MailPart must be inside a Mail tag"); 118 } 119}