aboutsummaryrefslogtreecommitdiffstats
path: root/news2mail.py
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2014-12-31 12:12:02 +0100
committerMatěj Cepl <mcepl@cepl.eu>2014-12-31 12:12:02 +0100
commit527e535279dcceeb6ffcf091bc9e8fc23b46f287 (patch)
tree5a2c6bbeed90ee47e4a13dcfa854df6513a775f2 /news2mail.py
parentcdd9f1d6a872fbc20e368fc23ddaf98eb1ef3741 (diff)
downloadpyg-527e535279dcceeb6ffcf091bc9e8fc23b46f287.tar.gz
Remove the spaghetti code from the main scripts.
Diffstat (limited to 'news2mail.py')
-rw-r--r--news2mail.py34
1 files changed, 19 insertions, 15 deletions
diff --git a/news2mail.py b/news2mail.py
index 7338fd8..4248be2 100644
--- a/news2mail.py
+++ b/news2mail.py
@@ -24,13 +24,12 @@ normal (what pygs does) operations flow is:
"""
from collections import OrderedDict
import email
+from mail2news import VERSION, DESC
import smtplib
from socket import gethostbyaddr, gethostname
import sys
import time
-from mail2news import VERSION, DESC
-
# logging.basicConfig(level=logging.DEBUG)
class news2mail(object):
@@ -39,6 +38,7 @@ class news2mail(object):
def __init__(self, verbose=False):
self.wlfile = None
self.logfile = None
+ self.verbose = verbose
self.sender = ''
self.rcpt = ''
@@ -50,15 +50,13 @@ class news2mail(object):
self.heads_dict = {}
self.article, self.headers, self.body = [], [], []
- self.message = email.message_from_file(sys.stdin)
+ self.message = self.__addheads(email.message_from_file(sys.stdin))
- self.verbose = verbose
-
- def addheads(self):
+ def __addheads(self, msg):
"""add new header like X-Gateway: Received:
"""
- self.message['X-Gateway'] = 'pyg {0} {1}'.format(VERSION, DESC)
+ msg['X-Gateway'] = 'pyg {0} {1}'.format(VERSION, DESC)
# to make Received: header
t = time.ctime(time.time())
@@ -79,10 +77,13 @@ class news2mail(object):
'\n\tfor <' + self.rcpt + '> ; ' + \
t + ' (' + tzone + ')\n'
- self.message['Received'] = tmp
+ msg['Received'] = tmp
- def renameheads(self):
- """rename headers such as Newsgroups: to X-Newsgroups:
+ return msg
+
+ def __renameheads(self):
+ """remove headers like Xref: Path: Lines:
+ rename headers such as Newsgroups: to X-Newsgroups:
headers renamed are useless or not rfc 822 copliant
"""
@@ -99,10 +100,6 @@ class news2mail(object):
except KeyError as ex:
print(ex)
- def removeheads(self):
- """remove headers like Xref: Path: Lines:
- """
-
try:
# removing some others useless headers ....
# that includes BOTH 'From ' and 'From'
@@ -122,7 +119,7 @@ class news2mail(object):
except KeyError, message:
print message
- def sortheads(self):
+ def __sortheads(self):
"""make list sorting heads, Received: From: To: Subject: first,
others, X-*, Resent-* last"""
@@ -150,6 +147,13 @@ class news2mail(object):
if k.startswith('Resent-'):
self.message[k] = heads_dict[k]
+ def process_message(self):
+ """phase 3:
+ format rfc 822 headers from input article
+ """
+ self.__renameheads() # remove other heads
+ self.__sortheads()
+
def sendarticle(self):
"""Talk to SMTP server and try to send email."""
s = smtplib.SMTP(self.smtpserver)