#!/usr/bin/ruby1.8 # #-- # rbmhl : rbmhshow 0.4.2 # # Copyright (C) 2004--2005 Merlin Hughes # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # #++ # MH mail viewer component based on RubyMail. # # See rbmhshow docs. $: << "#{ENV['HOME']}/.ruby" require 'tempfile' require 'rbmh' cmd = [ "/usr/lib/mh/mhl" ] files = [] while (arg = ARGV.shift) # NB: The man pages is out of date, as is the -help output # (consider the undocumented -forwall option) so this may # be incomplete.. TODO: look at nmh source if (arg =~ /^-(folder|form|length|width|moreproc)$/) # 1-arg commands cmd.push(arg, ARGV.shift) elsif (arg =~ /^-/) # no-arg commands cmd.push(arg) else # files files.push(arg) end end if (cmd.join(" ") !~ /mhl\.(reply|forward)/) # ugly! cmd.push(*files) exec(*cmd) end # monochrome ENV['MONOCHROME'] = 'true' # full headers for mhl ENV['RBMH_HEADERS'] = 'full' # reduced width for quoting ENV['COLUMNS'] = '76' # TODO: use context flags or somesuch, maybe, and just copy from env # in main loop of rbmhshow? context = RBMH::Context.new() context.no_scissors = true if (files.empty?) message = context.parse(STDIN) tmpf = Tempfile.new("rbmhl") tmpf.unlink context.shower.rshow(message, tmpf) tmpf.seek(0) STDIN.reopen(tmpf) exec(*cmd) # mhl on the processed stdin else tmpfs = [] # defer finalization and deletion files.each { |filename| file = File.open(filename, "r") message = context.parse(file) file.close tmpf = Tempfile.new("rbmhl") cmd.push(tmpf.path) context.shower.rshow(message, tmpf) tmpf.close tmpfs.push(tmpf) } # system vs exec so tempfiles are not finalized system(*cmd) # mhl on the processed stdin end ## The following should work for single items, but mhl seems to fsck up ## and not '>' when subprocesses start and stop so you wind up with bits of ## unquoted text. maybe the write() or read() returns an error, who knows. ## try replying to a message with signatures and word files... # message = context.parse(STDIN) # rd, wr = IO.pipe # fork { # rd.close # # STDERR.reopen(wr) # context.shower.rshow(message, wr) # } # wr.close # STDIN.reopen(rd) # rd.close # exec(*cmd) # mhl in the processed stdin