From 45552a9cb1ac5433fd2010d1736b41a3393b9b6b Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Mon, 22 Dec 2014 02:40:39 +0100 Subject: pygm2n and mail2news also use email.Parser. --- news2mail.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'news2mail.py') diff --git a/news2mail.py b/news2mail.py index 4dd83fc..e1909a1 100644 --- a/news2mail.py +++ b/news2mail.py @@ -23,6 +23,9 @@ normal (what pygs does) operations flow is: """ import email +import logging +from collections import OrderedDict +# logging.basicConfig(level=logging.DEBUG) import sys import smtplib import time @@ -58,7 +61,6 @@ class news2mail(object): @staticmethod def puthead(from_dict, out_list, key): """private, x-form dict entries in out_list entries""" - if key in from_dict: out_list.append(key + ' ' + from_dict.get(key)) else: @@ -76,24 +78,26 @@ class news2mail(object): self.puthead(self.heads_dict, self.headers, k) for k in self.heads_dict.keys(): - if k[:2] != 'X-' and k[:7] != 'Resent-' and k not in header_set: + if not k.startswith('X-') and not k.startswith('Resent-') \ + and k not in header_set: self.puthead(self.heads_dict, self.headers, k) for k in self.heads_dict.keys(): - if k[:2] == 'X-': + if k.startswith('X-'): self.puthead(self.heads_dict, self.headers, k) for k in self.heads_dict.keys(): - if k[:7] == 'Resent-': + if k.startswith('Resent-'): self.puthead(self.heads_dict, self.headers, k) + logging.debug('self.headers = %s', self.headers) return self.headers def mergeheads(self): """make a unique headers dictionary from NNTP and SMTP single headers dictionaries.""" - self.heads_dict = {} + self.heads_dict = OrderedDict() try: for header in self.nntpheads.keys(): # fill it w/ nntp old heads -- cgit