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 /news2mail.py | |
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
Diffstat (limited to 'news2mail.py')
-rw-r--r-- | news2mail.py | 71 |
1 files changed, 26 insertions, 45 deletions
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 |