Skip to content

Commit

Permalink
Ignore IMs from people not on your buddy list or in your nickname file.
Browse files Browse the repository at this point in the history
Spammers apparently don't get sent on to me for viewing, but their IMs are
landing in the ejabber archive database, so this lets us ignore them here.
  • Loading branch information
icculus committed Aug 22, 2015
1 parent 86dd086 commit f194a72
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions archive_jabber.pl
Expand Up @@ -239,7 +239,22 @@ sub signal_catcher {
'mysql_enable_utf8' => 1
});

my $sql = 'select m.id, m.utc, m.dir, m.body,' .
my $baseuser = $xmppuser;
$baseuser =~ s/\@.*\Z//;

my $sql = "select jid from rosterusers where username='$baseuser'";
dbgprint("sql = '$sql'\n");
my $sth = $link->prepare($sql);
$sth->execute() or fail "can't execute the query: ${sth->errstr}";
my %authorized;
while (my @row = $sth->fetchrow_array()) {
my ($buddy) = @row;
dbgprint("Authorized: '$buddy'\n");
$authorized{$buddy} = 1;
}
$sth->finish();

$sql = 'select m.id, m.utc, m.dir, m.body,' .
' c.id, c.with_user, c.with_server, c.with_resource,' .
' c.utc, c.change_utc' .
' from archive_messages as m' .
Expand All @@ -248,7 +263,7 @@ sub signal_catcher {
" and (c.us = '$xmppuser')" .
' order by c.with_user, c.with_server, m.id';
dbgprint("sql = '$sql'\n");
my $sth = $link->prepare($sql);
$sth = $link->prepare($sql);
$sth->execute() or fail "can't execute the query: ${sth->errstr}";

my $lastspeaker = '';
Expand All @@ -275,6 +290,11 @@ sub signal_catcher {
}
}

if (not $authorized{$with} and not $nicknames{$with}) {
dbgprint("'$with' isn't authorized. Probably spam? Skip it.");
next;
}

$startmsgid = $msgid if (not defined $startmsgid);

if (not defined $startids{$with}) {
Expand Down

0 comments on commit f194a72

Please sign in to comment.