~burner/xsb/debianized-xsb

« back to all changes in this revision

Viewing changes to misc/installation/mailarchive.pl

  • Committer: Michael R. Head
  • Date: 2006-09-06 22:11:55 UTC
  • Revision ID: burner@n23-20060906221155-7e398d23438a7ee4
Add the files from the 3.0.1 release package

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
## File:      mailarchive.pl
 
4
## Author(s): Jun Wang
 
5
## Contact:   xsb-contact@cs.sunysb.edu
 
6
## 
 
7
## Copyright (C) The Research Foundation of SUNY, 2000
 
8
## 
 
9
## XSB is free software; you can redistribute it and/or modify it under the
 
10
## terms of the GNU Library General Public License as published by the Free
 
11
## Software Foundation; either version 2 of the License, or (at your option)
 
12
## any later version.
 
13
## 
 
14
## XSB is distributed in the hope that it will be useful, but WITHOUT ANY
 
15
## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
16
## FOR A PARTICULAR PURPOSE.  See the GNU Library General Public License for
 
17
## more details.
 
18
## 
 
19
## You should have received a copy of the GNU Library General Public License
 
20
## along with XSB; if not, write to the Free Software Foundation,
 
21
## Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
22
##
 
23
## $Id: mailarchive.pl,v 1.1 2000/05/25 22:31:53 kifer Exp $
 
24
## 
 
25
##
 
26
 
 
27
# Invocation: mailarchive.pl [--keep] [MailBox] [SavedMailFile]
 
28
# Default MailBox: /var/spool/mail/$ENV{'LOGNAME'}
 
29
# Default SavedMailFile: $ENV{'HOME'}/mbox
 
30
 
 
31
$True=1;
 
32
$False=0;
 
33
 
 
34
$Keep=$False;
 
35
if(@ARGV[0] =~ /^\-\-keep$/i){          #case insensitive
 
36
    $Keep=$True;
 
37
    shift(@ARGV);
 
38
}
 
39
$MailBox=@ARGV[0];
 
40
$SavedEmail=@ARGV[1];
 
41
# Set defaults, if arguments aren't given
 
42
if ($MailBox eq "") {
 
43
    $MailBox="/var/spool/mail/$ENV{'LOGNAME'}";
 
44
}
 
45
if ($SavedEmail eq "") {
 
46
    $SavedEmail="$ENV{'HOME'}/mbox";
 
47
}
 
48
 
 
49
#General Config
 
50
$ConfigFile="datafields.cfg";
 
51
$InstallationLog="archive.P";
 
52
$InstalSubject="\\\[Xsb-installation\\\]";
 
53
$InstalTitle="INSTALLATION SUMMARY";
 
54
 
 
55
 
 
56
#Reading config file. 
 
57
#All the fields will be extracted from email installation log 
 
58
#need to be stored in this file, one in each line.
 
59
unless (open(CONFFILE, $ConfigFile)) {
 
60
        die ("cannot open configure file $ConfigFile\n");
 
61
}
 
62
     @ConfigInput = <CONFFILE>;
 
63
#     print (@ConfigInput);
 
64
 
 
65
 
 
66
 
 
67
#Open email file and the new file to save after trimmed the installation log.
 
68
unless (open(EMAILFILE, $MailBox)) {
 
69
        die ("Cannot open system mailbox: \'$MailBox\'\n");
 
70
}
 
71
unless (open(NEWEMAILFILE, ">>$SavedEmail")) {
 
72
        die ("Cannot open local mailbox: \'$SavedEmail\'\n");
 
73
}
 
74
unless (open(XSBLOG, ">>$InstallationLog")) {
 
75
        die ("Cannot open installation archive: \'$InstallationLog\'\n");
 
76
}
 
77
 
 
78
 
 
79
 
 
80
#Readin email, one by one.
 
81
$LineOrigin=<EMAILFILE>;
 
82
#Ignore lines otherthan "From ", which indicate a email, notice the space
 
83
while($LineOrigin ne "" && $LineOrigin !~ /^From /){
 
84
        $LineOrigin=<EMAILFILE>;
 
85
}
 
86
$emailcounter=0;
 
87
while($LineOrigin ne ""){
 
88
   $FirstBlock=$True;
 
89
   $linecounter=0;
 
90
   $EmailCurrent[$linecounter]=$LineOrigin;
 
91
   $LineOrigin=<EMAILFILE>;
 
92
   $emailcounter++;
 
93
   while($LineOrigin ne "" && $LineOrigin !~ /^From /){
 
94
      $linecounter++;
 
95
      $EmailCurrent[$linecounter]=$LineOrigin;
 
96
 
 
97
      #find the Subject and the From line
 
98
      #the Subject and the From line has to be in the first block of email msg
 
99
      if($EmailCurrent[$linecounter] eq "\n"){
 
100
         $FirstBlock=$False;
 
101
      }
 
102
      if($FirstBlock==$True){
 
103
         if($EmailCurrent[$linecounter] =~ /^Subject: /){
 
104
            $SubjectLine = $EmailCurrent[$linecounter];
 
105
            $SubjectLine =~ s/^Subject: //;
 
106
         }
 
107
         if($EmailCurrent[$linecounter] =~ /^From: /){
 
108
            $FromLine = $EmailCurrent[$linecounter];
 
109
            $FromLine =~ s/^From: //;
 
110
         }
 
111
      }
 
112
      $LineOrigin=<EMAILFILE>;
 
113
   }
 
114
 
 
115
   # If a XSB installation log is found, this email will not be saved,
 
116
   # and the file $InstallationLog will be updated.
 
117
   $Found=$False;
 
118
   if($SubjectLine =~ /$InstalSubject/){ 
 
119
      for($loop=0; $loop<=$linecounter; $loop++){
 
120
           if($EmailCurrent[$loop]=~/$InstalTitle/){
 
121
              $Found=$True;
 
122
           }
 
123
      }
 
124
   }
 
125
   if($Found == $False) { 
 
126
      for($loop=0; $loop<=$linecounter; $loop++){
 
127
         print NEWEMAILFILE ($EmailCurrent[$loop]);
 
128
      }
 
129
   }
 
130
   else{
 
131
 
 
132
      #extract the name and email info.
 
133
      if($FromLine =~ /\(|\</){
 
134
          # this addr has both name & email separated by <> or ()
 
135
          $Name = $FromLine;
 
136
          $Name =~ s/[\(\<].*//;
 
137
          $Name =~ s/^[ \t\n]*//; 
 
138
          $Name =~ s/[ \t\n]*$//;
 
139
          $EmailAddress=$FromLine;
 
140
          $EmailAddress=~ s/^[^\(\<]*[\(\<]//;
 
141
          $EmailAddress=~ s/[\)\>].*//;
 
142
          $EmailAddress=~ s/[ \t\n]*$//;
 
143
          $EmailAddress=~ s/^[ \t\n]*//;
 
144
          if($Name=~/\@/){
 
145
              $Temp=$Name;
 
146
              $Name=$EmailAddress;
 
147
              $EmailAddress=$Temp;
 
148
          }
 
149
      }
 
150
      else{
 
151
         $EmailAddress=$FromLine;
 
152
         $EmailAddress=~ s/[ \t\n]*$//;
 
153
         $EmailAddress=~ s/^[ \t\n]*//;
 
154
         $Name = "";
 
155
         if($EmailAddress !~ /\@/){
 
156
            $Temp=$Name;
 
157
            $Name=$EmailAddress;
 
158
            $EmailAddress=$Temp;
 
159
         }
 
160
      }
 
161
     print XSBLOG ("installation\(\[\n");
 
162
     print XSBLOG ("\t\'name\'\(\'$Name\'\)\,\n");
 
163
     print XSBLOG ("\t\'email\'\(\'$EmailAddress\'\)");
 
164
 
 
165
     #extract the info from configure file.
 
166
     foreach $ConfigInput (@ConfigInput){
 
167
         $ConfigInput =~ s/[\n \t]*$//;
 
168
         $ConfigInput =~ s/^[\n \t]*//;
 
169
         if ($ConfigInput =~ /^\#/ || $ConfigInput eq "") {
 
170
             next;
 
171
         }
 
172
         @ConfigInputWords = split(/[ \t]*!![ \t]*/, $ConfigInput);
 
173
         $ConfigInputTemplate = $ConfigInputWords[0] . ":";
 
174
         $ConfigInputKey = $ConfigInputWords[1];
 
175
         for($loop=0; $loop<=$linecounter; $loop++){
 
176
             if($EmailCurrent[$loop]=~ /$ConfigInputTemplate/){
 
177
                 print XSBLOG "\,\n";  # terminate the previous line
 
178
                 print XSBLOG ("\t\'$ConfigInputKey\'");
 
179
                 $ConfigInputValue = $EmailCurrent[$loop];
 
180
                 $ConfigInputValue =~ s/$ConfigInputTemplate//;
 
181
                 $ConfigInputValue =~ s/[\n \t]*$//;
 
182
                 $ConfigInputValue =~ s/^[\n \t]*//;
 
183
                 print XSBLOG ("\(\'$ConfigInputValue\'\)");
 
184
             }
 
185
         }
 
186
     }
 
187
      print XSBLOG ("\n\t\]\).\n\n");
 
188
   }
 
189
#   print ("$emailcounter \n");
 
190
}
 
191
close(CONFFILE);
 
192
close(EMAILFILE);
 
193
close(NEWEMAILFILE);
 
194
close(XSBLOG);
 
195
 
 
196
if($Keep != $True){
 
197
   `rm -f $MailBox`;
 
198
}