Article View: comp.mail.elm
Article #3703Re: How to convert MH mail files to something elm can read
From: DaviD W. Sanderson
Date: Tue, 17 Aug 1993 23:40
Date: Tue, 17 Aug 1993 23:40
214 lines
5461 bytes
5461 bytes
In <24qt34$ecb@nda.nda.com> kovar@news.nda.com (David Kovar) writes:
> I have a number of old mail files that I managed with MH. MH splits
>every mail message into it's own file. I now am without MH and am using
>elm. Is there any way to pack all those files back into a mailbox that
>elm can read?
Use this. You will have to diddle with it for local configuration. If
you don't have convdate(1) then you can either use some other program
to parse the Date: field of the messages, or be content with a
hardcoded date in the "From " lines of the output folder.
DaviD W. Sanderson (dws@ssec.wisc.edu)
"The Noah Webster of smileys is David Sanderson"
- The Wall Street Journal, 15 Sep 1992
#!/bin/sh
# This is a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 08/17/1993 23:34 UTC by dws@ssec
# Source directory /home/dws/src/perl
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 3060 -rwx------ mbox.pl
#
# ============= mbox.pl ==============
if test -f 'mbox.pl' -a X"$1" != X"-c"; then
echo 'x - skipping mbox.pl (File already exists)'
else
echo 'x - extracting mbox.pl (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'mbox.pl' &&
eval 'exec perl -S $0 ${1+"$@"}'
X if 0;
#-------
# $Id: mbox.pl,v 1.5 1993/07/29 15:50:25 dws Exp dws $
#
# mbox.pl - takes a file (or MH message ID) and writes out its contents
# in mbox form. Mbox only interprets an argument X as an MH id if
# stat(X) fails.
#
# Examples: mbox cur > xxx
# mbox 23-30 >> xxx
#
# Now you can use 'elm -f xxx' to look at those messages.
#
# This program uses the INN convdate(1) program to convert the value of
# the 'Date:' field into a useful form.
#
# $Log: mbox.pl,v $
# Revision 1.5 1993/07/29 15:50:25 dws
# added some comments
#
# Revision 1.4 1993/07/29 15:36:18 dws
# removed use of getdate()
#
# Revision 1.3 1993/06/20 19:16:42 dws
# changed to use convdate(1)
#
# Revision 1.2 1993/06/20 18:20:59 dws
# Changed to take an argument as an MH message number if there
# is no file named for the argument.
#
#-------
X
require 'ctime.pl';
X
#-------
# Configuration section.
#
# $convdate - location of the INN news convdate program
#-------
X
$convdate = 'convdate';
X
exit &main;
X
#-------
# convdate - given a string representation of a time, return the
# unix internal form representing the equivalent local time.
#
# $seconds = &convdate('Sun Feb 9 15:57:23 CST 1992');
#
# Adapted from a posting by tchrist@convex.COM (Tom Christiansen)
#-------
sub convdate
{
X local($_) = shift;
X local($seconds);
X
X $seconds = `$convdate -n '$_'`;
X chop $seconds;
#print STDERR "convdate: '$_' -> $seconds\n";
X $seconds;
}
X
#-------
# Returns the contents of the given field in the given file,
# or '' if none.
#-------
sub Header
{
X local($field, $file) = @_;
X local($_);
X local($ans) = '';
X
X local($hfile) = $file;
X $hfile = "fcat $file|" if $file =~ /\.F$/;
X $hfile = "zcat $file|" if $file =~ /\.Z$/;
X
X open(HFILE, $hfile) || die "can't open $hfile: $!\n";
scan: while (<HFILE>)
X {
X #-------
X # Quit processing this file after the first located
X # header line.
X #-------
X if (/^${field}:\s*/i)
X {
X chop($ans = $');
X last scan;
X }
X }
X close(HFILE);
X
X $ans;
}
X
#-------
# fromtime - given a date in unix internal form representing a local
# time, return the time in the string form appropriate to a mbox
# 'From ' line.
#-------
sub fromtime
{
X local($ans) = &ctime($_[0]);
X chop($ans);
X $ans;
}
X
#-------
# mbox - copy the given file to stdout in UNIX mbox form
#
# Prints the filename to stderr as a progress indicator.
#-------
sub mbox
{
X local($file) = @_;
X local($from);
X
print STDERR "$file\n";
X
X if(($date = &Header('date', $file)) eq '')
X {
X warn "$file: no date\n";
X return;
X }
X
X if(($date = &convdate($date)) eq '')
X {
X warn "$file: corrupted date\n";
X return;
X }
X
X
X $from = 'From mbox ' . &fromtime($date) . "\n";
X
X print $from;
X
X open(MAIL, $file) || die "can't open $file: $!\n";
scan: while (<MAIL>)
X {
X s/^From />$&/;
X print;
X }
X close(MAIL);
}
X
sub main
{
X local(@path);
X
X for(@ARGV)
X {
X if(-f $_)
X {
X &mbox($_);
X }
X else
X {
X @path = ();
X @path = split(' ', `mhpath $_`);
X next if ($? >> 8) != 0;
X next if @path == 0;
X for(@path)
X {
X &mbox($_);
X }
X }
X }
}
SHAR_EOF
chmod 0700 mbox.pl ||
echo 'restore of mbox.pl failed'
Wc_c="`wc -c < 'mbox.pl'`"
test 3060 -eq "$Wc_c" ||
echo 'mbox.pl: original size 3060, current size' "$Wc_c"
fi
exit 0
Technical Details
Message-ID:
<1993Aug17.234035.10383@cs.wisc.edu>Path:
arc1-ca.pugleaf.net!wupost!howland.reston.ans.net!vixen.cso.uiuc.edu!uwm.edu!uwvax!ssec.wisc.edu!dwsReferences:
<24qt34$ecb@nda.nda.com>Show Full Headers
Complete Article Headers
Newsgroups: comp.mail.elm,alt.sources Path: arc1-ca.pugleaf.net!wupost!howland.reston.ans.net!vixen.cso.uiuc.edu!uwm.edu!uwvax!ssec.wisc.edu!dws From: dws@ssec.wisc.edu (DaviD W. Sanderson) Subject: Re: How to convert MH mail files to something elm can read Message-ID: <1993Aug17.234035.10383@cs.wisc.edu> Sender: news@cs.wisc.edu (The News) Reply-To: dws@ssec.wisc.edu Organization: UW-Madison Space Science and Engineering Center References: <24qt34$ecb@nda.nda.com> Date: Tue, 17 Aug 1993 23:40:35 GMT Lines: 214