Apache-App-Mercury

 view release on metacpan or  search on metacpan

Mercury/DBI.pm  view on Meta::CPAN

    }
    eval {
	my $dbh = DBI->connect
	  (Apache::App::Mercury::Config::DBI_CONNECT_STR,
	   Apache::App::Mercury::Config::DBI_LOGIN,
	   Apache::App::Mercury::Config::DBI_PASS,
	   {'RaiseError' => 1});
	my $sth = $dbh->prepare_cached
	  ("SELECT count(*) FROM ".Apache::App::Mercury::Config::DBI_SQL_MSG_TABLE()." WHERE recipient=? AND status=? AND recipient!=sender");
	$sth->execute($user, 'unread');
	$sth->bind_col(1, \$unread);
	$sth->fetchrow_arrayref;
	$sth->finish;
	$dbh->disconnect;
    };
    if ($@) {
	$self->log_error;
	return undef;
    }
    return $unread;
}

Mercury/DBI.pm  view on Meta::CPAN

	if !grep($new_status, ('unread','read','replied','forwarded','deleted'));

    if (!($all_in_this_box or @ids)) {
	$self->log_error("->change_status: must specify msg id or box to act on!");
	return 0;
    } elsif (!grep($new_status, ('unread','read','replied','forwarded','deleted'))) {
	$self->log_error("->change_status: new_status must be one of 'unread','read','replied','forwarded','deleted' - not $new_status");
	return 0;
    }

    my ($where_clause, @bind_params);
    if ($all_in_this_box) {
	$where_clause = "WHERE box=?";
	push(@bind_params, $all_in_this_box);
    } else {
	my $placeholders = join(", ", map {'?'} @ids);
	$where_clause = "WHERE id IN($placeholders)";
	@bind_params = @ids;
    }
    eval {
	my $dbh = DBI->connect
	  (Apache::App::Mercury::Config::DBI_CONNECT_STR,
	   Apache::App::Mercury::Config::DBI_LOGIN,
	   Apache::App::Mercury::Config::DBI_PASS,
	   {'RaiseError' => 1});
	# mark message(s) as $new_status
	my $sth = $dbh->prepare_cached
	  ("UPDATE ".Apache::App::Mercury::Config::DBI_SQL_MSG_TABLE()." SET $status_col=?,timestamp=timestamp $where_clause");
	$sth->execute($new_status, @bind_params);
	$sth->finish;
	$dbh->disconnect;
    };
    if ($@) {
	$self->log_error;
	return 0;
    }

    $self->warn("->change_status: set ".(@ids ? join(', ', @ids) : "all in $all_in_this_box")." to $new_status");

Mercury/DBI.pm  view on Meta::CPAN

}

sub change_box {
    my ($self, $to_box, $all_in_this_box, @ids) = @_;

    if (!$to_box and !(@ids and $all_in_this_box)) {
	$self->log_error("->change_box: must specify new mailbox and msg id or box to move all from!");
	return 0;
    }

    my ($where_clause, @bind_params);
    if ($all_in_this_box) {
	$where_clause = "WHERE box=?";
	push(@bind_params, $all_in_this_box);
    } else {
	my $placeholders = join(", ", map {'?'} @ids);
	$where_clause = "WHERE id IN($placeholders)";
	@bind_params = @ids;
    }

    eval {
	my $dbh = DBI->connect
	  (Apache::App::Mercury::Config::DBI_CONNECT_STR,
	   Apache::App::Mercury::Config::DBI_LOGIN,
	   Apache::App::Mercury::Config::DBI_PASS,
	   {'RaiseError' => 1});
	my $sth = $dbh->prepare_cached
	    ("UPDATE ".Apache::App::Mercury::Config::DBI_SQL_MSG_TABLE()." SET box=?,timestamp=timestamp $where_clause");
	$sth->execute($to_box, @bind_params);
	$sth->finish;
	$dbh->disconnect;
    };
    if ($@) {
	$self->log_error;
	return 0;
    }

    $self->warn("->change_box: moved ".(@ids ? join(', ', @ids) : "all in $all_in_this_box")." to $to_box");

Mercury/DBI.pm  view on Meta::CPAN

    }

    my $sorter = (($box and $self->{$box}->{'sortby'} and
		   $self->{$box}->{'sortby'} ne 'time')
		  ? $self->{$box}->{'sortby'} : 'timestamp');

    my $sort_direction = (($box and $self->{$box}->{'sortdir'} and
			   $self->{$box}->{'sortdir'} eq 'up')
			  ? 'ASC' : 'DESC');

    my ($where_clause, @bind_params);

    if ($box) {
	$where_clause = ($box eq 'outbox'
			 ? "WHERE sender=? AND status_sender!='deleted'"
			 : "WHERE recipient=? AND status!='deleted'");
	push(@bind_params, $user);
	if ($box eq 'inbox') {
	    $where_clause .= " AND (box='' OR box='inbox')";
	} elsif ($box ne 'outbox') {
	    $where_clause .= " AND box=?";
	    push(@bind_params, $box);
	}
	$self->{$box}->{'index'} = [];
    } elsif ($smtp_status) {
	$where_clause = "WHERE status_smtp=?";
	push(@bind_params, $smtp_status);
    } else {
	if (ref $ids eq 'ARRAY') {
	    my $placeholders = join(", ", map {'?'} @$ids);
	    $where_clause = "WHERE id IN($placeholders)";
	    @bind_params = @$ids;
	}
	if ($trans_code) {
	    $where_clause .=
		($where_clause ? " AND" : "WHERE")." code=? AND trans=?";
	    push(@bind_params, $trans_code, 'show');
	}
    }

    eval {
	my $dbh = DBI->connect
	  (Apache::App::Mercury::Config::DBI_CONNECT_STR,
	   Apache::App::Mercury::Config::DBI_LOGIN,
	   Apache::App::Mercury::Config::DBI_PASS,
	   {'RaiseError' => 1});
	my $sth = $dbh->prepare_cached
	    ("SELECT id,recipient,sent_to,sender,timestamp,DATE_FORMAT(timestamp, '%a %b %d %r %Y'),subject,body,attachments,status,status_smtp,code,trans,security,box FROM ".Apache::App::Mercury::Config::DBI_SQL_MSG_TABLE()." $where_clause ORDER BY $sorter...
	$sth->execute(@bind_params);
	my ($id, $recip, $sent_to, $sender, $timestamp, $time_recvd, $subj,
	    $body, $attach, $status, $smtp_status, $code, $display_trans,
	    $security, $thebox);
	$sth->bind_columns
	  (\ ($id, $recip, $sent_to, $sender, $timestamp, $time_recvd, $subj,
	      $body, $attach, $status, $smtp_status, $code, $display_trans,
	      $security, $thebox) );
	while ($sth->fetchrow_arrayref) {
	    $msgs{$id} = Apache::App::Mercury::Message->new
	      ({ 'id' => $id,
		 'recipient' => $recip,
		 'sent_to' => $sent_to,
		 'sender' => $sender,
		 'time' => $timestamp,

Mercury/Message/Attachment.pm  view on Meta::CPAN

			       {'RaiseError' => 1});
	my $sth = $dbh->prepare_cached
	  ("INSERT INTO ".SQL_ATTACHMENT_TABLE." SET filesys=?, attachment=?, msg_ids=?");
	$sth->execute($self->{'Filename'}, $self->{'Name'},
		      join(' ', sort {$a<=>$b} keys %{$self->{'MessageIDs'}}));
	$sth->finish;

	my $sth2 = $dbh->prepare_cached("SELECT LAST_INSERT_ID()");
	$sth2->execute;
	$self->{'AttachmentID'} = '';
	$sth2->bind_columns(\$self->{'AttachmentID'});
	$sth2->fetchrow_arrayref;
	$sth2->finish;

	$dbh->disconnect;
    };
    if ($@) {
	$self->log_error;
	return 0;
    }
    return 1;

Mercury/Message/Attachment.pm  view on Meta::CPAN

}

sub retrieve {
    my ($self) = @_;

    unless (defined $self->{'AttachmentID'} or defined $self->{'Filename'}) {
	$self->log_error("->retrieve: an AttachmentID or Filename is required for retrieval");
	return undef;
    }

    my ($where_clause, @bind_params);
    if (defined $self->{'AttachmentID'}) {
	$where_clause = 'aid=?';
	push(@bind_params, $self->{'AttachmentID'});
    } else {
	$where_clause = 'filesys=?';
	push(@bind_params, $self->{'Filename'});
    }

    eval {
	my $dbh = DBI->connect(Apache::App::Mercury::Config::DBI_CONNECT_STR(),
			       Apache::App::Mercury::Config::DBI_LOGIN(),
			       Apache::App::Mercury::Config::DBI_PASS(),
			       {'RaiseError' => 1});
	my $sth2 = $dbh->prepare_cached
	  ("SELECT aid,filesys,attachment,msg_ids FROM ".SQL_ATTACHMENT_TABLE." WHERE $where_clause");
	$sth2->execute(@bind_params);

	$self->{'AttachmentID'} = '';
	$self->{'Name'} = '';
	$self->{'Filename'} = '';
	my $msg_ids;
	$sth2->bind_columns(\ ($self->{'AttachmentID'}, $self->{'Filename'},
			       $self->{'Name'}, $msg_ids) );
	$sth2->fetchrow_arrayref;
	$self->{'MessageIDs'} = { map { $_ => 1 } split(/\s+/, $msg_ids) };

	$sth2->finish;
	$dbh->disconnect;
    };
    if ($@) {
	$self->log_error($@);
	return undef;

Mercury/Message/DBI.pm  view on Meta::CPAN

	       ($is_memo || $self->{'nocopy'} || $after_first
		? 'deleted' : 'unread'),
	       ($self->{'transcode'} ? $self->{'transcode'} : ''),
	       ($self->{'transcode'} && !$after_first
		? ($self->{'display_trans'} ? $self->{'display_trans'} :'show')
		: 'hide'),
	       ($self->{'security'} ? $self->{'security'} : 'medium'));

	    $sth2->execute;
	    my $msgid;
	    $sth2->bind_columns(\$msgid);
	    $sth2->fetchrow_arrayref;
	    $sth2->finish;

	    $self->{'MessageIDs'}->{$msgid} = 1;
	    $after_first = 1;
	}

	$dbh->disconnect;
    };
    if ($@) {



( run in 1.704 second using v1.01-cache-2.11-cpan-2398b32b56e )