aboutsummaryrefslogtreecommitdiffstats
path: root/mail2news.py
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2014-12-24 14:24:24 +0100
committerMatěj Cepl <mcepl@cepl.eu>2014-12-24 14:32:23 +0100
commit8af6ecfe31a7767f1d76f36581b01ddd26fb3220 (patch)
treea5cf60c5de6a34843fceb23895473cbb25c80fa2 /mail2news.py
parent45552a9cb1ac5433fd2010d1736b41a3393b9b6b (diff)
downloadpygn-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 'mail2news.py')
-rw-r--r--mail2news.py71
1 files changed, 26 insertions, 45 deletions
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