head	1.9;
access;
symbols
	TIGRIS_0_9_2_4:1.5
	TIGRIS_0_9_2_3:1.5
	HELM_PEER_PORT_BRANCH:1.8.0.2
	TURBINE_PEER:1.8
	TIGRIS_0_9_2_1:1.8
	TIGRIS_0_9_2:1.5.0.4
	TIGRIS_0_9_0:1.5.0.2
	TIGRIS_0_8_4:1.4.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1;
locks; strict;
comment	@# @;


1.9
date	2001.02.21.03.48.30;	author edk;	state dead;
branches;
next	1.8;

1.8
date	2001.01.26.18.29.05;	author edk;	state Exp;
branches
	1.8.2.1;
next	1.7;

1.7
date	2001.01.26.05.24.06;	author edk;	state dead;
branches;
next	1.6;

1.6
date	2001.01.25.00.26.08;	author edk;	state Exp;
branches;
next	1.5;

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

1.4
date	2000.12.02.23.15.04;	author edk;	state Exp;
branches;
next	1.3;

1.3
date	2000.12.02.06.30.03;	author leonardr;	state Exp;
branches;
next	1.2;

1.2
date	2000.11.17.01.34.49;	author edk;	state Exp;
branches;
next	1.1;

1.1
date	2000.11.12.21.16.10;	author dlr;	state Exp;
branches
	1.1.1.1;
next	;

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

1.8.2.1
date	2001.01.28.01.02.18;	author dlr;	state dead;
branches;
next	;


desc
@@


1.9
log
@renamed to ProjectMailingListList
@
text
@/* ================================================================
 * 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 com.workingdogs.village.*;

import org.webmacro.util.*;
import org.webmacro.servlet.*;
import org.webmacro.engine.*;
import org.webmacro.broker.*;
import org.webmacro.resource.*;

import org.joist.*;
import org.joist.util.*;
import org.joist.session.*;
import org.joist.security.RedirectException;
import org.joist.mail.Emailer;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.tool.mail.MailingList;
import org.tigris.helm.domain.User;
import org.tigris.helm.domain.Domain;
import org.tigris.helm.security.HelmServlet;

public class ProjectMail extends org.tigris.helm.security.HelmServlet {
    public static final  String versionID = "$Id: ProjectMail.java,v 1.8 2001/01/26 18:29:05 edk Exp $";
    private static Log log = new Log("ProjectMail", "Tigris StartPage");
    private static boolean debug = true;

    /**
     *  Display and process the login screen.
     */
    protected String
	processRequest (Connection connection, WebContext context)
	throws HandlerException, RedirectException
    {
	if (debug) log.info("ProjectMail: started!");

	String templateName = super.processRequest(connection, context);
	Project currentProject = getCurrentProject(context);
        Domain currentDomain = getCurrentDomain(context);
        User loginUser = getLoginUser(context);

	try {
	    String projectID = currentProject.getID();
	    List mailingLists = currentProject.getMailingLists();
	    context.put("mailingLists", mailingLists);
	}
	catch (Exception e) {
	    log.exception(e);
	    String message = "ProjectMail: " + e.getMessage();
	    if (debug) log.info(message);
	    context.put("message", message);
	}	
	if (debug) log.info("ProjectMail:  done retrieving lists");
	
        String action = getAction(context);
        if (action == null || action.equals("") || action.equals("none")) {
            return templateName;
        }

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

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

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

        MailingList ml = null;

        if (listName == null || listName.equals("")) {
            missingFields.add(listName);
        } else {
            try {
                ml = new MailingList(connection, getDataManager(context),
                        currentProject.getID(), listName);
            } catch (DoesNotExist e) {
                if (debug) log.info("invalid list name: " + listName + ":" +
                        e.getMessage());
                validationErrors.add("invalid list name");
            } catch (Exception e) {
                log.exception(e);
                if (debug)
                    log.info("unable to get mailing list by name " + listName);
                throw new HandlerException("unable to get mailing list : "+
                        e.getMessage());
            }
        }

        String userEmail = null;
        if (validationErrors.isEmpty() && missingFields.isEmpty()) {
            try {
                userEmail = loginUser.getEmail();
            } catch (DataSetException e) {
                log.exception(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 exception, but we'll handle this
                    validationErrors.add("invalid action");           // below
                }
                mailingListOperation.append(userEmail.replace('@@', '='));
                address = ml.getAddress(mailingListOperation.toString());
            } catch (DataSetException e) {
                log.exception(e);
                if (debug) log.info("error in getAddress: " + e.getMessage());
                throw new HandlerException("mailing list error");
            }
            if (debug) log.info("address to be used: "+address);
        }

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


1.8
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d78 1
a78 1
    public static final  String versionID = "$Id: ProjectMail.java,v 1.5 2000/12/20 23:28:20 edk Exp $";
@


1.8.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d78 1
a78 1
    public static final  String versionID = "$Id: ProjectMail.java,v 1.8 2001/01/26 18:29:05 edk Exp $";
@


1.7
log
@revert this stuff to its state as of 2001/01/24 12:42:00 GMT -- with
the following exceptions, which have some different modifications so
they'll work with changes which have happened in joist:

ProjectNewsEdit.java
SkinManager.java
SkinStyleElementValueManager.java
StyleElementManager.java
StyleManager.java

it compiles.  i dunno if it works, though.
@
text
@d78 1
a78 1
    public static final  String versionID = "$Id: ProjectMail.java,v 1.6 2001/01/25 00:26:08 edk Exp $";
d129 1
a129 1
                ml = new MailingList(getDataManager(context),
@


1.6
log
@MailingList changes to more closely resemble other business objects (I
don't like certain parts of the pattern, but consistency is more important)
including changes to avoid keeping reference to Connections.
@
text
@d78 1
a78 1
    public static final  String versionID = "$Id: ProjectMail.java,v 1.5 2000/12/20 23:28:20 edk Exp $";
@


1.5
log
@support subscription to the digest list as well as the normal version
of the list.
@
text
@d78 1
a78 1
    public static final  String versionID = "$Id: ProjectMail.java,v 1.4 2000/12/02 23:15:04 edk Exp $";
d129 1
a129 1
                ml = new MailingList(connection, getDataManager(context),
@


1.4
log
@appendToMessage is *only* for error messages.  other messages currently
need to be done in a per-template/servlet fashion (which may make sense)
@
text
@d78 1
a78 1
    public static final  String versionID = "$Id: ProjectMail.java,v 1.3 2000/12/02 06:30:03 leonardr Exp $";
d121 1
d154 6
d161 1
a161 2
                    address = ml.getAddress("subscribe-" +
                            userEmail.replace('@@', '='));
d163 3
a165 4
                    address = ml.getAddress("unsubscribe-" +
                            userEmail.replace('@@', '='));
                } else {
                    validationErrors.add("invalid action");
d167 2
@


1.3
log
@Provide feedback on success.
@
text
@d78 1
a78 1
    public static final  String versionID = "$Id: ProjectMail.java,v 1.2 2000/11/17 01:34:49 edk Exp $";
d186 1
a186 1
                appendToMessage(context, "Subscription Request Sent");
d190 1
a190 1
                appendToMessage(context, "Subscription Request Failed");
@


1.2
log
@support buttons for starting subscription process
@
text
@d78 1
a78 1
    public static final  String versionID = "$Id: ProjectMail.java,v 1.1.1.1 2000/11/12 21:16:10 dlr Exp $";
d186 1
@


1.1
log
@Initial revision
@
text
@d69 1
d71 4
d78 1
a78 1
    public static final  String versionID = "$Id: ProjectMail.java,v 1.5 2000/11/06 06:15:31 edk Exp $";
d89 1
a89 1
	if (debug) log.debug("ProjectMail: started!");
d93 2
d104 1
a104 1
	    if (debug) log.debug(message);
d107 1
d109 83
a191 2
	if (debug) log.debug("ProjectMail:  done");

a193 1
  
@


1.1.1.1
log
@Merging newhelm tree into helm, as per IZ issue #557.  Previous major version of helm is tagged TIGRIS_NOV_11_2000.
@
text
@@
