home *** CD-ROM | disk | FTP | other *** search
/ Netscape Plug-Ins Developer's Kit / Netscape_Plug-Ins_Developers_Kit.iso / SOFTWARE / mhonarc / mosaic.pl < prev   
Encoding:
Perl Script  |  1996-05-22  |  5.2 KB  |  149 lines

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