зеркало из https://github.com/mozilla/gecko-dev.git
130 строки
2.5 KiB
Perl
130 строки
2.5 KiB
Perl
#!/usr/sbin/perl
|
|
|
|
# mkfolder
|
|
#
|
|
# This script converts a series of test files, each containing
|
|
# a single icalendar object into a single mail folder with messages
|
|
# for each iCalendar object.
|
|
#
|
|
# Currently the name of the folder produced is hardcoded as "newIMIP"
|
|
#
|
|
# To convert mail folders into a series of test files use mktest
|
|
#
|
|
# Usage:
|
|
# mkfolder test*.txt
|
|
#
|
|
# -sman
|
|
|
|
|
|
if (0 > $#ARGV)
|
|
{
|
|
print STDERR "You need to supply a list of test files on the cmd line\n";
|
|
die;
|
|
}
|
|
|
|
#
|
|
# Hardcode some values to get things rolling...
|
|
#
|
|
$MailFolderName = "newIMIP";
|
|
$TestCount = 0;
|
|
$Day = 7;
|
|
$Hour = 0;
|
|
$Min = 0;
|
|
$Sec = 0;
|
|
|
|
sub mailHeader
|
|
{
|
|
local($m) = pop(@_);
|
|
$fline = sprintf("From - Feb %02d %02d:%02d:%02d 1998\n",
|
|
$Day, $Hour, $Min, $Sec);
|
|
print MFOLDER "$fline";
|
|
print MFOLDER "Return-Path: <sman\@netscape.com>\n";
|
|
print MFOLDER "From: sman\@netscape.com\n";
|
|
print MFOLDER "To: terry\@netscape.com\n";
|
|
print MFOLDER "Subject: $ARGV[$i]\n";
|
|
print MFOLDER "Mime-Version: 1.0\n";
|
|
print MFOLDER "Content-Type:text/calendar; method=".${m}."; charset=US-ASCII\n";
|
|
print MFOLDER "Content-Transfer-Encoding: 7bit\n";
|
|
print MFOLDER "\n";
|
|
if ( (++$Sec) > 59 )
|
|
{
|
|
$Sec = 0;
|
|
if ( (++$Min) > 59 )
|
|
{
|
|
$Min = 0;
|
|
if ( (++$Hour) > 23 )
|
|
{
|
|
$Hour = 0;
|
|
++$Day; # this is enough for now
|
|
}
|
|
}
|
|
}
|
|
foreach $j (0 .. $i-1)
|
|
{
|
|
print MFOLDER $keep[$j];
|
|
}
|
|
}
|
|
|
|
|
|
#
|
|
# Open the mail folder and get going.
|
|
#
|
|
if (!open(MFOLDER,">> $MailFolderName"))
|
|
{
|
|
print STDERR "Can't create $MailFolderName \n";
|
|
print STDERR "error: $!\n";
|
|
die;
|
|
}
|
|
|
|
|
|
#
|
|
# Spin through the list of supplied folders, add them to MFOLDER
|
|
#
|
|
foreach $i (0..$#ARGV)
|
|
{
|
|
if (!open(TESTFILE,$ARGV[$i]))
|
|
{
|
|
print STDERR "Can't open $filename \n";
|
|
print STDERR "error: $!\n";
|
|
die;
|
|
}
|
|
|
|
++$TestCount;
|
|
|
|
#
|
|
# Save lines until we find the method...
|
|
#
|
|
$Looking = 1;
|
|
$i = 0;
|
|
while ($Looking == 1)
|
|
{
|
|
if ($line = <TESTFILE>)
|
|
{
|
|
$keep[$i++] = $line;
|
|
if ($line =~ /METHOD:/)
|
|
{
|
|
$Looking = 0;
|
|
$method = substr( $line, 1+index($line,":") );
|
|
chop($method);
|
|
&mailHeader($method);
|
|
}
|
|
}
|
|
}
|
|
|
|
#
|
|
# Add the lines in the test folder...
|
|
#
|
|
while ($line = <TESTFILE>)
|
|
{
|
|
print MFOLDER $line
|
|
}
|
|
print MFOLDER "\n";
|
|
|
|
}
|
|
|
|
close MFOLDER;
|
|
print "new mail folder created: $MailFolderName\n";
|
|
print "entries added: $TestCount \n";
|
|
|
|
|