home *** CD-ROM | disk | FTP | other *** search
/ Using the Internet / 21003.iso / webutils / mhonarc / HtmlMail.pl next >
Perl Script  |  1996-09-20  |  5KB  |  125 lines

  1. #! /usr/local/bin/perl
  2.  
  3. ##---------------------------------------------------------------------------##
  4. ##  File:
  5. ##      HtmlMail
  6. ##  Author:
  7. ##      Earl Hood       ehood@convex.com
  8. ##    Copyright (C) 1994, Wed Oct 26 14:56:26 CDT 1994
  9. ##
  10. ##  Description:
  11. ##      HtmlMail is a simple Perl program that loads a single mail
  12. ##    message from STDIN into a WWW client.  Even though, this
  13. ##    program can be used to with NCSA Mosaic, it is better to
  14. ##    use MosaicMail since it tries to load the message in an
  15. ##    existent Mosaic session.
  16. ##
  17. ##    MHonArc is called to do the actual conversion of the e-mail
  18. ##    message.  Therefore, MIME messages will be converted, and
  19. ##    text/plain messages will have URLs hyperlinked.
  20. ##
  21. ##    Change the values in the CONFIG section below to suit your
  22. ##    needs.
  23. ##
  24. ##  Notes:
  25. ##    o  For MH users, the following can be used to process the current
  26. ##       mail message:
  27. ##
  28. ##        % show -noshowproc -noheader | HtmlMail
  29. ##
  30. ##    o  For Trn users, you can load a newsgroup post into a WWW client
  31. ##       by piping the post to HtmlMail:
  32. ##
  33. ##        | HtmlMail
  34. ##
  35. ##    o  MHonArc needs to be in your search path
  36. ##
  37. ##    o  If extra files are created by MHonArc (i.e. for graphics,
  38. ##       binaries, etc), they will not get removed.  You'll have
  39. ##       to manually remove them.
  40. ##
  41. ##---------------------------------------------------------------------------##
  42. ##    Copyright (C) 1995        Earl Hood, ehood@convex.com
  43. ##
  44. ##    This program is free software; you can redistribute it and/or modify
  45. ##    it under the terms of the GNU General Public License as published by
  46. ##    the Free Software Foundation; either version 2 of the License, or
  47. ##    (at your option) any later version.
  48. ##
  49. ##    This program is distributed in the hope that it will be useful,
  50. ##    but WITHOUT ANY WARRANTY; without even the implied warranty of
  51. ##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  52. ##    GNU General Public License for more details.
  53. ##
  54. ##    You should have received a copy of the GNU General Public License
  55. ##    along with this program; if not, write to the Free Software
  56. ##    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  57. ##---------------------------------------------------------------------------##
  58.  
  59. ##---------------------------------------------------------------------------
  60. #############################################################################
  61. ##---------------------------------------------------------------------------
  62. ##    CONFIG: Change the following variables to reflect your needs
  63.  
  64. ## WWW client to invoke (client must be able to take a file://localhost/...
  65. ## URL for loading converted message).
  66. $WWWClient = "lynx -force_html";
  67.  
  68. ## Location of converted message; directory must exist and be a FULL
  69. ## pathname.
  70. $DESTDIR = "$ENV{'HOME'}/tmp";
  71.  
  72. ## Uncomment and set the following variable to a MHonArc resource file if
  73. ## you want to customize the format of the converted message
  74. #$ENV{'M2H_RCFILE'} = "mhonarc.rc";
  75.  
  76. ##    CONFIG: End change section
  77. ##---------------------------------------------------------------------------
  78. #############################################################################
  79. ##---------------------------------------------------------------------------
  80.  
  81. ##---------------------------------------------------------------------------
  82. ##    Actual code to do the conversion (Should not have to edit)
  83.  
  84. ## Set html filename
  85. $htmlfile  = "$DESTDIR/" . time() . ".$$.html";
  86.  
  87. ## Set handler to clean up if program is interrupted
  88. $SIG{'ABRT'} =
  89. $SIG{'HUP'}  =
  90. $SIG{'INT'}  =
  91. $SIG{'QUIT'} =
  92. $SIG{'TERM'} = 'cleanup';
  93.  
  94. ## Set web client command
  95. $webcmd = "$WWWClient file://localhost$htmlfile";
  96.  
  97. ## Convert message to HTML by using MHonArc
  98. open(MHONARC, "|mhonarc -single -outdir $DESTDIR > $htmlfile");
  99. print MHONARC <STDIN>;
  100. close(MHONARC);
  101.  
  102. ## Reset STDIN to terminal for text based WWW clients (Lynx goes wacko
  103. ## if this isn't done)
  104. close(STDIN);
  105. open(STDIN, "/dev/tty") || &error("Unable to open terminal: $!\n");
  106.  
  107. ## Call web client
  108. print STDOUT "$webcmd\n";
  109. if ($ret = system($webcmd)) {
  110.     &error("Error status from $WWWClient: ", $ret/256, "\n");
  111. }
  112.  
  113. &cleanup();
  114.  
  115. ##---------------------------------------------------------------------------
  116. sub cleanup {
  117.     unlink $htmlfile;
  118.     exit 0;
  119. }
  120. ##---------------------------------------------------------------------------
  121. sub error {
  122.     warn @_;
  123.     &cleanup();
  124. }
  125.