MHonArc
view release on metacpan or search on metacpan
contrib/mhastart.pl view on Meta::CPAN
return prtheader(), '<pre>', '<b>Output will appear here</b>';
}
sub add {
print prtheader(), '<pre>', "<b>Add messages to $name</b>\n\n";
popretrieve() if $pop3;
updatearchive('-add');
}
sub remove {
print prtheader(), '<pre>', "<b>Remove messages from $name</b>\n\n";
updatearchive('-rmm', $in{msgnumber});
}
sub remove_mbox {
my @msgs = read_mbox($mbox);
my $deleted = $mbox . '_deleted';
my $latestmsg = pop @msgs;
open FILE, ">> $deleted" or die "Couldn't open $deleted\n$!";
flock FILE, 2;
print FILE @$latestmsg;
close FILE;
open FILE, "> $mbox" or die "Couldn't open $mbox\n$!";
flock FILE, 2;
print FILE @$_ for @msgs;
close FILE;
print prtheader(), '<pre>', "<b>Remove raw messages from $name</b>\n\n",
"The latest message was removed from $mbox\nand appended to $deleted.\n\n",
'The mailbox file now includes ', scalar @msgs, ' message',
(scalar @msgs == 1 ? '.' : 's.');
}
sub shell {
my $checkpop;
require 'shellwords.pl';
@ARGV =
shellwords($in{command}); # the list of entered options is assigned
my $command = shift @ARGV; # to @ARGV, and with that passed to MHonArc
for my $element (@ARGV) {
if ($element eq '$archive') { $element = $archive }
elsif ($element eq '$mbox') { $element = $mbox }
elsif ($element eq '$mrc') { $element = $mrc }
elsif ($element eq '-add') { $checkpop = 1 }
}
print prtheader(), '<pre>';
if ($command =~ /^(?:mhonarc|mha-d)/) {
print "<b>Command executed:</b>\n$command @ARGV\n\n<b>Output:</b>\n";
popretrieve() if $pop3 and $checkpop;
require File::Spec->catfile($mhonarc, $command)
or die "Couldn't invoke $command\n$!";
} else {
print "That wasn't a MHonArc command, was it?";
}
}
##---------------------------------------------------------------------------
sub updatembox {
my $msgref = shift;
open FILE, ">> $mbox" or die "Couldn't open $mbox\n$!";
flock FILE, 2;
print FILE ($pop3 ? join '', @$msgref : $$msgref), "\n\n";
close FILE;
}
sub updatearchive {
@ARGV = (@_, '-outdir', $archive);
push @ARGV, $mbox unless $in{routine} eq 'remove';
require 'mhamain.pl' or die "Couldn't require mhamain.pl\n$!";
mhonarc::initialize(); # skipped the 'mhonarc' program file in
mhonarc::process_input(); # order to avoid the ending exit call
}
sub popretrieve {
require Net::POP3;
my $pop = Net::POP3->new($pophost);
my $cnt;
POP: {
$cnt = $pop->login($user, $password);
my $msgs = $pop->list();
last POP unless $cnt > 0;
my ($msg, $msgnum, $line, $list, $to,
$subject, $tmp, $key, $aref, %header
);
## Loop thru each message and append to $newmail
foreach $msgnum (sort { $a <=> $b } keys %$msgs) {
$msg = $pop->get($msgnum);
next unless defined $msg;
## Grab message header
%header = ();
$aref = undef;
foreach $line (@$msg) {
last if $line =~ /^$/;
$tmp = $line;
chomp $tmp;
if ($tmp =~ s/^\s//) {
next unless defined $aref;
$aref->[$#$aref] .= $tmp;
next;
}
if ($tmp =~ s/^([^:]+):\s*//) {
$key = lc $1;
if (defined $header{$key}) { $aref = $header{$key} }
else { $aref = $header{$key} = [] }
push @$aref, $tmp;
next;
}
}
unshift @$msg,
"From username\@domain.com Sat Jan 1 00:00:00 2000\n";
updatembox($msg);
$pop->delete($msgnum);
}
$pop->quit();
undef $pop;
print "$cnt message"
. ($cnt > 1 ? 's' : '')
. " from $user\@$pophost\n", "appended to $mbox\n\n"
if $in{routine} eq ('add' or 'shell');
}
$pop->quit() if defined $pop;
( run in 0.778 second using v1.01-cache-2.11-cpan-bbcb1afb8fc )