Dear Wiki user, You have subscribed to a wiki page or wiki category on "James Wiki" for change notification.
The following page has been changed by GuillermoGrandes: http://wiki.apache.org/james/BeanShellExamples The comment on the change is: Added RemoveMimeHeader Example ------------------------------------------------------------------------------ Can you see that this scripted code use log4j, you also can setup, see also [wiki:Self:log4j Log4J in James] + ---- + === RemoveMimeHeader === + This is an example exacted from request of MailetIdeas. + + ==== Config of Scripted RemoveMimeHeader: SAR-INF/config.xml ==== + + {{{ + <mailet match="All" class="BeanShell"> + <script>/opt/james/bsh/mimeheads.bsh</script> + <method>RemoveMimeHeader</method> + <name>X-BadHeader</name> + </mailet> + }}} + + ==== RemoveMimeHeader BeanShell Mailet: /opt/james/bsh/mimeheads.bsh ==== + + {{{ + #!java + /* + Scripted RemoveMimeHeader for BeanShell and James + Author: Guillermo Grandes + + The ASF licenses this file to you under the Apache License v2.0 + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND + + http://www.apache.org/licenses/LICENSE-2.0 + */ + import javax.mail.internet.MimeMessage; + + setStrictJava(true); + + void RemoveMimeHeader(Mail mail, Mailet ma) { + // + // Init parameters + String headerName = ma.getInitParameter("name"); + + // Check if needed config values are used + if (headerName == null || headerName.equals("")) { + ma.log("Please configure a name"); + } + + try { + MimeMessage message = mail.getMessage(); + + //Set the header name and value (supplied at init time). + message.removeHeader(headerName); + message.saveChanges(); + } catch (javax.mail.MessagingException me) { + ma.log(me.getMessage()); + } + } + return this; + }}} + + In only 10 mins, is fantastic, right? :-) + + See also [http://svn.apache.org/viewvc/james/server/branches/v2.3/src/java/org/apache/james/transport/mailets/SetMimeHeader.java?view=markup SetMimeHeader] +