#-*-perl-*-
sub type_unknown {
    $name = &make_external("txt");
    print "type unknown!!\n";
    print OUT "<a href=\"$name\"><img src=\"$name.icon.gif\" align=middle>" .
	&pretty_name($name,"Unknown file type $contenttype") . "</a><p>\n";

}

sub application_postscript {
    $name = &make_external(@postscript);
    print OUT "<a href=\"$name\"><img src=\"$name.icon.gif\" align=middle>" .
	&pretty_name($name,"Unnamed Postscript Document") . "</a><p>\n";
}

sub application_octet_stream {
    $name = &make_external(); #we have no preferences for filename extension!
    &guesscontenttype;
    print OUT "<a href=\"$name\"><img src=\"$name.icon.gif\" align=middle>" .
	&pretty_name($name,"Unnamed Data stream") . "</a><p>\n";
}
sub image_gif {
    $name = &make_external(@gif);
    print OUT "<a href=\"$name\"><img src=\"$name.icon.gif\" align=middle>" .
	&pretty_name($name,"Unnamed GIF") . "</a><p>\n";
}

sub image_jpeg {
    $name = &make_external(@jpg);
    print OUT "<a href=\"$name\"><img src=\"$name.icon.gif\" align=middle>" .
	&pretty_name($name,"Unnamed JPEG") . "</a><p>\n";

}

sub message_rfc822 {
    print OUT "<ul><h2>An embedded message follows:</h2>\n\n";
    &basic_rfc822;
    print OUT "</ul>\n";
}

sub multipart_digest {
    local($done);
    $done = 0;
    while ($boundary ) {
	&message_rfc822;
    }
}

sub multipart_header_set {
    &get_body;
    # Throw out the first part of the header set;
    &get_headers;
    &get_body;
    # now comes the real part
    &get_headers;
    &do_body;
}

sub multipart_mixed {
    local($myboundary);
    $done = 0;
    $myboundary = $boundary;
    &get_body;
    while("$myboundary" eq "$boundary") {
	&get_headers;
	&do_body;
    }
}

sub text_enriched {
    &make_internal;
    $fontsize = "0";
    print OUT "<html>\n";
    foreach $_ (@lines) {
	if ( m/^$/) {
	    $break++;
	    next;
	} else {
	    if ($break == 1) {
		print OUT "<br>\n";
	    } elsif ( $break > 1) {
		print OUT "<p>\n";
	    }
	    $break =0 ;
	}
	s=<<=&lt\;=g;
	while ( m=(<)([^>]*)(>)=) {
	    print OUT "$`";
	    $param = $2;
	    $rest = $';
	    $param =~ s=^nl=br=g;
	    $param =~ s=^bold=b=g;
	    $param =~ s=^/bold=/b=g;
	    $param =~ s=^italics=i=g;
	    $param =~ s=^/italics=/i=g;
	    $param =~ s=^nofill=pre=g;
	    $param =~ s=^/nofill=/pre=g;
	    if ( $param =~ m=^smaller= ) {
		$fontsize = $fontsize -1;
		$param = sprintf("font size=\"%+d\"",$fontsize);
	    }
	    if ($param =~ m=/smaller= ) {
		$fontsize = $fontsize +1;
		$param = "/font";
	    }
	    if ( $param =~ m=^bigger= ) {
		$fontsize = $fontsize +1;
		$param = sprintf("font size=\"%+d\"",$fontsize);
	    }
	    if ( $param =~ m=/bigger= ) {
		$fontsize = $fontsize -1;
		$param = "font";
	    }

	    print OUT "<$param>";
	    $_ = $rest;
	}
	s:>:\&gt\;:g;
	print OUT "$_";
    }
    print OUT "<p></html>\n";

}
sub text_plain {
    print OUT "<pre>\n";
    undef @newlines;
    &make_internal;
    # PW, 8/17/95
    $dourls = 1;
    foreach $_ (@lines) {
	if (/html>/) {
	    @newlines = (@newlines,split(/(<\/?html>)/i));
       } else {
	    @newlines = (@newlines, $_);
	}
    }
    foreach $_ (@newlines) {
	$foo = $_;
	if (m/<html>/) {
	    $dourls = 0;
	    print OUT "<!-- html --></pre>\n";
	    next;
	}
	if (m/<\/html>/) {
	    $dourls = 1;
	    print OUT "<!-- /html --><pre>\n";
	    next;
	}
	# Handle URLS
        s:<:\&lt\;:g if $dourls;
        s:>:\&gt\;:g if $dourls;
	s!\b([a-z]+://\S*)(\s)!<a href=\"\1\">\1</a>\2!g if $dourls;
	s/^\s*&gt\;(.*)$/<i>&gt\; \1<\/i> /g;
	  
	print OUT ;
    }
    print OUT "</pre>\n";
}

sub text_x_html {
    &make_internal;
    print OUT @lines;
}

sub video_mpeg {
    $name = &make_external(@mpeg);
    print OUT "<a href=\"$name\"><img src=\"$name.icon.gif\" align=middle>" .
	&pretty_name($name,"Unnamed MPEG") . "</a><p>\n";
}

sub video_quicktime {
    $name = &make_external(@quicktime);
    print OUT "<a href=\"$name\"><img src=\"$name.icon.gif\" align=middle>" .
	&pretty_name($name,"Unnamed QuickTime Movie") . "</a><p>\n";
}


sub guesscontenttype {
    # need to guess a contenttype based on file extension
    $name =~ m/([^.]*)$/;
    $current = $1;
    %guesstypes = ( "gif","image/gif",
		   "jpeg","image/jpeg",
		   "mpeg","video/mpeg",
		   "quicktime","video/qt",
		   );
    foreach $type ("gif","jpeg","mpeg","quicktime") {
	$done = 0;
	foreach $ext ( eval "\@$type" ) {
	    if ($current eq $ext) {
		$done =1;	
		$contenttype = "$guesstypes{$type}";
		last;
	    }
	}
	last if $done;
    }
    if ( $contenttype !~ /application\/octect-stream/ ) {
	print "Guessing $contenttype based on $ext\n";
	unlink("$hthome/$theproject/$name.icon.gif");
	&makeicon;
    }
}

1;
