1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
diff --git b/mail2news.py a/mail2news.py
index e7cbcf9..412e4ee 100644
--- b/mail2news.py
+++ a/mail2news.py
@@ -24,80 +28,41 @@ import pyginfo
class mail2news:
"""news to mail gateway class"""
-
reader = None # mode reader
-# newsgroups = None # Newsgroups: local.test,local.moderated...
-# approved = None # Approved: kame@aragorn.lorien.org
newsserver = 'localhost' # no comment :)
port = 119
user = None
password = None
+# """phase 3:
+# format rfc 822 headers from input article
+# """
+#
+# m2n.mergeheads() # make unique dict from NNTP and SMTP dicts
+#
+# m2n.addheads() # add some important heads
+# m2n.renameheads() # rename useless heads
+# m2n.removeheads() # remove other heads
+#
+# m2n.sortheads() # sort remaining heads :)
+#
+# if opt.verbose:
+# for line in m2n.headers:
+# print line[:-1]
@@ -142,14 +108,11 @@ class mail2news:
self.heads_dict = {}
- try:
- for header in self.smtpheads.keys(): # fill it w/ smtp old heads
- self.heads_dict[header] = self.smtpheads[header]
-
- # and replace them w/ nntp new heads
- for header in self.nntpheads.keys():
- self.heads_dict[header] = self.nntpheads[header]
+ # FIXME something like a = set() ; a = self.message.items() ?
+ try:
+ for header in self.message.keys(): # fill it w/ smtp old heads
+ self.heads_dict[header] = self.message[header]
except KeyError, message:
print message
@@ -236,51 +166,32 @@ class mail2news:
def removeheads(self, heads=None):
"""remove headers like Xref: Path: Lines:
"""
-
- try:
# removing some others useless headers .... (From is not From:)
rmheads = ['Received:', 'From', 'NNTP-Posting-Host:',
'X-Trace:', 'X-Compliants-To:', 'NNTP-Posting-Date:']
- if(heads):
+ if heads:
rmheads.append(heads)
for head in rmheads:
- if head in self.heads_dict:
- del self.heads_dict[head]
-
-# if 'From' in self.heads_dict: # neither 'From ' nor 'From:'
-# del self.heads_dict['From']
-
-# # neither 'From ' nor 'From:'
-# if 'NNTP-Posting-Host:' in self.heads_dict:
-# del self.heads_dict['']
-
-# if 'Lines:' in self.heads_dict:
-# del self.heads_dict['Lines:']
+ if head in self.message:
+ del self.message[head]
- # it is usually set by INN, if ng is moderated...
-# if 'Sender:' in self.heads_dict:
-# del self.heads_dict['Sender:']
-
- if 'Message-id:' in self.heads_dict:
+ # FIXME the following lines are buggy, because they don't expect
+ # the header 'Message-Id' being already present
+ 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:
msgid = '<pyg.%d@tuchailepuppapera.org>\n' % (getpid())
self.heads_dict['Message-Id:'] = msgid
- except KeyError, message:
- print message
-
- return self.heads_dict
-
def sendemail(self):
"""Talk to NNTP server and try to send email."""
try:
|