aboutsummaryrefslogtreecommitdiffstats
path: root/cleanup_failing.patch
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2014-12-22 00:26:30 +0100
committerMatěj Cepl <mcepl@cepl.eu>2014-12-22 00:46:41 +0100
commit5b25c51d3a02d49db2c7e33f9b65fad5432219f4 (patch)
tree6e8231c81e84d4b6873cb45c78a24a2a4d31074c /cleanup_failing.patch
parentd3b3442e6bd72e3ba91cceb5c94e5e222b61af3a (diff)
downloadpygn-5b25c51d3a02d49db2c7e33f9b65fad5432219f4.tar.gz
pygn2m and news2mail.py use stdlib email parser.
Instead of doing it on their own (poorly).
Diffstat (limited to 'cleanup_failing.patch')
-rw-r--r--cleanup_failing.patch291
1 files changed, 0 insertions, 291 deletions
diff --git a/cleanup_failing.patch b/cleanup_failing.patch
index 334cc82..480d2d3 100644
--- a/cleanup_failing.patch
+++ b/cleanup_failing.patch
@@ -2,19 +2,6 @@ diff --git b/mail2news.py a/mail2news.py
index e7cbcf9..412e4ee 100644
--- b/mail2news.py
+++ a/mail2news.py
-@@ -1,9 +1,11 @@
-+# -*- coding: utf-8 -*-
- """Mail to news gateway script. Copyright 2000 Cosimo Alfarano
-
- Author: Cosimo Alfarano
- Date: September 16 2000
-
--mail2news.py - (C) 2000 by Cosimo Alfarano <Alfarano@Students.CS.UniBo.It>
-+mail2news.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.
-
@@ -14,6 +16,8 @@ Gets news email and sends it via SMTP.
class mail2news is hopefully conform to rfc850.
@@ -340,281 +327,3 @@ index e7cbcf9..412e4ee 100644
def sendemail(self):
"""Talk to NNTP server and try to send email."""
try:
-diff --git b/news2mail.py a/news2mail.py
-index bfd6fd1..a74655a 100644
---- b/news2mail.py
-+++ a/news2mail.py
-@@ -1,9 +1,11 @@
-+# -*- coding: utf-8 -*-
- """News to mail gateway script. Copyright 2000 Cosimo Alfarano
-
- Author: Cosimo Alfarano
- Date: June 11 2000
-
--news2mail.py - (C) 2000 by Cosimo Alfarano <Alfarano@Students.CS.UniBo.It>
-+news2mail.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.
-
-@@ -23,9 +25,13 @@ normal (what pygs does) operations flow is:
- Date:, normal headers ending with X-* and Resent-* headers.
-
- """
-+
-+import email
- import sys
- import smtplib
-+import string
- import time
-+#import rfc822
- from socket import gethostbyaddr, gethostname
- import tempfile
- import pyginfo
-@@ -37,6 +43,7 @@ class news2mail:
- TMPFILE = tempfile.mktemp()
- wlfile = None
- logfile = None
-+ debug = 1
-
- sender = ''
- rcpt = ''
-@@ -44,60 +51,9 @@ class news2mail:
-
- smtpserver = 'localhost'
-
-- hostname = gethostbyaddr(gethostname())[0]
--
-- heads_dict, smtpheads, nntpheads = {}, {}, {}
-- article, headers, body = [], [], []
--
-- debug = 1
--
-- def readfile(self):
--
-- for line in sys.stdin.readlines():
-- self.article.append(line)
--
-- if (len(self.article) == 1 and self.article[0][0] == '/'):
-- file = self.article[0][:-1]
-- del self.article[0]
-- for line in open(file, 'r').readlines():
-- self.article.append(line)
--
-- def parsearticle(self):
-- """get news article from file or stdin and separate heads from body
--
-- REMEBER: headers value has '\n' as last char.
-- Use string[:-1] to ignore newline.
-- """
--
-- try:
-- body = 0 # are we in body or in headers?
--
--# voidline = compile('^$') # I need '\n', ^$ matches anything
--# spaceending = compile('\s*\n$')
--
-- for line in self.article:
-- if not body and len(line) == 1:
-- body = 1 # starts article body section
--
-- if not body:
-- try:
-- head, value = line.split(' ', 1)
-- self.nntpheads[head] = value
-- except (ValueError), message:
-- print('string error: %s' % message)
-- print('(probably missing couple "Header: value" in %s)'
-- % line)
-- sys.exit(1)
--
-- elif len(line) > 0 and body:
-- self.body.append(line)
--
-- return self.nntpheads, self.body
--
--# except (re.error, ValueError), message:
-- except (ValueError), message:
-- print message
-- sys.exit(1)
-+ def __init__(self):
-+ self.hostname = gethostbyaddr(gethostname())[0] # FQDN
-+ self.message = email.message_from_file(sys.stdin)
-
- def puthead(self, dict, list, key):
- """private, x-form dict entries in list entries"""
-@@ -138,7 +94,8 @@ class news2mail:
- self.heads_dict = {}
-
- try:
-- for header in self.nntpheads.keys(): # fill it w/ nntp old heads
-+ # fill it w/ nntp old heads
-+ for header in self.nntpheads.keys():
- self.heads_dict[header] = self.nntpheads[header]
-
- # and replace them w/ smtp new heads
-@@ -160,9 +117,6 @@ class news2mail:
- self.heads_dict['X-Gateway:'] = info.PROGNAME + ' ' + \
- info.__doc__ + '\n'
-
-- ##self.heads_dict['X-Gateway:'] = '%s %s\n' %
-- ## (info.PROGNAME, info.__doc__)
--
- # to make Received: header
- t = time.ctime(time.time())
-
-@@ -194,12 +148,12 @@ class news2mail:
- headers renamed are useless or not rfc 822 copliant
- """
- try:
-- if 'Newsgroups:' in self.heads_dict:
-+ if 'Newsgroups:' in self.message:
- self.heads_dict['X-Newsgroups:'] = \
- self.heads_dict['Newsgroups:']
- del self.heads_dict['Newsgroups:']
-
-- if 'NNTP-Posting-Host:' in self.heads_dict:
-+ if 'NNTP-Posting-Host:' in self.message:
- self.heads_dict['X-NNTP-Posting-Host:'] = \
- self.heads_dict['NNTP-Posting-Host:']
- del self.heads_dict['NNTP-Posting-Host:']
-@@ -215,37 +169,37 @@ class news2mail:
- try:
- # removing some others useless headers ....
-
-- if 'Approved:' in self.heads_dict:
-+ if 'Approved:' in self.message:
- del self.heads_dict['Approved:']
-
-- if 'From' in self.heads_dict: # neither 'From ' nor 'From:'
-+ if 'From' in self.message: # neither 'From ' nor 'From:'
- del self.heads_dict['From']
-
-- if 'Xref:' in self.heads_dict:
-+ if 'Xref:' in self.message:
- del self.heads_dict['Xref:']
-
-- if 'Path:' in self.heads_dict:
-+ if 'Path:' in self.message:
- del self.heads_dict['Path:']
-
-- if 'Lines:' in self.heads_dict:
-+ if 'Lines:' in self.message:
- del self.heads_dict['Lines:']
-
- # it is usually set by INN, if ng is moderated...
-- if 'Sender:' in self.heads_dict:
-+ if 'Sender:' in self.message:
- del self.heads_dict['Sender:']
-
-- 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:' 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:
- # It should put a real user@domain
-- msgid = 'pyg@puppapera.org' # FIXME unused variable
-+ self.message['Message-Id'] = 'pyg@puppapera.org'
-
- except KeyError, message:
- print message
-diff --git b/pygm2n a/pygm2n
-index 49d83c3..9601c23 100755
---- b/pygm2n
-+++ a/pygm2n
-@@ -1,5 +1,5 @@
- #!/usr/bin/env python
--# -*- coding: utf-8 -*-
-+
- """News to mail gateway script. Copyright 2000 Cosimo Alfarano
-
- Author: Cosimo Alfarano
-@@ -13,34 +13,37 @@ Thanks to md for this useful formula. Beer is beer.
-
-
- def parse_cmdline():
-+ """
-+ set a dictionary with smtp new header in gw parameter (gw.smtpheads)
-+ return (test,verbose) boolean tuple
-+ """
-
-@@ -86,14 +89,6 @@ try:
-
- opt = parse_cmdline()
-
-- # reads stdin and parses article separating head from body
-- m2n.readfile(opt)
-- m2n.parseemail()
--
-- """phase 2:
-- check whitelist for user's permission
-- """
--
- """phase 3:
- format rfc 822 headers from input article
- """
-diff --git b/pygn2m a/pygn2m
-index 0b958f1..b46b40f 100755
---- b/pygn2m
-+++ a/pygn2m
-@@ -1,5 +1,6 @@
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
-+
- """News to mail gateway script. Copyright 2000 Cosimo Alfarano
-
- Author: Cosimo Alfarano
-@@ -13,16 +14,19 @@ Thanks to md for this useful formula. Beer is beer.
-+
-+
-+sys.path.append('/usr/lib/pyg')
-+
-+# import mail2news
-
-
- def parse_cmdline():
-@@ -82,28 +84,24 @@ try:
- n2m = news2mail.news2mail()
- owner = None
-
-- # it returns only test, other parms are set directly in the actual
-- # parameter
- args = parse_cmdline()
-
- # check if n2m has some file prefercences set on commandline
-- if n2m.wlfile is None:
-- wl = os.environ['HOME'] + '/pyg.whitelist'
-+ if args.wlfile is None:
-+ wl = os.path.expanduser('~/pyg.whitelist')
- else:
-- wl = n2m.wlfile
-+ wl = args.wlfile
-
-- if n2m.logfile is None:
-- log = os.environ['HOME'] + '/pyg.log'
-+ if args.logfile is None:
-+ log = os.path.expanduser('~/pyg.log')
- else:
-- log = n2m.logfile
--
--# print 'using %s %s\n' % (wl,log)
-+ log = args.logfile
-
- wl = whitelist.whitelist(wl, log)
-
- # reads stdin and parses article separating head from body
-- n2m.readfile()
-- n2m.parsearticle()
-+ ## n2m.readfile()
-+ ## n2m.parsearticle()
-
- """phase 2:
- check whitelist for user's permission