[Subversion] / DadaFork / DADA / App / Messages.pm  

View of /DadaFork/DADA/App/Messages.pm

Parent Directory | Revision Log
Revision: 2253 - (download)
Wed Jan 10 14:34:26 2007 UTC (17 years, 3 months ago) by pje
File size: 8416 byte(s)
Base version: DadaMail 2.10.12
package DADA::App::Messages; 

use lib qw(./ ../  ../DADA ../DADA/perllib); 

use DADA::Config qw(!:DEFAULT); 
use DADA::App::Guts; 

require Exporter; 
@ISA = qw(Exporter); 

@EXPORT = qw(

send_confirmation_message
send_unsub_confirm_email

send_unsubscription_email
send_subscribed_message

send_owner_happenings


send_newest_archive


); 

use strict; 
use vars qw(@EXPORT); 


sub send_confirmation_message { 

	my %args = (
			-List         => undef, 
			-Email        => undef, 
			-Settings_obj => undef, 
			@_		
	);
	
	my $li    = $args{-Settings_obj}->get;
	my $email = $args{-Email}; 
	my $list  = $args{-List}; 

	my $Body =  $li->{confirmation_message}; 
		
		# I need to eat, I'm as thin as a rail!
		$Body .= $DADA::Config::FOOTER  if $DADA::Config::FOOTER  ne '';
		
		my $headers = {To              => '"'. escape_for_sending($li->{list_name}) .'" <'. $email .'>', , 
					   Subject         => $li->{list_name} . ' Mailing List Confirmation', 
					  };
		
		my $msg = undef; 
	
		   $msg .= $_ . ': ' . $headers->{$_} . "\n"
			foreach(keys %$headers); 
		   $msg .= "\n" . $Body; 
			
		require DADA::App::FormatMessages; 
		my $fm = DADA::App::FormatMessages->new(-List => $list); 
		   $fm->use_header_info(1);
		   $fm->use_email_templates(0); 
		   
		my ($header_str, $body_str) = $fm->format_headers_and_body(-msg => $msg );
		
		require DADA::Mail::Send;  
		my $mh = DADA::Mail::Send->new($li); 
	
		$mh->send($mh->return_headers($header_str), 
				  Body => $body_str,
				 ); 
				 
}




sub send_unsub_confirm_email { 

	my %args = (
			-List         => undef, 
			-Email        => undef, 
			-Settings_obj => undef, 
			@_	
		); 
		
	my $email = $args{-Email}; 
	my $list  = $args{-List}; 
	
	if (! $args{-Settings_obj}){
		require DADA::MailingList::Settings; 
		$args{-Settings_obj} = DADA::MailingList::Settings->new(-LIst => $args{-List}); 
	}
	my $li = $args{-Settings_obj}->get; # yeah, I have no idea why this is being passed...

	my $headers = { 
					To              =>    $email, 
					Subject         =>    $li->{list_name} . ' Mailing List Confirmation', 
				  }; 
	my $msg = undef; 
	
	$msg .= $_ . ': ' . $headers->{$_} . "\n"
	   	foreach(keys %$headers); 
	$msg .= "\n" . $li->{unsub_confirmation_message};
	
	require DADA::App::FormatMessages; 
	my $fm = DADA::App::FormatMessages->new(-List => $list); 
	   $fm->use_header_info(1);
	   $fm->use_email_templates(0); 
	   
	my ($header_str, $body_str) = $fm->format_headers_and_body(-msg => $msg );
	
	require DADA::Mail::Send;  
	my $mh = DADA::Mail::Send->new($li); 

	$mh->send($mh->return_headers($header_str), 
		      Body => $body_str,
		     ); 
}




sub send_generic_email { 

	my %args = (
			-List         => undef, 
			-Email        => undef, 
			-Settings_obj => undef,
			-Subject      => '', 
			-Message      => '', 
			@_	
		); 
		
	my $email = $args{-Email}; 
	my $list  = $args{-List}; 
	
	if (! $args{-Settings_obj}){
		require DADA::MailingList::Settings; 
		$args{-Settings_obj} = DADA::MailingList::Settings->new(-List => $args{-List}); 
	}
	my $li = $args{-Settings_obj}->get; # yeah, I have no idea why this is being passed...

    $args{-Subject} =~ s/\[list_name\]/$li->{list_name}/g; # should be everything... but... meh.
    
	my $headers = { 
					To              =>    $email, 
					Subject         =>    $args{-Subject}, 
				  }; 

	my $msg = undef; 
	
	$msg .= $_ . ': ' . $headers->{$_} . "\n"
	   	foreach(keys %$headers); 
	$msg .= "\n" . $args{-Message};
	
	require  DADA::App::FormatMessages; 
	my $fm = DADA::App::FormatMessages->new(-List => $list); 
	   $fm->use_header_info(1);
	   $fm->use_email_templates(0); 
	   
	my ($header_str, $body_str) = $fm->format_headers_and_body(-msg => $msg );
	
	require DADA::Mail::Send;  
	my $mh = DADA::Mail::Send->new($li); 

	$mh->send(
	   $mh->return_headers($header_str), 
	   Body => $body_str,
    ); 

}




sub send_unsubscription_email{ 

	my %args = (-List      => undef,
				-Email     => undef,
				-List_Info => undef,
				@_);

	my $li    = $args{-List_Info};
	my $email = $args{-Email}; 
	my $list  = $args{-List}; 
	
	my $headers = { To              =>   $email, 
					Subject         =>   $li->{list_name} . ' Unsubscription', 
				  }; 
	
	my $msg = undef; 
	
	$msg .= $_ . ': ' . $headers->{$_} . "\n"
	   	foreach(keys %$headers); 
	$msg .= "\n" . $li->{unsubscribed_message};
	
	require DADA::App::FormatMessages;
	
	my $fm = DADA::App::FormatMessages->new(-List => $li->{list}); 
	   $fm->use_header_info(1);
	   $fm->use_email_templates(0); 
	   
	my ($header_str, $body_str) = $fm->format_headers_and_body( -msg => $msg );
	
	require DADA::Mail::Send;  
	my $mh = DADA::Mail::Send->new($li); 

	$mh->send($mh->return_headers($header_str), 
		      Body => $body_str,
		     ); 
		     
}



sub send_subscribed_message { 

	my %args = (
	-List         => undef, 
	-Email        => undef, 
	-Settings_obj => undef, 
	@_	
	); 

	my $email = $args{-Email}; 
	my $list  = $args{-List}; 
	
	if (! $args{-Settings_obj}){
		require DADA::MailingList::Settings; 
		$args{-Settings_obj} = DADA::MailingList::Settings->new(-LIst => $args{-List}); 
	}
	my $li = $args{-Settings_obj}->get; # yeah, I have no idea why this is being passed...
	

	my $headers = {
					To            => "\"New Subscriber\" <$email>", 
					Subject       => "Welcome to " . $li->{list_name}, 
				   };
				   
	my $msg  = undef; 
	   $msg .= $_ . ': ' . $headers->{$_} . "\n"
		foreach(keys %$headers); 
	   
	   $msg .= "\n" . $li->{subscribed_message};
		
	require DADA::App::FormatMessages; 
	
	my $fm = DADA::App::FormatMessages->new(-List => $list); 
	   $fm->use_header_info(1);
	   $fm->use_email_templates(0); 
	   
	my ($header_str, $body_str) = $fm->format_headers_and_body(-msg => $msg );
	
	require DADA::Mail::Send;  
	my $mh = DADA::Mail::Send->new($li); 

	$mh->send($mh->return_headers($header_str), 
			  Body => $body_str,
			 ); 
				 
}




sub send_owner_happenings { 

	my $list    = shift; 
	my $email   = shift; 
	my $status  = shift; 
	my $lh_obj  = shift || undef; # bad form..
	my $ls_obj  = shift || undef; # bad form..
	my $note    = shift || '';    # gah.

	my $send_it = 1; 
	
	my $ls; 
	if($ls_obj){ 
		$ls = $ls_obj; 	
	}else{ 
		require  DADA::MailingList::Settings; 
		   $ls = DADA::MailingList::Settings->new(-List => $list); 
	}
	
	my $li = $ls->get; 
	
	if($status eq "subscribed"){  
	   if(exists($li->{get_sub_notice})){ 
		 if($li->{get_sub_notice} == 0){         
			$send_it = 0; 
			}
		 }   
	   }elsif($status eq "unsubscribed"){  
		if(exists($li->{get_unsub_notice})){ 
		  if($li->{get_unsub_notice} == 0){ 
			$send_it = 0; 
		   }
		}   
	  } 
		
	if($send_it == 1){ 
	
		my $lh;		
		if($lh_obj){ 
			$lh = $lh_obj; 
		}else{ 
			$lh = DADA::MailingList::Subscribers->new(-List => $list); 
		}
		
							   
		my $num_subscribers = $lh->num_subscribers;   
		
		my $localtime = scalar(localtime());

my $Body = qq{

Hello,
This is a quick note to say that 
$email has $status on list: $li->{list_name} 

Server Time: $localtime
IP Logged:   $ENV{'REMOTE_ADDR'}
$note

There is now a total of: $num_subscribers subscribers.

-$DADA::Config::PROGRAM_NAME

};
		require DADA::Mail::Send;  
		my $mh = DADA::Mail::Send->new($li);
		my %mailing = ( 
		'Reply-To'     => $email, 
		To             =>  '"List Owner for: '. escape_for_sending($li->{list_name}) .'" <'. $li->{list_owner_email} .'>', 
		Subject        => "$status $email",
		Body           => $Body,
		);  
		
		$mh->send(%mailing); 	
	}
}




sub send_newest_archive { 

	my %args = (-List         => undef, 
				-Email        => undef, 
				-Settings_obj => undef, 
				@_); 

	die "no list!"         if ! $args{-List}; 
	die "no email!"        if ! $args{-Email}; 
	die "no settings obj!" if ! $args{-Settings_obj};
	
	my $ls = $args{-Settings_obj}; 
	my $li = $ls->get; 
	
	require DADA::MailingList::Archives; 
	my $ah = DADA::MailingList::Archives->new(-List => $li); 
	
	my @a = $ah->get_available_archives; 


    
    my $newest_entry = $ah->newest_entry; 

	if(defined($newest_entry) && ($newest_entry > 1)){ 
		
		my ($head, $body) = $ah->massage_msg_for_resending(-key => $newest_entry, '-split' => 1);
		
		require DADA::Mail::Send; 
		my $mh = DADA::Mail::Send->new($li);
		
		
		
		$mh->send(
				  $mh->return_headers($head), 
				  To => $args{-Email}, 
				  Body => $body, 
		); 	
		
	}
	return 1; 

}






1;

cvs-admin@eby-sarna.com

Powered by ViewCVS 1.0-dev

ViewCVS and CVS Help