tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
* SUMMARY: VMS mail conversion utility
@ 1999-03-19 17:40 Mark Van Overbeke
  0 siblings, 0 replies; only message in thread
From: Mark Van Overbeke @ 1999-03-19 17:40 UTC (permalink / raw)
  To: tru64-unix-managers

I received a number of pointers to a utility called fixmail.  The one I got from 
Uwe Siodlaczek <siodlack@pit.physik.uni-tuebingen.de> did the trick.  I will include that
file below.  Thanks to all.

   Mark

--
Mark Van Overbeke                   Systems Administrator
Computing Services
600 East 4th Street
University of Minnesota, Morris     e-mail:  markvo@mrs.umn.edu 
Morris, MN   56267                  Phone:   1-320-589-6378 
--
Success is the progressive realization of your worthwhile goal or dream!


#!/bin/perl -i.vms
'di';
'ig00';
#
#       Fixmail - convert VMS mail files to Unix form.
#               To save a VMS e-mail folder in a usable text file...
#               inside of VMS MAIL
#               EXTRACT/ALL/MAIL  filename
#
#       N.B.: does in-place editing.
#
#       04.12.97 modified by U. Siodlaczek to handle also OpenVMS mail
#  
$/ = "\f\nFrom" ;                               # Break at messages, not lines

$frompat1 = '^:\t(\S+)'                         # sender address
         . ' +(".+")?'                          # sender name
         . ' *(\d+)-(\w{3})-(\d{2}(\d{2}))'     # dd-mm-yyyy date
         . ' +(\d+:\d+:\d+)\.?\d*'              # hh:mm:ss.xx time
         . " *\n" ;

$frompat2 = '^:\t(\S+)'                         # sender address
         . ' +(".+")?'                          # sender name
         . ' *(\d+)-(\w{3})-(\d{2}(\d{2}))'     # dd-mm-yyyy date
         . ' +(\d+:\d+)\.?\d*'                  # hh:mm:ss.xx time
         . " *\n" ;

while (<>)                                      # Read next message
    {
    s|$/$|\n| ;                                 # Drop start of next message

    if ($. == 1)                                # First message in input file?
        {
        s/^\s*From// ;                          # Handle missing initial \f\n
        next if ! /\S/ ;                        # Handle leading \f\nFrom
        }
    $mesg++ ;                                   # Count messages
    
#    warn (" ($addr, $name, $day, $mon, $year, $yr, $time) = (/$frompat/) \n");

    if (($addr, $name, $day, $mon, $year, $yr, $time) = (/$frompat1/))
        {
        s/^.*\n// ;                                     # drop From: line
        (($to)   = /^To:\t(\S+) */)     && s/^.*\n// ;  # drop To:   line
        (($cc)   = /^CC:\t(.*)/)        && s/^.*\n// ;  # drop CC:   line
        (($subj) = /^Subj:\t(.*)/)      && s/^.*\n// ;  # drop Subj: line

        $name =~ s/^"(.+)"$/$1/ ;                       # drop quotes
        $addr =~ s/^IN%"([^"]+)"$/$1/i ;                # fix IN%
        $addr =~ s/^ARPA%"([^"]+)"$/$1/i ;              # fix ARPA%
        $addr =~ s/^JNET%"([^"]+)"$/$1.bitnet/i ;       # fix JNET%
        $addr =~ s/^UUCP%"([^"]+)"$/$1.uucp/i ;         # fix UUCP%
        $addr =~ s/^BITNET%"([^"]+)"$/$1/i ;            # fix BITNET%
        $addr =~ s/(\S+)::(\S+)/$2\@$1/ ;               # fix VMS hosts
        $day  = sprintf ("%2d", $day) ;                 # pad date
        $wkdy = &weekday ($day, $mon, $year) ;

        print "From \L$addr\E $wkdy \u\L$mon $day $time $year\n" ;
        print "From: $name <\L$addr\E>\n"                       if $name ;
        print "Subject: $subj\n"                                if $subj ;
        print "To: \L$to\n"                                     if $to ;
        print "Date: $wkdy, $day \u\L$mon\E $yr $time\n" ;
        print "Cc: $cc\n"                                       if $cc ;
        print ;
        next ;
        }
    if (($addr, $name, $day, $mon, $year, $yr, $time) = (/$frompat2/))
        {
        s/^.*\n// ;                                     # drop From: line
        (($to)   = /^To:\t(\S+) */)     && s/^.*\n// ;  # drop To:   line
        (($cc)   = /^CC:\t(.*)/)        && s/^.*\n// ;  # drop CC:   line
        (($subj) = /^Subj:\t(.*)/)      && s/^.*\n// ;  # drop Subj: line

        $name =~ s/^"(.+)"$/$1/ ;                       # drop quotes
        $addr =~ s/^IN%"([^"]+)"$/$1/i ;                # fix IN%
        $addr =~ s/^ARPA%"([^"]+)"$/$1/i ;              # fix ARPA%
        $addr =~ s/^JNET%"([^"]+)"$/$1.bitnet/i ;       # fix JNET%
        $addr =~ s/^UUCP%"([^"]+)"$/$1.uucp/i ;         # fix UUCP%
        $addr =~ s/^BITNET%"([^"]+)"$/$1/i ;            # fix BITNET%
        $addr =~ s/(\S+)::(\S+)/$2\@$1/ ;               # fix VMS hosts
        $day  = sprintf ("%2d", $day) ;                 # pad date
        $wkdy = &weekday ($day, $mon, $year) ;

        print "From \L$addr\E $wkdy \u\L$mon $day $time $year\n" ;
        print "From: $name <\L$addr\E>\n"                       if $name ;
        print "Subject: $subj\n"                                if $subj ;
        print "To: \L$to\n"                                     if $to ;
        print "Date: $wkdy, $day \u\L$mon\E $yr $time\n" ;
        print "Cc: $cc\n"                                       if $cc ;
        print ;
        next ;
        }
    /^(.*)/ && warn ("\nSkipping garbled message \#$mesg:\n\tFrom$1\n") ;
    }
continue
    {
    close (ARGV) if (eof) ;             # Reset line numbers if multiple files
    }

sub weekday
    {
    local ($day, $mon, $year) = @_ ;
    %month  = ( jan, 0, feb, 1, mar, 2, apr, 3, may,  4, jun, 5,
                jul, 6, aug, 7, sep, 8, oct, 9, nov, 10, dec, 11 ) ;
    @offset = ( 0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5 ) ;
    @wkday  = ( Mon, Tue, Wed, Thu, Fri, Sat, Sun ) ;

    $m = $month {"\L$mon"} ;                            # month number
    $y = $year - ($year % 4) ;                          # previous leapyear
    $leap = $year == $y ;                               # current leapyear
    $weekday  = 5 ;                                     # for 1/1/2000
    $weekday += 5 * ($y - 2000) / 4 ;                   # for 1/1/$y
    $weekday += ($year - $y) + !$leap ;                 # for 1/1/$year
    $weekday += $offset [$m] + ($leap && ($m > 1)) ;    # for $m/1/$year
    $weekday += $day - 1 ;                              # for $m/$day/$year
    $wkday [$weekday % 7] ;
    }
########################

.00;

'di
.nr nl 0-1
.nr % 0
'; __END__

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1999-03-19 17:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-03-19 17:40 SUMMARY: VMS mail conversion utility Mark Van Overbeke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox