summaryrefslogtreecommitdiff
path: root/src/mailman/runners/nntp.py
diff options
context:
space:
mode:
authorBarry Warsaw2012-04-01 10:55:52 -0600
committerBarry Warsaw2012-04-01 10:55:52 -0600
commit664d7d73e13b649f003f51a727bf39fdfdc2ab65 (patch)
tree1b1c42f94b93dc527bbc68a7864505583715b5e5 /src/mailman/runners/nntp.py
parent2404a8acad7c3f800e08e143ffb1e812e869a5a7 (diff)
downloadmailman-664d7d73e13b649f003f51a727bf39fdfdc2ab65.tar.gz
mailman-664d7d73e13b649f003f51a727bf39fdfdc2ab65.tar.zst
mailman-664d7d73e13b649f003f51a727bf39fdfdc2ab65.zip
Diffstat (limited to 'src/mailman/runners/nntp.py')
-rw-r--r--src/mailman/runners/nntp.py30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/mailman/runners/nntp.py b/src/mailman/runners/nntp.py
index 411fbb6f2..11c3942f0 100644
--- a/src/mailman/runners/nntp.py
+++ b/src/mailman/runners/nntp.py
@@ -157,18 +157,26 @@ def prepare_message(mlist, msg, msgdata):
# reject the message because of other problems.
for header in config.nntp.remove_headers.split():
del msg[header]
- for rewrite_pairs in config.nntp.rewrite_duplicate_headers.splitlines():
- if len(rewrite_pairs.strip()) == 0:
- continue
- header, rewrite = rewrite_pairs.split()
- values = msg.get_all(header, [])
+ dup_headers = config.nntp.rewrite_duplicate_headers.split()
+ if len(dup_headers) % 2 != 0:
+ # There are an odd number of headers; ignore the last one.
+ bad_header = dup_headers.pop()
+ log.error('Ignoring odd [nntp]rewrite_duplicate_headers: {0}'.format(
+ bad_header))
+ dup_headers.reverse()
+ while dup_headers:
+ source = dup_headers.pop()
+ target = dup_headers.pop()
+ values = msg.get_all(source, [])
if len(values) < 2:
- # We only care about duplicates
+ # We only care about duplicates.
continue
- del msg[header]
- # But keep the first one...
- msg[header] = values[0]
- for v in values[1:]:
- msg[rewrite] = v
+ # Delete all the original headers.
+ del msg[source]
+ # Put the first value back on the original header.
+ msg[source] = values[0]
+ # And put all the subsequent values on the destination header.
+ for value in values[1:]:
+ msg[target] = value
# Mark this message as prepared in case it has to be requeued.
msgdata['prepped'] = True