You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by pg...@apache.org on 2002/08/23 09:48:31 UTC

cvs commit: jakarta-james/src/java/org/apache/james/transport/mailets GenericListserv.java AvalonListserv.java

pgoldstein    2002/08/23 00:48:31

  Modified:    src/java/org/apache/james/transport/mailets
                        GenericListserv.java AvalonListserv.java
  Log:
  Changing the listserver behavior to allow administrator specification of whether the subject prefix is bracketed.
  
  Also added code to elegantly handle a syntactically invalid member email address on the list
  
  Thanks to Noel Bergman
  
  Revision  Changes    Path
  1.9       +22 -8     jakarta-james/src/java/org/apache/james/transport/mailets/GenericListserv.java
  
  Index: GenericListserv.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/transport/mailets/GenericListserv.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- GenericListserv.java	16 Aug 2002 17:05:49 -0000	1.8
  +++ GenericListserv.java	23 Aug 2002 07:48:31 -0000	1.9
  @@ -57,11 +57,22 @@
       }
   
       /**
  -     * An optional subject prefix which will be surrounded by [].
  +     * An optional subject prefix.
        */
       public abstract String getSubjectPrefix() throws MessagingException;
   
       /**
  +     * Should the subject prefix be automatically surrounded by [].
  +     *
  +     * @return whether the subject prefix will be surrounded by []
  +     *
  +     * @throws MessagingException never, for this implementation
  +     */
  +    public boolean isPrefixAutoBracketed() throws MessagingException {
  +        return true; // preserve old behavior unless subclass overrides.
  +    }
  +
  +    /**
        * Processes the message.  Assumes it is the only recipient of this forked message.
        */
       public final void service(Mail mail) throws MessagingException {
  @@ -105,13 +116,16 @@
               }
   
               //Set the subject if set
  -            if (getSubjectPrefix() != null) {
  -                StringBuffer prefixBuffer =
  -                    new StringBuffer(64)
  -                        .append("[")
  -                        .append(getSubjectPrefix())
  -                        .append("]");
  -                String prefix = prefixBuffer.toString();
  +            String prefix = getSubjectPrefix();
  +            if (prefix != null) {
  +                if (isPrefixAutoBracketed()) {
  +                    StringBuffer prefixBuffer =
  +                        new StringBuffer(64)
  +                            .append("[")
  +                            .append(prefix)
  +                            .append("]");
  +                    prefix = prefixBuffer.toString();
  +                }
                   String subj = message.getSubject();
                   if (subj == null) {
                       subj = "";
  
  
  
  1.5       +111 -8    jakarta-james/src/java/org/apache/james/transport/mailets/AvalonListserv.java
  
  Index: AvalonListserv.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/transport/mailets/AvalonListserv.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AvalonListserv.java	19 Aug 2002 18:57:07 -0000	1.4
  +++ AvalonListserv.java	23 Aug 2002 07:48:31 -0000	1.5
  @@ -23,11 +23,33 @@
    * MailingListServer capability.
    * 
    * <p>Requires a configuration element in the .conf.xml file of the form:
  - * <br>&lt;repositoryName&gt;name of user repository configured in UsersStore block &lt;/repositoryName&gt;
  - * <br>&lt;membersonly&gt;
  - * <br>&lt;attachmentsallowed&gt;
  - * <br>&lt;replytolist&gt;
  - * <br>&lt;subjectprefix&gt;
  + * <br>  &lt;mailet match="RecipientIs=LIST-ADDRESS" class="AvalonListserv"&gt;
  + * <br>    &lt;repositoryName&gt;LIST-NAME&lt;/repositoryName&gt;
  + * <br>    &lt;membersonly&gt;[true|false]&lt;/membersonly&gt;
  + * <br>    &lt;attachmentsallowed&gt;[true|false]&lt;/attachmentsallowed&gt;
  + * <br>    &lt;replytolist&gt;[true|false]&lt;/replytolist&gt;
  + * <br>    &lt;autobracket&gt;[true|false]&lt;/autobracket&gt;
  + * <br>    &lt;subjectprefix [xml:space="preserve"]&gt;SUBJECT-PREFIX&lt;/subjectprefix&gt;
  + * <br>  &lt;/mailet&gt;
  + * <p>repositoryName - the name of a user repository configured in the
  + * UsersStore block, e.g.,
  + * <br>  &lt;repository name="list-name" class="org.apache.james.userrepository.ListUsersJdbcRepository" destinationURL="db://maildb/lists/list-name"&gt;
  + * <br>    &lt;sqlFile&gt;file://conf/sqlResources.xml&lt;/sqlFile&gt;
  + * <br>  &lt;/repository&gt;
  + * <p>or
  + * <br>  &lt;repository name="list-name" class="org.apache.james.userrepository.UsersFileRepository"&gt;
  + * <br>    &lt;destination URL="file://var/lists/list-name/"/&gt;
  + * <br>  &lt;/repository&gt;
  + * <p>membersonly - if true only members can post to the list
  + * <p>attachmentsallowed - if false attachments are not allowed
  + * <p>replytolist - if true, replies go back to the list address; if
  + * false they go to the sender.
  + * <p>subjectprefix - a prefix that will be inserted at the front of
  + * the subject.  If autobracketing is disabled (see below), the
  + * xml:space="preserve" attribute can be used to precisely control the
  + * prefix.
  + * <p>autobracket - if true the subject prefix will be rendered as
  + * "[PREFIX] ", if false, the prefix will be used literally.
    *
    * @author  <a href="sergek@lokitech.com">Serge Knystautas </a>
    * @version This is $Revision$
  @@ -35,27 +57,64 @@
    */
   public class AvalonListserv extends GenericListserv {
   
  +    /**
  +     * Whether only members can post to the list
  +     */
       protected boolean membersOnly = false;
  +
  +    /**
  +     * Whether attachments can be sent to the list
  +     */
       protected boolean attachmentsAllowed = true;
  +
  +    /**
  +     * Whether the reply-to header should be set to the list address
  +     */
       protected boolean replyToList = true;
  +
  +    /**
  +     * A String to prepend to the subject of the message when it
  +     * is sent to the list
  +     */
       protected String subjectPrefix = null;
  +
  +    /**
  +     * Whether the subject prefix should be bracketed with '[' and ']'
  +     */
  +    protected boolean autoBracket = true;
  +
  +    /**
  +     * The repository containing the users on this list
  +     */
       private UsersRepository members;
   
  +    /**
  +     * Initialize the mailet
  +     */
       public void init() {
           try {
               membersOnly = new Boolean(getInitParameter("membersonly")).booleanValue();
           } catch (Exception e) {
  +            // Ignore any exceptions, default to false
           }
           try {
               attachmentsAllowed = new Boolean(getInitParameter("attachmentsallowed")).booleanValue();
           } catch (Exception e) {
  +            // Ignore any exceptions, default to true
           }
           try {
               replyToList = new Boolean(getInitParameter("replytolist")).booleanValue();
           } catch (Exception e) {
  +            // Ignore any exceptions, default to true
           }
           subjectPrefix = getInitParameter("subjectprefix");
   
  +        try {
  +            autoBracket = new Boolean(getInitParameter("autobracket")).booleanValue();
  +        } catch (Exception e) {
  +            // Ignore any exceptions, default to true
  +        }
  +
           ComponentManager compMgr = (ComponentManager)getMailetContext().getAttribute(Constants.AVALON_COMPONENT_MANAGER);
           try {
               UsersStore usersStore = (UsersStore)compMgr.lookup("org.apache.james.services.UsersStore");
  @@ -72,25 +131,69 @@
       public Collection getMembers() throws ParseException {
           Collection reply = new Vector();
           for (Iterator it = members.list(); it.hasNext(); ) {
  -            reply.add(new MailAddress(it.next().toString()));
  +            String member = it.next().toString();
  +            try {
  +                reply.add(new MailAddress(member));
  +            }
  +            catch(Exception e) {
  +                // Handle an invalid subscriber address by logging it and
  +                // proceeding to the next member.
  +                StringBuffer logBuffer =
  +                    new StringBuffer(1024)
  +                            .append("Invalid subscriber address: ")
  +                            .append(member)
  +                            .append(" caused: ")
  +                            .append(e.getMessage());
  +                log(logBuffer.toString());
  +            }
           }
           return reply;
       }
   
  +    /**
  +     * Get whether posting to this list is restricted to list members
  +     *
  +     * @return whether posting to this list is restricted to list members
  +     */
       public boolean isMembersOnly() {
           return membersOnly;
       }
   
  +    /**
  +     * Get whether attachments can be sent to this list
  +     *
  +     * @return whether attachments can be sent to this list
  +     */
       public boolean isAttachmentsAllowed() {
           return attachmentsAllowed;
       }
   
  +    /**
  +     * Get whether the reply-to header for messages sent to this list
  +     * will be replaced with the list address
  +     *
  +     * @return whether replies to messages posted to this list will go to the entire list
  +     */
       public boolean isReplyToList() {
           return replyToList;
       }
   
  +    /**
  +     * Get the prefix prepended to the subject line
  +     *
  +     * @return whether the prefix for subjects on this list will be bracketed.
  +     */
       public String getSubjectPrefix() {
           return subjectPrefix;
  +    }
  +
  +    /**
  +     * Return whether the prefix for subjects on this list will be bracketed.
  +     *
  +     * @return whether the prefix for subjects on this list will be bracketed.
  +     */
  +    public boolean isPrefixAutoBracketed() {
  +        return autoBracket;
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>