[vhffs-dev] [680] Add moderation of subscriptions to listengine, fixes some bugs here and here ;) |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
- To: vhffs-dev@xxxxxxxxx
- Subject: [vhffs-dev] [680] Add moderation of subscriptions to listengine, fixes some bugs here and here ;)
- From: subversion@xxxxxxxxx
- Date: Sat, 07 Jul 2007 04:11:57 +0200
Revision: 680
Author: gradator
Date: 2007-07-07 02:11:55 +0000 (Sat, 07 Jul 2007)
Log Message:
-----------
Add moderation of subscriptions to listengine, fixes some bugs here and here ;)
Modified Paths:
--------------
trunk/vhffs-api/src/Vhffs/Listengine/Intl.pm
trunk/vhffs-api/src/Vhffs/Services/Mailing.pm
trunk/vhffs-listengine/src/listengine.pl
Modified: trunk/vhffs-api/src/Vhffs/Listengine/Intl.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Listengine/Intl.pm 2007-07-06 13:03:47 UTC (rev 679)
+++ trunk/vhffs-api/src/Vhffs/Listengine/Intl.pm 2007-07-07 02:11:55 UTC (rev 680)
@@ -53,15 +53,17 @@
push( @result , gettext("lang [fr|us|es]\t - set listengine language\n") );
push( @result , "\n" );
push( @result , gettext("Only this list administrators can use the following commands.\n" ) );
- push( @result , gettext("moderate XXXXX\t\t\t - moderate the message with message-id XXXXX\n" ) );
- push( @result , gettext("moderate validate XXXXX\t\t\t - moderate the message with message-id XXXXX\n" ) );
- push( @result , gettext("moderate refused XXXXX\t\t\t - refuse the message with message-id XXXXX\n" ) );
+ push( @result , gettext("subscription accept XXXXX\t\t - accept the subscription with key XXXXX\n" ) );
+ push( @result , gettext("subscription refuse XXXXX\t\t - refuse the subscription with key XXXXX\n" ) );
+ push( @result , gettext("moderate XXXXX\t\t\t - accept the message with message-id XXXXX\n" ) );
+ push( @result , gettext("moderate accept XXXXX\t\t\t - accept the message with message-id XXXXX\n" ) );
+ push( @result , gettext("moderate refused XXXXX\t\t\t - refuse the message with message-id XXXXX\n" ) );
push( @result , gettext("moderate list\t\t\t - give the message list for moderation\n" ) );
push( @result , gettext("user unsubscribe user\@domain.tld\t - delete user user\@domain.tld from list\n") );
push( @result , gettext("user subscribe user\@domain.tld\t\t - register the user user\@domain.tld on the list\n") );
push( @result , gettext("user right RIGHT user\@domain.tld\t - change right for this user\n") );
push( @result , gettext("\t\t\t\t RIGHT can be subscriber or admin\n") );
- push( @result , gettext("user info user\@domain.tld\t\t - show this user's informations\n" ));
+ push( @result , gettext("user info user\@domain.tld\t\t - show user information\n") );
push( @result , "\n" );
@@ -76,11 +78,11 @@
my $pass = shift;
my @result;
- push( @result , sprintf( "You sent a request to subscribe to the following list:\n\n%s\n\n" , $list->get_listname) );
+ push( @result , sprintf( "You sent a request to be subscribed to the following mailing list:\n %s\n\nWith the following email:\n %s\n\n" , $list->get_listname , $from ) );
push( @result , gettext( "You must confirm your request by sending a confirmation email\n") );
- push( @result , sprintf( gettext( "This mail must have the following subject : \"confirm subscribe %s\"\n") , $pass ) );
+ push( @result , sprintf( gettext( "This mail must have the following subject : \"confirm subscribe %s\"\nOn most clients it should work by just replying this email\n") , $pass ) );
push( @result , "\n" );
- push( @result , gettext( "If you haven't asked to be subscribed to this list,\nplease don't answer to this mail\n" ) );
+ push( @result , gettext( "If you don't asked to be subscribed to this mailing list,\njust forget this email\n" ) );
push( @result , "\n" );
return( \@result );
@@ -127,7 +129,7 @@
my $from = shift;
my @result;
- push( @result , sprintf( gettext( "Subscription to the following list is forbidden:\n\n%s\n\nHave a nice day.\n" ) , $list->get_listname) );
+ push( @result , sprintf( gettext( "Subscription to the following list is forbidden:\n %s\n\nHave a nice day.\n" ) , $list->get_listname) );
return( \@result );
}
@@ -139,7 +141,7 @@
my $from = shift;
my @result;
- push( @result , sprintf( gettext( "You have been successfully subscribed to the list %s\n" ) , $list->get_listname) );
+ push( @result , sprintf( gettext( "You have been successfully subscribed to the following mailing list:\n %s\n" ) , $list->get_listname) );
push( @result , gettext( "\n") );
push( @result , gettext( "You may get some help on listengine by sending an email to\n") );
push( @result , sprintf( gettext( "%s-request\@%s with subject \"help\"\n") , $list->get_localpart , $list->get_domain ) );
@@ -155,7 +157,7 @@
my $from = shift;
my @result;
- push( @result , sprintf( gettext( "You have been successfully subscribed to the list %s\n" ) , $list->get_listname) );
+ push( @result , sprintf( gettext( "You have been successfully subscribed to the following mailing list:\n %s\n" ) , $list->get_listname) );
push( @result , gettext( "\n") );
push( @result , gettext( "However this list require approval for new subscribers.\n") );
push( @result , gettext( "You will receive an email with the decision of administrators.\n") );
@@ -174,7 +176,7 @@
my $from = shift;
my @result;
- push( @result , sprintf( gettext( "You have been successfully removed from the following list:\n\n%s\n" ) , $list->get_listname) );
+ push( @result , sprintf( gettext( "You have been successfully removed from the following list:\n %s\n" ) , $list->get_listname) );
return( \@result );
}
@@ -186,7 +188,7 @@
my $from = shift;
my @result;
- push( @result , sprintf( gettext( "An error occured during your subscription to the following list:\n\n%s\n\n" ) , $list->get_listname) );
+ push( @result , sprintf( gettext( "An error occured during your subscription to the following list:\n %s\n\n" ) , $list->get_listname) );
push( @result , gettext("The confirmation code was wrong\n" ));
push( @result , gettext("Please try again !\n" ));
push( @result , "\n" );
@@ -202,7 +204,7 @@
my @result;
- push( @result , sprintf( gettext( "The following address %s is not on the list %s\n" ) , $from , $list->get_listname) );
+ push( @result , sprintf( gettext( "The following address %s is not on the following mailing list:\n %s\n" ) , $from , $list->get_listname) );
push( @result , gettext("You demand was refused\n" ));
push( @result , "\n" );
@@ -290,7 +292,7 @@
my @result;
- push( @result , gettext( "Unknow command\n" ) );
+ push( @result , gettext( "Unknow command\n\n" ) );
push( @result , gettext( "Please read help of listengine\n" ) );
push( @result , gettext( "Send an email with the subject \"help\" to the following address: \n" ) );
push( @result , sprintf( "%s\@%s" , $list->get_localpart , $list->get_domain) );
@@ -391,12 +393,10 @@
my $subject = shift;
my @result;
- push( @result , sprintf( gettext( "A mail to moderate is on the list %s.\n" ) , $list->get_listname) );
- push( @result , sprintf( gettext( "This mail was sent by %s with the following subject: \n" ) , $from) );
- push( @result , $subject );
- push( @result , "-------\n" );
- push( @result , gettext( "To put this post on the list, send a message \n" ) );
- push( @result , sprintf( gettext( "to %s-request\@%s with the following subject : \"moderate %s\" \n" ) , $list->get_localpart , $list->get_domain , $hash) );
+ push( @result , sprintf( gettext( "A mail to moderate is on the following mailing list:\n %s\n\n" ) , $list->get_listname) );
+ push( @result , sprintf( gettext( "This mail was sent by %s with the following subject:\n %s\n\n" ) , $from, $subject) );
+ push( @result , sprintf( gettext( "To put this post on the list, send a message to:\n %s-request\@%s\n" ) , $list->get_localpart , $list->get_domain) );
+ push( @result , sprintf( gettext( "with the following subject :\n \"moderate %s\" \n" ) , $hash) );
push( @result , "\n" );
return( \@result );
@@ -407,23 +407,88 @@
{
my $list = shift;
my $from = shift;
+ my $pass = shift;
my @result;
- push( @result , sprintf( gettext( "A new person wants to subscribe to the following mailing list:\n\n%s\n\n" ) , $list->get_listname) );
+ push( @result , sprintf( gettext( "A new person wants to subscribe to the following mailing list:\n %s\n\n" ) , $list->get_listname) );
push( @result , sprintf( gettext( "His email address is:\n %s\n" ) , $from) );
push( @result , $subject );
push( @result , "\n" );
push( @result , gettext( "To accept this subscriber, send a message to\n" ) );
- push( @result , sprintf( gettext( " %s-request\@%s\nwith the following subject :\n \"accept %s\" \n" ) , $list->get_localpart , $list->get_domain , $from) );
+ push( @result , sprintf( gettext( " %s-request\@%s\nwith the following subject :\n \"subscription accept %s %s\" \n" ) , $list->get_localpart , $list->get_domain , $from, $pass) );
push( @result , "\n" );
push( @result , gettext( "To refuse this subscriber, send a message to\n" ) );
- push( @result , sprintf( gettext( " %s-request\@%s\nwith the following subject :\n \"refuse %s\" \n" ) , $list->get_localpart , $list->get_domain , $from) );
+ push( @result , sprintf( gettext( " %s-request\@%s\nwith the following subject :\n \"subscription refuse %s %s\" \n" ) , $list->get_localpart , $list->get_domain , $from, $pass) );
push( @result , "\n" );
return( \@result );
}
+sub moderate_subscription_accepted
+{
+ my $list = shift;
+ my $from = shift;
+ my @result;
+
+ push( @result , sprintf( gettext( "Your subscription was accepted to the following mailing list:\n %s\n" ) , $list->get_listname) );
+ push( @result , gettext( "\n") );
+ push( @result , gettext( "You may get some help on listengine by sending an email to\n") );
+ push( @result , sprintf( gettext( "%s-request\@%s with subject \"help\"\n") , $list->get_localpart , $list->get_domain ) );
+ push( @result , "\n" );
+
+ return( \@result );
+}
+
+
+sub moderate_subscription_accept_ack
+{
+ my $list = shift;
+ my $subscriber = shift;
+ my @result;
+
+ push( @result , sprintf( gettext( "We confirm that you accepted the subscription of:\n %s\n\nto the following mailing list:\n %s\n\n") , $subscriber, $list->get_listname ) );
+
+ return( \@result );
+}
+
+
+sub moderate_subscription_refused
+{
+ my $list = shift;
+ my $from = shift;
+ my @result;
+
+ push( @result , sprintf( gettext( "Your subscription was refused to the following mailing list:\n %s\n\nHave a nice day.\n" ) , $list->get_listname) );
+
+ return( \@result );
+}
+
+
+sub moderate_subscription_refuse_ack
+{
+ my $list = shift;
+ my $subscriber = shift;
+ my @result;
+
+ push( @result , sprintf( gettext( "We confirm that you REFUSED the subscription of:\n %s\n\nto the following mailing list:\n %s\n\n") , $subscriber, $list->get_listname ) );
+
+ return( \@result );
+}
+
+
+sub moderate_subscription_error
+{
+ my $list = shift;
+ my $subscriber = shift;
+ my @result;
+
+ push( @result , sprintf( gettext( "An error occured during your approval of subscription of:\n %s\ninto the following mailing list:\n %s\n\n" ) , $subscriber, $list->get_listname) );
+
+ return( \@result );
+}
+
+
sub value_month
{
my $value = shift;
Modified: trunk/vhffs-api/src/Vhffs/Services/Mailing.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Mailing.pm 2007-07-06 13:03:47 UTC (rev 679)
+++ trunk/vhffs-api/src/Vhffs/Services/Mailing.pm 2007-07-07 02:11:55 UTC (rev 680)
@@ -265,7 +265,7 @@
return change_right_for_sub(@_);
}
-sub set_randompass
+sub set_randomhash
{
my $self = shift;
my $subscriber = shift;
Modified: trunk/vhffs-listengine/src/listengine.pl
===================================================================
--- trunk/vhffs-listengine/src/listengine.pl 2007-07-06 13:03:47 UTC (rev 679)
+++ trunk/vhffs-listengine/src/listengine.pl 2007-07-07 02:11:55 UTC (rev 680)
@@ -42,6 +42,9 @@
use Vhffs::Services::Mailing;
use Vhffs::Listengine::Intl;
+# open (MYFILE, '>/tmp/grunt');
+# print MYFILE "FROM: '$from' FROMPERM: '$subs->{$from}{'perm'}' SUB: '$subscriber' SUBPERM: '$subs->{$subscriber}{'perm'}' SUBHASH: '$subs->{$subscriber}{'hash'}' HASH: '$hash'\n";
+# close (MYFILE);
#Huho, if the program stop heres, you have some problems with your MTA configuration
if( $#ARGV != 2 )
@@ -60,7 +63,7 @@
my $ADMIN = $vhffs->get_config->get_listengine_listmaster;
my $SMTP_SERVER = $vhffs->get_config->get_listengine_smtp;
-#Be carefule, listengine will create /data/listengine/archives for archives
+# Be careful, listengine will create /data/listengine/archives for archives
#and /data/listengine/tomoderate for moderation
my $DIRECTORY = $vhffs->get_config->get_listengine_datadir;
@@ -174,6 +177,7 @@
$header = new Mail::Header( );
$header->replace( 'From' , $LISTMASTER );
+ $header->replace( 'To' , join(', ' , @tos) );
$header->replace( 'Subject' , "moderate $filehash" );
$header->replace( 'Reply-To' , $list->get_localpart ."-request"."\@".$list->get_domain);
@@ -199,7 +203,7 @@
if( $sub_ctrl == Vhffs::Constants::ML_SUBSCRIBE_CLOSED )
{
- $message = "Subscribtion are not allowed for this list";
+ $message = "Subscription are not allowed for this list";
push @body , $message ;
push @body , "\n";
@@ -308,16 +312,11 @@
my $from = shift;
my $hash = shift;
-
my $subs = $list->get_members;
-
- #Check if su$bscription exists and the subscriber is waiting for reply
- if( ( defined $subs->{$from} ) && ( $subs->{$from}{'perm'} == Vhffs::Constants::ML_RIGHT_SUB_WAITING_FOR_REPLY ) )
+ # Check if subscription exists and the subscriber is waiting for reply and taht the hash is valid
+ if( ( defined $subs->{$from} ) && ( $subs->{$from}{'perm'} == Vhffs::Constants::ML_RIGHT_SUB_WAITING_FOR_REPLY ) && ( $hash eq $subs->{$from}{'hash'} ) )
{
- # Ok, hash are the same, treat the mail now
- if( $hash eq $subs->{$from}{'hash'} )
- {
my $header = new Mail::Header( );
$header->replace( 'To' , $from );
$header->replace( 'From' , $LISTMASTER );
@@ -335,7 +334,7 @@
);
$list->change_state_for_sub( $from , Vhffs::Constants::ML_RIGHT_SUB_WAITING_FOR_VALIDATION );
- $list->clear_hash( $from );
+ my $pass = $list->set_randomhash ( $from );
sendmail( $email , $from );
my @tos;
@@ -349,7 +348,7 @@
my $header = new Mail::Header( );
$header->replace( 'From' , $LISTMASTER );
- $header->replace( 'To' , $LISTMASTER );
+ $header->replace( 'To' , join(', ' , @tos) );
my $subject = 'approval '.$from;
$subject = '['.$list->get_prefix.'] '.$subject if( length( $list->get_prefix ) > 0 );
$header->replace( 'Subject' , $subject );
@@ -357,7 +356,7 @@
$email = Mail::Internet->new( [ <> ] ,
Header => $header,
- Body => Vhffs::Listengine::Intl::moderate_subscriber( $list , $from )
+ Body => Vhffs::Listengine::Intl::moderate_subscriber( $list , $from , $pass )
);
sendmail( $email , \@tos ) if( ( defined $email ) && ( $#tos >= 0 ) );
@@ -389,7 +388,6 @@
Body => Vhffs::Listengine::Intl::error_sub( $list , $from )
);
sendmail( $email , $from );
- }
}
}
@@ -441,9 +439,153 @@
}
+sub sub_accept
+{
+ my $list = shift;
+ my $from = shift;
+ my $subscriber = shift;
+ my $hash = shift;
+ my $subs = $list->get_members;
+ # Check if subscription exists and the subscriber is waiting for approval and that the hash is valid
+ if( ( defined $subs->{$from} ) && ( $subs->{$from}{'perm'} == Vhffs::Constants::ML_RIGHT_ADMIN ) && ( defined $subs->{$subscriber} ) && ( $subs->{$subscriber}{'perm'} == Vhffs::Constants::ML_RIGHT_SUB_WAITING_FOR_VALIDATION ) && ( $subs->{$subscriber}{'hash'} eq $hash ) )
+ {
+ #send a mail to the subscriber
+ my $header = new Mail::Header( );
+ $header->replace( 'To' , $subscriber );
+ $header->replace( 'From' , $LISTMASTER );
+ my $subject = 'Subscription accepted';
+ $subject = '['.$list->get_prefix.'] '.$subject if( length( $list->get_prefix ) > 0 );
+ $header->replace( 'Subject' , $subject );
+ $header->replace('Date' , gmtime()." +00");
+ my $email = Mail::Internet->new( [ <> ] ,
+ Header => $header ,
+ Body => Vhffs::Listengine::Intl::moderate_subscription_accepted( $list , $from )
+ );
+
+ $list->change_state_for_sub( $subscriber , Vhffs::Constants::ML_RIGHT_SUB );
+ $list->clear_hash( $subscriber );
+ sendmail( $email , $subscriber );
+
+ #send a mail to all admins
+ my @tos;
+ my $members = $list->get_members;
+
+ # send a mail to all admins
+ foreach ( keys %{$members} )
+ {
+ push( @tos , $_ ) if( $members->{$_}{perm} == Vhffs::Constants::ML_RIGHT_ADMIN );
+ }
+
+ $header = new Mail::Header( );
+ $header->replace( 'From' , $LISTMASTER );
+ $header->replace( 'To' , join(', ' , @tos) );
+ $subject = 'Subscription approval confirmation '.$from;
+ $subject = '['.$list->get_prefix.'] '.$subject if( length( $list->get_prefix ) > 0 );
+ $header->replace( 'Subject' , $subject );
+
+ $email = Mail::Internet->new( [ <> ] ,
+ Header => $header,
+ Body => Vhffs::Listengine::Intl::moderate_subscription_accept_ack( $list , $subscriber )
+ );
+
+ sendmail( $email , \@tos ) if( ( defined $email ) && ( $#tos >= 0 ) );
+ }
+ else
+ {
+ my $header = new Mail::Header( );
+ $header->replace( 'To' , $from );
+ $header->replace( 'From' , $LISTMASTER );
+ my $subject = 'Subscription moderation error';
+ $subject = '['.$list->get_prefix.'] '.$subject if( length( $list->get_prefix ) > 0 );
+ $header->replace( 'Subject' , $subject );
+ $header->replace('Date' , gmtime()." +00");
+
+ my $email = Mail::Internet->new( [ <> ] ,
+ Header => $header ,
+ Body => Vhffs::Listengine::Intl::moderate_subscription_error( $list , $subscriber )
+ );
+ sendmail( $email , $from );
+ }
+}
+
+
+sub sub_refuse
+{
+ my $list = shift;
+ my $from = shift;
+ my $subscriber = shift;
+ my $hash = shift;
+
+ my $subs = $list->get_members;
+
+ # Check if subscription exists and the subscriber is waiting for approval and that the hash is valid
+ if( ( defined $subs->{$from} ) && ( $subs->{$from}{'perm'} == Vhffs::Constants::ML_RIGHT_ADMIN ) && ( defined $subs->{$subscriber} ) && ( $subs->{$subscriber}{'perm'} == Vhffs::Constants::ML_RIGHT_SUB_WAITING_FOR_VALIDATION ) && ( $subs->{$subscriber}{'hash'} eq $hash ) )
+ {
+ #send a mail to the subscriber
+ my $header = new Mail::Header( );
+ $header->replace( 'To' , $subscriber );
+ $header->replace( 'From' , $LISTMASTER );
+ my $subject = 'Subscription refused';
+ $subject = '['.$list->get_prefix.'] '.$subject if( length( $list->get_prefix ) > 0 );
+ $header->replace( 'Subject' , $subject );
+ $header->replace('Date' , gmtime()." +00");
+
+ my $email = Mail::Internet->new( [ <> ] ,
+ Header => $header ,
+ Body => Vhffs::Listengine::Intl::moderate_subscription_refused( $list , $from )
+ );
+
+ $list->del_sub( $subscriber );
+ sendmail( $email , $subscriber );
+
+ #send a mail to all admins
+ my @tos;
+ my $members = $list->get_members;
+
+ # send a mail to all admins
+ foreach ( keys %{$members} )
+ {
+ push( @tos , $_ ) if( $members->{$_}{perm} == Vhffs::Constants::ML_RIGHT_ADMIN );
+ }
+
+ $header = new Mail::Header( );
+ $header->replace( 'From' , $LISTMASTER );
+ $header->replace( 'To' , join(', ' , @tos) );
+ $subject = 'Subscription approval confirmation '.$from;
+ $subject = '['.$list->get_prefix.'] '.$subject if( length( $list->get_prefix ) > 0 );
+ $header->replace( 'Subject' , $subject );
+
+ $email = Mail::Internet->new( [ <> ] ,
+ Header => $header,
+ Body => Vhffs::Listengine::Intl::moderate_subscription_refuse_ack( $list , $subscriber )
+ );
+
+ sendmail( $email , \@tos ) if( ( defined $email ) && ( $#tos >= 0 ) );
+ }
+ else
+ {
+ my $header = new Mail::Header( );
+ $header->replace( 'To' , $from );
+ $header->replace( 'From' , $LISTMASTER );
+ my $subject = 'Subscription moderation error';
+ $subject = '['.$list->get_prefix.'] '.$subject if( length( $list->get_prefix ) > 0 );
+ $header->replace( 'Subject' , $subject );
+ $header->replace('Date' , gmtime()." +00");
+
+ my $email = Mail::Internet->new( [ <> ] ,
+ Header => $header ,
+ Body => Vhffs::Listengine::Intl::moderate_subscription_error( $list , $subscriber )
+ );
+ sendmail( $email , $from );
+ }
+}
+
+
+
+
#Change some mail headers and send it to each subscriber
sub sendmail_to_list
{
@@ -637,6 +779,7 @@
my ( $from ) = ( $mail->get('From') =~ /(([\+\.a-zA-Z_\-0-9^\s]+)@([\.a-zA-Z_\-0-9^\s]+)\.(\w+))/);
my $subject = $mail->get('Subject');
my $action;
+ my $subscriber;
my $hash;
my $email;
my $header;
@@ -699,7 +842,7 @@
sendmail( $email , $from );
}
}
- elsif( ( $temp ) = $subject =~ /^[.\s]*moderate\s([a-zA-Z0-9\s]+)$/ )
+ elsif( ( $temp ) = $subject =~ /[.\s]*moderate\s([a-zA-Z0-9\s]+)$/ )
{
#To moderate messages, users must be at least ADMIN
#So, we check this NOW
@@ -716,7 +859,7 @@
sendmail( $email , $from );
}
- elsif( ( $hash ) = $temp =~ /validate\s([a-zA-Z0-9]+)$/ )
+ elsif( ( $hash ) = $temp =~ /accept\s([a-zA-Z0-9]+)$/ )
{
if( validate_message( $list , $hash , $from ) < 0 )
@@ -823,6 +966,20 @@
}
}
+ elsif( ( ( $action , $subscriber , $hash ) = $subject =~ /^.*subscription[.\s]([a-z]+)\s([a-z0-9\_\-\.]+@[a-z0-9\-\.]+)\s([a-zA-Z0-9]+)(.*)$/i ) )
+ {
+ if( $action =~ /^accept$/i )
+ {
+ # Here, this is a validation of subscription
+ sub_accept( $list , $from , $subscriber , $hash );
+ }
+ elsif( $action =~ /^refuse$/i )
+ {
+ # And here to deny it
+ sub_refuse( $list , $from , $subscriber , $hash );
+ }
+
+ }
else
{
$mail = Mail::Internet->new( [ <> ],