[vhffs-dev] [998] mail user is no more not deleted if user left its last group, he can keep is mail account or forward until its account is deleted ( automatically or manually)

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 998
Author:   gradator
Date:     2007-10-16 19:58:33 +0000 (Tue, 16 Oct 2007)

Log Message:
-----------
mail user is no more not deleted if user left its last group, he can keep is mail account or forward until its account is deleted (automatically or manually)

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Group.pm
    trunk/vhffs-api/src/Vhffs/Services/Mail.pm
    trunk/vhffs-api/src/Vhffs/Services/MailUser.pm
    trunk/vhffs-panel/user/prefs.pl


Modified: trunk/vhffs-api/src/Vhffs/Group.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Group.pm	2007-10-16 15:00:08 UTC (rev 997)
+++ trunk/vhffs-api/src/Vhffs/Group.pm	2007-10-16 19:58:33 UTC (rev 998)
@@ -144,36 +144,9 @@
 
 sub remove_user
 {
-	use Vhffs::User;
-
 	my $self = shift;
 	my $uid = shift;
-	my $user = Vhffs::User::get_by_uid( $self->{'main'} , $uid );
-	return -1 unless defined $user;
 
-	# delete mail user if mail user is enabled, and if a group is needed to have a mail user, and if this is the last group of this user
-	if( $self->{'main'}->get_config->get_service_availability('mailuser') == 1  &&  $self->{'main'}->get_config->get_service('mailuser')->{groupneeded} eq 'yes' )
-	{
-		use Vhffs::Services::Mail;
-		use Vhffs::Services::MailUser;
-		my $mu = init Vhffs::Services::MailUser( $self->{'main'} , $user );
-
-		if( defined $mu )   {
-
-			my $sql = 'SELECT COUNT(*) FROM vhffs_user_group WHERE uid=?';
-			my $request = $self->{'db'}->prepare( $sql );
-			if( $request->execute( $uid )  )  {
-				my $row = $request->fetchrow_arrayref;
-				if( $row )  {
-					if( $row->[0] <= 1 )  {
-						$mu->delbox;
-						$mu->delforward;
-					}
-				}
-			}
-		}
-	}
-
 	my $sql = 'UPDATE vhffs_user_group SET state=? WHERE gid=? AND uid=?';
 	return $self->{db}->do( $sql, {}, Vhffs::Constants::TO_DELETE, $self->{gid}, $uid ) > 0;
 }

Modified: trunk/vhffs-api/src/Vhffs/Services/Mail.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Mail.pm	2007-10-16 15:00:08 UTC (rev 997)
+++ trunk/vhffs-api/src/Vhffs/Services/Mail.pm	2007-10-16 19:58:33 UTC (rev 998)
@@ -340,9 +340,10 @@
 	my $name = shift;
 	my $remote = shift;
 
-    return -1 unless(defined($name) && defined($remote) && $name =~ /^[a-z0-9\_\-\.]+$/ && Vhffs::Functions::valid_mail( $remote ) );
-	return -2 if( ( defined ( $self->{'forward'}{$name} ) ) || ( defined( $self->{'boxes'}{$name} ) ) ||
-        Vhffs::Services::MailingList::address_exists($self->get_main, $name, $self->{domain}) );
+	return -1 unless(defined($name) && defined($remote) && $name =~ /^[a-z0-9\_\-\.]+$/ && Vhffs::Functions::valid_mail( $remote ) );
+	return -2 if( defined $self->{'forward'}{$name}
+		||  ( defined $self->{'boxes'}{$name}  &&  $self->{'boxes'}{$name}{'state'} != Vhffs::Constants::TO_DELETE )
+		||  Vhffs::Services::MailingList::address_exists($self->get_main, $name, $self->{domain}) );
 
     my $sql = 'INSERT INTO vhffs_forward(domain, local_part, remote_name, password) VALUES(?, ?, ?, \'x\')';
     my $dbh = $self->{db};
@@ -424,10 +425,9 @@
 	delete $self->{forward}{$name};
 
     my $dbh = $self->get_db_object;
-    my $sql = 'DELETE FROM vhffs_forwards WHERE local_part = ? AND domain = ?';
+    my $sql = 'DELETE FROM vhffs_forward WHERE local_part = ? AND domain = ?';
     $dbh->do($sql, undef, $name, $self->{domain});
     $sql = 'UPDATE vhffs_mxdomain SET catchall = \'\' WHERE catchall = ?';
-    warn $name.'@'.$self->{domain};
     $dbh->do($sql, undef, $name.'@'.$self->{domain});
 }
 

Modified: trunk/vhffs-api/src/Vhffs/Services/MailUser.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/MailUser.pm	2007-10-16 15:00:08 UTC (rev 997)
+++ trunk/vhffs-api/src/Vhffs/Services/MailUser.pm	2007-10-16 19:58:33 UTC (rev 998)
@@ -55,12 +55,12 @@
 	return undef unless ( defined $vhffs  &&  defined  $user  &&  $vhffs->get_config->get_service_availability('mailuser') );
 	my $config = $vhffs->get_config->get_service('mailuser');
 
-	return undef if( $config->{groupneeded} eq 'yes'  &&  $user->have_activegroups <= 0 );
-
 	# Fetches the mail domain defined in config
 	my $mail_service = Vhffs::Services::Mail::get_by_mxdomain( $vhffs, $config->{domain} );
 	return undef unless defined $mail_service;
 
+	return undef unless( $config->{groupneeded} ne 'yes'  ||  $user->have_activegroups > 0  ||  $mail_service->exists( $user->get_username ) );
+
 	my $this = {};
 	$this->{main} = $vhffs;
 	$this->{config} = $config;

Modified: trunk/vhffs-panel/user/prefs.pl
===================================================================
--- trunk/vhffs-panel/user/prefs.pl	2007-10-16 15:00:08 UTC (rev 997)
+++ trunk/vhffs-panel/user/prefs.pl	2007-10-16 19:58:33 UTC (rev 998)
@@ -178,7 +178,9 @@
                 if( ! defined $usage ) {
                     $panel->add_error( gettext("You must choose a method for your mail") );
                 } elsif( $usage == 1 ) {
-                  #In this case, we treat for popable accounts
+                    #Delete forward if necessary
+                    $mu->delforward;
+                    #In this case, we treat for popable accounts
                     if( $mu->exists_box == 0 ) {
                         # Box doesn't exists, need a password
                          if( $pwd_change == 0 ) {
@@ -222,9 +224,11 @@
                         }
                     }
                 } elsif( $usage == 2 ) {
+                    #Delete the box if necessary
+                    $mu->delbox;
                     #Here, we create the forward
                     my $ad = $user->get_mail;
-                    if(  $mu->exists_forward == 0 ) {
+                    if( $mu->exists_forward == 0 ) {
                         if( ! defined $ad ) {
                             $panel->add_error( gettext("There is a problem with the address you filled in your profile, unable to add forwarding") );
                         } elsif( $mu->addforward( $user->get_mail ) < 0) {


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/