1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
#! /usr/local/bin/perl
##---------------------------------------------------------------------------##
## File:
## MosaicMail
## Author:
## Earl Hood ehood@convex.com
## Copyright (C) 1994, Wed Oct 26 15:00:44 CDT 1994
## Thanks:
## Roman Czyborra <czyborra@cs.tu-berlin.de> -- Whose feedback
## and sh script greatly improved the program.
##
## Description:
## MosaicMail is a simple Perl program that loads a single mail
## message from STDIN into a running Mosaic process. If no Mosaic
## process is running, the script will exec Mosaic.
## MHonArc is called to do the actual conversion of the e-mail
## message. Therefore, MIME messages will be converted.
##
## Change the values in the CONFIG section below to suit your
## needs.
##
## Notes:
## o For MH users, the following can be used to process the current
## mail message:
##
## % show -noshowproc -noheader | MosaicMail
##
## o For Trn users, you can load a newsgroup post into Mosaic
## by piping the post to MosaicMail:
##
## | MosaicMail
##
## o MHonArc needs to be in your search path
##
## o If extra files are created by MHonArc (i.e. for graphics,
## binaries, etc), they will not get removed. You'll have
## to manually remove them.
##
##---------------------------------------------------------------------------##
## Copyright (C) 1995 Earl Hood, ehood@convex.com
##
## 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., 675 Mass Ave, Cambridge, MA 02139, USA.
##---------------------------------------------------------------------------##
##---------------------------------------------------------------------------
#############################################################################
##---------------------------------------------------------------------------
## CONFIG: Change the following variables to reflect your needs
## Location of converted message; directory must exist and be a FULL
## pathname.
$DESTDIR = "$ENV{'HOME'}/tmp";
## Set the following variable to "goto" or "newwin". "goto" will make
## Mosaic load the message into the current window. "newwin" causes
## Mosaic to load the message into a new window.
$directive = "newwin";
## Give location of mknod command for creating FIFO files to communicate
## with Mosaic.
$mknod = '/etc/mknod';
## Uncomment and set the following variable to a MHonArc resource file if
## you want to customize the format of the converted message
#$ENV{'M2H_RCFILE'} = "mhonarc.rc";
## CONFIG: End change section
##---------------------------------------------------------------------------
#############################################################################
##---------------------------------------------------------------------------
##---------------------------------------------------------------------------
## Actual code to do the conversion (Should not have to edit)
## Read .mosaicpid to find PID of last Mosaic process
if (open(PID, "$ENV{'HOME'}/.mosaicpid")) {
$pid = <PID>; chop $pid; close(PID);
$tmpfile = "/tmp/Mosaic.$pid";
} else {
$pid = 0; # No Moasic process to attach to
}
## Set html filename
$htmlfile = "$DESTDIR/" . time() . ".$$.html";
## Set handler to clean up if program is interrupted
$SIG{'ABRT'} =
$SIG{'HUP'} =
$SIG{'INT'} =
$SIG{'QUIT'} =
$SIG{'TERM'} = 'cleanup';
## Make FIFO for html file
system("$mknod $htmlfile p") && &error("Unable to create $htmlfile: $!\n");
## Set Mosaic command to use if Mosaic is not currently running
$Mosaiccmd = "Mosaic file://localhost/$htmlfile 2>&1 > /dev/null";
if ($pid && (kill 'CONT', $pid)) { # Mosaic session active
## Set Mosaic control file
system("$mknod $tmpfile p") && &error("Unable to create $tmpfile: $!\n");
## Signal Mosaic to read control file
kill 'USR1', $pid;
## Write instructions to control file
open(MTMP, ">$tmpfile") || &error("Unable to open $tmpfile: $!\n");
print MTMP "$directive\n",
"file://localhost/$htmlfile\n";
close(MTMP);
} else { # Call Mosaic explicitly
if (!fork()) { # child
exec($Mosaiccmd);
&error("Unable to exec $Mosaiccmd: $!\n");
}
}
## Convert message to HTML by using MHonArc
open(MHONARC, "|mhonarc -single -outdir $DESTDIR > $htmlfile");
print MHONARC <STDIN>;
close(MHONARC);
&cleanup();
##---------------------------------------------------------------------------
sub cleanup {
unlink "/tmp/Mosaic.$pid", $htmlfile;
exit 0;
}
##---------------------------------------------------------------------------
sub error {
warn @_;
&cleanup();
}
|