head	1.11;
access;
symbols
	TIGRIS_1_1_0RC2:1.4.6.2
	TIGRIS_1_1_0RC1:1.4.6.2
	TIGRIS_1_1:1.4.6.2.0.2
	TIGRIS_1_0_8:1.4.6.2
	TIGRIS_1_0_8RC3:1.4.6.2
	TIGRIS_1_0_8RC2:1.4.6.2
	TIGRIS_1_0_8RC1:1.4.6.2
	TIGRIS_1_0_7:1.4.6.2
	TIGRIS_1_0_7RC3:1.4.6.2
	TIGRIS_1_0_7RC2:1.4.6.2
	TIGRIS_1_0_7RC1:1.4.6.2
	TIGRIS_1_0_6:1.4.6.2
	TIGRIS_1_0_6RC5:1.4.6.2
	TIGRIS_1_0_6RC4:1.4.6.2
	TIGRIS_1_0_6RC3:1.4.6.2
	TIGRIS_1_0_6RC2:1.4.6.2
	TIGRIS_1_0_6RC1:1.4.6.2
	TIGRIS_1_0_5:1.4
	TIGRIS_1_0_5RC6:1.4
	TIGRIS_1_0_5RC5:1.4
	TIGRIS_1_0_5RC4:1.4
	TIGRIS_1_0_5RC3:1.4
	TIGRIS_1_0_5RC2:1.4
	TIGRIS_1_0_5RC1:1.4
	TIGRIS_1_0_4:1.4
	TIGRIS_1_0_3:1.4
	TIGRIS_1_0_2:1.4
	TIGRIS_1_0_1:1.4
	TIGRIS_1_0:1.4.0.6
	TIGRIS_1_0_0:1.4
	TIGRIS_1_0_0_RC1:1.4.0.2
	dlr:1.1.1
	HELM_PEER_PORT_BRANCH:1.1.1.1;
locks; strict;
comment	@# @;


1.11
date	2001.08.28.17.45.17;	author leonardr;	state Exp;
branches;
next	1.10;

1.10
date	2001.08.11.09.08.07;	author dlr;	state Exp;
branches;
next	1.9;

1.9
date	2001.07.19.19.54.04;	author dlr;	state Exp;
branches;
next	1.8;

1.8
date	2001.07.18.10.05.14;	author dlr;	state Exp;
branches;
next	1.7;

1.7
date	2001.07.17.20.10.49;	author leonardr;	state Exp;
branches;
next	1.6;

1.6
date	2001.05.23.01.50.15;	author dlr;	state Exp;
branches;
next	1.5;

1.5
date	2001.05.18.01.05.48;	author edk;	state Exp;
branches;
next	1.4;

1.4
date	2001.03.10.03.52.56;	author edk;	state Exp;
branches
	1.4.6.1;
next	1.3;

1.3
date	2001.03.07.01.53.24;	author lucas;	state Exp;
branches;
next	1.2;

1.2
date	2001.02.21.01.36.26;	author dlr;	state Exp;
branches;
next	1.1;

1.1
date	2001.02.13.02.21.23;	author elicia;	state dead;
branches
	1.1.1.1
	1.1.2.1;
next	;

1.1.1.1
date	2001.02.21.00.35.00;	author dlr;	state Exp;
branches;
next	;

1.1.2.1
date	2001.02.13.02.21.23;	author elicia;	state Exp;
branches;
next	1.1.2.2;

1.1.2.2
date	2001.02.13.04.05.06;	author elicia;	state Exp;
branches;
next	1.1.2.3;

1.1.2.3
date	2001.02.14.23.20.29;	author leonardr;	state Exp;
branches;
next	1.1.2.4;

1.1.2.4
date	2001.02.15.20.50.42;	author leonardr;	state Exp;
branches;
next	1.1.2.5;

1.1.2.5
date	2001.02.16.03.01.34;	author dlr;	state Exp;
branches;
next	1.1.2.6;

1.1.2.6
date	2001.02.20.09.49.21;	author edk;	state Exp;
branches;
next	;

1.4.6.1
date	2001.06.06.16.54.28;	author edk;	state Exp;
branches;
next	1.4.6.2;

1.4.6.2
date	2001.06.07.05.09.31;	author edk;	state Exp;
branches;
next	;


desc
@@


1.11
log
@More methods migrated to ContextAPI.
@
text
@/* ================================================================
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * 3. The end-user documentation included with the redistribution, if
 * any, must include the following acknowlegement: "This product includes
 * software developed by Collab.Net (http://www.Collab.Net/)."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 * 
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 * 
 * 5. Products derived from this software may not use the "Tigris" name
 * nor may "Tigris" appear in their names without prior written
 * permission of Collab.Net.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ====================================================================
 * 
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */


package org.tigris.helm.project;

import java.io.*;
import java.util.*;

import org.apache.turbine.util.Log;
import org.apache.commons.util.exception.NestableException;

import org.apache.velocity.context.Context;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.om.*;
import org.tigris.helm.tool.HelmEmailer;
import org.tigris.helm.security.*;
import org.tigris.helm.tool.ContextAPI;

public class ProjectMailingListList extends HelmServlet {

    private static boolean debug = true;

    protected String processRequest(Context context)
	     throws NestableException, RedirectException
    {
        if (debug) Log.debug("ProjectMailingListList: started!");
      
        String templateName = super.processRequest(context);
        Project currentProject = getCurrentProject(context);
        Domain currentDomain = getCurrentDomain(context);
        User loginUser = null;
        AccessControlList acl = null;
 
        try {
            loginUser = getLoginUser(context);
            acl = getLoginUser(context).getACL();
        }   
        catch (Exception e) {
            Log.error(e);
            String message = "ProjectMailingListList: " + e.getMessage();
            if (debug) Log.debug(message);
            context.put("message", message);
        }	

        try {
            String projectID = currentProject.getID();
            List mailingLists = currentProject.getMailingLists(acl);
            context.put("mailingLists", mailingLists);
        }
        catch (Exception e) {
            Log.error(e);
            String message = "ProjectMailingListList: " + e.getMessage();
            if (debug) Log.debug(message);
            context.put("message", message);
        }	

        if (debug) Log.debug("ProjectMailingListList:  done retrieving lists");
	
        String action = getAction(context);
        if (action == null || action.equals("") || action.equals("none")) {
            return templateName;
        }

        if (debug) Log.debug("ProjectMailingListList:  action is " + action);

        String listName = ContextAPI.getParameter(context, "listName");
        String address = null;
        String subscriptionType = ContextAPI.getParameter(context, "subtype");

        MailingList ml = null;

        if (listName == null || listName.equals("")) 
        {
            ContextAPI.addMissingField(context, listName);
        } 
        else 
        {
            try 
            {
                ml = MailingListPeer.getInstanceByName(currentProject,listName);
            } 
            catch (Exception e) 
            {
                Log.error(e);
                throw new NestableException("Error getting mailing list", e);
            }
        }

        String userEmail = loginUser.getEmail();
        if (ContextAPI.isValidUserInput(context)) 
        {
            try 
            {
                StringBuffer mailingListOperation = new StringBuffer();
                if (subscriptionType != null &&
                        subscriptionType.equals("digest")) {
                    mailingListOperation.append("digest-");
                }

                if (action.equals("Subscribe")) {
                    mailingListOperation.append("subscribe-");
                } else if (action.equals("Unsubscribe")) {
                    mailingListOperation.append("unsubscribe-");
                } else { // we could throw an error, but we'll handle this
                    ContextAPI.addError(context, "invalid action");// below
                }
                mailingListOperation.append(userEmail.replace('@@', '='));
                address = ml.getAddress(mailingListOperation.toString());
            } catch (Exception e) {
                Log.error(e);
                if (debug) Log.debug("error in getAddress: " + e.getMessage());
                throw new NestableException(e);
            }
            if (debug) Log.debug("address to be used: "+address);
        }

        if (ContextAPI.isValidUserInput(context))
        {
            try 
            {
                if (debug) 
                {
                    Log.debug("mail from: " + userEmail);
                    Log.debug("mail to:   " + address);
                }
                new HelmEmailer().sendMailFromUser(address, loginUser,
                                                    "subscribe", "subscribe");
                context.put("debug", action + " Request Sent");
            } 
            catch (Exception e) 
            {
                Log.error("Sending mail failed", e);
                ContextAPI.addError(context, action + " Request Failed");
            }
        }
        return templateName;
    }
} /* end class ProjectMailingListList */
@


1.10
log
@Upgrading to Turbine 3.0-dev, Fulcrum 1.0, and Torque 1.0.
@
text
@d111 1
a111 1
        String listName = getParameter(context, "listName");
d113 1
a113 1
        String subscriptionType = getParameter(context, "subtype");
@


1.9
log
@Removed Joist references.
@
text
@d54 1
a54 1
import org.apache.turbine.util.TurbineException;
d69 1
a69 1
	     throws TurbineException, RedirectException
d130 1
a130 1
                throw new TurbineException("Error getting mailing list", e);
d157 1
a157 1
                throw new TurbineException(e);
@


1.8
log
@Ported Joist Redirect*Exception to Helm.
@
text
@a57 2
import org.joist.JoistException;

@


1.7
log
@Ported servlets to new error-handling mechanism.
@
text
@a51 4
import java.util.List;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
a54 3
import org.apache.turbine.util.TurbineException;

import com.workingdogs.village.*;
a58 1
import org.joist.security.RedirectException;
@


1.6
log
@Ported Helm from WebMacro to Velocity.
@
text
@d72 1
d78 1
a78 1
    protected String processRequest(Context ctx)
d83 3
a85 3
        String templateName = super.processRequest(ctx);
        Project currentProject = getCurrentProject(ctx);
        Domain currentDomain = getCurrentDomain(ctx);
d90 2
a91 2
            loginUser = getLoginUser(ctx);
            acl = getLoginUser(ctx).getACL();
d97 1
a97 1
            ctx.put("message", message);
d103 1
a103 1
            ctx.put("mailingLists", mailingLists);
d109 1
a109 1
            ctx.put("message", message);
d114 1
a114 1
        String action = getAction(ctx);
d121 1
a121 4
        ArrayList missingFields = new ArrayList ();
        ArrayList validationErrors = new ArrayList ();

        String listName = getParameter(ctx, "listName");
d123 1
a123 1
        String subscriptionType = getParameter(ctx, "subtype");
d127 8
a134 4
        if (listName == null || listName.equals("")) {
            missingFields.add(listName);
        } else {
            try {
d136 3
a138 1
            } catch (Exception e) {
d145 4
a148 2
        if (validationErrors.isEmpty() && missingFields.isEmpty()) {
            try {
d160 1
a160 1
                    validationErrors.add("invalid action");           // below
d172 6
a177 11
        if (!missingFields.isEmpty()) {
            appendToMessage (ctx, "Missing Fields", missingFields);
            if (debug)
                Log.debug ("Missing Fields: " + missingFields.toString ());
        } else if (!validationErrors.isEmpty()) {
            appendToMessage (ctx, "Validation Errors", validationErrors);
            if (debug)
                Log.debug ("Validation Errors: " + validationErrors.toString());
        } else {
            try {
                if (debug) {
d183 4
a186 2
                ctx.put("debug", action + " Request Sent");
            } catch (Exception e) {
d188 1
a188 1
                appendToMessage(ctx, action + " Request Failed");
@


1.5
log
@update the name which is logged to be the new name of the servlet
@
text
@d58 2
d63 1
a63 1
import org.webmacro.servlet.*;
d77 2
a78 2
    protected String processRequest (Connection conn, WebContext ctx)
	     throws HandlerException, RedirectException
d82 1
a82 1
        String templateName = super.processRequest(conn, ctx);
d123 1
a123 1
        String listName = ctx.getForm("listName");
d125 1
a125 1
        String subscriptionType = ctx.getForm("subtype");
d136 1
a136 2
                throw new HandlerException("error getting mailing list : " +
                        e.getMessage());
d161 1
a161 1
                throw new HandlerException("mailing list error");
@


1.4
log
@use the new Project.getMailingLists(AccessControlList), which filters
out the results which aren't viewable.
@
text
@d78 1
a78 1
        if (debug) Log.debug("ProjectMail: started!");
d92 1
a92 1
            String message = "ProjectMail: " + e.getMessage();
d104 1
a104 1
            String message = "ProjectMail: " + e.getMessage();
d109 1
a109 1
        if (debug) Log.debug("ProjectMail:  done retrieving lists");
d116 1
a116 1
        if (debug) Log.debug("ProjectMail:  action is " + action);
d189 1
a189 1
} /* end class ProjectMail */
@


1.4.6.1
log
@correct debug lines
@
text
@d78 1
a78 1
        if (debug) Log.debug("ProjectMailingListList: started!");
d92 1
a92 1
            String message = "ProjectMailingListList: " + e.getMessage();
d104 1
a104 1
            String message = "ProjectMailingListList: " + e.getMessage();
d109 1
a109 1
        if (debug) Log.debug("ProjectMailingListList:  done retrieving lists");
d116 1
a116 1
        if (debug) Log.debug("ProjectMailingListList:  action is " + action);
@


1.4.6.2
log
@don't try to handle an action unless we know what it is.  changing this
code shouldn't have been necessary, but joist's redirectTo doesn't delete
the action, and now MailingListDelete redirects to this after a delete
has been confirmed.
@
text
@d109 1
a109 1
        if (debug) Log.debug("ProjectMailingListList: done retrieving lists");
d112 24
a135 26
        if (action.equals("Subscribe") || action.equals("Unsubscribe"))
        {
            if (debug) Log.debug("ProjectMailingListList: action is " + action);

            ArrayList missingFields = new ArrayList ();
            ArrayList validationErrors = new ArrayList ();

            String listName = ctx.getForm("listName");
            String address = null;
            String subscriptionType = ctx.getForm("subtype");

            MailingList ml = null;

            if (listName == null || listName.equals("")) {
                missingFields.add(listName);
            }
            else {
                try {
                    ml = MailingListPeer.getInstanceByName(currentProject,
                            listName);
                }
                catch (Exception e) {
                    Log.error(e);
                    throw new HandlerException("error getting mailing list : " +
                            e.getMessage());
                }
d137 1
d139 22
a160 28
            String userEmail = loginUser.getEmail();
            if (validationErrors.isEmpty() && missingFields.isEmpty()) {
                try {
                    StringBuffer mailingListOperation = new StringBuffer();
                    if (subscriptionType != null &&
                            subscriptionType.equals("digest")) {
                        mailingListOperation.append("digest-");
                    }

                    if (action.equals("Subscribe")) {
                        mailingListOperation.append("subscribe-");
                    }
                    else if (action.equals("Unsubscribe")) {
                        mailingListOperation.append("unsubscribe-");
                    }
                    else { // we could throw an error, but we'll handle this
                        validationErrors.add("invalid action");     // below
                    }
                    mailingListOperation.append(userEmail.replace('@@', '='));
                    address = ml.getAddress(mailingListOperation.toString());
                }
                catch (Exception e) {
                    Log.error(e);
                    if (debug) Log.debug("error in getAddress: " 
                           + e.getMessage());
                    throw new HandlerException("mailing list error");
                }
                if (debug) Log.debug("address to be used: "+address);
d162 2
d165 10
a174 8
            if (!missingFields.isEmpty()) {
                appendToMessage (ctx, "Missing Fields", missingFields);
                if (debug) {
                    Log.debug ("Missing Fields: " + missingFields.toString ());
                }
            }
            else if (!validationErrors.isEmpty()) {
                appendToMessage (ctx, "Validation Errors", validationErrors);
d176 2
a177 17
                    Log.debug ("Validation Errors: " +
                            validationErrors.toString());
                }
            }
            else {
                try {
                    if (debug) {
                        Log.debug("mail from: " + userEmail);
                        Log.debug("mail to:   " + address);
                    }
                    new HelmEmailer().sendMailFromUser(address, loginUser,
                            "subscribe", "subscribe");
                    ctx.put("debug", action + " Request Sent");
                }
                catch (Exception e) {
                    Log.error("Sending mail failed", e);
                    appendToMessage(ctx, action + " Request Failed");
d179 6
@


1.3
log
@Corrected regex madness for Torque upgrade.  -dlr
@
text
@d99 1
a99 1
            List mailingLists = currentProject.getMailingLists();
@


1.2
log
@Merging in changes from the HELM_PEER_PORT_BRANC.
@
text
@a67 2
import org.tigris.helm.om.peer.*;
import org.tigris.helm.om.base.*;
@


1.1
log
@file ProjectMailingListList.java was initially added on branch HELM_PEER_PORT_BRANCH.
@
text
@d1 191
@


1.1.1.1
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@a0 191
/* ================================================================
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * 3. The end-user documentation included with the redistribution, if
 * any, must include the following acknowlegement: "This product includes
 * software developed by Collab.Net (http://www.Collab.Net/)."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 * 
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 * 
 * 5. Products derived from this software may not use the "Tigris" name
 * nor may "Tigris" appear in their names without prior written
 * permission of Collab.Net.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ====================================================================
 * 
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */


package org.tigris.helm.project;

import java.io.*;
import java.util.*;
import java.util.List;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.turbine.util.Log;

import com.workingdogs.village.*;

import org.webmacro.servlet.*;

import org.joist.JoistException;
import org.joist.security.RedirectException;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.om.*;
import org.tigris.helm.om.peer.*;
import org.tigris.helm.om.base.*;
import org.tigris.helm.tool.HelmEmailer;
import org.tigris.helm.security.*;

public class ProjectMailingListList extends HelmServlet {

    private static boolean debug = true;

    protected String processRequest (Connection conn, WebContext ctx)
	     throws HandlerException, RedirectException
    {
        if (debug) Log.debug("ProjectMail: started!");
      
        String templateName = super.processRequest(conn, ctx);
        Project currentProject = getCurrentProject(ctx);
        Domain currentDomain = getCurrentDomain(ctx);
        User loginUser = null;
        AccessControlList acl = null;
 
        try {
            loginUser = getLoginUser(ctx);
            acl = getLoginUser(ctx).getACL();
        }   
        catch (Exception e) {
            Log.error(e);
            String message = "ProjectMail: " + e.getMessage();
            if (debug) Log.debug(message);
            ctx.put("message", message);
        }	

        try {
            String projectID = currentProject.getID();
            List mailingLists = currentProject.getMailingLists();
            ctx.put("mailingLists", mailingLists);
        }
        catch (Exception e) {
            Log.error(e);
            String message = "ProjectMail: " + e.getMessage();
            if (debug) Log.debug(message);
            ctx.put("message", message);
        }	

        if (debug) Log.debug("ProjectMail:  done retrieving lists");
	
        String action = getAction(ctx);
        if (action == null || action.equals("") || action.equals("none")) {
            return templateName;
        }

        if (debug) Log.debug("ProjectMail:  action is " + action);

        ArrayList missingFields = new ArrayList ();
        ArrayList validationErrors = new ArrayList ();

        String listName = ctx.getForm("listName");
        String address = null;
        String subscriptionType = ctx.getForm("subtype");

        MailingList ml = null;

        if (listName == null || listName.equals("")) {
            missingFields.add(listName);
        } else {
            try {
                ml = MailingListPeer.getInstanceByName(currentProject,listName);
            } catch (Exception e) {
                Log.error(e);
                throw new HandlerException("error getting mailing list : " +
                        e.getMessage());
            }
        }

        String userEmail = loginUser.getEmail();
        if (validationErrors.isEmpty() && missingFields.isEmpty()) {
            try {
                StringBuffer mailingListOperation = new StringBuffer();
                if (subscriptionType != null &&
                        subscriptionType.equals("digest")) {
                    mailingListOperation.append("digest-");
                }

                if (action.equals("Subscribe")) {
                    mailingListOperation.append("subscribe-");
                } else if (action.equals("Unsubscribe")) {
                    mailingListOperation.append("unsubscribe-");
                } else { // we could throw an error, but we'll handle this
                    validationErrors.add("invalid action");           // below
                }
                mailingListOperation.append(userEmail.replace('@@', '='));
                address = ml.getAddress(mailingListOperation.toString());
            } catch (Exception e) {
                Log.error(e);
                if (debug) Log.debug("error in getAddress: " + e.getMessage());
                throw new HandlerException("mailing list error");
            }
            if (debug) Log.debug("address to be used: "+address);
        }

        if (!missingFields.isEmpty()) {
            appendToMessage (ctx, "Missing Fields", missingFields);
            if (debug)
                Log.debug ("Missing Fields: " + missingFields.toString ());
        } else if (!validationErrors.isEmpty()) {
            appendToMessage (ctx, "Validation Errors", validationErrors);
            if (debug)
                Log.debug ("Validation Errors: " + validationErrors.toString());
        } else {
            try {
                if (debug) {
                    Log.debug("mail from: " + userEmail);
                    Log.debug("mail to:   " + address);
                }
                new HelmEmailer().sendMailFromUser(address, loginUser,
                                                    "subscribe", "subscribe");
                ctx.put("debug", action + " Request Sent");
            } catch (Exception e) {
                Log.error("Sending mail failed", e);
                appendToMessage(ctx, action + " Request Failed");
            }
        }
        return templateName;
    }
} /* end class ProjectMail */
@


1.1.2.1
log
@ported to turbine, changed name from ProjectMail
@
text
@a0 193
/* ================================================================
 * Copyright (c) 2000 CollabNet.  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * 3. The end-user documentation included with the redistribution, if
 * any, must include the following acknowlegement: "This product includes
 * software developed by Collab.Net (http://www.Collab.Net/)."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 * 
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 * 
 * 5. Products derived from this software may not use the "Tigris" name
 * nor may "Tigris" appear in their names without prior written
 * permission of Collab.Net.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ====================================================================
 * 
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */


package org.tigris.helm.project;

import java.io.*;
import java.util.*;
import java.util.List;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.turbine.util.Log;

import com.workingdogs.village.*;

import org.webmacro.servlet.*;

import org.joist.JoistException;
//import org.joist.session.*;
import org.joist.security.RedirectException;
import org.joist.mail.Emailer;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.om.*;
import org.tigris.helm.om.peer.*;
import org.tigris.helm.security.*;

public class ProjectMailingListList extends HelmServlet {

    private static boolean debug = true;

    protected String processRequest (Connection conn, WebContext ctx)
	     throws HandlerException, RedirectException
    {
        if (debug) Log.debug("ProjectMail: started!");
      
        String templateName = super.processRequest(conn, ctx);
        Project currentProject = getCurrentProject(ctx);
        Domain currentDomain = getCurrentDomain(ctx);
        User loginUser = null;
        AccessControlList acl = null;
 
        try {
            loginUser = getLoginUser(ctx);
            acl = getLoginUser(ctx).getACL();
        }   
        catch (Exception e) {
            Log.error(e);
            String message = "ProjectMail: " + e.getMessage();
            if (debug) Log.debug(message);
            ctx.put("message", message);
        }	

        try {
            String projectID = currentProject.getID();
            List mailingLists = currentProject.getMailingLists();
            ctx.put("mailingLists", mailingLists);
        }
        catch (Exception e) {
            Log.error(e);
            String message = "ProjectMail: " + e.getMessage();
            if (debug) Log.debug(message);
            ctx.put("message", message);
        }	

        if (debug) Log.debug("ProjectMail:  done retrieving lists");
	
        String action = getAction(ctx);
        if (action == null || action.equals("") || action.equals("none")) {
            return templateName;
        }

        if (debug) Log.debug("ProjectMail:  action is " + action);

        ArrayList missingFields = new ArrayList ();
        ArrayList validationErrors = new ArrayList ();

        String listName = ctx.getForm("listName");
        String address = null;
        String subscriptionType = ctx.getForm("subtype");

        MailingList ml = null;

        if (listName == null || listName.equals("")) {
            missingFields.add(listName);
        } else {
            ml = MailingList.add(currentProject, listName);
        }

        String userEmail = null;
        if (validationErrors.isEmpty() && missingFields.isEmpty()) {
            try {
                userEmail = loginUser.getEmail();
            } catch (Exception e) {
                Log.error(e);
                throw new HandlerException("error getting user email: " +
                        e.getMessage());
            }
            try {
                StringBuffer mailingListOperation = new StringBuffer();
                if (subscriptionType != null &&
                        subscriptionType.equals("digest")) {
                    mailingListOperation.append("digest-");
                }

                if (action.equals("Subscribe")) {
                    mailingListOperation.append("subscribe-");
                } else if (action.equals("Unsubscribe")) {
                    mailingListOperation.append("unsubscribe-");
                } else { // we could throw an error, but we'll handle this
                    validationErrors.add("invalid action");           // below
                }
                mailingListOperation.append(userEmail.replace('@@', '='));
                address = ml.getAddress(mailingListOperation.toString());
            } catch (Exception e) {
                Log.error(e);
                if (debug) Log.debug("error in getAddress: " + e.getMessage());
                throw new HandlerException("mailing list error");
            }
            if (debug) Log.debug("address to be used: "+address);
        }

        if (!missingFields.isEmpty()) {
            appendToMessage (ctx, "Missing Fields", missingFields);
            if (debug)
                Log.debug ("Missing Fields: " + missingFields.toString ());
        } else if (!validationErrors.isEmpty()) {
            appendToMessage (ctx, "Validation Errors", validationErrors);
            if (debug)
                Log.debug ("Validation Errors: " + validationErrors.toString());
        } else {
            try {
                if (debug) {
                    Log.debug("mail from: " + userEmail);
                    Log.debug("mail to:   " + address);
                }
                new Emailer().sendEmailFrom(userEmail, address,
                        "subscribe", "subscribe");
                ctx.put("debug", action + " Request Sent");
            } catch (JoistException e) {
                Log.error(e);
                if (debug) Log.debug("sending mail failed: " + e.getMessage());
                appendToMessage(ctx, action + " Request Failed");
            }
        }
        return templateName;
    }
} /* end class ProjectMail */
@


1.1.2.2
log
@added acl to the MailingList.add method
@
text
@d64 1
d132 1
a132 8
            try {
                ml = MailingList.add(acl, currentProject, listName);
            } catch (Exception e) {
                Log.error(e);
                throw new HandlerException("error adding new mail list : " +
                        e.getMessage());
            }

@


1.1.2.3
log
@Big wide-ranging patch being committed all at once due to network downness. Features of this patch include: lots of added and updated JavaDoc, conversion of emails to use TemplateInterpolator and HelmEmailer, rearrangement of methods, changing code that gets mappings and loops over them to code that just gets the appropriate objects from the peer using AddJoin.
@
text
@d65 1
a69 1
import org.tigris.helm.tool.HelmEmailer;
d141 1
a141 1
        String userEmail = loginUser.getEmail();
d144 7
d188 2
a189 2
                new HelmEmailer().sendMailFromUser(address, loginUser,
                                                    "subscribe", "subscribe");
d191 3
a193 2
            } catch (Exception e) {
                Log.error("Sending mail failed", e);
@


1.1.2.4
log
@Normalized copyright dates.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
@


1.1.2.5
log
@Added new imports necessitated by Torque.
@
text
@a68 1
import org.tigris.helm.om.base.*;
@


1.1.2.6
log
@* port MailingList* to the peer system
* add some necessary methods to MailingList, update AnzuTask to use those
* this compiles, but some methods still need to be implemented, so it
  doesn't all work
@
text
@d133 1
a133 1
                ml = MailingListPeer.getInstanceByName(currentProject,listName);
d136 1
a136 1
                throw new HandlerException("error getting mailing list : " +
d139 1
@


