From 4e12aa09b12c758e1d085ae09f06bae906ce8bed Mon Sep 17 00:00:00 2001
From: Geoffrey Thomas <geofft@mit.edu>
Date: Fri, 6 Nov 2009 01:28:22 -0500
Subject: [PATCH] Check that senders are on sipb-office, rather than being sipb0

---
 lib/BarnOwl/Module/Twitter.pm |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/lib/BarnOwl/Module/Twitter.pm b/lib/BarnOwl/Module/Twitter.pm
index c4652f9..440c020 100644
--- a/lib/BarnOwl/Module/Twitter.pm
+++ b/lib/BarnOwl/Module/Twitter.pm
@@ -18,6 +18,7 @@ our $VERSION = 0.2;
 use Net::Twitter;
 use JSON;
 use List::Util qw(first);
+use Net::LDAP;
 
 use BarnOwl;
 use BarnOwl::Hooks;
@@ -174,12 +175,16 @@ sub match {
 sub handle_message {
     my $m = shift;
     ($class, $instance, $opcode) = map{BarnOwl::getvar("twitter:$_")} qw(class instance opcode);
+    my $sender = $m->sender;
+    $sender =~ s/\@.*//;
+    my $ldap = Net::LDAP->new('ldap-dev-1.mit.edu');
     if($m->type eq 'zephyr'
-       && $m->sender eq BarnOwl::zephyr_getsender()
+       && $m->auth eq 'YES'
+       && $ldap->search(base => 'ou=lists,ou=moira,dc=mit,dc=edu',
+                        filter => '(&(cn=sipb-office)(member=uid=' . $sender . ',ou=users,ou=moira,dc=mit,dc=edu))')->count
        && match($m->class, $class)
        && match($m->instance, $instance)
-       && match($m->opcode, $opcode)
-       && $m->auth eq 'YES') {
+       && match($m->opcode, $opcode)) {
         for my $handle (@twitter_handles) {
             $handle->twitter($m->body) if $handle->{cfg}->{publish_tweets};
         }
-- 
1.6.3.3

