1 |
#!/usr/bin/perl |
2 |
|
3 |
use strict; |
4 |
use warnings; |
5 |
|
6 |
# how are we called? |
7 |
if (! $ARGV[0]) { print STDERR "Call as nb_mail \$blog_dir."; exit(1); } |
8 |
|
9 |
my ($message, $msgstring); |
10 |
my ($title, $cat, $body); |
11 |
my ($blog_dir, $status); |
12 |
|
13 |
# blog directory |
14 |
$blog_dir = $ARGV[0]; |
15 |
chomp($blog_dir); |
16 |
$blog_dir =~ s/~/$ENV{HOME}/; |
17 |
$blog_dir .= '/' if ($blog_dir !~ /.*\/$/); |
18 |
|
19 |
# read mail from STDIN |
20 |
if (!open(IN, '-')) { print STDERR "Could not read from STDIN: $!\n"; exit(1); } |
21 |
my @message = <IN>; |
22 |
close IN; |
23 |
|
24 |
# create one string |
25 |
foreach my $line (@message) { |
26 |
chomp($line); |
27 |
next if ($line =~/^$/); |
28 |
$msgstring .= $line; |
29 |
} |
30 |
|
31 |
# grep variables |
32 |
($title, $cat, $body) = ($msgstring =~ /^.*TITLE:\s*(.+?)\s*CAT:\s*(.+?)\s*BODY:\s*(.+?)\s*$/); |
33 |
|
34 |
#print "title: $title\n"; |
35 |
#print "cat: $cat\n"; |
36 |
#print "body: $body\n"; |
37 |
|
38 |
|
39 |
# call nb |
40 |
umask 0002; |
41 |
$status = system("PATH=\"/usr/local/bin:/usr/bin:/bin\" nb -b $blog_dir -c $cat -t \"$title\" -B \"$body\" -a"); |
42 |
if ($status != 0) { print STDERR "Error while executing nb: $?\n"; exit(1); } |
43 |
print "$status\n"; |
44 |
exit (0); |