diff -urp ./mailing_list.install ../mailing_list_enhanced/mailing_list.install
--- ./mailing_list.install	2008-09-02 11:30:49.000000000 -0400
+++ ../mailing_list_enhanced/mailing_list.install	2008-09-29 18:04:52.000000000 -0400
@@ -26,28 +26,41 @@ function mailing_list_schema() {
         'length' => 255,
         'not null' => TRUE,
       ),
+      'notify' => array(
+      	'description' => t('To notify or not to notify'),
+      	'type' => 'int',
+      	'size' => 'tiny',
+      ),
+      'notification_email' => array(
+      	'description' => t('Where to send notification'),
+      	'type' => 'varchar',
+      	'length' => 255,
+      ),
     ),
     'primary key' => array('id'),  
   );
   $schema['mailing_list_emails'] = array(
-    'description' => t('Emails subscribed to specific fields'),
+    'description' => t('Emails subscribed to specific lists'),
     'fields' => array(
-      'id'        => array(
+      'id' => array(
         'type'    => 'int',
+        'type' => 'serial',
         'unsigned' => TRUE,
         'not null' => TRUE,
       ),
+      'mailing_list_id' => array(
+      	'description' => t('Which mailing list the address is subscribed to.'),
+      	'type' => 'int',
+      	'not null' => TRUE,
+      ),
       'email'  =>  array(
-        'description' => t('The title of this mailing list'),
+        'description' => t('The email'),
         'type' => 'varchar',
         'length' => 255,
         'not null' => TRUE,
       ),
     ),
     'primary key' => array('id'),  
-    'unique keys' => array(
-      'sub'     => array('id', 'email'),
-      ),
   );
   
   
diff -urp ./mailing_list.module ../mailing_list_enhanced/mailing_list.module
--- ./mailing_list.module	2008-07-20 02:11:35.000000000 -0400
+++ ../mailing_list_enhanced/mailing_list.module	2008-09-29 18:38:21.000000000 -0400
@@ -1,27 +1,92 @@
 <?php
// $Id: mailing_list.module,v 1.1 2008/07/20 06:11:35 litwol Exp $
+
+/* ****************************************************************** *
+ *                               Hooks                                *
+ * ****************************************************************** *
+ */
+
+/* *********************************
+ * mailing_list_perm
+ * 
+ * Implements permissions hook
+ * 
+ * administer mailing list allows
+ * access to administration functions
+ * 
+ * export mailing list allows access
+ * to the export function
+ * 
+ * access mailing list allows access
+ * to the unsubscribe page
+ * 
+ * *********************************
+ */
 function mailing_list_perm() {
-  return array('administer mailing list', 'export mailing list');
+  return array('administer mailing lists', 'export mailing list', 'access mailing lists');
 }
 
+/* *********************************
+ * mailing_list_menu
+ * 
+ * @return $items
+ * 
+ * register paths for mailing list
+ * 
+ * *********************************
+ */
 function mailing_list_menu() {
   $items = array();
+  
   $items['admin/settings/mailing-list'] = array(
     'title'             => t('Mailing List'),
+    'description'	=> t('Create, edit, and delete mailing lists.'),
     'page callback'     => 'mailing_list_admin',
-    'access arguments'  => array('administer mailing list'),
+    'access arguments'  => array('administer mailing lists'),
   );
+  
   $items['admin/settings/mailing-list/%mailing_list/edit'] = array(
     'title'             => t('Edit Mailing List'),
     'page callback'     => 'drupal_get_form',
     'page arguments'=> array('mailing_list_form', 3),
-    'access arguments'  => array('administer mailing list'),
+    'access arguments'  => array('administer mailing lists'),
   );
   
+  $items['admin/settings/mailing-list/%mailing_list/delete'] = array(
+  	'title' => t('Delete Mailing List'),
+  	'page callback' => 'drupal_get_form',
+  	'page arguments' => array('mailing_list_delete_form', 3),
+  	'access arguments'  => array('administer mailing lists'),
+  );
+  
+  $items['mailing-list/%mailing_list/unsubscribe'] = array(
+  	'title' => t('Unsubscribe from a Mailing List'),
+  	'page callback' => 'mailing_list_unsubscribe',
+  	'page arguments' => array(1),
+  	'access arguments' => array('access mailing lists'),
+  );
+    
+  $items['mailing-list/%mailing_list/export'] = array(
+  	'title' => t('Export Mailing List'),
+  	'page callback' => 'mailing_list_export',
+		'page arguments' => array(1),
+		'access arguments' => array('export mailing list'),
+	);
   
   return $items;
 }
 
+/* *********************************
+ * mailing_list_block
+ * 
+ * @return $block
+ * 
+ * implements block hook
+ * 
+ * view shows subscription form for 
+ * a specific mailing list
+ * 
+ * *********************************
+ */
 function mailing_list_block($op = 'list', $delta = 0, $edit = array()) {
   $block = array();
   switch ($op) {
@@ -47,70 +112,79 @@ function mailing_list_block($op = 'list'
   
   return $block;
 }
-function mailing_list_subscription_form(&$form_state, $list ) {
-  $form = array();
-  $form['id']   = array(
-    '#type'       => 'hidden',
-    '#default_value' => $list->id,
-  );
-  $form['list']   = array(
-    '#type'       => 'hidden',
-    '#value'      => $list->list,
-  );
-  $form['email'] = array(
-    '#title'    => t('Email'),
-    '#type'     => 'textfield',
-    '#size'     => 20,
-  );
-  $form['submit'] = array(
-    '#value'      => t('Subscribe'),
-    '#type'       => 'submit',
-    '#submit'     => array('mailing_list_subscription_form_submit'),
-  );
-  $form['#validate'] = array('mailing_list_subscription_form_validate');
-  return $form;
-}
-function mailing_list_subscription_form_validate($form, &$form_state) {
-  $message = user_validate_mail($form_state['values']['email']);
-  if ($message) {
-    form_set_error('email', $message);
-  }
-}
-function mailing_list_subscription_form_submit($form, &$form_state) {
-  if ($form_state['values']['id'] == null) {
-    drupal_set_message('Error occured while saving your subscription. Please contact sie administrators', 'error');
-    return ;
-  }
-  $query = "INSERT INTO {mailing_list_emails} (id, email) VALUES (%d, '%s')";
-  if (db_query($query, $form_state['values']['id'], $form_state['values']['email'])) {
-    drupal_set_message('Your Subscription to <em>'. $form_state['values']['list'] .'</em> has been saved');
-  }
-  else {
-    drupal_set_message('Failed to subscribe to <em>'. $form_state['values']['list'] .'</em> please contact site administrators', 'error');
-  }
-}
+
+/* *********************************
+ * mailing_list_load
+ * 
+ * @param $id
+ * 
+ * @return $return
+ * 
+ * takes $id and returns mailing list from
+ * database for use in menu paths
+ * 
+ * *********************************
+ */
 function mailing_list_load($id) {
   $query = "SELECT * FROM {mailing_list} WHERE id = %d";
   $return = db_fetch_object(db_query($query, $id));  
   return $return;
 }
+
+/* ****************************************************************** *
+ *                         Admin Functions                            *
+ * ****************************************************************** *
+ */
+
+/* *********************************
+ * mailing_list_admin
+ * 
+ * @return $output
+ * 
+ * generates admin form
+ * 
+ * *********************************
+ */
 function mailing_list_admin() {
   $output = '';
   $output .= drupal_get_form('mailing_list_form');
   $output .= mailing_list_lists();
   return $output;
 }
+
+/* *********************************
+ * mailing_list_lists
+ * 
+ * @return theme('item_list', $rows, "Available Mailing Lists")
+ * 
+ * generates themed list of mailing lists 
+ * with links to edit the lists
+ * 
+ * *********************************
+ */
 function mailing_list_lists() {
   $query  = "SELECT * FROM {mailing_list}";
   $result = db_query($query);
   $rows = array();
   while ($row = db_fetch_object($result)) {
-    $rows[] = $row->list . ' ' . l('edit', 'admin/settings/mailing-list/'. $row->id .'/edit');
+    $rows[] = $row->list . ' | ' . l('edit', 'admin/settings/mailing-list/'. $row->id .'/edit') . ' | ' . l('delete', 'admin/settings/mailing-list/' . $row->id . '/delete') . ' | ' . l('unsubscribe link' , 'mailing-list/' . $row->id . '/unsubscribe') . ' | ' . l('export' , 'mailing-list/' . $row->id . '/export');
   }
   
   return theme('item_list', $rows, "Available Mailing Lists");
 }
 
+/* *********************************
+ * mailing_list_form
+ * 
+ * @param &$form_state
+ * @param $list = null
+ * 
+ * @return $form
+ * 
+ * mailing list creation / editing form
+ * 
+ * *********************************
+ */
 function mailing_list_form(&$form_state, $list = null) {
 
   $form = array();
@@ -130,8 +204,21 @@ function mailing_list_form(&$form_state,
     '#title'      => t('Mailing List Name'),
     '#type'       => 'textfield',
     '#required'   => TRUE,
-    '#default_value'=> isset($form_state['values']['list_name']) ? $form_state['values']['list_name']: isset($list)?$list->list:'',
+    '#default_value'=> isset($form_state['values']['list_name']) ? $form_state['values']['list_name']: isset($list)?$list->list : '',
   );
+  
+  $form['form']['notify'] = array(
+  	'#type' => 'checkbox',
+  	'#title' => 'Send notification when list changes',
+  	'#default_value' => isset($form_state['values']['notify']) ? $form_state['values']['notify']: ( isset($list) ? $list->notify : 0 ),
+  );
+  
+  $form['form']['notification_email'] = array(
+  	'#type' => 'textfield',
+  	'#title' => 'Email Address to Receive Notification',
+  	'#default_value' => isset($form_state['values']['notification_email']) ? $form_state['values']['notification_email']: ( isset($list) ? $list->notification_email : '' ),
+  );
+  
   $form['form']['submit'] = array(
     '#value'      => t('Save'),
     '#type'       => 'submit',
@@ -141,16 +228,71 @@ function mailing_list_form(&$form_state,
   return $form;
 }
 
+/* *********************************
+ * mailing_list_form_validate
+ * 
+ * @param $form
+ * @param &$form_state
+ * 
+ * *********************************
+ */
+function mailing_list_form_validate($form, &$form_state){
+	
+	//list id will be set automatically or is already set
+	//list name doesn't have any restrictions, and will
+	//be sanitized in the submit function, so that leaves
+	//checking notify and notification email.
+	
+	//save form values into variables for easier reference	
+	$notify = $form_state['values']['notify'];
+	$notification_email = $form_state['values']['notification_email'];
+	
+	//only check notification email if notify is set
+	if($notify)
+	{
+		if(!$notification_email)
+		{
+			form_set_error('notification_email','You must provide an email address to which to send notification.');
+		}
+		elseif(!filter_var($notification_email, FILTER_VALIDATE_EMAIL))
+		{
+			form_set_error('notification_email','Notification must be sent to a valid email address. Please check that you\'ve entered it correctly.');
+		}
+	}
+		
+}// function mailing_list_form_validate
+
+/* *********************************
+ * mailing_list_form_submit
+ * 
+ * @param $form
+ * @param &$form_state
+ * 
+ * updates database with new information
+ * 
+ * *********************************
+ */
 function mailing_list_form_submit($form, &$form_state) {
-  if (isset($form_state['values']['id'])) {
-    $query = "UPDATE {mailing_list} SET list = '%s' WHERE id = %d";
-    $result = db_query($query, $form_state['values']['list_name'], $form_state['values']['id']);
+	
+	//sanitize list name
+	$form_state['values']['list_name'] = filter_var($form_state['values']['list_name']);
+	
+	//are we updating an existing list or creating a new one?
+  if (isset($form_state['values']['id'])) 
+  {
+  	//update values if list exists
+    $query = "UPDATE {mailing_list} SET list = '%s',notify='%d',notification_email='%s' WHERE id = %d";
+    $result = db_query($query, $form_state['values']['list_name'], $form_state['values']['notify'], $form_state['values']['notification_email'], $form_state['values']['id']);
+    
   }
-  else {
-    $query = "INSERT INTO {mailing_list} (list) VALUES ('%s')";
-    $result = db_query($query, $form_state['values']['list_name']);
+  else 
+  {
+  	//insert new values if it doesn't
+    $query = "INSERT INTO {mailing_list} (list,notify,notification_email) VALUES ('%s','%d','%s')";
+    $result = db_query($query, $form_state['values']['list_name'], $form_state['values']['notify'], $form_state['values']['notification_email']);
   }
   
+  //create and set appropriate messages
   if ($result) {
     if (isset($form_state['values']['id']) ) {
       drupal_set_message('Updated Mailing List: '. check_plain($form_state['values']['list_name']));
@@ -167,4 +309,495 @@ function mailing_list_form_submit($form,
       drupal_set_message('Failed to Create New Mailing List: '. check_plain($form_state['values']['list_name']), 'error'); 
     }
   }
-}
\ No newline at end of file
+}
+
+/* *********************************
+ * mailing_list_delete_form
+ * 
+ * @param $form_state
+ * @param object $list
+ * 
+ * form to delete a mailing list and all
+ * associated email addresses from database
+ * 
+ * *********************************
+ */
+function mailing_list_delete_form($form_state, $list) {
+	
+	//warning paragraph - markup
+	$form['warning'] = array(
+		'#type' => 'markup',
+		'#value' => '<h2>Delete ' . $list->list .'</h2><p class="messages error">You are about to delete this entire mailing list <strong>including all email address associated with it.</strong></p><p>Are you sure you want to do this?</p>',
+	);
+	
+	//hidden field - list id
+	$form['list_id'] = array(
+		'#type' => 'hidden',
+		'#value' => $list->id,
+	);
+	
+	$form['list_name'] = array(
+		'#type' => 'hidden',
+		'#value' => $list->list,
+	);
+	
+	//first submit button - cancel
+	$form['cancel'] = array(
+		'#type' => 'submit',
+		'#value' => t('Cancel'),
+	);
+	
+	$form['delete'] = array(
+		'#type' => 'submit',
+		'#value' => t('Delete'),
+	);
+	
+  $form['#redirect'] = 'admin/settings/mailing-list';
+  return $form;
+	
+}//function mailing_list_delete_form
+
+/* *********************************
+ * mailing_list_delete_form_submit
+ * 
+ * @param $form
+ * @param &$form_state
+ * 
+ * checks which button was pushed.
+ * Just redirects if it was cancelled,
+ * otherwise deletes the mailing list
+ * and the email addresses associated
+ * with it.
+ * 
+ * *********************************
+ */
+function mailing_list_delete_form_submit($form, &$form_state) {
+	
+	//if the delete buttom was pressed, we delete
+	//otherwise, do nothing, just redirect as normal.
+	if ($form_state['clicked_button']['#id'] == 'edit-delete')
+	{
+		//the bad submit button was pressed so now we have
+		//to kill one of our beautiful mailing lists *sob*
+		
+		$id = $form_state['values']['list_id'];
+		$name = $form_state['values']['list_name'];
+		
+		//delete all the email address entries
+		$query = "DELETE FROM {mailing_list_emails} WHERE mailing_list_id='%d'";
+		$email_result = db_query($query, $id);
+		
+		//delete the mailing list itself
+		$query = "DELETE FROM {mailing_list} WHERE id='%d'";
+		$list_result = db_query($query, $id);
+		
+		//delete the block
+		$query = "DELETE FROM {blocks} WHERE module = 'mailing_list' AND delta='%d'";
+		$block_result = db_query($query, $id);
+		
+		//generate appropriate messages
+		if($email_result && $list_result)
+		{
+			//success!
+			drupal_set_message($name . ' has successfully been deleted!');
+		
+		}
+		else
+		{
+			if(!$email_result)
+			{
+				drupal_set_message('The email addresses associated with ' . $name . ' could not be deleted.', 'error');
+			}// if(!$email_result)
+			
+			if(!$list_result)
+			{
+				drupal_set_message($name . 'could not be deleted.' , 'error');
+			}// if(!$list_result)
+			
+		}// if($email_result && $list_result)
+	
+	}//	if ($form_state['clicked_button']['#id'] == 'edit-delete')
+	
+}// function mailing_list_delete_form_submit
+
+/* ****************************************************************** *
+ *                       Subscribe Functions                          *
+ * ****************************************************************** *
+ */
+
+/* *********************************
+ * mailing_list_subscription_form
+ * 
+ * @param &$form_state
+ * @param $list
+ * 
+ * @return $form
+ * 
+ * Shows subscription form in block
+ *
+ * *********************************
+ */
+function mailing_list_subscription_form(&$form_state, $list) {
+  $form = array();
+  
+  //mailing list id
+  $form['id']   = array(
+    '#type'       => 'hidden',
+    '#default_value' => $list->id,
+  );
+  
+  //mailing list
+  $form['list']   = array(
+    '#type'       => 'hidden',
+    '#value'      => $list->list,
+  );
+  
+  //email text field
+  $form['email'] = array(
+    '#title'    => t('Email'),
+    '#type'     => 'textfield',
+    '#size'     => 15,
+  );
+  
+	//submit button 
+  $form['submit'] = array(
+    '#value'      => t('Subscribe'),
+    '#type'       => 'submit',
+  );
+  
+  return $form;
+}
+
+/* *********************************
+ * mailing_list_subscription_form_validate
+ * 
+ * @param $form
+ * @param &$form_state
+ * 
+ * calls built in email validation function
+ * sets error if it fails
+ * 
+ * *********************************
+ */
+function mailing_list_subscription_form_validate($form, &$form_state) {
+  $message = user_validate_mail($form_state['values']['email']);
+  if ($message) {
+    form_set_error('email', $message);
+  }
+}
+
+/* *********************************
+ * mailing_list_subscription_form_submit
+ * 
+ * @param $form
+ * @param $&form_state
+ * 
+ * inserts email address into database and
+ * sends notification if requested
+ * 
+ * *********************************
+ */
+function mailing_list_subscription_form_submit($form, &$form_state) {
+  if ($form_state['values']['id'] == null) {
+    drupal_set_message('Error occured while saving your subscription. Please contact site administrators', 'error');
+    return ;
+  }
+  $query = "INSERT INTO {mailing_list_emails} (mailing_list_id, email) VALUES (%d, '%s')";
+  if (db_query($query, $form_state['values']['id'], $form_state['values']['email'])) {
+  	mailing_list_notify($form_state['values']['email'],$form_state['values']['id']);
+    drupal_set_message('Your Subscription to <em>'. $form_state['values']['list'] .'</em> has been saved');
+    
+  }
+  else {
+    drupal_set_message('Failed to subscribe to <em>'. $form_state['values']['list'] .'</em> please contact site administrators', 'error');
+  }
+}
+
+/* ****************************************************************** *
+ *                      Unsubscribe Functions                         *
+ * ****************************************************************** *
+ */
+
+/* *********************************
+ * mailing_list_unsubscribe
+ * 
+ * @param $list
+ * 
+ * checks that the list passed through
+ * the menu path exists and if so,
+ * calls drupal get form for the the 
+ * unsubscribe form. If not, it outputs
+ * an error message.
+ * 
+ * *********************************
+ */
+function mailing_list_unsubscribe($list) {
+	
+	//check that the list exists
+	if($list)
+	{
+		//set introductory text
+		$output = "<h2>Unsubscribe from " . $list->list ."</h2>";
+	
+		//get form
+		$output.= drupal_get_form('mailing_list_unsubscribe_form',$list);
+		
+		return $output;
+		
+	}
+	else
+	{
+		drupal_set_message('You\'re trying to unsubscribe from a mailing list that doesn\'t exist.','error');
+	}
+	
+}// function mailing_list_unsubscribe
+
+/* *********************************
+ * mailing_list_unsubscribe_form
+ * 
+ * @param $form_state
+ * 
+ * @param $list
+ *   an object containing the attributes
+ *   of a particular mailing list
+ * 
+ * defines form to unsubscribe from a
+ * mailing list
+ * 
+ * *********************************
+ */
+function mailing_list_unsubscribe_form($form_state, $list){ 
+	
+	$form = array();
+  
+  //mailing list id
+  $form['id']   = array(
+    '#type'       => 'hidden',
+    '#default_value' => $list->id,
+  );
+  
+  //mailing list name
+  $form['list']   = array(
+    '#type'       => 'hidden',
+    '#value'      => $list->list,
+  );
+  
+  //email text field
+  $form['email'] = array(
+    '#title'    => t('Email'),
+    '#type'     => 'textfield',
+    '#size'     => 15,
+    '#default_value' => $form_state['values']['email'],
+  );
+  
+	//submit button 
+  $form['submit'] = array(
+    '#value'      => t('Unsubscribe'),
+    '#type'       => 'submit',
+  );
+  
+  return $form;
+
+}// function mailing_list_unsubscribe_form
+
+/* *********************************
+ * mailing_list_unsubscribe_form_validate
+ * 
+ * @param $form
+ * @param &$form_state
+ * 
+ * unsubscribe form validation function
+ * 
+ * *********************************
+ */
+function mailing_list_unsubscribe_form_validate($form, &$form_state) {
+	
+	//store values
+	$email = $form_state['values']['email'];
+	$id = $form_state['values']['id'];
+	
+	//check that email address is valid
+	if(!filter_var($email, FILTER_VALIDATE_EMAIL))
+	{
+		form_set_error('email','Email is not valid, please check that you have entered it correctly.');
+	}
+	
+	//check that email address is in database
+	
+	////select the row matching email and id,
+	$query = "SELECT * FROM {mailing_list_emails} WHERE mailing_list_id='%d' AND email='%s'";
+	
+	$result = db_query($query, $id, $email);
+	
+	////if there is a result, then we know
+	////the email address is in the database.
+	if(!db_fetch_object($result))
+	{
+		form_set_error('email','Sorry, but it seems that your email address isn\'t subscribed to this mailing list. Maybe you already unsubscribed? Check that you entered your email address correctly. If so, and if you continue to receive unwanted email, please contact the site administrators.');
+	}
+	
+} //function mailing_list_unsubscribe_form_validate
+
+/* *********************************
+ * mailing_list_unsubscribe_form_submit
+ * 
+ * @param $form
+ * @param &$form_state
+ * 
+ * This function removes the listing from
+ * the database, and sends notification
+ * of change.
+ * 
+ * *********************************
+ */
+function mailing_list_unsubscribe_form_submit($form, &$form_state)
+{
+	//store values
+	$id = $form_state['values']['id'];
+	$email = $form_state['values']['email'];
+	$list = $form_state['values']['list'];
+	
+	//update database
+	$query = "DELETE FROM {mailing_list_emails} WHERE mailing_list_id='%d' AND email='%s'";
+	
+	if(db_query($query, $id, $email))
+	{
+		//success message!
+		drupal_set_message('You have been successfully unsubscribed from <em>'. $list . '</em>.');
+	}
+	else
+	{
+		//boo! didn't work so let them know!
+		drupal_set_message('Failed to unsubscribe to <em>'. $list.'</em>, please contact site administrators.', 'error');
+	}
+	
+	//send notification
+	mailing_list_notify($email, $id, 1);
+
+}// function mailing_list_unsubscribe_form_submit
+
+/* ****************************************************************** *
+ *                         Notify Function                            *
+ * ****************************************************************** *
+ */
+
+/* *********************************
+ * mailing_list_notify
+ * 
+ * @param $email 
+ *   the email address added
+ * 
+ * @param $id
+ *   the primary key of the mailing list
+ * 
+ * @param $unsubscribe 
+ *   boolean; if it evaluates to true, 
+ * 	 an unsubscribe notification is sent.	
+ * 
+ * pulls the email address for notification,
+ * the notify boolean, and the list name out
+ * of the database and if notify is set and
+ * an email address is set, sends an email
+ * notifying the addition to the mailing list
+ * 
+ * *********************************
+ */
+function mailing_list_notify($email, $id, $unsubscribe = 0)
+{
+	//pull notification email and list name out of db
+	$query = "SELECT notify,notification_email,list FROM {mailing_list} WHERE id = %d";
+	$result = db_fetch_object(db_query($query, $id));	
+	
+	//check that the mailing list is set to notification
+	//and has an email address set	
+	if($result->notify && $result->notification_email)
+	{
+		//---define mail information---//
+		
+		//set address to receive notification
+		$to = $result->notification_email;
+		
+		//set appropriate subject and body based on $unsubscribe flag
+		if($unsubscribe)
+		{
+			$subject = $result->list . ": Unsubscribe";
+			$message = "Due to an unsubscribe request, $email has been removed from " . $result->list . ".";
+		}
+		else
+		{
+			$subject = $result->list . ": New Subscriber";
+			$message = $result->list . " has a new subscriber: \n\t $email";
+		}// if($unsubscribe)
+		
+		//set From header
+		$headers = "From: $email \r\n";
+	
+		//send notification 
+		mail($to, $subject, $message, $headers);
+	
+	}// if($result->notify && $result->notification_email)
+	
+}//function mailing_list_new_subscription_notify
+
+/* ****************************************************************** *
+ *                        Export Functions                            *
+ * ****************************************************************** *
+ */
+
+/* *********************************
+ * mailing_list_export
+ * 
+ * @param $list
+ *   mailing list as object
+ * 
+ * create comma separated list of email 
+ * addresses subscribed to given list
+ * and transmit the file over http
+ * 
+ * *********************************
+ */
+function mailing_list_export($list){
+	
+// --- set up file for export ---//
+	
+	//get file directory
+	$path = file_directory_path();
+	
+	//create file to hold email list
+	$filename = $list->list. '.csv';
+	
+	//full path name
+	$full_path = $path.'/'.$filename;
+	
+// --- get email addresses from database ---//
+	
+	//create query for selection of emails 
+	$query = "SELECT * FROM {mailing_list_emails} WHERE mailing_list_id='%d'";
+	
+	//run query 
+	$result = db_query($query, $list->id);
+	
+	//create string with all the emails
+	$emails = "";
+	while ($row=db_fetch_object($result)){
+		$emails .= $row->email.",\n";
+	}
+	
+	//remove trailing , and \n 
+	$emails = trim ($emails , ",\n");
+	
+	//write resultant string to file
+	
+	file_save_data($emails, $full_path, FILE_EXISTS_REPLACE);
+	
+	//set headers for file transfer
+	$headers = array(
+		'Content-Type: application/octet-stream',
+		'Content-Disposition: attachment; filename="' . basename($full_path) . '";',
+		'Content-Length: ' . sprintf('%u', filesize($full_path)),
+	);
+		
+	file_transfer($full_path, $headers);
+
+}//function mailing_list_export
+	
