inject: Insert correct Lines header.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 27 Mar 2006 14:11:24 +0000 (15:11 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 27 Mar 2006 14:11:24 +0000 (15:11 +0100)
bin/inject

index 62a75fd..6dbfdb3 100755 (executable)
@@ -100,6 +100,7 @@ class NNTP (object):
 
 def send():
   hdr = StringIO()
+  body = StringIO()
   hdr.write('Path: newsgate\r\n'
             'Distribution: mail\r\n'
             'Newsgroups: %s\r\n'
@@ -135,7 +136,6 @@ def send():
               % (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):
@@ -145,7 +145,7 @@ def send():
   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
@@ -155,7 +155,12 @@ def send():
         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()