add it to the main line
[spider.git] / perl / process_ursa.pl
1 #!/usr/bin/perl
2 #
3 # Process and import for mail SIDC Ursagrams
4 #
5 # This program takes a mail message on its standard input
6 # and, if it is an URSIGRAM, imports it into the local
7 # spider msg queue.
8 #
9 # Copyright (c) Dirk Koopman G1TLH
10 #
11 # $Id$
12 #
13
14 use strict;
15 use Mail::Internet;
16 use Mail::Header;
17
18 my $import = '/spider/msg/import';
19
20 my $msg = Mail::Internet->new(\*STDIN) or die "Mail::Internet $!";
21 my $head = $msg->head->header_hashref;
22
23 if ($head && $head->{From}->[0] =~ /sidc/i && $head->{Subject}->[0] =~ /Ursigram/i) {
24         my $body = $msg->body;
25         my $title = 'SIDC Ursigram';
26         my $date = '';
27         foreach my $l (@$body) {
28                 if ($l =~ /SIDC\s+SOLAR\s+BULLETIN\s+(\d+)\s+(\w+)\s+20(\d\d)/) {
29                         $date = "$1$2$3";
30                         $title .= " $date";
31                         last;
32                 }
33         }
34         open OUT, ">$import/ursigram$date.txt" or die "import $!";
35         print OUT "SB ALL\n$title\n";
36         print OUT map {s/\r\n$/\n/; $_} @$body;
37         print OUT "/ex\n";
38         close OUT;
39 }
40
41 exit(0);