#!/bin/sh # # # glob eml files into mbox # # restart using tcl \ exec tclsh8.3 "$0" "$@" if { $argc != 1 } { puts "globeml <outfile>" exit 1 } proc parseDate { str } { # from: Date: Wed, 11 Dec 2002 21:48:26 -0500 # to : Tue Jan 14 17:05:06 2003 set DayOfWeek [string range $str 6 8] set Month [string range $str 14 16] set Day [string range $str 11 12] set Time [string range $str 23 30] set Year [string range $str 18 21] return "$DayOfWeek $Month $Day $Time $Year" } set fname [lindex $argv 0] set oid [open [lindex $argv 0] "w"] foreach eml [glob *.eml] { # read email set fid [open "$eml" "r"] set emltext [read $fid] close $fid # get date set ind [string first "Date:" $emltext] set indend [string first "\n" $emltext $ind] set datetext [string range $emltext $ind [expr $indend-1]] set date [parseDate $datetext] # prevent errors from duplicate "From " set count [regsub -all "From " $emltext ">From " emltext2] # read in email set emllist [split "$emltext2" "\n\r"] puts "$eml ($count) $datetext --> $date" # MBOX header puts -nonewline $oid "From ???@??? $date\r" # output each line foreach i $emllist { puts -nonewline $oid "$i\r" } #MBOX trailer puts -nonewline $oid "\r\r" } close $oid