-------- Original Message --------
From: Mark Sapiro [mailto:m...@msapiro.net]
Sent: Saturday, March 6, 2021, 23:27 UTC
To: mailman-users@python.org
Subject: [Mailman-Users] Re: Pipermail scrubbing ascii txt to ksh attachment

> The patch I posted previously was bad. This one is correct. If you patch
> Scrubber.py with this patch, you won't need to edit the mbox and rebuild
> the archive as that message won't get scrubbed.

Hi Mark. Your patch to Scrubber.py has solved the problem. Thank you.

A summary below: 

====================================================

PROBLEM: Plain text emails being automatically posted to a list, via a Perl 
script, were displaying okay in subscribers' email clients, but in the archive 
-- the body of the message is scrubbed as "attachment.ksh".

CAUSE: The headers of the posts to the list contained the lines: 

        Content-Disposition: inline
        Content-Type: text/plain 

Mark wrote: "If the script that sends this mail can be altered to either 
include the charset= on the Content-Type: text/plain header or not include the
Content-Disposition: inline header or both, that would solve this." He then 
wrote a patch for Mailman/Handlers/Scrubber.py to do this (in the event that 
the script could not be modified).

=== modified file 'Mailman/Handlers/Scrubber.py'
--- Mailman/Handlers/Scrubber.py        2020-06-21 18:45:30 +0000
+++ Mailman/Handlers/Scrubber.py        2021-03-06 19:10:28 +0000
@@ -90,6 +90,9 @@
     if ctype.lower == 'application/octet-stream':
         # For this type, all[0] is '.obj'. '.bin' is better.
         return '.bin'
+    if ctype.lower == 'text/plain':
+        # For this type, all[0] is '.ksh'. '.txt' is better.
+        return '.txt'
     return all and all[0]
 
 
@@ -196,8 +199,11 @@
                 format = part.get_param('format')
                 delsp = part.get_param('delsp')
             # TK: if part is attached then check charset and scrub if none
-            if part.get('content-disposition') and \
-               not part.get_content_charset():
+            # MAS: Content-Disposition is not a good test for 'attached'.
+            # RFC 2183 sec. 2.10 allows Content-Disposition on the main body.
+            # Make it specifically 'attachment'.
+            if (part.get('content-disposition', '').lower() == 'attachment'
+                    and not part.get_content_charset()):
                 omask = os.umask(002)
                 try:
                     url = save_attachment(mlist, part, dir)


IN ADDITION: The following script was run to tidy up the list's .mbox file.

#!/bin/bash
PATH=/usr/sbin:/usr/bin:/sbin:/bin
LISTNAME=your_list_name_goes_here
echo $LISTNAME archive rebuild started at $(date +%H:%M:%S)
sed -i '/Content-Disposition: inline/d' 
/var/lib/mailman/archives/private/$LISTNAME.mbox/$LISTNAME.mbox
sed -i 's/Content-Type: text\/plain/Content-Type: text\/plain; 
charset="us-ascii"/' 
/var/lib/mailman/archives/private/$LISTNAME.mbox/$LISTNAME.mbox
/usr/lib/mailman/bin/arch --wipe $LISTNAME
echo $LISTNAME archive rebuild completed at $(date +%H:%M:%S)
exit 0


==================================================== 
------------------------------------------------------
Mailman-Users mailing list -- mailman-users@python.org
To unsubscribe send an email to mailman-users-le...@python.org
https://mail.python.org/mailman3/lists/mailman-users.python.org/
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: https://www.mail-archive.com/mailman-users@python.org/
    https://mail.python.org/archives/list/mailman-users@python.org/

Reply via email to