3
## File: mailarchive.pl
5
## Contact: xsb-contact@cs.sunysb.edu
7
## Copyright (C) The Research Foundation of SUNY, 2000
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)
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
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.
23
## $Id: mailarchive.pl,v 1.1 2000/05/25 22:31:53 kifer Exp $
27
# Invocation: mailarchive.pl [--keep] [MailBox] [SavedMailFile]
28
# Default MailBox: /var/spool/mail/$ENV{'LOGNAME'}
29
# Default SavedMailFile: $ENV{'HOME'}/mbox
35
if(@ARGV[0] =~ /^\-\-keep$/i){ #case insensitive
41
# Set defaults, if arguments aren't given
43
$MailBox="/var/spool/mail/$ENV{'LOGNAME'}";
45
if ($SavedEmail eq "") {
46
$SavedEmail="$ENV{'HOME'}/mbox";
50
$ConfigFile="datafields.cfg";
51
$InstallationLog="archive.P";
52
$InstalSubject="\\\[Xsb-installation\\\]";
53
$InstalTitle="INSTALLATION SUMMARY";
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");
62
@ConfigInput = <CONFFILE>;
63
# print (@ConfigInput);
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");
71
unless (open(NEWEMAILFILE, ">>$SavedEmail")) {
72
die ("Cannot open local mailbox: \'$SavedEmail\'\n");
74
unless (open(XSBLOG, ">>$InstallationLog")) {
75
die ("Cannot open installation archive: \'$InstallationLog\'\n");
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>;
87
while($LineOrigin ne ""){
90
$EmailCurrent[$linecounter]=$LineOrigin;
91
$LineOrigin=<EMAILFILE>;
93
while($LineOrigin ne "" && $LineOrigin !~ /^From /){
95
$EmailCurrent[$linecounter]=$LineOrigin;
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"){
102
if($FirstBlock==$True){
103
if($EmailCurrent[$linecounter] =~ /^Subject: /){
104
$SubjectLine = $EmailCurrent[$linecounter];
105
$SubjectLine =~ s/^Subject: //;
107
if($EmailCurrent[$linecounter] =~ /^From: /){
108
$FromLine = $EmailCurrent[$linecounter];
109
$FromLine =~ s/^From: //;
112
$LineOrigin=<EMAILFILE>;
115
# If a XSB installation log is found, this email will not be saved,
116
# and the file $InstallationLog will be updated.
118
if($SubjectLine =~ /$InstalSubject/){
119
for($loop=0; $loop<=$linecounter; $loop++){
120
if($EmailCurrent[$loop]=~/$InstalTitle/){
125
if($Found == $False) {
126
for($loop=0; $loop<=$linecounter; $loop++){
127
print NEWEMAILFILE ($EmailCurrent[$loop]);
132
#extract the name and email info.
133
if($FromLine =~ /\(|\</){
134
# this addr has both name & email separated by <> or ()
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]*//;
151
$EmailAddress=$FromLine;
152
$EmailAddress=~ s/[ \t\n]*$//;
153
$EmailAddress=~ s/^[ \t\n]*//;
155
if($EmailAddress !~ /\@/){
161
print XSBLOG ("installation\(\[\n");
162
print XSBLOG ("\t\'name\'\(\'$Name\'\)\,\n");
163
print XSBLOG ("\t\'email\'\(\'$EmailAddress\'\)");
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 "") {
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\'\)");
187
print XSBLOG ("\n\t\]\).\n\n");
189
# print ("$emailcounter \n");