[vhffs-dev] [2064] Merged mail_deleteboxes.pl and mail_createboxes.pl to mail.pl

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


Revision: 2064
Author:   gradator
Date:     2012-02-26 03:01:26 +0100 (Sun, 26 Feb 2012)
Log Message:
-----------
Merged mail_deleteboxes.pl and mail_createboxes.pl to mail.pl

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Robots/Mail.pm
    trunk/vhffs-api/src/Vhffs/Services/Mail.pm
    trunk/vhffs-robots/Makefile.am
    trunk/vhffs-robots/src/mail.pl

Removed Paths:
-------------
    trunk/vhffs-robots/src/mail_createboxes.pl
    trunk/vhffs-robots/src/mail_deleteboxes.pl

Modified: trunk/vhffs-api/src/Vhffs/Robots/Mail.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Mail.pm	2012-02-25 23:10:49 UTC (rev 2063)
+++ trunk/vhffs-api/src/Vhffs/Robots/Mail.pm	2012-02-26 02:01:26 UTC (rev 2064)
@@ -54,7 +54,7 @@
 
 	my $request = $vhffs->{'db'}->prepare( $sql );
 	return undef unless $request->execute( @params );
-	return $request->fetchall_arrayref( {} );
+	return $request->fetchall_arrayref({});
 }
 
 sub create {
@@ -133,4 +133,58 @@
 	return 1;
 }
 
+sub create_mailbox {
+	my $mail = shift;
+	my $localpart = shift;
+	return undef unless defined $mail and defined $localpart and $mail->get_box_status($localpart) == Vhffs::Constants::WAITING_FOR_CREATION;
+
+	my $vhffs = $mail->get_main;
+	my $mailconf = $vhffs->get_config->get_service('mail');
+
+	my $dir = $mail->get_box_dir($localpart);
+
+	my $prevumask = umask 0;
+	File::Path::make_path( $dir, { mode => 0755, error => \my $errors } );
+	File::Path::make_path( $dir.'/Maildir/cur', $dir.'/Maildir/new', $dir.'/Maildir/tmp', { mode => 0700, error => \$errors }) unless @$errors;
+	umask $prevumask;
+
+	if( @$errors ) {
+		$mail->set_box_status( $localpart, Vhffs::Constants::CREATION_ERROR );
+		Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while creating mail box '.$localpart.'@'.$mail->get_domain.' to the filesystem: '.join(', ', @$errors) );
+		return undef;
+	}
+
+	# make_path owner and group directives do not seem to work if owner and group and numeric
+	Vhffs::Robots::chown_recur( $dir, $mailconf->{'boxes_uid'}, $mailconf->{'boxes_gid'} );
+	chmod 0700, $dir;
+
+	Vhffs::Robots::vhffs_log( $vhffs, 'Created mail box '.$localpart.'@'.$mail->get_domain );
+	$mail->set_box_status( $localpart, Vhffs::Constants::ACTIVATED );
+	return 1;
+}
+
+sub delete_mailbox {
+	my $mail = shift;
+	my $localpart = shift;
+	return undef unless defined $mail and defined $localpart and $mail->get_box_status($localpart) == Vhffs::Constants::WAITING_FOR_DELETION;
+
+	my $vhffs = $mail->get_main;
+	my $dir = $mail->get_box_dir($localpart);
+
+	Vhffs::Robots::archive_targz( $mail, $dir, [ $localpart ] ); 
+
+	File::Path::remove_tree( $dir, { error => \my $errors } );
+	# Remove the letter/ directory if empty
+	rmdir File::Basename::dirname($dir);
+
+	if( @$errors ) {
+		$mail->set_box_status( $localpart, Vhffs::Constants::DELETION_ERROR );
+		Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while deleting mail box '.$localpart.'@'.$mail->get_domain.' from the filesystem: '.join(', ', @$errors) );
+		return undef;
+	}
+
+	Vhffs::Robots::vhffs_log( $vhffs, 'Deleted mail box '.$localpart.'@'.$mail->get_domain );
+	return $mail->delbox($localpart);
+}
+
 1;

Modified: trunk/vhffs-api/src/Vhffs/Services/Mail.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Mail.pm	2012-02-25 23:10:49 UTC (rev 2063)
+++ trunk/vhffs-api/src/Vhffs/Services/Mail.pm	2012-02-26 02:01:26 UTC (rev 2064)
@@ -504,6 +504,7 @@
 	$self->{'forward'}{$name}{'remote_name'} = $remote;
 	$self->{forward}{$name}{password} = 'x';
 
+	$self->add_history( $name.'@'.$self->get_domain.' forward added to '.$remote );
 	return 1;
 }
 
@@ -543,6 +544,7 @@
 	my $sth = $dbh->prepare($sql);
 	$sth->execute($self->{domain}, $name, $domainhash, $password, $userhash, Vhffs::Constants::WAITING_FOR_CREATION) or return -3;
 
+	$self->add_history( $name.'@'.$self->get_domain.' mail box added' );
 	return 1;
 }
 
@@ -559,6 +561,8 @@
 	$dbh->do($sql, undef, $name, $self->{domain});
 	$sql = 'UPDATE vhffs_mxdomain SET catchall = \'\' WHERE catchall = ?';
 	$dbh->do($sql, undef, $name.'@'.$self->{domain});
+
+	$self->add_history( $name.'@'.$self->get_domain.' mail box deleted' );
 }
 
 sub delforward {
@@ -573,6 +577,8 @@
 	$dbh->do($sql, undef, $name, $self->{domain});
 	$sql = 'UPDATE vhffs_mxdomain SET catchall = \'\' WHERE catchall = ?';
 	$dbh->do($sql, undef, $name.'@'.$self->{domain});
+
+	$self->add_history( $name.'@'.$self->get_domain.' forward deleted' );
 }
 
 # Returns a hashref with all forwards

Modified: trunk/vhffs-robots/Makefile.am
===================================================================
--- trunk/vhffs-robots/Makefile.am	2012-02-25 23:10:49 UTC (rev 2063)
+++ trunk/vhffs-robots/Makefile.am	2012-02-26 02:01:26 UTC (rev 2064)
@@ -26,8 +26,6 @@
 	src/group_quota.pl \
 	src/listengine_publicarchives.pl \
 	src/mail.pl \
-	src/mail_createboxes.pl \
-	src/mail_deleteboxes.pl \
 	src/mailinglist.pl \
 	src/mailing.pl \
 	src/mysql.pl \

Modified: trunk/vhffs-robots/src/mail.pl
===================================================================
--- trunk/vhffs-robots/src/mail.pl	2012-02-25 23:10:49 UTC (rev 2063)
+++ trunk/vhffs-robots/src/mail.pl	2012-02-26 02:01:26 UTC (rev 2064)
@@ -38,6 +38,9 @@
 my $vhffs = init Vhffs::Main;
 exit 1 unless defined $vhffs;
 
+my $mailconf = $vhffs->get_config->get_service('mail');
+die('Unable to find mail configuration (boxes_uid/boxes_gid)') unless defined $mailconf and defined $mailconf->{'boxes_uid'} and $mailconf->{'boxes_gid'};
+
 Vhffs::Robots::lock( $vhffs, 'mail' );
 
 my $mails = Vhffs::Services::Mail::getall( $vhffs, Vhffs::Constants::WAITING_FOR_CREATION );
@@ -55,5 +58,17 @@
 	Vhffs::Robots::Mail::modify( $_ );
 }
 
+my $boxes = Vhffs::Robots::Mail::getall_boxes( $vhffs, Vhffs::Constants::WAITING_FOR_CREATION );
+foreach ( @{$boxes} ) {
+	my $mail = Vhffs::Services::Mail::get_by_mxdomain( $vhffs, $_->{domain} );
+	Vhffs::Robots::Mail::create_mailbox( $mail, $_->{local_part} );
+}
+
+$boxes = Vhffs::Robots::Mail::getall_boxes( $vhffs, Vhffs::Constants::WAITING_FOR_DELETION );
+foreach ( @{$boxes} ) {
+	my $mail = Vhffs::Services::Mail::get_by_mxdomain( $vhffs, $_->{domain} );
+	Vhffs::Robots::Mail::delete_mailbox( $mail, $_->{local_part} );
+}
+
 Vhffs::Robots::unlock( $vhffs, 'mail' );
 exit 0;

Deleted: trunk/vhffs-robots/src/mail_createboxes.pl
===================================================================
--- trunk/vhffs-robots/src/mail_createboxes.pl	2012-02-25 23:10:49 UTC (rev 2063)
+++ trunk/vhffs-robots/src/mail_createboxes.pl	2012-02-26 02:01:26 UTC (rev 2064)
@@ -1,78 +0,0 @@
-#!%PERL%
-# Copyright (c) vhffs project and its contributors
-# 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. Neither the name of vhffs nor the names of its contributors 
-#   may be used to endorse or promote products derived from this 
-#   software without specific prior written permission.
-#
-#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-#"AS IS" AND ANY EXPRESS 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 THE 
-#COPYRIGHT OWNER OR 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 robot create mail boxes
-
-use strict;
-use utf8;
-use File::Path;
-
-use lib '%VHFFS_LIB_DIR%';
-use Vhffs::Services::Mail;
-use Vhffs::Robots::Mail;
-use Vhffs::Robots;
-use Vhffs::Main;
-
-my $vhffs = init Vhffs::Main;
-die('Unable to initialize VHFFS main object') unless defined $vhffs;
-my $mailconf = $vhffs->get_config->get_service('mail');
-die('Unable to find mail configuration (boxes_uid/boxes_gid)') unless ( defined $mailconf && defined $mailconf->{'boxes_uid'} && $mailconf->{'boxes_gid'} );
-
-Vhffs::Robots::lock( $vhffs , 'mail' );
-
-my $boxes = Vhffs::Robots::Mail::getall_boxes( $vhffs , Vhffs::Constants::WAITING_FOR_CREATION );
-foreach my $b ( @{$boxes} )
-{
-	my $mail = Vhffs::Services::Mail::get_by_mxdomain( $vhffs, $b->{domain} );
-	if( defined $mail )  {
-
-		my $dir = $mail->get_box_dir( $b->{local_part} );
-		my $prevumask = umask 0;
-		File::Path::make_path( $dir, { mode => 0755, error => \my $errors });
-		File::Path::make_path( $dir.'/Maildir/cur', $dir.'/Maildir/new', $dir.'/Maildir/tmp', { mode => 0700, error => \$errors }) unless @$errors;
-		umask $prevumask;
-		
-		unless( @$errors ) {
-			# make_path owner and group directives do not seem to work if owner and group and numeric
-			Vhffs::Robots::chown_recur( $dir, $mailconf->{'boxes_uid'}, $mailconf->{'boxes_gid'} );
-			chmod 0700, $dir;
-
-			$mail->set_box_status( $b->{local_part} , Vhffs::Constants::ACTIVATED );
-		} else  {
-			$mail->set_box_status( $b->{local_part} , Vhffs::Constants::CREATION_ERROR );
-		}
-	}
-}
-
-Vhffs::Robots::unlock( $vhffs , 'mail' );
-
-
-exit 0;

Deleted: trunk/vhffs-robots/src/mail_deleteboxes.pl
===================================================================
--- trunk/vhffs-robots/src/mail_deleteboxes.pl	2012-02-25 23:10:49 UTC (rev 2063)
+++ trunk/vhffs-robots/src/mail_deleteboxes.pl	2012-02-26 02:01:26 UTC (rev 2064)
@@ -1,72 +0,0 @@
-#!%PERL%
-# Copyright (c) vhffs project and its contributors
-# 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. Neither the name of vhffs nor the names of its contributors 
-#   may be used to endorse or promote products derived from this 
-#   software without specific prior written permission.
-#
-#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-#"AS IS" AND ANY EXPRESS 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 THE 
-#COPYRIGHT OWNER OR 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 robot archives and delete mail boxes
-use strict;
-use utf8;
-
-use lib '%VHFFS_LIB_DIR%';
-use Vhffs::Services::Mail;
-use Vhffs::Robots::Mail;
-use Vhffs::Robots;
-use Vhffs::Main;
-use File::Path;
-use File::Basename;
-
-my $vhffs = init Vhffs::Main;
-die('Unable to initialize VHFFS main object') unless defined $vhffs;
-my $mailconf = $vhffs->get_config->get_service('mail');
-die('Unable to find mail configuration (boxes_uid/boxes_gid)') unless defined $mailconf;
-
-Vhffs::Robots::lock( $vhffs , 'mail' );
-
-my $boxes = Vhffs::Robots::Mail::getall_boxes( $vhffs , Vhffs::Constants::WAITING_FOR_DELETION );
-foreach my $b ( @{$boxes} )
-{
-	my $mail = Vhffs::Services::Mail::get_by_mxdomain( $vhffs, $b->{domain} );
-	next unless defined $mail;
-
-	my $dir = $mail->get_box_dir( $b->{local_part} );
-	Vhffs::Robots::archive_targz( $mail, $dir, [ $b->{local_part} ] ); 
-
-	if( -d $dir ) {
-		# TODO: check remove_tree
-		File::Path::remove_tree($dir);
-		# Remove the letter/ directory if empty
-		rmdir File::Basename::dirname($dir);
-	}
-	$mail->delbox( $b->{local_part} );
-}
-
-Vhffs::Robots::unlock( $vhffs , 'mail' );
-
-
-exit 0;


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