3 # Process and import for mail SIDC Ursagrams
5 # This program takes a mail message on its standard input
6 # and, if it is an URSIGRAM, imports it into the local
9 # Copyright (c) 2004 Dirk Koopman G1TLH
20 # search local then perl directories
22 # root of directory tree for this system
24 $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
26 unshift @INC, "$root/perl"; # this IS the right way round!
27 unshift @INC, "$root/local";
30 my $import = "$root/msg/import";
31 my $tmp = "$root/tmp";
33 my $msg = Mail::Internet->new(\*STDIN) or die "Mail::Internet $!";
34 my $head = $msg->head->header_hashref;
35 my $fromcall = shift || 'G1TLH';
37 if ($head && $head->{From}->[0] =~ /sidc/i && $head->{Subject}->[0] =~ /Ursigram/i) {
38 my $body = $msg->body;
39 my $title = 'SIDC Ursigram';
41 foreach my $l (@$body) {
42 if ($l =~ /SIDC\s+SOLAR\s+BULLETIN\s+(\d+)\s+(\w+)\s+20(\d\d)/) {
48 my $fn = "ursigram$date.txt.$$";
49 open OUT, ">$tmp/$fn" or die "import $tmp/$fn $!";
50 print OUT "SB ALL < $fromcall\n$title\n";
51 print OUT map {s/\r\n$/\n/; $_} @$body;
54 link "$tmp/$fn", "$import/$fn";