--- ../eud2mbox.pl	Sun May 27 10:23:48 2001
+++ eud2mbox.pl	Sun May 27 15:34:45 2001
@@ -22,6 +22,14 @@
 # lines. Possibly do this with all messages? Use Text::Wrap to do the actual
 # wrapping.
 # 
+
+# Patched by Ward Vandewege (ward@pong.be) on 2001/05/27
+# Just a couple of bugfixes:
+#		1. Deal with CR/LF style files properly
+#		2. Deal with mbox-files that contain some lines in CR/LF format and others in LF format
+#		3. Cleared out the parsing of the TOC files with some information found in the toc.pl script by Christopher Russo <crusso@mit.edu>, Feb. 1997
+# This version of the eud2mbox.pl script lives online at http://patch.be/eud2mbox/
+
 my $RCSiD = 'eud2mbox.pl,v 1.35 2000/08/08 22:42:05 miner Exp';
 
 use Getopt::Long;
@@ -34,6 +42,9 @@
 my $VERSION_ALPHA = "b";
 my $VERSION = "$VERSION_MAJ.$VERSION_MIN".$VERSION_ALPHA;
 
+my $HEADER = "a6 a2 a32 c a61 l l C*";
+my $MESSAGE = "lll C C*";
+
 sub get_toc($);
 sub get_messages($);
 
@@ -204,14 +215,11 @@
 
 sub get_toc($) {
     my $mboxName = shift;
+		my ($buf,$d1,$d2,$nm1,$nm2,@x);
+		my $count = read(TOC, $buf, 104);
+		($toc{'version'}, $d1, $toc{'mboxname'}, $toc{'mboxtype'}, $d2, $nm1, $nm2, @x) = unpack($HEADER, $buf);
 
-    $toc{'version'} = read_toc("l",6);
-
-    $toc{'mboxname'} = read_toc("A*",28,2);
-
-    $toc{'mboxtype'} = read_toc("s",2,4);
-
-    $toc{'messages'} = read_toc("s",2,60);
+		$toc{'messages'} = $nm1 + $nm2*256;
 
     if ($verbose) {
         printf "Name: %s\n", $toc{'mboxname'};
@@ -227,53 +235,25 @@
     %toc;
 }
 
-# Function read_toc( $pattern, $num, $skip )
-# Skips $skip bytes (if $skip is defined)
-# Reads $num bytes from TOC and unpacks with $pattern
-# Returns the value.
-
-sub read_toc($$) {
-
-    my $temp;
-    my $out;
-    
-    my $pattern = shift;
-    my $num = shift;
-    my $skip = shift;
-
-    read TOC, $temp, $skip if (defined($skip));
-    
-    read TOC, $temp, $num;
-
-    $out = unpack($pattern, $temp);
-
-    $out;
-}
-
 sub get_messages($) {
 
     my $num_msg = shift;
 
     for (my $i = 0; $i < $num_msg; $i++) {
         my %message = ();
-        my $status;
         my %tempmsg = ();
-
-        $message{'offset'} = read_toc("i",4);
-
-        $message{'length'} = read_toc("i",4);
-
-        $message{'date'} = read_toc("i",4);
-
-        $status = read_toc("s",2);
+				my $msgbuf;
+			
+				seek(TOC, 104+218*$i, 0);
+				my $count = read(TOC, $msgbuf, 218);
+				my ($msgoffset,$msgsize,$secs,$status,$read,$x) = unpack($MESSAGE,$msgbuf);
+				$message{'offset'} = $msgoffset;
+				$message{'length'} = $msgsize;
+				$message{'date'} = $secs;
 
         $message{'status'} = $statuses[$status];
         $message{'x-status'} = ($status == 2) ? 'A' : undef;
 
-        $message{'options'} = read_toc("c",1);
-
-        seek TOC, 203, 1;
-
         if ($verbose) {
             print "Message $i\n";
             printf "Length: %d\n", $message{'length'};
@@ -282,7 +262,6 @@
                    defined($message{'x-status'}) ? $message{'x-status'} : "");
             if ($debug) {
                 printf "Offset: %d\n", $message{'offset'};
-                printf "Options: %x\n", $message{'options'};
             }
             print "------\n";
         }
@@ -298,7 +277,8 @@
         for (my $i = 1; $i <= $entry->{'toc'}->{'length'}; $i++) {
             read MBOX, $in, 1;
             if ((ord $in) == 10) {
-                $i++;
+                my $chop = chop($buf);	#Throw away last character (probably CR)
+								$buf .= $chop if ((ord $chop) != 13);	#But append the character again if it is not a CR!
                 push @lines, $buf;
                 $buf = "";
             } else {
