diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2020-07-01 16:16:44 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2020-07-01 16:19:16 +0200 |
commit | d5fc1faf927a5ff91f3416eb97014c0eadb14742 (patch) | |
tree | 2cb34082a4df13685c2ee0f46e1360cfdf4a8e88 | |
parent | 19388fa2e3e6b02e7d7fd5c0b5dc9ee0cd9ef100 (diff) | |
download | pygn-d5fc1faf927a5ff91f3416eb97014c0eadb14742.tar.gz |
Sync with 0.10.1 release on PyPI0.10.1
Port to Python 3.
-rw-r--r-- | HOWTO | 33 | ||||
-rw-r--r-- | PKG-INFO | 61 | ||||
-rw-r--r-- | mail2news.py | 104 | ||||
-rw-r--r-- | news2mail.py | 134 | ||||
-rwxr-xr-x | pygm2n | 99 | ||||
-rw-r--r-- | pygm2n.1 | 68 | ||||
-rwxr-xr-x | pygn2m | 126 | ||||
-rw-r--r-- | pygn2m.1 | 79 | ||||
-rw-r--r-- | setup.cfg | 4 | ||||
-rw-r--r-- | setup.py | 15 | ||||
-rw-r--r--[-rwxr-xr-x] | test/test_pyg.py | 22 | ||||
-rw-r--r--[-rwxr-xr-x] | test/test_wlp.py | 2 | ||||
-rw-r--r-- | whitelist-pygn2m | 3 | ||||
-rw-r--r-- | whitelist.py | 1 | ||||
-rw-r--r-- | wlp.py | 2 | ||||
-rw-r--r-- | wlp_parser.py | 1 |
16 files changed, 339 insertions, 415 deletions
@@ -1,33 +0,0 @@ -MUST BE FINISHED! - - -It is a (very) small HOWTO to make pyg working properly. - -pygm2n: - -Pre: a fully working MTA (ie postfix) where you can run procmail or any other MDA. -A news server (local or remote) where you can create groups (admin -privileges). - -Create a user, ie mailgate, set its procmail as: - -:0 bhc: -| pygm2n -n local.test - -or its maildrop (thanks to Joy): - -dotlock pygm2n.`echo $$`.lock { - `pygm2n -n local.test` -} - -you can use -a your@address and -s nntphost if local.test is moderated, -or nntphost isn't localhost - -[NOTE: if you've configuration for any other MDA, please file a wishlist -bug against pyg] - -Create local.test (if it doen't exist). - -Now any mail you will write to mailgate user, will be sent to the -server. Read local.test on localhost (or nntphost), you will see -message. diff --git a/PKG-INFO b/PKG-INFO new file mode 100644 index 0000000..d88a6ff --- /dev/null +++ b/PKG-INFO @@ -0,0 +1,61 @@ +Metadata-Version: 1.1 +Name: pygn +Version: 0.10.1 +Summary: The Python Gateway Script: news2mail mail2news gateway +Home-page: https://gitlab.com/mcepl/pyg +Author: Cosimo Alfarano, Matej Cepl +Author-email: kalfa@debian.org, mcepl@cepl.eu +License: GPLv3 +Description: Python Gateway Script from news to mail and vice versa. + + Copyright: + Copyright (C) 2000-2001,2012 Cosimo Alfarano <kalfa@debian.org> + Copyright (C) 2014 Matěj Cepl <mcepl@cepl.eu> + + A copy of the GNU General Public License, version 3, can be found in + http://www.gnu.org/licenses/gpl-3.0.txt + + It is intended to be a full SMTP/NNTP rfc compliant gateway + with whitelist manager. + + You will probably have to install a mail-transport-agent and/or + news-transport-system package to manage SMTP/NNTP traffic. + + MTA is needed for mail2news service, since mail have to be + processed on a box where pyg is installed. You can use a remote + smtpserver for news2mail. + + News system is useful but not needed, since you can send articles to a + remote SMTP server (ie: moderated NG) where is installed pyg, otherwise you + will need it. + + It refers to rfc 822 (mail) and 850 (news). + + ---------------- + + List of file: + + mail2news.py mail to news python class module + news2mail.py news to mail 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 + wlp C backend for whitelist parser (wlp) directory + examples documentation and exaples directory + +Keywords: nntp,email,gateway +Platform: UNKNOWN +Classifier: Development Status :: 3 - Alpha +Classifier: Programming Language :: Python :: 2.7 +Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python :: 3.4 +Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 +Classifier: Intended Audience :: System Administrators +Classifier: Topic :: Utilities +Classifier: Topic :: Communications :: Usenet News +Classifier: Environment :: Console +Classifier: Operating System :: OS Independent +Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3) +Requires: rply diff --git a/mail2news.py b/mail2news.py index 6e60d4c..34cfed8 100644 --- a/mail2news.py +++ b/mail2news.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 """Mail to news gateway script. Copyright 2000 Cosimo Alfarano Author: Cosimo Alfarano @@ -15,8 +14,9 @@ Gets news email and sends it via SMTP. class mail2news is hopefully conform to rfc850. """ -import argparse -from io import StringIO +from __future__ import absolute_import +from __future__ import print_function +import io from collections import OrderedDict import email import logging @@ -27,11 +27,11 @@ from socket import gethostbyaddr, gethostname import sys -# logging.basicConfig(level=logging.DEBUG) +#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.14' +VERSION = '0.10.1' DESC = "The Python Gateway Script: news2mail mail2news gateway" @@ -55,11 +55,7 @@ class mail2news(object): self.hostname = gethostbyaddr(gethostname())[0] self.heads_dict, self.smtpheads, self.nntpheads = {}, {}, {} - if options.input == '': - self.message = self.__readfile(options, sys.stdin) - else: - with open(options.input, 'r') as inp_stream: - self.message = self.__readfile(options, inp_stream) + self.message = self.__readfile(options) self.message['X-Gateway'] = 'pyg {0} {1}'.format(VERSION, DESC) @@ -69,8 +65,8 @@ class mail2news(object): if value: msg[header] = value.strip() - def __readfile(self, opt, input_stream): - message = email.message_from_file(input_stream) + def __readfile(self, opt): + message = email.message_from_file(sys.stdin) if (len(message) == 0) \ and message.get_payload().startswith('/'): @@ -186,88 +182,6 @@ class mail2news(object): if self.verbose: server.set_debuglevel(2) - data = [x.encode() for x in self.message.as_string().split('\n')] - logging.debug('data = type %s', type(data)) - server.post(data) + server.post(io.BytesIO(self.message.as_bytes())) server.quit() - -def parse_cmdline(args): - parser = argparse.ArgumentParser( - description='%s version %s - Copyright 2000 Cosimo Alfarano\n%s' % - ('pyg', VERSION, DESC)) - - parser.add_argument('-s', '--newsserver', default='') - parser.add_argument('-a', '--approver', default='', - help="address of moderator/approver") - parser.add_argument('-n', '--newsgroup', default='', - help='newsgroup[s] (specified as comma separated ' + - 'without spaces list)', required=True) - parser.add_argument('-u', '--user', default='', - help='NNTP server user (for authentication)') - parser.add_argument('-p', '--password', default='', - help='NNTP server password (for authentication)') - parser.add_argument('-P', '--port', default='') - parser.add_argument('-e', '--envelope', default='') - parser.add_argument('-i', '--input', default='') - parser.add_argument('-l', '--logfile') - - parser.add_argument('-T', '--test', action='store_true', - help='test mode (not send article via NNTP)') - parser.add_argument('-v', '--verbose', action='store_true', - help='verbose output ' + - '(usefull with -T option for debugging)') - - args = parser.parse_args(args) - - if not args.newsgroup: - raise argparse.ArgumentError('Error: Missing Newsgroups\n') - - return args - - -def main(args=sys.argv[1:]): - """main is structured in 4 phases: - 1) check and set pyg's internal variables - 2) check whitelist for users' permission - 3) format rfc 822 headers from input article - 4) open smtp connection and send e-mail - """ - out = '' - - try: - """phase 1: - check and set pyg's internal variables - """ - opt = parse_cmdline(args) - - m2n = mail2news(opt) - owner = None - - """phase 3: - format rfc 822 headers from input article - """ - m2n.renameheads() # rename useless heads - m2n.removeheads() # remove other heads - - m2n.sortheads() # sort remaining heads :) - - if opt.verbose: - out += m2n.message.as_string() + '\n' - - logging.debug('m2n.payload = len %d', len(m2n.message.get_payload())) - if len(m2n.message.get_payload()) > 0: - # wl.logmsg(m2n.heads_dict,wl.ACCEPT,owner) - if not opt.test: - try: - resp = m2n.sendemail() - except nntplib.NNTPError as ex: - logging.exception(ex) - except KeyboardInterrupt: - logging.error('Keyboard Interrupt') - sys.exit(0) - - if opt.input == '': - print(out) - else: - return out diff --git a/news2mail.py b/news2mail.py index 29f4271..b63df46 100644 --- a/news2mail.py +++ b/news2mail.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 """News to mail gateway script. Copyright 2000 Cosimo Alfarano Author: Cosimo Alfarano @@ -23,27 +22,25 @@ normal (what pygs does) operations flow is: Date:, normal headers ending with X-* and Resent-* headers. """ -import argparse -import os -import os.path -import collections +from __future__ import absolute_import +from __future__ import print_function +from collections import OrderedDict import email from mail2news import VERSION, DESC import smtplib -import socket +from socket import gethostbyaddr, gethostname import sys import time -import whitelist # logging.basicConfig(level=logging.DEBUG) class news2mail(object): """news to mail gateway class""" - def __init__(self, options): + def __init__(self, verbose=False): self.wlfile = None self.logfile = None - self.verbose = options.verbose + self.verbose = verbose self.sender = '' self.rcpt = '' @@ -51,16 +48,11 @@ class news2mail(object): self.smtpserver = 'localhost' - self.hostname = socket.gethostbyaddr(socket.gethostname())[0] + self.hostname = gethostbyaddr(gethostname())[0] self.heads_dict = {} self.article, self.headers, self.body = [], [], [] - - if options.input == '': - self.message = self.__addheads(email.message_from_file(sys.stdin)) - else: - with open(options.input, 'r') as inp_stream: - self.message = self.__addheads(email.message_from_file(inp_stream)) + self.message = self.__addheads(email.message_from_file(sys.stdin)) def __addheads(self, msg): """add new header like X-Gateway: Received: @@ -141,7 +133,7 @@ class news2mail(object): # put at top header_set = ('Received', 'From', 'To', 'Subject', 'Date') - heads_dict = collections.OrderedDict(self.message) + heads_dict = OrderedDict(self.message) for hdr in self.message.keys(): del self.message[hdr] @@ -178,111 +170,3 @@ class news2mail(object): s.quit() -def parse_cmdline(args): - """ - set a dictionary with smtp new header in gw parameter (gw.smtpheads) - return (test,verbose) boolean tuple - """ - parser = argparse.ArgumentParser( - 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='') - parser.add_argument('-e', '--envelope', default='') - parser.add_argument('-t', '--to', dest='rcpt', required=True) - parser.add_argument('-w', '--wlfile') - parser.add_argument('-i', '--input', default='') - parser.add_argument('-l', '--logfile') - - parser.add_argument('-T', '--test', - help='test mode (not send article via SMTP)', - action='store_true') - parser.add_argument('-v', '--verbose', help='verbose output', - action='store_true') - - opts = parser.parse_args(args) - -# By rfc822 [Resent-]Sender: should be ever set, unless == From: -# (not this case). Should be a human, while [Resent-]From: may be a program. - - if opts.rcpt == '' or opts.sender == '': - raise argparse.ArgumentError('missing command line option') - - if opts.envelope == '' and opts.sender != '': - opts.envelope = opts.sender - - return opts - -def main(args=sys.argv[1:]): - """main is structured in 4 phases: - 1) check and set pyg's internal variables - 2) check whitelist for users' permission - 3) format rfc 822 headers from input article - 4) open smtp connection and send e-mail - """ - - """phase 1: - check and set pyg's internal variables - """ - out = '' - - # it returns only test, other parms are set directly in the actual - # parameter - args = parse_cmdline(args) - - n2m = news2mail(args) - owner = None - - # check if n2m has some file prefercences set on commandline - if args.wlfile is None: - wl = os.path.expanduser(os.path.join(os.path.dirname(__file__), 'pyg.whitelist')) - else: - wl = args.wlfile - - if args.logfile is None: - log = os.path.expanduser(os.path.join(os.path.dirname(__file__), 'pyg.log')) - else: - log = args.logfile - - wl = whitelist.whitelist(wl, log) - - """phase 2: - check whitelist for user's permission - """ - - # make a first check of From: address - owner = wl.checkfrom(n2m.message['From']) - if owner is None: - if sys.stdin.isatty() == 1 or args.test: - out += str('"%s" is not in whitelist!' % (n2m.message['From'][:-1])) + '\n' - else: - wl.logmsg(n2m.nntpheads, wl.DENY) - - # if verbose, I want to print out headers, so I can't - # exit now. - if not args.verbose: - sys.exit(1) - - # Reformat the message - n2m.process_message() - - # prints formatted email message only (without send) if user wants - if args.verbose: - out += n2m.message.as_string() + '\n' - - if owner is None: - sys.exit(1) - - """phase 4: - open smtp connection and send e-mail - """ - - wl.logmsg(n2m.heads_dict, wl.ACCEPT, owner) - if not args.test: - n2m.sendarticle() - - if args.input == '': - print(out) - else: - return out @@ -0,0 +1,99 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +"""News to mail gateway script. Copyright 2000 Cosimo Alfarano + +Author: Cosimo Alfarano +Date: June 11 2000 + +pygs - 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. +""" +from __future__ import print_function + +import argparse +import logging +import mail2news +import nntplib +import sys + +# logging.basicConfig(level=logging.DEBUG) + +def parse_cmdline(): + parser = argparse.ArgumentParser( + description='%s version %s - Copyright 2000 Cosimo Alfarano\n%s' % + ('pyg', mail2news.VERSION, mail2news.DESC)) + + parser.add_argument('-s', '--newsserver', default='') + parser.add_argument('-a', '--approver', default='', + help="address of moderator/approver") + parser.add_argument('-n', '--newsgroup', default='', + help='newsgroup[s] (specified as comma separated ' + + 'without spaces list)', required=True) + parser.add_argument('-u', '--user', default='', + help='NNTP server user (for authentication)') + parser.add_argument('-p', '--password', default='', + help='NNTP server password (for authentication)') + parser.add_argument('-P', '--port', default='') + parser.add_argument('-e', '--envellope', default='') + parser.add_argument('-l', '--logfile') + + parser.add_argument('-T', '--test', action='store_true', + help='test mode (not send article via NNTP)') + parser.add_argument('-v', '--verbose', action='store_true', + help='verbose output ' + + '(usefull with -T option for debugging)') + + args = parser.parse_args() + + if not args.newsgroup: + raise argparse.ArgumentError('Error: Missing Newsgroups\n') + + return args + + +"""main is structured in 4 phases: + 1) check and set pyg's internal variables + 2) check whitelist for users' permission + 3) format rfc 822 headers from input article + 4) open smtp connection and send e-mail +""" + + +try: + + """phase 1: + check and set pyg's internal variables + """ + opt = parse_cmdline() + + m2n = mail2news.mail2news(opt) + owner = None + + """phase 3: + format rfc 822 headers from input article + """ + m2n.renameheads() # rename useless heads + m2n.removeheads() # remove other heads + + m2n.sortheads() # sort remaining heads :) + + if opt.verbose: + print(m2n.message.as_string()) + + logging.debug('m2n.payload = len %d', len(m2n.message.get_payload())) + if len(m2n.message.get_payload()) > 0: +# wl.logmsg(m2n.heads_dict,wl.ACCEPT,owner) + if not opt.test: + try: + resp = m2n.sendemail() + except nntplib.NNTPError as ex: + print(ex) + +except KeyboardInterrupt: + print('Keyboard Interrupt') + sys.exit(0) diff --git a/pygm2n.1 b/pygm2n.1 deleted file mode 100644 index 63f2e09..0000000 --- a/pygm2n.1 +++ /dev/null @@ -1,68 +0,0 @@ -.\" wing requests are required for all man pages. -.TH pygm2n 1 "Sun Sep 12 18:10:00 CEST 2000" "" "Python Gateway mail to news" -.SH NAME -pygm2n - Python Gateway mail to news -.SH SYNOPSIS -.B pygm2n -.BR -n -.IR newsgroups -[ -.BR -s -.IR newsserver -] -[ -.BR -h -] - -.SH DESCRIPTION -.B IMPORTANT: -this man page is to be continued. The Whole pyg gateway is in -.B devel.\ state. -try -h option for more detailed option. - -pygm2n reads from stdin an email, sending it to newsgroups, a comma separated list without spaces of newsgroup names (at least one), rfc799 compliant. - -If pygm2n reads from stdin a sigle line starting with /, it is -considered an absolute path to a single-email mailbox, -so pygm2n will open and read it. - -.B Note -that now pyg can't read a real mailbox, with many emails. If you -give it in input, pyg will post the whole mailbox as a single email. - -\" The following requests should be uncommented and -.\" used where appropriate. This next request is -.\" for sections 2 and 3 function return values only. -.\" .Sh RETURN VALUES -.\" This next request is for sections 1, 6, 7 & 8 only -.\" .Sh ENVIRONMENT -.\" .Sh FILES -.SH EXAMPLES -There is some documetation in /urs/share/doc/pyg - -I created mailgate user (moderator of local.moderated ng). -Subscribe to a list with this user (or simply email one message to). -Every email posted to this user will send to newsgroups, -in its .procmailrc I've put something like: - -:0 bh -* ^From *mailinglist-request@lists.debian.org -| $HOME/pygm2n -n local.debian.mailinglist - - -.\" This next request is for sections 1, 6, 7 & 8 only -.\" (command return values (to shell) and -.\" fprintf/stderr type diagnostics) -.\" .Sh DIAGNOSTICS -.\" The next request is for sections 2 and 3 error -.\" and signal handling only. -.\" .Sh ERRORS -.\" .Sh SEE ALSO -.\" .Sh STANDARDS -.\" .Sh HISTORY -.SH AUTHORS -Cosimo Alfarano <alfarano@students.cs.unibo.it> - -.SH BUGS -Boh. send any bug, advice or opinion to the author, please. - @@ -0,0 +1,126 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +"""News to mail gateway script. Copyright 2000 Cosimo Alfarano + +Author: Cosimo Alfarano +Date: June 11 2000 + +pygs - 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 from stdin and sends it via SMTP. +""" +from __future__ import print_function + +import argparse +from mail2news import VERSION, DESC +import news2mail +import os +import sys +import whitelist + + +def parse_cmdline(): + """ + set a dictionary with smtp new header in gw parameter (gw.smtpheads) + return (test,verbose) boolean tuple + """ + parser = argparse.ArgumentParser( + 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='') + parser.add_argument('-e', '--envelope', default='') + parser.add_argument('-t', '--to', dest='rcpt', required=True) + parser.add_argument('-w', '--wlfile') + parser.add_argument('-l', '--logfile') + + parser.add_argument('-T', '--test', + help='test mode (not send article via SMTP)', + action='store_true') + parser.add_argument('-v', '--verbose', help='verbose output', + action='store_true') + + opts = parser.parse_args() + +# By rfc822 [Resent-]Sender: should be ever set, unless == From: +# (not this case). Should be a human, while [Resent-]From: may be a program. + + if opts.rcpt == '' or opts.sender == '': + raise argparse.ArgumentError('missing command line option') + + if opts.envelope == '' and opts.sender != '': + opts.envelope = opts.sender + + return opts + + +"""main is structured in 4 phases: + 1) check and set pyg's internal variables + 2) check whitelist for users' permission + 3) format rfc 822 headers from input article + 4) open smtp connection and send e-mail +""" + +"""phase 1: +check and set pyg's internal variables +""" + +# it returns only test, other parms are set directly in the actual +# parameter +args = parse_cmdline() + +n2m = news2mail.news2mail(verbose=args.verbose) +owner = None + +# check if n2m has some file prefercences set on commandline +if args.wlfile is None: + wl = os.path.expanduser(os.path.join(os.path.dirname(__file__), 'pyg.whitelist')) +else: + wl = args.wlfile + +if args.logfile is None: + log = os.path.expanduser(os.path.join(os.path.dirname(__file__), 'pyg.log')) +else: + log = args.logfile + +wl = whitelist.whitelist(wl, log) + +"""phase 2: +check whitelist for user's permission +""" + +# make a first check of From: address +owner = wl.checkfrom(n2m.message['From']) +if owner is None: + if sys.stdin.isatty() == 1 or args.test: + print ('"%s" is not in whitelist!' % (n2m.message['From'][:-1])) + else: + wl.logmsg(n2m.nntpheads, wl.DENY) + + # if verbose, I want to print out headers, so I can't + # exit now. + if not args.verbose: + sys.exit(1) + +# Reformat the message +n2m.process_message() + +# prints formatted email message only (without send) if user wants +if args.verbose: + print(n2m.message.as_string()) + +if owner is None: + sys.exit(1) + +"""phase 4: +open smtp connection and send e-mail +""" + +wl.logmsg(n2m.heads_dict, wl.ACCEPT, owner) +if not args.test: + n2m.sendarticle() diff --git a/pygn2m.1 b/pygn2m.1 deleted file mode 100644 index 5b2750e..0000000 --- a/pygn2m.1 +++ /dev/null @@ -1,79 +0,0 @@ -.\" wing requests are required for all man pages. -.TH pygn2m 1 "Sun Sep 12 22:40:00 CEST 2000" "" "Python Gateway news to mail" -.SH NAME -pygn2m - Python Gateway news to mail -.SH SYNOPSIS -.B pygs -.BR -t -.IR recipient@domain1 -.BR -s -.IR sender@domain2 -[ -.BR -e -.IR envelope@domain3 -] -[ -.BR -h -] - -.SH DESCRIPTION -.B IMPORTANT: -this man page is to be continued. The Whole pyg gateway is in -.B devel.\ state. -try -h option for more detailed option. - -pygn2m reads from stdin a nntp article, sending it to recipient@domain1 -a rfc822 compliant email setting Resent-Sender: sender@domain2 -and envelope envelope@domain3 if exists, else sender@domain2. - -If pygn2m reads from stdin a sigle line starting with /, it is -considered an absolute path to an article (ie in a spool), -so pygn2m will open and read it. - -\" The following requests should be uncommented and -.\" used where appropriate. This next request is -.\" for sections 2 and 3 function return values only. -.\" .Sh RETURN VALUES -.\" This next request is for sections 1, 6, 7 & 8 only -.\" .Sh ENVIRONMENT -.\" .Sh FILES -.SH EXAMPLES -There is some documetation in /urs/share/doc/pyg - -I created mailgate user (moderator of local.moderated ng). -Every article posted in local.moderated is sent to mailgate, -in its .procmailrc I've put: - -:0 bhc -* ^To: *local-moderated -| $HOME/pygs -t kalfa@localhost -e mailgate@students.cs.unibo.it -s 'cosimo@students.cs.unibo.it' - - -where kalfa@localhost is the recipient (usually a mailing list) - -Here is an header extract from kalfa@localhost mbox: - -From mailgate@students.cs.unibo.it -From: whosentnntparticle@domain4 -To: kalfa@localhost -Resent-Sender: cosimo@students.cs.unibo.it - -note that sender and envelope are different. rfc822 says that Sender: have to be a human user (not a program or similia). envelope can mailgate user. - - -.\" This next request is for sections 1, 6, 7 & 8 only -.\" (command return values (to shell) and -.\" fprintf/stderr type diagnostics) -.\" .Sh DIAGNOSTICS -.\" The next request is for sections 2 and 3 error -.\" and signal handling only. -.\" .Sh ERRORS -.\" .Sh SEE ALSO -.\" .Sh STANDARDS -.\" .Sh HISTORY -.SH AUTHOR -Cosimo Alfarano <alfarano@students.cs.unibo.it> - -.SH BUGS -Boh. send any bug to the author, please. - diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..8bfd5a1 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,4 @@ +[egg_info] +tag_build = +tag_date = 0 + @@ -1,6 +1,8 @@ -#!/usr/bin/python3 +#!/usr/bin/python # -*- coding: utf-8 -*- +from __future__ import print_function +from __future__ import absolute_import from mail2news import VERSION, DESC import os.path from setuptools import setup @@ -20,18 +22,17 @@ setup(name='pygn', py_modules=['mail2news', 'news2mail', 'setup', 'whitelist', 'wlp', 'wlp_parser'], test_suite="test", - entry_points={ - "console_scripts": [ - "pygm2n = mail2news:main", - "pygn2m = news2mail:main" - ] - }, + scripts=['pygm2n', 'pygn2m'], requires=['rply'], license="GPLv3", keywords=["nntp", "email", "gateway"], classifiers=[ 'Development Status :: 3 - Alpha', 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', 'Intended Audience :: System Administrators', 'Topic :: Utilities', 'Topic :: Communications :: Usenet News', diff --git a/test/test_pyg.py b/test/test_pyg.py index ddf8146..d3fa3a7 100755..100644 --- a/test/test_pyg.py +++ b/test/test_pyg.py @@ -1,10 +1,12 @@ #!/usr/bin/python +# -*- coding: utf-8 -*- + +from __future__ import absolute_import import re import subprocess import unittest import mail2news -import news2mail class TestM2N(unittest.TestCase): @@ -26,7 +28,12 @@ one line test """ % (mail2news.VERSION, mail2news.DESC) def test_m2n(self): - out = mail2news.main(['-T', '-v', '-i', 'examples/mail', '-n', 'pyg.test']) + with open('examples/mail') as in_mail: + pid = subprocess.Popen(['python', 'pygm2n', '-Tv', '-n', 'pyg.test'], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + universal_newlines=True) + out, _ = pid.communicate(in_mail.read()) self.assertEqual(out, self.expected_output) @@ -53,17 +60,22 @@ Resent-Sender: sender@example.com def test_n2m(self): with open('examples/articletest.accepted') as in_mail: + pid = subprocess.Popen(['python', 'pygn2m', '-Tvt', 'test@example.com', + '-s', 'sender@example.com', + '-w', 'examples/whitelist.example'], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + universal_newlines=True) in_message = in_mail.read().replace('pyg@pyg.server.tld', 'kame@inwind.it') - out = news2mail.main(['-T', '-v', '-t', 'test@example.com', - '-s', 'sender@example.com', - '-w', 'examples/whitelist.example']) + out, err = pid.communicate(in_message) out = re.sub(r'^Message-Id:.*$', '', out) # Not sure how to compare two email mesages (with different # times, etc.) so for now just to make sure the script doesn’t # blow up and gives some output # otherwise it would be # self.assertEqual(out, expected_output) + self.assertEqual(pid.returncode, 0) self.assertGreater(len(out), 0) diff --git a/test/test_wlp.py b/test/test_wlp.py index 929fb1c..061673c 100755..100644 --- a/test/test_wlp.py +++ b/test/test_wlp.py @@ -1,4 +1,6 @@ #!/usr/bin/python +# -*- coding: utf-8 -*- +from __future__ import absolute_import import unittest import wlp_parser diff --git a/whitelist-pygn2m b/whitelist-pygn2m deleted file mode 100644 index 33044bc..0000000 --- a/whitelist-pygn2m +++ /dev/null @@ -1,3 +0,0 @@ -<ceplm@seznam.cz> { - From: = 'ceplm@seznam.cz' -} diff --git a/whitelist.py b/whitelist.py index d12aea3..4e02f0e 100644 --- a/whitelist.py +++ b/whitelist.py @@ -12,6 +12,7 @@ Thanks to md for this useful formula. Beer is beer. whitelist manage a list of trusted user. """ +from __future__ import absolute_import import logging # logging.basicConfig(level=logging.DEBUG) import sys @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import import wlp_parser diff --git a/wlp_parser.py b/wlp_parser.py index 35da516..e2e0d19 100644 --- a/wlp_parser.py +++ b/wlp_parser.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import rply __lg = rply.LexerGenerator() |