Email embedding

Hello!

Seeing the XML-like format one of the quiz posters used for sending in
his program, I wrote two programs that can embed and extract multiple
files from an email. I’ll include the programs in their own format so
you can understand :wink:

Someone may have already done something like this, but if not, here you
go.

I know of one problem - the uncruncher adds a blank line at the end of
the files it extracts, so someone might want to fix that.

#/usr/bin/env ruby

email_crunch

usage: email_crunch.rb *.rb > crunchfile.txt

puts “
ARGV.each do |f|
next if FileTest.directory?(f)

puts “<CRUNCHFILE: #{f}>”
puts File.new(f).read
puts “</CRUNCHFILE: #{f}>”
end
puts “

</CRUNCHFILE: email_crunch.rb>
<CRUNCHFILE: email_uncrunch.rb>
#/usr/bin/env ruby

email_uncrunch

usage: cat crunch_file | email_uncrunch.rb

or : email_uncrunch.rb crunch_file

require ‘breakpoint’

if ARGV.length != 0
text = File.new(ARGV[0]).read
else
text = $stdin.read
end

text =~ /(.*)</code>/m
code = $1

filename = “”
f = nil

code.each_line do |line|
line.chomp!
if line =~ /^<CRUNCHFILE: (.+?)>$/
filename = $1
puts “Creating #{filename}”
f = File.new(filename, “w”)
elsif !filename.empty?
if line == “</CRUNCHFILE: #{filename}>”
f.close
filename = “”
else
f.puts(line)
end
end
end

</CRUNCHFILE: email_uncrunch.rb>

  • Les