#!/usr/bin/perl # Perl script to convert PM Mail (v 1.91) for OS/2 email folders # to Netscape (v 4) Messenger for Linux # Also required is the "file-lib.pl" script, which I'm just using # to make a Perl-clean "ls $DIR/*.fld" call # # Usage: simple, mount your OS/2 drive, set $top_dir to the name # of the PM Mail account folder, and then set $new_dir to a temp # dir name. Run the script. That's it. # # It will try to keep your existing folder names, but converts # " " to "_", and "/" to "-", and then tosses any other characters # besides letters or numbers, just to be safe. # # Seriously, I renamed my (empty) ~/nsmail in case Netscape # got mad, and did a "cp -r /tmp/nsmail ~/nsmail" without Netscape # running... As soon as you try to open a folder Netscape will do # some initial parsing, and thanks to BoB and Icon, PMMail even # marks the "read" messages correctly !!! # # This script is copyright 1997 Peter W, copying allowed under # terms of the GNU Copyright (http://www.gnu.org/) # # Please email me if you have any troubles or suggestions, though # I'd bet we're all just going to use this once ;-) # # -Peter W (mailto:peterw@clark.net) # July 18, 1997 # # Note to BoB & Icon: thanks for the great mail app. Nothing else comes # close to PM Mail. Now if you'd only make a Linux version I'd be very # happy. Best of luck to you both. # require "file-lib.pl"; $top_dir = "/os2/ftpware/southsde/pmmail/peterw_1.act"; $new_dir = "/tmp/nsmail"; $tally = 0; $start[$tally] = $top_dir; $target[$tally] = $new_dir; $tally += 1; for ($out_loop = 0 ; $out_loop < $tally ; ++$out_loop ) { &MakeFolder($start[$out_loop],$target[$out_loop]); } exit 0; # ------------------------------------------------------------- sub MakeFolder { local ($start_dir,$final_dir) = @_; if ( ($start_dir eq "") || ($final_dir eq "") ) { return 0; } local @Subdirs, $make_subdir, $num_Subdirs, $loop; local @Startdirs, $buffer, $filename; local $wkday, $from_line, $wkday, $month, $monum, $time, $year; local $write_folder; #print "Starting with \"$start_dir\", writing to \"$final_dir\"\n"; $write_folder = 1; if (! open(INI,"<$start_dir/folder.ini") ) { print "Cannot open folder.ini\n"; $write_folder = 0; #exit 3; } $_ = ; close INI; $pm_name = ""; ($pm_name,$other) = split /\xde/, $_; while ( $pm_name =~ / / ) { $pm_name =~ s/ /\_/; } while ( $pm_name =~ /\// ) { $pm_name =~ s/\//\-/; } while ( $pm_name =~ /[^\w\_\-]/ ) { $pm_name =~ s/[^\w\_\-]//; } if ( $pm_name ne "" ) { #print "Looks like we should call this folder \"$pm_name\"\n"; } if (! open(BAG,"<$start_dir/folder.bag") ) { print "Cannot open folder.bag\n"; $write_folder = 0; #exit 1; } #print "Trying to chdir to $start_dir\n"; if (! chdir($start_dir) ) { print "Can't get to directory\n"; exit 5; } #print "Getting list of directories in $start_dir\n"; @Subdirs = &ListFiles($start_dir,'\.fld$'); $make_subdir = 0; $num_Subdirs = @Subdirs; for ($loop = 0; $loop < $num_Subdirs; ++$loop) { $sub1 = $Subdirs[$loop]; #print "Checking out $sub1\n"; if ( $sub1 =~ /\w/ ) { $make_subdir = 1; if ( $pm_name ne "" ) { $start[$tally] = $Startdirs[$loop] = $start_dir."/".$Subdirs[$loop]; $target[$tally] = $final_dir."/".$pm_name.".sbd"; } else { $start[$tally] = $Startdirs[$loop] = $start_dir."/".$Subdirs[$loop]; $target[$tally] = $final_dir; } $tally += 1; #print "call ".$start[$tally]." ".$target[$tally]."\n"; #print "call ".$Startdirs[$loop]."\n"; # ".$Subdirs[$loop]."\n"; } } if ( ($make_subdir == 1) && ( $pm_name ne "") ) { mkdir( $final_dir."/".$pm_name.".sbd", 0700); #print "Making dir \"". $final_dir."/".$pm_name.".sbd\"\n"; } if ($write_folder == 1 ) { if (! open(MBOX,">$final_dir/$pm_name") ) { print "Cannot open temp mailbox\n"; exit 2; } while() { while (/\n/) { s/\n//; } while (/\r/) { s/\r//; } ($x,$y,$date,$time,$subject,$to_at,$to_name,$from_at,$from_name,$size,$filename) = split /\xde/, $_; $filename = uc($filename); if ( open(MSG,"<$filename") ) { $buffer = ""; while() { $buffer .= $_; if ( /^Date\: / ) { # parse the date for mbox ($pre,$wkday,$monum,$month,$year,$time,$offset) = split / /, $_; $wkday =~ s/\,//; $from_line = "From - $wkday $month $monum $time $year\n"; } } print MBOX $from_line; print MBOX $buffer; close MSG; } else { print "Cannot open \"$filename\"\n"; } } # looping through folder.bag close BAG; } # if Write_folder == 1 return 0; } # -------------------------------------------------------------