You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Eric Gillespie <ep...@pretzelnet.org> on 2005/04/16 19:08:48 UTC

[PATCH] mailer.py over-aggressively encodes Subject

With r13453, our commit mailer suddenly started sending out RFC
2047 encoded Subject headers for no reason:

Subject: =?utf-8?q?svn_commit=3A_r13453_-_in_branches/locking/subvers?=
 =?utf-8?q?ion=3A_clients/cmdline_include_libsvn=5Fsubr_svnadmin?=

Subject: svn commit: r13453 - in branches/locking/subversion:
clients/cmdline include libsvn_subr svnadmin

This is due to mailer.py r14222.  We should only be doing this if
the header actually contains characters absent from 7-bit ASCII,
which is clearly not the case here (or for any of the mails that
have arrived since then).  This is very annoying when looking at
raw message files, as i frequently do.

Any objection if i commit this?

* tools/hook-scripts/mailer/mailer.py
  (MailedOutput.mail_headers): Only RFC 2047 encode the Subject
  header if it contains non-ASCII characters.

=== mailer.py
==================================================================
--- mailer.py  (revision 2607)
+++ mailer.py  (local)
@@ -185,7 +185,11 @@
 
   def mail_headers(self, group, params):
     from email.Header import Header
-    subject = Header(self.make_subject(group, params), 'utf-8').encode()
+    subject = self.make_subject(group, params)
+    try:
+      subject.encode('ascii')
+    except UnicodeDecodeError:
+      subject = Header(subject, 'utf-8').encode()
     hdrs = 'From: %s\n'    \
            'To: %s\n'      \
            'Subject: %s\n' \

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] mailer.py over-aggressively encodes Subject

Posted by Branko Čibej <br...@xbc.nu>.
Eric Gillespie wrote:

>With r13453, our commit mailer suddenly started sending out RFC
>2047 encoded Subject headers for no reason:
>
>Subject: =?utf-8?q?svn_commit=3A_r13453_-_in_branches/locking/subvers?=
> =?utf-8?q?ion=3A_clients/cmdline_include_libsvn=5Fsubr_svnadmin?=
>
>Subject: svn commit: r13453 - in branches/locking/subversion:
>clients/cmdline include libsvn_subr svnadmin
>
>This is due to mailer.py r14222.  We should only be doing this if
>the header actually contains characters absent from 7-bit ASCII,
>which is clearly not the case here (or for any of the mails that
>have arrived since then).  This is very annoying when looking at
>raw message files, as i frequently do.
>
>Any objection if i commit this?
>
>* tools/hook-scripts/mailer/mailer.py
>  (MailedOutput.mail_headers): Only RFC 2047 encode the Subject
>  header if it contains non-ASCII characters.
>  
>
Looks reasonable.

-- Brane


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] mailer.py over-aggressively encodes Subject

Posted by Tobias Ringström <to...@ringstrom.mine.nu>.
C. Michael Pilato wrote:
> Erp.  No, that didn't work at all.  Seems I also need to hand the hook
> script's stdin to mailer.py.

Ah, right, I forgot about that.  I'll look into adding some helpful 
documentation somewhere.

/Tobias

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] mailer.py over-aggressively encodes Subject

Posted by "C. Michael Pilato" <cm...@collab.net>.
"C. Michael Pilato" <cm...@collab.net> writes:

> Tobias Ringström <to...@ringstrom.mine.nu> writes:
> 
> > C. Michael Pilato wrote:
> > > And installed on svn.collab.net.  Thanks.
> > 
> > Nice.  Can you also update the post-revprop-hook(s) to use propchange2
> > to enable propchange diffs?  (See issue 2204 if you want to boost your
> > issue resolve statistics :)
> 
> And, done.  (Did I only have to tweak "propchange" to "propchange2"
> and pass the new ${ACTION} flag?)

Erp.  No, that didn't work at all.  Seems I also need to hand the hook
script's stdin to mailer.py.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org


Re: [PATCH] mailer.py over-aggressively encodes Subject

Posted by "C. Michael Pilato" <cm...@collab.net>.
Tobias Ringström <to...@ringstrom.mine.nu> writes:

> C. Michael Pilato wrote:
> > And installed on svn.collab.net.  Thanks.
> 
> Nice.  Can you also update the post-revprop-hook(s) to use propchange2
> to enable propchange diffs?  (See issue 2204 if you want to boost your
> issue resolve statistics :)

And, done.  (Did I only have to tweak "propchange" to "propchange2"
and pass the new ${ACTION} flag?)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org


Re: [PATCH] mailer.py over-aggressively encodes Subject

Posted by Tobias Ringström <to...@ringstrom.mine.nu>.
C. Michael Pilato wrote:
> And installed on svn.collab.net.  Thanks.

Nice.  Can you also update the post-revprop-hook(s) to use propchange2 
to enable propchange diffs?  (See issue 2204 if you want to boost your 
issue resolve statistics :)

/Tobias

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] mailer.py over-aggressively encodes Subject

Posted by "C. Michael Pilato" <cm...@collab.net>.
Eric Gillespie <ep...@pretzelnet.org> writes:

> "C. Michael Pilato" <cm...@collab.net> writes:
> 
> > And as a minor optimization, you can move the import of Header into
> > the "except" clause.
> 
> Good idea; thanks.  Committed in r14258.

And installed on svn.collab.net.  Thanks.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] mailer.py over-aggressively encodes Subject

Posted by Eric Gillespie <ep...@pretzelnet.org>.
"C. Michael Pilato" <cm...@collab.net> writes:

> And as a minor optimization, you can move the import of Header into
> the "except" clause.

Good idea; thanks.  Committed in r14258.

--  
Eric Gillespie <*> epg@pretzelnet.org

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] mailer.py over-aggressively encodes Subject

Posted by "C. Michael Pilato" <cm...@collab.net>.
Eric Gillespie <ep...@pretzelnet.org> writes:

> ==================================================================
> --- mailer.py  (revision 2607)
> +++ mailer.py  (local)
> @@ -185,7 +185,11 @@
>  
>    def mail_headers(self, group, params):
>      from email.Header import Header
> -    subject = Header(self.make_subject(group, params), 'utf-8').encode()
> +    subject = self.make_subject(group, params)
> +    try:
> +      subject.encode('ascii')
> +    except UnicodeDecodeError:
> +      subject = Header(subject, 'utf-8').encode()
>      hdrs = 'From: %s\n'    \
>             'To: %s\n'      \
>             'Subject: %s\n' \

And as a minor optimization, you can move the import of Header into
the "except" clause.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] mailer.py over-aggressively encodes Subject

Posted by "C. Michael Pilato" <cm...@collab.net>.
Eric Gillespie <ep...@pretzelnet.org> writes:

> With r13453, our commit mailer suddenly started sending out RFC
> 2047 encoded Subject headers for no reason:
> 
> Subject: =?utf-8?q?svn_commit=3A_r13453_-_in_branches/locking/subvers?=
>  =?utf-8?q?ion=3A_clients/cmdline_include_libsvn=5Fsubr_svnadmin?=
> 
> Subject: svn commit: r13453 - in branches/locking/subversion:
> clients/cmdline include libsvn_subr svnadmin
> 
> This is due to mailer.py r14222.  We should only be doing this if
> the header actually contains characters absent from 7-bit ASCII,
> which is clearly not the case here (or for any of the mails that
> have arrived since then).  This is very annoying when looking at
> raw message files, as i frequently do.

Heheh.  I had the following patch ready to commit:

   def mail_headers(self, group, params):
-    from email.Header import Header
-    subject = Header(self.make_subject(group, params), 'utf-8').encode()
+    # Get our Subject: line, MIME-encoding if any of the characters
+    # have ordinal values > 127
+    subject = self.make_subject(group, params)
+    if True in [ord(subject[i]) > 127 for i in range(len(subject))]: # woot!
+      from email.Header import Header
+      subject = Header(subject, 'utf-8').encode()
     hdrs = 'From: %s\n'    \
            'To: %s\n'      \
            'Subject: %s\n' \

But yours was much less obfuscated.  :-)  Please do commit it up.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org