#!/usr/local/bin/perl -Tw # # createIMAPDir # # Create /var/imap/ with the right permissions. # Released under GPL. # # NOTE: createIMAPDir requires a file called /var/mail/mbxnull. This is # just an empty mbx format file. You can create one using mbxcreat # (imaputils) with the right c-client.a linked in OR just download # it from http://www.carumba.com/talk/imap/mbxnull # # $Id: createIMAPDir,v 1.1 1998/08/30 06:34:44 jauderho Exp jauderho $ # (C) Copyright 1998 Jauder Ho # # 070498 jauderho [added account creation date for tracking] # 082998 jauderho [slight rework to account for greeting message] # [insists that user must exist in YP to be created] # 090198 jauderho [added automatic Trash folder creation] # 090898 jauderho [we only need to do getpwnam() once] # 091198 jauderho [fix insecure dependency] # 091798 jauderho [fix chown problems] # use Text::Wrap; use File::Copy 'cp'; $ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin"; my @newFolders = ("INBOX","Trash"); # List folders you want created my $imapRoot = "/var/imap"; my $imapUser = $ARGV[0]; my $imapUserUID; my $mbxFormat = "mbx"; my $hostname = `hostname`; chomp($hostname); die "ERROR: You must run this on deepthought.\n" unless ($hostname =~ /deepthought/); $imapUser =~ /^(.*)$/; # Cleanse the input $imapUser = $1; $imapUserUID = (getpwnam($imapUser))[2,3]; die "ERROR: No such user ($imapUser) exists. Please recheck YP passwd maps.\n" unless defined($imapUserUID); if ( ! -f "/var/mail/$imapUser" ) { print "Creating /var/mail/$imapUser ...\n"; cp("/var/mail/greeting","/var/mail/$imapUser"); chown($imapUserUID, $imapUserUID, "/var/mail/$imapUser"); chmod(0600,"/var/mail/$imapUser"); } if ( ! -d "$imapRoot/$imapUser" ) { my $pre1 = ""; my $pre2 = ""; my $folder; mkdir("$imapRoot/$imapUser",0700); chown($imapUserUID, $imapUserUID, "$imapRoot/$imapUser"); # Create folders beforehand for $folder (@newFolders) { print "Creating /var/imap/$imapUser/$folder ...\n"; cp("/var/mail/mbxnull","$imapRoot/$imapUser/$folder"); chown($imapUserUID, $imapUserUID, "$imapRoot/$imapUser/$folder"); chmod(0600,"$imapRoot/$imapUser/$folder"); } print "\n"; # Filler space # Record account creation date `touch $imapRoot/$imapUser/.inbox.create`; chown($imapUserUID, $imapUserUID, "$imapRoot/$imapUser/.inbox.create"); print wrap($pre1, $pre2, "An empty inbox at /var/imap/$imapUser/INBOX has been created. The next time $imapUser reads mail, all the mail in /var/mail/$imapUser will be brought over safely into the new mailbox.\n"); } else { die "ERROR: $imapRoot/$imapUser already exists ...\n"; }