Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Problem reading & displaying MHTML file type

Reply
Thread Tools

Problem reading & displaying MHTML file type

 
 
Robert
Guest
Posts: n/a
 
      02-15-2006
Hi,

I have a small piece of code where perl reads an .HTM file and displays it
in your browser:

#!/usr/bin/perl

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use strict;

open (FH, "<page.htm") or die &error;
my @page = <FH>;
close(FH);

print "Content-type: text/html \n\n";
print @page;
exit;

This works totally fine.

The problem is now we are working with .MHTML files. Using the code above,
when trying to open and display a MHTML file, the contents of the file's
source is displayed instead of a formatted page. MHTML files define the
Content-type within the file itself at the top and use multipart/related. I
tried modifying my code above to that content-type but that didnt work. I'm
hoping maybe someone has a suggestion on how I can make this work. Many
thanx in advance.

Robert


 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      02-15-2006
"Robert" <(E-Mail Removed)> wrote in
news:6DMIf.13589$B94.5803@pd7tw3no:

> Hi,
>
> I have a small piece of code where perl reads an .HTM file and
> displays it in your browser:
>
> #!/usr/bin/perl
>
> use CGI qw(:standard);
> use CGI::Carp qw(fatalsToBrowser);
> use strict;


use warnings;

missing.

$| = 1;

is a good idea with CGI scripts.

> open (FH, "<page.htm") or die &error;


open my $fh, '<', 'page.htm' or die error();

Lexical filehandles and the three argument form of open is generally
preferable.

&error has specific effects (see perldoc perlsub). If you don't know
what those are, you don't need them.

> my @page = <FH>;


Why slurp the whole file only to print it out

print while <$fh>;

scales much better.

> close(FH);
>
> print "Content-type: text/html \n\n";


Why use CGI.pm if you are not going to use it.

print header('text/html');

> print @page;
> exit;


exit is completely unnecessary here.

>
> This works totally fine.


So, to wrap it up:

open my $html, '<', 'page.htm' or die error();

print header('text/html');
print while <$html>;

close $html;

> The problem is now we are working with .MHTML files. Using the code
> above, when trying to open and display a MHTML file, the contents of
> the file's source is displayed instead of a formatted page. MHTML
> files define the Content-type within the file itself at the top and
> use multipart/related. I tried modifying my code above to that
> content-type but that didnt work. I'm hoping maybe someone has a
> suggestion on how I can make this work. Many thanx in advance.


I don't know anything about mhtml files, but maybe using the correct
MIME type would work:

print header('message/rfc822');

Sinan

--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Microsoft Internet Explorer MHTML URI Buffer Overflow Vulnerability Imhotep Computer Security 0 06-03-2006 02:52 AM
Announcement: Cool MHTML library available for review (pre-alpha). Peter Rilling ASP .Net 0 02-09-2006 03:54 AM
MHTML Streaming =?Utf-8?B?TUVSNzg=?= ASP .Net 2 02-06-2006 07:13 PM
'mhtml' files Earl Costello Computer Support 5 03-10-2005 07:05 PM
Stream mhtml to browser mparker@costar.com ASP .Net 0 12-15-2003 06:09 PM



Advertisments