from getopt import getopt, GetoptError
from sys import stdin, stdout, stderr, argv, exit
from cStringIO import StringIO
+env = OS.environ
prog = argv[0]
host = 'localhost'
dist = 'mail'
path = 'newsgate'
+sender = env.get('SENDER')
+recip = env.get('RECIPIENT')
group = None
def opts():
- global approved, remote, host, dist, path, group
+ global approved, remote, host, dist, path, group, sender, recip
try:
- opts, args = getopt(argv[1:], 'a:d:h:r:p:',
+ opts, args = getopt(argv[1:], 'a:d:h:r:p:S:R:',
['approved=', 'distribution=',
+ 'sender=', 'recipient=',
'hostname=', 'remote=', 'path='])
except GetoptError:
usage()
host = a
elif o in ('-r', '--remote'):
remote = (lambda addr, port = 119: (addr, int(port)))(*a.split(':'))
+ elif o in ('-R', '--recipient'):
+ recip = a
+ elif o in ('-S', '--sender'):
+ sender = a
if len(args) != 1:
usage()
group, = args
def send():
hdr = StringIO()
+ body = StringIO()
hdr.write('Path: newsgate\r\n'
'Distribution: mail\r\n'
'Newsgroups: %s\r\n'
- 'Approved: %s\r\n'
- % (group, approved or 'newsgate@%s' % host))
+ % group)
+ if approved: hdr.write('Approved: %s\r\n' % approved)
+ if sender: hdr.write('Return-Path: <%s>\r\n' % sender)
+ if recip: hdr.write('Delivered-To: %s\r\n' % recip)
xify = {}
for h in '''
lines xref newsgroups path distribution approved received
% (T.strftime('%a, %d %b %Y %H:%M:%S %Z')))
if 'subject' not in seen:
hdr.write('Subject: (no subject)\r\n')
- hdr.write('\r\n')
msgid = seen['message-id']
if not rx_msgid.match(msgid):
nntp.cmd('IHAVE %s' % msgid)
rc, msg = nntp.reply()
if rc == '335':
- nntp.write(hdr.getvalue())
+ n = 0
for i in stdin:
if i.startswith('.'):
i = '.' + i
i = i[:-1] + '\r\n'
else:
i = i + '\r\n'
- nntp.write(i)
+ body.write(i)
+ n += 1
+ hdr.write('Lines: %d\r\n' % n)
+ hdr.write('\r\n')
+ nntp.write(hdr.getvalue())
+ nntp.write(body.getvalue())
nntp.write('.\r\n')
nntp.flush()
rc, msg = nntp.reply()