Apache-App-Mercury

 view release on metacpan or  search on metacpan

Mercury.pm  view on Meta::CPAN


sub delete_mailbox {
    my ($self, $old_box, $delete_mail_in_box) = @_;
    my $controller = $self->{controller};
    my $user = $self->{user_manager}->userprofile('user');

    my $num_displaced = $#{$self->{$old_box}->{'index'}} + 1;

    # get rid of filters, if necessary
    $self->remove_filters_for($old_box);

    # then move out the mail
    if ($delete_mail_in_box) {
	$self->change_status(undef, 'deleted', $old_box);
    } else {
	$self->change_box('inbox', $old_box);
    }

    my @boxes = $self->{user_manager}->mailboxes;
    @boxes = grep($_ ne $old_box, @boxes);

    if ($self->{user_manager}->mailboxes($user, @boxes)) {
	delete $self->{$old_box};

	# if mail has been transfered to inbox, rebuild it
	#  - doesn't seem to work otherwise . . .
	if (!$delete_mail_in_box) {
	    my ($sortby, $sortdir) = $self->get_sortby('inbox');
	    delete $self->{'inbox'};
	    $self->set_sortby('inbox', $sortby, $sortdir);
	    $self->makebox('inbox');
	}
	$self->{'current_box'} = 'inbox' if $self->{'current_box'} eq $old_box;

	$controller->infomsg(ucfirst($old_box)." has been deleted".($delete_mail_in_box ? " along with the $num_displaced messages stored there." : ".  The $num_displaced messages stored there have been moved to your Inbox."));
    }
}

sub edit_filters {
    my ($self) = @_;
    my $q = $self->{q};

    if ($q->param('trans_filter') and
	$q->param('trans_filter') ne $self->{user_manager}->mail_trans_filter) {
	$self->{user_manager}->mail_trans_filter($q->param('trans_filter'));
    }
}

sub remove_filters_for {
    my ($self, $old_box) = @_;

    # this is the only filter, add filter checks as filters are created
    if ($self->{user_manager}->mail_trans_filter eq $old_box) {
	# set transaction filter back to 'inbox'
	unless ($self->{user_manager}->mail_trans_filter('inbox')) {
	    $self->warn("->remove_filters_for($old_box) FAILED!");
	}
    }
}

sub update_auto_forward {
    my ($self) = @_;
    my $q = $self->{q};

    $self->{user_manager}->auto_forward('low', $q->param('forward_low'));
    $self->{user_manager}->auto_forward('medium', $q->param('forward_medium'));
    $self->{user_manager}->auto_forward('high', $q->param('forward_high'));
}


sub count_unread {
    my ($self, $user, $this_box, $force_db) = @_;
    my $no_need_db;

    if (!$force_db and $self->{'mailboxes'}) {
	my $cnt = 0;
	my $this_cnt = 0;
	foreach my $box (@{$self->{'mailboxes'}}) {
	    if ($box ne 'outbox' and
		ref $self->{$box}->{'msgs'} eq 'HASH' and
		ref $self->{$box}->{'index'} eq 'ARRAY') {
		$no_need_db = 1;
		foreach (@{$self->{$box}->{'index'}}) {
		    my $msg = $self->{$box}->{'msgs'}->{$_};
		    $cnt++ if ($msg->{'status'} eq 'unread' and
			       $msg->{'recipient'} ne $msg->{'sender'});
		    $this_cnt++ if ($box eq $this_box and
				    $msg->{'status'} eq 'unread' and
				    $msg->{'recipient'} ne $msg->{'sender'});
		}
	    }
	}
	if ($no_need_db) {
	    if ($this_box) {
		return ($cnt, $this_cnt);
	    } else {
		return $cnt;
	    }
	}
    }

    # only use database if forced or if there's no legitimate mailboxes
    if ($force_db or !$no_need_db) {
	$user = $self->{user_manager}->userprofile('user') if !$user;
	return $self->dbi_count_unread($user);
    }
}


1;

__END__

=head1 NAME

Apache::App::Mercury - Internal web messaging for Apache mod_perl (1.x)

=head1 SYNOPSIS

  # first, edit Apache/App/Mercury/Config.pm and set variables appropriately

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.049 second using v1.00-cache-2.02-grep-82fe00e-cpan-1310916c57ae )