|
A perl script may call the csoftadm program in the following ways:
open(CSOFTADM, '|csoftadm -') || die;
print CSOFTADM qq{mail alias add "user@domain.ext" "insn"};
close(CSOFTADM);
my @aliases = `csoftadm -c "mail alias list"`;
print @aliases, "\n";
The MGID module, however, provides a much more efficient interface
than the csoftadm program ("mgid" is the name of the basic open-source
package
which csoftadm is based on).
MGID is a Perl XS module for libmgid (the csoftadm C library).
This module is documented in the
MGID(3p) manual page.
The following script authenticates and outputs the server announcements
using the low-level query interface:
#!/usr/bin/perl
use MGID;
my $mgi = MGID->new('localhost', 73, $USERNAME, $PASSWORD)
|| die MGID::Error();
if ($mgi->ModuleAvail('Info')) {
print $mgi-<QueryList('Info', 'Motd'), "\n";
}
The following script uses the high-level interface to mail
configuration (see
MGID::MailDeliveryCfg
for details):
#!/usr/bin/perl
use MGID;
my $mgi = MGID->new('localhost', 73, $USERNAME, $PASSWORD)
|| die MGID::Error();
unless ($mgi->ModuleAvail('Alias')) {
die MGID::Error();
}
# Print addresses
my $mailCfg = $mgi->MailDeliveryCfg();
foreach my $addr ($mailCfg->Addresses()) {
print $addr->AddressUTF8()."\n";
foreach my $insn ($addr->Insns()) {
foreach my $cond ($insn->Conds()) {
print "(if )".$cond->String()."\n";
}
print $insn->String()."\n";
}
}
# Configure new address
my $addr = MGID::MailAddress->new('test-addr@domain.ext');
$addr->Add(MGID::MailInsn->newForward('dest1@domain.ext'));
$addr->Add(MGID::MailInsn->newForward('dest2@domain.ext'));
$addr->Commit($mgi) || die MGID::Error();
|