--Boundary-00=_jWkFH5Zrh6K2Hdc
Content-Type: Multipart/Mixed;
boundary="Boundary-00=_jWkFH5Zrh6K2Hdc"
--Boundary-00=_jWkFH5Zrh6K2Hdc
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
From: Robert Klemme [mailto:
[email protected]]=20
# case
# when new_record && /^---\+\+ / =3D~ s
Thanks to all who replied!
I've tried the suggested approaches and variations that I could think of, a=
nd=20
still no luck.
I've attached the following small files in case anyone wants to try to see =
if=20
they can get it to work:
* askconvert: the code--at the point in question you will find two=20
commented out lines and a comment that will be fairly self explanatory (I=20
think)
* test.txt: a test file
* test.aml.txt: a file containing the desired result
* utest: a bash script for doing a sort of poor man's unit test--this ma=
y=20
not work for you unless you make some modifications (like to the ./askconve=
rt=20
line)
The unit test works by running the program and then doing a diff between=20
text.aml (the output from the program) and test.aml.txt. Note that the=20
current date and time are incorporated in two of the header lines, the From=
=20
and the Date: line, so those will always show up as different. So, I=20
visually inspect the diff for these two criteria:
* the only lines in the diff related to From and Date lines with differe=
nt=20
dates
* all titles in the diff should show up as variations of "Primary"
The other thing that will show up is the minor spacing issue mentioned belo=
w.
Someday, I might write code (in that unit test file) to, one way or another=
,=20
ignore those dates so they don't show up in the diff. (I might process=20
test.aml and test.aml.std to replace the real date/times with dummys that a=
re=20
all the same.)
Note that there is one minor linespace issue remaining in the program that =
I=20
just haven't been able to resolve so far. It is so minor that I'm going to=
=20
ignore it for now, but, you can spot it if you watch carefully when you run=
=20
the diff.
Randy Kramer
oops, yes. That's what i get on pasting without thinkig (nor testing
=20
# Note the matching operator, otherwise $_ will be matched.
# Note also, that it is superfluous to match the rest of the
# string unless the content need to be further processed. =20
# I'd probably also reverse the order since I assume=20
# new_record is a local variable and that test is=20
# likely faster than the regexp matching.
=20
indeed and many thanks.
kind regards -botp
=20
=20
--Boundary-00=_jWkFH5Zrh6K2Hdc
Content-Type: application/x-ruby;
name="askconvert"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="askconvert"
#! /usr/bin/env ruby
# This is iter(ation)-4 (in progress) of ruby program askconvert to convert (initially) askRhk03 formatted files to askRhk04 format. (Later versions may perform additional conversions.) This version does work only for the hard coded conversion of file test.txt to test.aml. Iter-5 will presumably address getting the filenames from the command line. Iter-4 is sort of a break--code cleanup and maybe some comments--much as it is against my religion, I'm sort of trying to see to what extent this is (or can be made) "self-documenting"--I do have plenty of documentation (some pretty rough) in other files like askconvert.dev.aml.
File.open("test.aml", "w") do |f|
first_record = true
new_record = false
titles = Array.new
File.open("test.txt").each do |line|
case line
when /^\x80\x81\x82\x83$/
new_record = true
# when new_record && /^---\+\+ / =~ line
# titles.push $1.strip
# the previous two lines could replace the next five lines if the previous two lines worked (or I could change the case statement to an if, elsif, elsif ... (or whatever)--case just seemed more "elegant" somehow--I'll wait and see if anybody can show me how to get those two lines to work.
when /^---\+\+ (.*)/
if new_record
titles.push $1.strip
else
f.puts line.rstrip + "\n" end
else
if new_record then
# I could take the next 14 lines and "move" them to a module / method named something like "process_header"--I'd probably also learn something by doing so. I think I'm "learned out" for the moment. ;-)
unless first_record then f.puts "morF\n\n"
else first_record = false end
if titles.length == 3 then
title = titles.pop
titles.reverse!
else
title = titles.shift end
f.puts "From \"" + title + "\" " + %x{date -u +"%a %b %d %T %Z %Y"} + "Date: " + %x{date +"%D %H:%M %P %Z"} + "Subject: " + title + "\n"
unless titles.empty?
f.puts "\n"
titles.each { |title| if title.strip.length > 0 then f.puts "T: " + title + "\n" end}
f.puts "\n" end
titles.clear
new_record= false
else
f.puts line.rstrip + "\n" end
end
end
f.puts "morF\n"
end
--Boundary-00=_jWkFH5Zrh6K2Hdc
Content-Type: application/vnd.sun.xml.draw.template;
name="test.aml.std"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="test.aml.std"
=46rom "Primary" Wed Oct 17 17:02:59 UTC 2007
Date: 10/17/07 13:02 pm EDT
Subject: Primary
=46ile test.txt, for testing.
A few lines, to start.
Goodbye.
=2D--++ Another heading
The heading above this should not disappear.
morF
=46rom "Primary" Wed Oct 17 17:02:59 UTC 2007
Date: 10/17/07 13:02 pm EDT
Subject: Primary
T: Secondary
=46ile test.txt, for testing.
A few lines, to start.
Goodbye.
=2D--++ Another heading
The heading above this should not disappear.
morF
=46rom "Primary1" Wed Oct 17 17:02:59 UTC 2007
Date: 10/17/07 13:02 pm EDT
Subject: Primary1
T: Secondary1
T: Tertiary1
=46ile test.txt, for testing.
A few lines, to start.
Goodbye.
=2D--++ Another heading
The heading above this should not disappear.
morF
=46rom "Primary1" Wed Oct 17 17:02:59 UTC 2007
Date: 10/17/07 13:02 pm EDT
Subject: Primary1
=46ile test.txt, for testing.
A few lines, to start.
Goodbye.
=2D--++ Another heading
The heading above this should not disappear.
morF
=46rom "Primary1" Wed Oct 17 17:02:59 UTC 2007
Date: 10/17/07 13:02 pm EDT
Subject: Primary1
T: Secondary1
=46ile test.txt, for testing.
A few lines, to start.
Goodbye.
=2D--++ Another heading
The heading above this should not disappear.
morF
=46rom "Primary2" Wed Oct 17 17:02:59 UTC 2007
Date: 10/17/07 13:02 pm EDT
Subject: Primary2
T: Secondary2
T: Tertiary2
T: Fourtiary2 ;-)
=46ile test.txt, for testing.
A few lines, to start.
Goodbye.
=2D--++ Another heading
The heading above this should not disappear.
morF
--Boundary-00=_jWkFH5Zrh6K2Hdc
Content-Type: text/plain;
charset="iso-8859-1";
name="test.txt"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="test.txt"
=80=81=82=83
=2D--++ Primary
=2D--++=20
=20
=46ile test.txt, for testing.
A few lines, to start.
Goodbye.
=2D--++ Another heading
The heading above this should not disappear.
=80=81=82=83
=2D--++ Primary
=2D--++ Secondary
=20
=46ile test.txt, for testing.
A few lines, to start.
Goodbye.
=2D--++ Another heading
The heading above this should not disappear.
=80=81=82=83
=2D--++ Tertiary1
=2D--++ Secondary1
=2D--++ Primary1
=20
=46ile test.txt, for testing.
A few lines, to start.
Goodbye.
=2D--++ Another heading
The heading above this should not disappear.
=80=81=82=83
=2D--++=20
=2D--++=20
=2D--++ Primary1
=20
=46ile test.txt, for testing.
A few lines, to start.
Goodbye.
=2D--++ Another heading
The heading above this should not disappear.
=80=81=82=83
=2D--++=20
=2D--++ Secondary1
=2D--++ Primary1
=20
=46ile test.txt, for testing.
A few lines, to start.
Goodbye.
=2D--++ Another heading
The heading above this should not disappear.
=80=81=82=83
=2D--++ Primary2
=2D--++ Secondary2
=2D--++ Tertiary2
=2D--++ Fourtiary2 ;-)
=20
=46ile test.txt, for testing.
A few lines, to start.
Goodbye.
=2D--++ Another heading
The heading above this should not disappear.
--Boundary-00=_jWkFH5Zrh6K2Hdc
Content-Type: text/plain;
charset="iso-8859-1";
name="utest"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="utest"
#! /usr/bin/env bash
# the cd is helpful for me--others will have to adjust it appropriately (or delete/comment it out)--also consider what to do with ./askconvert
#cd /rhk/code/w/askRhk/askconvert
# to make sure diff is looking at a new version of test.aml
rm -f test.aml
/askconvert
# which currently runs the conversion on test.txt producing test.aml--later it will need the filenames on the command line
diff test.aml test.aml.std | less
--Boundary-00=_jWkFH5Zrh6K2Hdc--
--Boundary-00=_jWkFH5Zrh6K2Hdc--