<commit_before>/*****************************************************************************
 * Copyright (C) The Apache Software Foundation. All rights reserved.        *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Apache Software License *
 * version 1.1, a copy of which has been included  with this distribution in *
 * the LICENSE file.                                                         *
 *****************************************************************************/

package org.apache.james.transport.mailets;

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import org.apache.avalon.*;
import org.apache.james.*;
import org.apache.james.usermanager.*;
import org.apache.avalon.blocks.*;
import org.apache.mailet.*;
import org.apache.james.transport.*;

/**
 * Routes a given email address to a list of members, based on simple
 * listserv settings.
 *
 * Sample configuration:
 * <pre>
 * <mailet match="RecipientIs=<EMAIL>" class="MiniListserv">
 *     <membersonly>true</membersonly>
 *     <attachmentsallowed>false</attachmentsallowed>
 *     <replytolist>true</replytolist>
 *     <member><EMAIL></member>
 *     <member><EMAIL></member>
 * </mailet>
 * </pre>
 * @author  <NAME> <<EMAIL>>
 */
public class PicoListManager extends GenericMailet {

    private String listName;
    private UsersRepository members;
    private String subscribe;
    private String unsubscribe;

    public void init () {
        listName = getInitParameter("listName");
        subscribe = getInitParameter("subscribe");
        if (subscribe == null) {
            subscribe = listName + "-on";
        }
        unsubscribe = getInitParameter("unsubscribe");
        if (unsubscribe == null) {
            unsubscribe = listName + "-off";
        }

        ComponentManager comp = (ComponentManager)getMailetContext().getAttribute(Constants.AVALON_COMPONENT_MANAGER);
        UserManager manager = (UserManager) comp.getComponent(Resources.USERS_MANAGER);
        members = (UsersRepository) manager.getUserRepository("list-" + listName);
        //transport = (Mailet) context.get("transport");
        //log("PicoListserv: " + listName + " sub " + subscribe + " unsub " + unsubscribe + "-" + transport);
    }

    public void service(Mail mail) throws MailetException {
        Collection recipients = mail.getRecipients();
        MailAddress recipient = (MailAddress) recipients.iterator().next();
        if (recipients.size() != 1) {
            log("bouncing back: Cannot handle more than one recipient");
            getMailetContext().bounce(mail, "Cannot handle more than one recipient");<commit_msg>Adding messaging exception to throws... still unclear on how to best handle -on -off subscription system.<commit_after>/*****************************************************************************
 * Copyright (C) The Apache Software Foundation. All rights reserved.        *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Apache Software License *
 * version 1.1, a copy of which has been included  with this distribution in *
 * the LICENSE file.                                                         *
 *****************************************************************************/

package org.apache.james.transport.mailets;

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import org.apache.avalon.*;
import org.apache.james.*;
import org.apache.james.usermanager.*;
import org.apache.avalon.blocks.*;
import org.apache.mailet.*;
import org.apache.james.transport.*;

/**
 * Routes a given email address to a list of members, based on simple
 * listserv settings.
 *
 * Sample configuration:
 * <pre>
 * <mailet match="RecipientIs=<EMAIL>" class="MiniListserv">
 *     <membersonly>true</membersonly>
 *     <attachmentsallowed>false</attachmentsallowed>
 *     <replytolist>true</replytolist>
 *     <member><EMAIL></member>
 *     <member><EMAIL></member>
 * </mailet>
 * </pre>
 * @author  <NAME> <<EMAIL>>
 */
public class PicoListManager extends GenericMailet {

    private String listName;
    private UsersRepository members;
    private String subscribe;
    private String unsubscribe;

    public void init () {
        listName = getInitParameter("listName");
        subscribe = getInitParameter("subscribe");
        if (subscribe == null) {
            subscribe = listName + "-on";
        }
        unsubscribe = getInitParameter("unsubscribe");
        if (unsubscribe == null) {
            unsubscribe = listName + "-off";
        }

        ComponentManager comp = (ComponentManager)getMailetContext().getAttribute(Constants.AVALON_COMPONENT_MANAGER);
        UserManager manager = (UserManager) comp.getComponent(Resources.USERS_MANAGER);
        members = (UsersRepository) manager.getUserRepository("list-" + listName);
        //transport = (Mailet) context.get("transport");
        //log("PicoListserv: " + listName + " sub " + subscribe + " unsub " + unsubscribe + "-" + transport);
    }

    public void service(Mail mail) throws MailetException, MessagingException {
        Collection recipients = mail.getRecipients();
        MailAddress recipient = (MailAddress) recipients.iterator().next();
        if (recipients.size() != 1) {
            log("bouncing back: Cannot handle more than one recipient");
            getMailetContext().bounce(mail, "Cannot handle more than one recipient");
{'fraction_non_alphanumeric': 0.1919210053859964, 'fraction_numerical': 0.0010771992818671453, 'mean_word_length': 2.9426751592356686, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4738289', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1372, 'n_words': 377}