diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2014-12-24 14:24:24 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2014-12-24 14:32:23 +0100 |
commit | 8af6ecfe31a7767f1d76f36581b01ddd26fb3220 (patch) | |
tree | a5cf60c5de6a34843fceb23895473cbb25c80fa2 | |
parent | 45552a9cb1ac5433fd2010d1736b41a3393b9b6b (diff) | |
download | pygn-8af6ecfe31a7767f1d76f36581b01ddd26fb3220.tar.gz |
Mighty cleanup
* Use more of the standard methods for OrderedDicts
* remove pyginfo module (with SSOT being mail2news module)
* remove TODO, INSTALL, and changelog.Debian
* all FIXMEs and TODOs are filed as bugs in the issue tracker
-rw-r--r-- | INSTALL | 29 | ||||
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | TODO | 12 | ||||
-rw-r--r-- | changelog.Debian | 248 | ||||
-rw-r--r-- | cleanup_failing.patch | 113 | ||||
-rw-r--r-- | mail2news.py | 71 | ||||
-rw-r--r-- | news2mail.py | 71 | ||||
-rw-r--r-- | pyginfo.py | 26 | ||||
-rwxr-xr-x | pygm2n | 9 | ||||
-rwxr-xr-x | pygn2m | 9 | ||||
-rw-r--r-- | setup.py | 14 | ||||
-rwxr-xr-x | test/test_wlp.py | 11 | ||||
-rw-r--r-- | whitelist.py | 40 |
13 files changed, 94 insertions, 561 deletions
diff --git a/INSTALL b/INSTALL deleted file mode 100644 index 599a64d..0000000 --- a/INSTALL +++ /dev/null @@ -1,29 +0,0 @@ -For debian user: - -Make package as usual: - -$ dpkg-buildpackage -uc -us -rfakeroot -and install .deb file made. - - - - -For non debian user only: - -Simply run make: - -$ make - -and install file where you want: -Something like: - -$ install -m 0755 -d /usr/local/lib/pyg -to create /usr/local/lib/pyg with right permissions - -$ make install DESTDIR=/usr/local -to install file in /usr/local as basedir -/usr/local/sbin pygs (pyg frontend) -/usr/local/lib/pyg *.py *.so (module classes) - -You may install manually documentation and examples in examples/ dir in -/usr/local/share/doc or where you wish. @@ -17,7 +17,7 @@ List of file: mail2news.py mail to news python class module news2mail.py news to mail python class module -pyginfo.py info about pygs python class module +setup.py setup script pygm2n mail to news gateway frontend pygn2m news to mail gateway frontend whitelist.py whitelist managing python class module @@ -1,12 +0,0 @@ -pygm2n: - -Handle better socket errors (try: in sendemail) -Let choose if remove (let server generate it), regenerete or leave Message-ID -Post to many server (server list)? maybe. -reads NNTPHOST environ var to set default host. - - -both: - -try: for open() in readfile() -finish to write HOWTO diff --git a/changelog.Debian b/changelog.Debian deleted file mode 100644 index f53d92d..0000000 --- a/changelog.Debian +++ /dev/null @@ -1,248 +0,0 @@ -pyg (0.9.8ubuntu2) raring; urgency=low - - * Fix build failure with python in multiarch location. - - -- Matthias Klose <doko@ubuntu.com> Mon, 08 Apr 2013 18:40:05 +0200 - -pyg (0.9.8ubuntu1) raring; urgency=low - - * Merge from Debian unstable. Remaining changes: - - adapt /wlp/C/Makefile for multiarched libfl.a - - include required string.h in wlp/C/commands.l - - -- Logan Rosen <logatronico@gmail.com> Mon, 26 Nov 2012 17:28:37 -0500 - -pyg (0.9.8) unstable; urgency=low - - * Added string.h to avoid implicit declarations in yacc definitions. - Closes: #689349 - * Remove some compile-time warning from wlp/C/wlp.c - * not ignore errors in clean targets on all Makefile - * debian/compat bump to 5 (higher should be tested) - * use dh_python2 - - -- Cosimo Alfarano <kalfa@debian.org> Tue, 02 Oct 2012 14:04:01 +0100 - -pyg (0.9.7ubuntu1) quantal; urgency=low - - * adapt /wlp/C/Makefile for multiarched libfl.a - * include required string.h in wlp/C/commands.{l,y} - - -- Julian Taylor <jtaylor@ubuntu.com> Mon, 01 Oct 2012 21:10:48 +0200 - -pyg (0.9.7) unstable; urgency=low - - * Added maildrop as a possible deps (Closes: #385771) - * Typos fixed in HOWTO. - * Creating md5sum control file - - -- Cosimo Alfarano <kalfa@debian.org> Fri, 18 Jul 2008 13:35:57 -0400 - -pyg (0.9.6-4.2) unstable; urgency=high - - * Non-maintainer upload. - * Add BLDSHARED to Makefile.pre.in for python2.5 compatibility. - Closes: #476160 - * Add shlibs:Depends in debian/control. - - -- Thomas Viehmann <tv@beamnet.de> Sun, 20 Apr 2008 16:49:23 +0200 - -pyg (0.9.6-4.1) unstable; urgency=low - - * Non-maintainer upload. - * Update package to the last python policy (Closes: #380905). - * Bump DH_COMPAT to 4. - * Bump Standards-Version to 3.7.2. - - -- Pierre Habouzit <madcoder@debian.org> Sat, 12 Aug 2006 14:01:38 +0200 - -pyg (0.9.6-4) unstable; urgency=low - - * added some more header to be stripepd in mail2news class - closes:Bug#165322 - - -- Cosimo Alfarano <kalfa@debian.org> Tue, 2 Mar 2004 21:40:59 +0100 - -pyg (0.9.6-3.1) unstable; urgency=low - - * apply the full (not modified) version of the Matt's patch, for - compatibility reasons - - -- Cosimo Alfarano <kalfa@debian.org> Thu, 6 Nov 2003 23:46:31 +0100 - -pyg (0.9.6-3) unstable; urgency=low - - * applied a modified version of patch from Matt Kraai sent in BTS - closes:Bug#213936 - - -- Cosimo Alfarano <kalfa@debian.org> Wed, 5 Nov 2003 11:59:29 +0100 - -pyg (0.9.6-2) unstable; urgency=low - - * typos in debian/control fixed (closes: #125276) - - -- Cosimo Alfarano <kalfa@debian.org> Sat, 6 Apr 2002 18:52:57 +0200 - -pyg (0.9.6-1) unstable; urgency=low - - * minor changes to mail2news.py sendemail() method - now does str(msg) on exception - * addedd support for void header ('Cc: \n\r') even if it is not fully rfc - conform. - * addedd support for multiline header of the form - "Received: \n\r<text>" (closes: #124396) - * fixed helo hostname sent, now it's the box name - (closes: #122851) - * sorry for the long fixing time, to everyone was waiting for them. - - -- Cosimo Alfarano <kalfa@debian.org> Wed, 3 Apr 2002 22:39:47 +0200 - -pyg (0.9.5-1) unstable; urgency=low - - * compiled against python2.1 (wlp.c) - * debian/control updated for dependancies - python (>= 2.1), I want it to be usable on any 2.X - the same for python-dev (closes: #119202) - - -- Cosimo Alfarano <kalfa@debian.org> Mon, 12 Nov 2001 22:17:28 +0100 - -pyg (0.9.4-7) unstable; urgency=low - - * fixed some typos - * fixed import of getopt module (thanks to zack@debian.org) - * inverted 'if' and 'else' in line 78 of mail2news.py - that's not a bug, but I do it for readability closes: #105922 - - -- Cosimo Alfarano <kalfa@debian.org> Fri, 20 Jul 2001 00:49:26 +0200 - -pyg (0.9.4-6) unstable; urgency=low - - * added -P port option to pygm2n - - -- Cosimo Alfarano <kalfa@debian.org> Sun, 11 Feb 2001 22:09:03 +0100 - -pyg (0.9.4-5) unstable; urgency=low - - * added suport for NNTP auth (thanks to Marc Sherman for his patch) closes: #84809 - - -- Cosimo Alfarano <kalfa@debian.org> Sun, 11 Feb 2001 16:43:09 +0100 - -pyg (0.9.4-4) unstable; urgency=low - - * moved files from /usr/sbin to /usr/bin closes: #84806 - * changed Maintainer: filed to kalfa@debian.org addr - - -- Cosimo Alfarano <alfarano@students.cs.unibo.it> Sun, 04 Feb 2000 18:50:00 +0100 - -pyg (0.9.4-3) unstable; urgency=low - - * Sponsored upload. - * fixed getopt problem with -M - - -- Davide Puricelli (evo) <evo@debian.org> Sun, 30 Sep 2000 21:50:00 +0200 - -pyg (0.9.4-2) unstable; urgency=low - - * added Approved: header (pygm2n) - * added selection of smtpserver for relay (pygn2m) - * added conversion from In-Reply-To: to References: (pygm2n) - * added Suggests: news-transport-system , mail-transport-agent - * removed NNTP-Posting-Host, X-Trace - * added TODO file - * mail to news is working fine. - - -- Cosimo Alfarano <alfarano@students.cs.unibo.it> Sun, 30 Sep 2000 21:50:00 +0200 - -pyg (0.9.4-1) unstable; urgency=low - - * Sponsored upload. - * New upstream version. - * mail to news gateway is working. Anyway testing it is adviced before use. - - -- Davide Puricelli (evo) <evo@debian.org> Mon, 18 Sep 2000 19:45:19 +0200 - -pyg (0.9.3-1) unstable; urgency=low - - * started to write mail to news gateway module - - -- Cosimo Alfarano <alfarano@students.cs.unibo.it> Sat, 16 Sep 2000 17:30:00 +0200 - -pyg (0.9.2-3) unstable; urgency=low - - * Sponsored upload. - * Swapped binary-{indep,arch} in debian/rules, closes: #71446. - * Added flex and bison to Build-Depends. - - -- Davide Puricelli (evo) <evo@debian.org> Thu, 14 Sep 2000 16:34:10 +0200 - -pyg (0.9.2-2) unstable; urgency=low - - * debian/rules rewritten to a more readble dh_make style. - * moved example files from debian/ to exaples/ - * dh_stripped *.so - * dh_undocumented *.py - * Sponsored upload for Cosimo Alfarano <alfarano@students.cs.unibo.it> - * Initial Debian release. - - -- Davide Puricelli (evo) <evo@debian.org> Sat, 2 Sep 2000 22:35:25 +0200 - -pyg (0.9.2-1) unstable; urgency=low - - * written the whitelist parser (wlp) in yacc+flex - * written C funtions as python built-in module for wlp - * fixed parsecommandline() return object - * added -T opt for test mode and -V for verbose output - - -- Cosimo Alfarano <alfarano@students.cs.unibo.it> Sun, 23 Jul 2000 19:30:00 +0200 - -pyg (0.9.1-5) unstable; urgency=low - - * added file locking on log - * modified default location of whitelist and log file to homedir. - log file will moved to /var/log as soon as possible - - -- Cosimo Alfarano <alfarano@students.cs.unibo.it> Sun, 03 Jul 2000 18:00:00 +0200 - -pyg (0.9.1-4) unstable; urgency=low - - * Added Message-Id: logging in whitelist - - -- Cosimo Alfarano <alfarano@students.cs.unibo.it> Sun, 02 Jul 2000 18:30:00 +0200 - -pyg (0.9.1-3) unstable; urgency=low - - * removed Sender: header from nntp article. It is usually set to news@news.domain - - -- Cosimo Alfarano <alfarano@students.cs.unibo.it> Thu, 29 Jun 2000 16:30:00 +0200 - -pyg (0.9.1-2) unstable; urgency=low - - * modified copyright note in sources - * moved parse_cmdline() from news2mail.py to pygs - - -- Cosimo Alfarano <alfarano@students.cs.unibo.it> Thu, 29 Jun 2000 02:30:00 +0200 - -pyg (0.9.1-1) unstable; urgency=low - - * enriched whitelist log system - - -- Cosimo Alfarano <alfarano@students.cs.unibo.it> Thu, 29 Jun 2000 01:30:00 +0200 - -pyg (0.9-3) unstable; urgency=low - - * corrected load path for modules in pygs. now points to /usr/lib/pyg - - -- Cosimo Alfarano <alfarano@students.cs.unibo.it> Wed, 28 Jun 2000 00:45:00 +0200 - -pyg (0.9-2) unstable; urgency=low - - * added basic (and rudimental) whitelist functionality (whitelist.py) - - -- Cosimo Alfarano <alfarano@students.cs.unibo.it> Wed, 28 Jun 2000 00:05:00 +0200 - -pyg (0.9-1) unstable; urgency=low - - * Initial release. - - -- Cosimo Alfarano <alfarano@students.cs.unibo.it> Sun, 25 Jun 2000 17:52:35 +0200 - diff --git a/cleanup_failing.patch b/cleanup_failing.patch deleted file mode 100644 index d7d049f..0000000 --- a/cleanup_failing.patch +++ /dev/null @@ -1,113 +0,0 @@ -diff --git b/mail2news.py a/mail2news.py -index e7cbcf9..412e4ee 100644 ---- b/mail2news.py -+++ a/mail2news.py -@@ -24,80 +28,41 @@ import pyginfo - - class mail2news: - """news to mail gateway class""" -- - reader = None # mode reader --# newsgroups = None # Newsgroups: local.test,local.moderated... --# approved = None # Approved: kame@aragorn.lorien.org - newsserver = 'localhost' # no comment :) - port = 119 - user = None - password = None - -+# """phase 3: -+# format rfc 822 headers from input article -+# """ -+# -+# m2n.mergeheads() # make unique dict from NNTP and SMTP dicts -+# -+# m2n.addheads() # add some important heads -+# m2n.renameheads() # rename useless heads -+# m2n.removeheads() # remove other heads -+# -+# m2n.sortheads() # sort remaining heads :) -+# -+# if opt.verbose: -+# for line in m2n.headers: -+# print line[:-1] - -@@ -142,14 +108,11 @@ class mail2news: - - self.heads_dict = {} - -- try: -- for header in self.smtpheads.keys(): # fill it w/ smtp old heads -- self.heads_dict[header] = self.smtpheads[header] -- -- # and replace them w/ nntp new heads -- for header in self.nntpheads.keys(): -- self.heads_dict[header] = self.nntpheads[header] -+ # FIXME something like a = set() ; a = self.message.items() ? - -+ try: -+ for header in self.message.keys(): # fill it w/ smtp old heads -+ self.heads_dict[header] = self.message[header] - except KeyError, message: - print message - - -@@ -236,51 +166,32 @@ class mail2news: - def removeheads(self, heads=None): - """remove headers like Xref: Path: Lines: - """ -- -- try: - # removing some others useless headers .... (From is not From:) - - rmheads = ['Received:', 'From', 'NNTP-Posting-Host:', - 'X-Trace:', 'X-Compliants-To:', 'NNTP-Posting-Date:'] -- if(heads): -+ if heads: - rmheads.append(heads) - - for head in rmheads: -- if head in self.heads_dict: -- del self.heads_dict[head] -- --# if 'From' in self.heads_dict: # neither 'From ' nor 'From:' --# del self.heads_dict['From'] -- --# # neither 'From ' nor 'From:' --# if 'NNTP-Posting-Host:' in self.heads_dict: --# del self.heads_dict[''] -- --# if 'Lines:' in self.heads_dict: --# del self.heads_dict['Lines:'] -+ if head in self.message: -+ del self.message[head] - -- # it is usually set by INN, if ng is moderated... --# if 'Sender:' in self.heads_dict: --# del self.heads_dict['Sender:'] -- -- if 'Message-id:' in self.heads_dict: -+ # FIXME the following lines are buggy, because they don't expect -+ # the header 'Message-Id' being already present -+ if 'Message-id:' in self.message: - self.heads_dict['Message-Id:'] = self.heads_dict['Message-id:'] - del(self.heads_dict['Message-id:']) - -- if 'Message-ID:' in self.heads_dict: -+ if 'Message-ID:' in self.message: - self.heads_dict['Message-Id:'] = self.heads_dict['Message-ID:'] - del(self.heads_dict['Message-ID:']) - - # If message-id is not present, I generate it -- if 'Message-Id:' not in self.heads_dict: -+ if 'Message-Id:' not in self.message: - msgid = '<pyg.%d@tuchailepuppapera.org>\n' % (getpid()) - self.heads_dict['Message-Id:'] = msgid - -- except KeyError, message: -- print message -- -- return self.heads_dict -- - def sendemail(self): - """Talk to NNTP server and try to send email.""" - try: diff --git a/mail2news.py b/mail2news.py index f802277..88c53ea 100644 --- a/mail2news.py +++ b/mail2news.py @@ -14,17 +14,22 @@ Gets news email and sends it via SMTP. class mail2news is hopefully conform to rfc850. """ +from collections import OrderedDict import email import logging -#logging.basicConfig(level=logging.DEBUG) import nntplib from os import getpid from re import findall -from collections import OrderedDict from socket import gethostbyaddr, gethostname import sys -import pyginfo + +#logging.basicConfig(level=logging.DEBUG) +# This is the single source of Truth +# Yes, it is awkward to have it assymetrically here +# and not in news2mail as well. +VERSION = '0.9.9' +DESC = "The Python Gateway Script: news2mail mail2news gateway" class mail2news: @@ -57,7 +62,6 @@ class mail2news: # introduce nntpheads if opt.newsgroup != '': - # TODO put it directly to self.message when we have it self.nntpheads['Newsgroups'] = opt.newsgroup if opt.approver != '': self.nntpheads['Approved'] = opt.approver @@ -66,7 +70,8 @@ class mail2news: @staticmethod def puthead(from_dict, out_list, key): - """private, x-form dict entries in out_list entries""" + """private, x-form dict entries in out_list entries + """ if key in from_dict: out_list.append(key + ': ' + from_dict.get(key)) else: @@ -77,35 +82,8 @@ class mail2news: """make a unique headers dictionary from NNTP and SMTP single headers dictionaries.""" - self.heads_dict = OrderedDict() - logging.debug('self.message.keys() = %s', self.message.keys()) - - try: - for header in self.message.keys(): # fill it w/ smtp old heads - self.heads_dict[header] = self.message[header] - - # and replace them w/ nntp new heads - for header in self.nntpheads.keys(): - self.heads_dict[header] = self.nntpheads[header] - - except KeyError, message: - print message - - return self.heads_dict - - def addheads(self): - """add new header like X-Gateway: - """ - - info = pyginfo.pygsinfo() - - try: - self.heads_dict['X-Gateway'] = info.PROGNAME + ' ' + \ - info.PROGDESC + ' - Mail to News' - - except KeyError, message: - print message - + self.heads_dict = OrderedDict(self.message) + self.heads_dict.update(self.nntpheads) return self.heads_dict def renameheads(self): @@ -160,18 +138,21 @@ class mail2news: if head in self.heads_dict: del self.heads_dict[head] - if 'Message-id' in self.heads_dict: - self.heads_dict['Message-Id'] = self.heads_dict['Message-id'] - del(self.heads_dict['Message-id']) - - if 'Message-ID' in self.heads_dict: - self.heads_dict['Message-Id'] = self.heads_dict['Message-ID'] - del(self.heads_dict['Message-ID']) - - # If message-id is not present, I generate it if 'Message-Id' not in self.heads_dict: - msgid = '<pyg.%d@tuchailepuppapera.org>\n' % (getpid()) - self.heads_dict['Message-Id'] = msgid + if 'Message-id' in self.heads_dict: + self.heads_dict['Message-Id'] = \ + self.heads_dict['Message-id'] + del(self.heads_dict['Message-id']) + + if 'Message-ID' in self.heads_dict: + self.heads_dict['Message-Id'] = \ + self.heads_dict['Message-ID'] + del(self.heads_dict['Message-ID']) + + # If message-id is not present, I generate it + if 'Message-Id' not in self.heads_dict: + msgid = '<pyg.%d@tuchailepuppapera.org>\n' % (getpid()) + self.heads_dict['Message-Id'] = msgid except KeyError, message: print message diff --git a/news2mail.py b/news2mail.py index e1909a1..71e0d17 100644 --- a/news2mail.py +++ b/news2mail.py @@ -22,17 +22,18 @@ normal (what pygs does) operations flow is: Date:, normal headers ending with X-* and Resent-* headers. """ +from collections import OrderedDict import email import logging -from collections import OrderedDict -# logging.basicConfig(level=logging.DEBUG) -import sys import smtplib -import time from socket import gethostbyaddr, gethostname -import pyginfo +import sys +import time + +from mail2news import VERSION, DESC +# logging.basicConfig(level=logging.DEBUG) class news2mail(object): """news to mail gateway class""" @@ -55,8 +56,7 @@ class news2mail(object): def readfile(self): self.message = email.message_from_file(sys.stdin) - self.nntpheads = dict(((key, value) - for (key, value) in self.message.items())) + self.nntpheads = OrderedDict(self.message) @staticmethod def puthead(from_dict, out_list, key): @@ -97,18 +97,8 @@ class news2mail(object): """make a unique headers dictionary from NNTP and SMTP single headers dictionaries.""" - self.heads_dict = OrderedDict() - - try: - for header in self.nntpheads.keys(): # fill it w/ nntp old heads - self.heads_dict[header] = self.nntpheads[header] - - # and replace them w/ smtp new heads - for header in self.smtpheads.keys(): - self.heads_dict[header] = self.smtpheads[header] - - except KeyError, message: - print message + self.heads_dict = OrderedDict(self.nntpheads) + self.heads_dict.update(self.smtpheads) return self.heads_dict @@ -116,37 +106,28 @@ class news2mail(object): """add new header like X-Gateway: Received: """ - info = pyginfo.pygsinfo() - - try: - self.heads_dict['X-Gateway'] = info.PROGNAME + ' ' + \ - info.__doc__ + '\n' - - ##self.heads_dict['X-Gateway'] = '%s %s\n' % - ## (info.PROGNAME, info.__doc__) + self.heads_dict['X-Gateway'] = 'pyg {0} {1}'.format(VERSION, DESC) - # to make Received: header - t = time.ctime(time.time()) + # to make Received: header + t = time.ctime(time.time()) - if time.daylight: - tzone = time.tzname[1] - else: - tzone = time.tzname[0] + if time.daylight: + tzone = time.tzname[1] + else: + tzone = time.tzname[0] - # An exemple from debian-italian: - # Received: from murphy.debian.org (murphy.debian.org [216.234.231.6]) - # by smv04.iname.net (8.9.3/8.9.1SMV2) with SMTP id JAA26407 - # for <kame.primo@innocent.com> sent by - # <debian-italian-request@lists.debian.org + # An example from debian-italian: + # Received: from murphy.debian.org (murphy.debian.org [216.234.231.6]) + # by smv04.iname.net (8.9.3/8.9.1SMV2) with SMTP id JAA26407 + # for <kame.primo@innocent.com> sent by + # <debian-italian-request@lists.debian.org - tmp = 'from GATEWAY by ' + self.hostname + \ - ' with ' + info.PROGNAME + \ - '\n\tfor <' + self.rcpt + '> ; ' + \ - t + ' (' + tzone + ')\n' + tmp = 'from GATEWAY by ' + self.hostname + \ + ' with pyg' + \ + '\n\tfor <' + self.rcpt + '> ; ' + \ + t + ' (' + tzone + ')\n' - self.heads_dict['Received'] = tmp - except KeyError, message: - print message + self.heads_dict['Received'] = tmp return self.heads_dict diff --git a/pyginfo.py b/pyginfo.py deleted file mode 100644 index a9a0bfa..0000000 --- a/pyginfo.py +++ /dev/null @@ -1,26 +0,0 @@ -"""News to mail gateway script. Copyright 2000 Cosimo Alfarano - -Author: Cosimo Alfarano -Date: June 11 2000 - -pyginfo.py - Copyright 2000 by Cosimo Alfarano <Alfarano@Students.CS.UniBo.It> -You can use this software under the terms of the GPL. If we meet some day, -and you think this stuff is worth it, you can buy me a beer in return. - -Thanks to md for this useful formula. Beer is beer. - - -Gets news article and sends it via SMTP. -""" - - -class pygsinfo: - """The Python Gateway Script: news2mail mail2news gateway""" - - PROGNAME = 'pyg' - PROGDESC= 'The Python Gateway' - - MAJOR = '0' - MINOR = '7b' - VERSION = MAJOR + '.' + MINOR - @@ -15,22 +15,20 @@ Gets news article and sends it via SMTP. """ from __future__ import print_function -import logging import sys + import argparse import mail2news -import pyginfo sys.path.append('/usr/lib/pyg') def parse_cmdline(): - i = pyginfo.pygsinfo() parser = argparse.ArgumentParser( description='%s version %s - Copyright 2000 Cosimo Alfarano\n%s' % - (i.PROGNAME, i.VERSION, i.__doc__)) + ('pyg', mail2news.VERSION, mail2news.DESC)) parser.add_argument('-s', '--newsserver', default='') parser.add_argument('-a', '--approver', default='', @@ -97,7 +95,8 @@ try: m2n.mergeheads() # make unique dict from NNTP and SMTP dicts - m2n.addheads() # add some important heads + m2n.heads_dict['X-Gateway'] = 'pyg {0} {1}'.format( + mail2news.VERSION, mail2news.DESC) m2n.renameheads() # rename useless heads m2n.removeheads() # remove other heads @@ -20,9 +20,9 @@ import argparse sys.path.append('/usr/lib/pyg') -import pyginfo import whitelist import news2mail +from mail2news import VERSION, DESC def parse_cmdline(): @@ -30,10 +30,9 @@ def parse_cmdline(): set a dictionary with smtp new header in gw parameter (gw.smtpheads) return (test,verbose) boolean tuple """ - i = pyginfo.pygsinfo() parser = argparse.ArgumentParser( - description='%s version %s - Copyright 2000 Cosimo Alfarano\n%s' % - (i.PROGNAME, i.VERSION, i.__doc__)) + description='pyg version %s - Copyright 2000 Cosimo Alfarano\n%s' % + (VERSION, DESC)) parser.add_argument('-H', '--smtpserver', default='') parser.add_argument('-s', '--sender', required=True, default='') @@ -42,8 +41,6 @@ def parse_cmdline(): parser.add_argument('-w', '--wlfile') parser.add_argument('-l', '--logfile') - # TODO eventually we should refactor these to be Boolean - # and use store_true parser.add_argument('-T', '--test', help='test mode (not send article via SMTP)', action='store_true') @@ -1,9 +1,12 @@ #!/usr/bin/python +# -*- coding: utf-8 -*- +from __future__ import print_function import unittest import sys from distutils.core import setup, Extension, Command from distutils.command.build_ext import build_ext from subprocess import check_call +from mail2news import VERSION, DESC class RunTests(Command): @@ -49,11 +52,12 @@ wlp_module = Extension('wlp', 'wlp/commands.tab.c', 'wlp/lex.yy.c']) + setup(name='pyg', - version='0.9.9', # the current Debian version is 0.9.8 - author="Cosimo Alfarano", - author_email="kalfa@debian.org", # FIXME I am an contributor? - description='Python Mail <-> News Gateway', + version=VERSION, # the current Debian version is 0.9.8 + author="Cosimo Alfarano, Matej Cepl", + author_email="kalfa@debian.org, mcepl@cepl.eu", + description=DESC, long_description=''' Python Gateway Script from news to mail and vice versa. @@ -73,7 +77,7 @@ setup(name='pyg', It refers to rfc 822 (mail) and 850 (news). ''', - py_modules=['mail2news', 'news2mail', 'pyginfo', 'setup', 'whitelist'], + py_modules=['mail2news', 'news2mail', 'setup', 'whitelist'], ext_modules=[wlp_module], scripts=['pygm2n', 'pygn2m'], cmdclass={'build_ext': Build_WLP_ext, diff --git a/test/test_wlp.py b/test/test_wlp.py index 486fb42..62b2551 100755 --- a/test/test_wlp.py +++ b/test/test_wlp.py @@ -8,6 +8,7 @@ import os import os.path import subprocess import re +import mail2news def distutils_dir_name(dname): @@ -52,15 +53,15 @@ Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii User-Agent: Mutt/1.2.5i X-Multiline: this header probably broke RFC, but is frequent. -X-Gateway: pyg The Python Gateway - Mail to News -""" +X-Gateway: pyg %s %s +""" % (mail2news.VERSION, mail2news.DESC) def test_m2n(self): with open('examples/mail') as in_mail: pid = subprocess.Popen(['./pygm2n', '-TV', '-n', 'pyg.test'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) - out, err = pid.communicate(in_mail.read()) + out, _ = pid.communicate(in_mail.read()) self.assertEqual(out, self.expected_output) @@ -78,11 +79,11 @@ Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Trace: pyg.server.tld 960672047 927 192.168.1.2 (10 Jun 2000 21:20:47 GMT) X-Newsgroups: local.moderated -X-Gateway: pyg The Python Gateway Script: news2mail mail2news gateway +X-Gateway: pyg %s %s X-NNTP-Posting-Host: pyg.server.tld Resent-From: sender@example.com Resent-Sender: sender@example.com -""" +""" % (mail2news.VERSION, mail2news.DESC) def test_n2m(self): env = os.environ diff --git a/whitelist.py b/whitelist.py index c017402..ea3f646 100644 --- a/whitelist.py +++ b/whitelist.py @@ -27,7 +27,7 @@ class whitelist(object): wl = {} debug = None - log = None # filedescriptor + logf = None # filedescriptor # constants DENY = 0 @@ -52,18 +52,18 @@ class whitelist(object): # print '%s: %s = %s' % (owner,option,self.wl[owner][option]) try: - self.log = open(logfile, 'a') + self.logf = open(logfile, 'a') self.lock() except (Exception), message: print '%s\nAre you authorized to use this program? ' % message sys.exit(1) def lock(self): - fcntl.flock(self.log.fileno(), fcntl.LOCK_EX) + fcntl.flock(self.logf.fileno(), fcntl.LOCK_EX) # to unlock fd locked, usually fd are unlocked after process exit() def unlock(self): - fcntl.flock(self.log.fileno(), fcntl.LOCK_UN) + fcntl.flock(self.logf.fileno(), fcntl.LOCK_UN) def checkfrom(self, fromhead): """have you permission to be here, sir?""" @@ -78,14 +78,12 @@ class whitelist(object): else: return None - # FIXME self.log has been already defined as a variable of None value on - # line 30. def log(self, string): """Captain Diary, Astral Date 962555394 from epoch. it rawly write a line in logfile. Remeber to indent it, if you like. """ - self.log.write(string + '\n') + self.logf.write(string + '\n') def logmsg(self, heads, ok=DENY, owner=None): """who are walking through my gate? @@ -100,33 +98,33 @@ class whitelist(object): tzone = time.tzname[0] if ok == self.ACCEPT: - self.log.write('Permission Accorded ') + self.logf.write('Permission Accorded ') else: - self.log.write('Permission Denied ') + self.logf.write('Permission Denied ') - self.log.write('at %s (%s)\n' % (ltime, tzone)) + self.logf.write('at %s (%s)\n' % (ltime, tzone)) if owner is not None: - self.log.write('\tWLOwner: ' + owner + '\n') - self.log.write('\tFrom: ' + heads.get('From', 'NOT PRESENT\n')) - self.log.write('\tSubject: ' + heads.get('Subject', 'NOT PRESENT\n')) - self.log.write('\tSender: ' + heads.get('Sender', 'NOT PRESENT\n')) - self.log.write('\tDate: ' + heads.get('Date', 'NOT PRESENT\n')) + self.logf.write('\tWLOwner: ' + owner + '\n') + self.logf.write('\tFrom: ' + heads.get('From', 'NOT PRESENT\n')) + self.logf.write('\tSubject: ' + heads.get('Subject', 'NOT PRESENT\n')) + self.logf.write('\tSender: ' + heads.get('Sender', 'NOT PRESENT\n')) + self.logf.write('\tDate: ' + heads.get('Date', 'NOT PRESENT\n')) # some client create Message-Id other Message-ID. if 'Message-ID' in heads: - self.log.write('\tMessage-ID: ' + heads.get('Message-ID')) + self.logf.write('\tMessage-ID: ' + heads.get('Message-ID')) else: - self.log.write('\tMessage-Id: ' + heads.get('Message-Id', + self.logf.write('\tMessage-Id: ' + heads.get('Message-Id', 'NOT PRESENT\n')) # X-Newsgroups: and To: are present if user is trusted, else # Newsgroup: exists since no changes on nntp headers are done. if 'X-Newsgroups' in heads: - self.log.write('\tTo: ' + heads.get('To', 'NOT PRESENT\n')) - self.log.write('\tX-Newsgroups: ' + heads.get('X-Newsgroups', + self.logf.write('\tTo: ' + heads.get('To', 'NOT PRESENT\n')) + self.logf.write('\tX-Newsgroups: ' + heads.get('X-Newsgroups', 'NOT PRESENT\n')) else: - self.log.write('\tNewsgroups: ' + + self.logf.write('\tNewsgroups: ' + heads.get('Newsgroups', 'NOT PRESENT\n')) - self.log.write('\n') + self.logf.write('\n') |