# $Id: Print.pm,v 1.3 2001/03/19 01:19:27 muhri Exp $
# -*- perl -*-
package Pronto::Print;
use strict;
use SelfLoader;
1;
__DATA__
sub print_message {

	my ($flag) = @_;
	my ($msgid, $child, $forrep, $sql, $query, $print, $printed);
	$forrep = 4;

	$msgid = &Pronto::MessageList::get_selected_msgid();

	if (! $msgid) {
		&main::err_dialog(_("Select the message You want to print!"));
		return 1;
	}

	$sql = "select contenttype from messages where id = $msgid";
	$query = $main::conn->prepare($sql);
	$query->execute();
	my ($type) = ($query->fetchrow_array());
	if ($type =~/html/) { &main::err_dialog(_("Can't print HTML Messages yet"));
		return 1;
	}

	if ($flag eq "withheader") { 

		$print->{'format'} = new Gtk::Text;
		my $header = &Pronto::Read::view_message($main::conn, $msgid, $print->{'format'}, 4, $forrep, undef, undef, undef, undef, undef, "n");
		my $body = &Pronto::Read::view_message($main::conn, $msgid, $print->{'format'}, 2, $forrep, undef, undef, undef, undef, undef, "n");
		$printed = $print->{'format'}->get_chars(0, -1);
                            
	} elsif ($flag eq "body") {

		$print->{'format'} = new Gtk::Text;
		my $body = &Pronto::Read::view_message($main::conn, $msgid, $print->{'format'}, 2, $forrep, undef, undef, undef, undef, undef, "y");
		$printed = $print->{'format'}->get_chars(0, -1);
        }
		    
	open (TMP, ">$main::prefs{'MailDir'}/tmp/printed$msgid");
	print TMP "$printed";
	close TMP;

	unless ($child = fork) { die "cannot fork: $~" unless defined $child;
		exec("$main::prefs{'PrintCommand'} $main::prefs{'MailDir'}/tmp/printed$msgid");
	}
	return 1;
}


syntax highlighted by Code2HTML, v. 0.9.1