3 # Process and import for mail WWV and Solar Data
5 # This program takes a mail message on its standard input
6 # and, if it is WWV or Solar info, imports it into the local
7 # spider chat_import queue.
9 # Both the "tmp" and the "chat_import" directories should be
12 # Copyright (c) 2004 Dirk Koopman G1TLH
23 # search local then perl directories
25 # root of directory tree for this system
27 $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
29 unshift @INC, "$root/perl"; # this IS the right way round!
30 unshift @INC, "$root/local";
33 my $import = "$root/chat_import";
34 my $tmp = "$root/tmp";
36 my $msg = Mail::Internet->new(\*STDIN) or die "Mail::Internet $!";
37 my $head = $msg->head->header_hashref;
40 if ($head->{Subject}->[0] =~ /wwv/i) {
42 } elsif ($head->{From}->[0] =~ /rwc\.boulder/i || $head->{'From '}->[0] =~ /rwc\.boulder/i) {
55 foreach (@{$msg->body}) {
58 next if /^\s*\r?\n$/s;
66 $l =~ s/\s*\.?\r?\n$//;
79 foreach (@{$msg->body}) {
80 if (!$state && /Space\s+Weather\s+Message\s+Code:/i) {
83 if ($state == 1 && /^[A-Z]+:/) {
86 if ($state == 2 && /^\s*\r?\n$/s) {
101 my $fn = "solar.txt.$$";
103 open OUT, ">$tmp/$fn" or die "import $tmp/$fn $!";
104 chmod 0666, "$tmp/$fn";
105 print OUT map { "$_\n" } @_;
108 # Note we do this this way to make the appearance of
109 # the file in /spider/chat_import atomic. Otherwise there
110 # exists the possiblity of race conditions and other nasties
111 link "$tmp/$fn", "$import/$fn";