# $Id: IPC.pm,v 1.1.1.1 2001/01/16 10:35:46 muhri Exp $
# -*- perl -*-
package Pronto::IPC;
use strict;
use POSIX ":sys_wait_h";
sub ALRM_handler {
	if($main::prefs{'AutoCheckTime'} > 0) {
		&main::check_mail(0,"all",$main::prefs{'AutoCheckProgress'});
		my $seconds = 60*$main::prefs{'AutoCheckTime'};
		alarm $seconds;
	}
}

sub USR1_handler {
	if(open(TMP,"<$main::prefs{'MailDir'}/pronto.address")) {
		my @fields;
		my $i = 0;
		while($fields[$i++] = <TMP>) {};
		$fields[0] =~ s/mailto\://;
		if(defined $fields[1]) {
			if(defined $fields[2]) {
				my $tmp = $fields[1];
				$fields[1] = $fields[2];
				$fields[2] = $tmp;
			}
			else {
				$fields[2] = $fields[1];
				$fields[1] = "";
			}
		}
		else {
	       		$fields[1] = "";
			$fields[2] = "";
		}
		
		chomp($fields[0]);
		chomp($fields[1]);
		chomp($fields[2]);
		&Pronto::Compose::init_msg_window(0, undef, \@fields);
		unlink("$main::prefs{'MailDir'}/pronto.address");
	}
	else {
		&Pronto::Compose::init_msg_window;
#		$main::root_window->window->show();
#		$main::root_window->show();
#		$main::root_window->window->raise();
	}
}

sub USR2_handler {
 	
	my $box = &Pronto::FolderTree::get_folder_id();
 	&Pronto::FolderTree::refresh_folder_tree(1); #to playsound if any
      	if (!$box) { $box = 0 }
       	if ($box !=1000) {
  		if ($main::prefs{'messageview'} eq "clist") {
			&Pronto::MessageList::refresh_messages;
 		} else {
			&Pronto::MessageList::refresh_ctree;
		}	
	}
 return 1;

}

sub CHLD_handler {
	waitpid(-1, WNOHANG);
	$SIG{CHLD}=\&CHLD_handler;
}

1;
