#!/usr/bin/python
#
# Copyright 2001 Specialized Systems Consultants.  All
# rights reserved.  No warranties are made.  You
# are licensed to use this software under the terms or
# the GNU General Public License.
#
# Fri Nov 30 12:55:53 PST 2001 dhw

from rfc822 import *
import sys

# Make a dictionary containing a list of list members.
# We're only using the keys, we don't care about values.

members = {}
fp = open('/var/lib/mailman/localdata/linux-questions-only')
for member in fp.readlines():
  members[(member[:-1])] = '1'
fp.close()

# Get the message headers
m = Message(sys.stdin)

del m['return-path']
del m['content-type']
del m['content-transfer-encoding']
del m['sender']
del m['errors-to']
del m['precedence']
del m['status']
del m['content-length']
del m['lines']

seen = {}
rcpts = "linux-questions-only@ssc.com"
querant  = ""
seen['linux-questions-only@ssc.com'] = '1'

for rcpt in (m.getaddrlist('to')
  + m.getaddrlist('from')
  + m.getaddrlist('cc')
  + m.getaddrlist('mail-followup-to')):
  if not members.has_key(rcpt[1]) and not seen.has_key(rcpt[1]):
    if rcpts != "":
      rcpts = rcpts + ","
    name = rcpt[0]
    if name != "":
      name = '"' + name + '"'
    if name != "":
      rcpts = rcpts + " " + name
    rcpts = rcpts + " <" + rcpt[1] + ">"
    if querant != "":
      querant = querant + ","
    if name != "":
      querant = querant + name
    querant = querant + " <" + rcpt[1] + ">"
    seen[rcpt[1]] = '1'

m['Reply-To'] = rcpts

print m

if querant != "":
  print ""
  print
"+-+--------------------------------------------------------------------+-+"
  print "+-+ Original question from: " + querant
  print
"+-+--------------------------------------------------------------------+-+"
  print ""

