[sork] Vacation feature suggestion
tuimonen@cc.hut.fi
tuimonen@cc.hut.fi
Thu, 18 Jul 2002 13:12:18 +0300 (EET DST)
Hello.
I made a one version for my own use which reads aliasfile (configured in
vacation/conf/conf.php as $conf['vacation']['aliasfile'] =
'/etc/mail/aliases'; ) and then searches the aliases for given user and
inserts them as " -a alias" before username in the vacation options. IE.
/usr/bin/vacation -a one -a or -a more -a aliases username
> Not all vacation programs support an alias (-a switch) so we'd have to
> make this configurable.
Actually this is accidentally taken care of (I didn't plan it), by
specifying the ['aliasfile']=''
The code checks for existence of aliasfile, and if not found (or if
unable to open it) returns false (or prints an error message and returns
false) and the vacation options won't include any -a aliases.
My vacation program doesn't function correct with aliased mails
(Firstname.Lastname@...) if only username is specified at the "command
line" (that is /usr/bin/vacation username), mails to username@... works
fine though. So I decided to give a try (with my pathetic coding skills)
and here it is:
this assumes alias file format to be:
alias: username
from vacation.php (sorry if the output is screwed, it's copypaste)
/**
* Get aliases for user
*/
function get_aliases($user)
{
$aliases = '';
$conf = &$GLOBALS['conf'];
$aliasfilename = @$conf['vacation']['aliasfile'];
if(!file_exists($aliasfilename)) {
// do something clever
return false;
// ooh, I'm impressed
// the .forward still works fine, but no aliases will be defined
}
if (!($fileHandle = fopen($aliasfilename, "r"))) {
$this->err_str = _("Could not open file %s",$aliasfilename);
return false;
}
while(!feof($fileHandle)) {
$buffer = fgets($fileHandle,1024);
if(ereg( "^([a-zA-Z0-9.]+)[:][[:space:]]*([a-zA-Z0-9]+)\n$", $buffer ,$item)) {
// $item[1]=The.Alias.Name
// $item[2]=username
if(strcmp($item[2],$user)==0) {
$name=split("[.]",$item[1]);
foreach($name as $n) {
$n=trim($n,".");
// don't add if the alias is already added
if(!strstr($aliases," -a $n")) { $aliases.= " -a $n";}
}
}
}
}
fclose($fileHandle);
return $aliases;
}
..and later on from the set_vacation function
$useraliases = $this->get_aliases($user);
$myFile = $this->write_temp_file("\\$user, \"|" . $conf['vacation']['path'] . "$useraliases $user\"");
and that's it.
If user has multiple aliases, like
Firstname: username
Lastname: username
Firstname.Lastname: username
the multiple entries are discarded output will be -a Firstname -a Lastname
and in cases like
My.Very.Long.Alias: username
output is -a My -a Very -a Long -a Alias
Why not -a My.Very.Long.Alias? Well, my vacation didn't work with that
(came with rh 7.2) and if user has aliases My@, Long@, Alias@ and also
My.Long.Alias@ they all work with this (at least works for me).
But one big problem still exists; When the Vacation module sets the
.vacation databases, they are empty (size=0) and my vacation program
didn't work with that. I had to run 'vacation -i' from the shell after
Vacation had written the empty database files in order to get all going
smooth.
I guess there is no (decent) way to get the 'vacation -i' command
executed automatically..
Tommi Uimonen
ps. And also (this is a rare one) if user has aliases like webmaster,
postmaster etc. they will be added, but I think it's bad image for any
company to have webmaster reply "Hi, I'm enjoying the sun at Bahamas.
Cheers". Of course there are workarounds for these, but hey, if you are
webmaster I think you can set up your .forward file yourself :)