Vinay Sajip <vinay_sa...@yahoo.co.uk> added the comment:

SMTPHandler provides an implementation for the simplest/most common case. Full 
support for encoding in emails is likely to be application-specific, i.e. no 
one-size-fits-all can be easily specified. For example, different encodings 
could be used for headers, subject and body - say, quoted-printable for the 
body and base64 for the subject. Unfortunately, support for quoted-printable 
requires a global state change, see for instance

http://radix.twistedmatrix.com/2010/07/how-to-send-good-unicode-email-with.html

so it seems not to be a good idea to implement in the logging package itself.

I would suggest implementing a handler which subclasses SMTPHandler and does 
the appropriate formatting as per (for example) the above post. To facilitate 
this, I coukd add two methods to SMTPHandler:

class SMTPHandler(logging.Handler):
    def prepareEmail(self, record):
        """
        Prepare a record for emailing, including setting up mail
        headers doing all necessary encodings. Return a value
        suitable for passing to the sendEmail method.

        The default implementation will assume all-ASCII content
        for headers and body, do no special encoding, and return a
        string.
        """

    def sendMail(self, smtp, msg):
        """
        Send a message via the provided SMTP instance.

        The default implementation will call smtplib.sendmail(),
        passing the result from the prepareEmail method.
        """

I'm not yet sure if this would meet all use cases.

Marking as pending, awaiting feedback. Will close in a couple of weeks if no 
feedback received.

----------
status: open -> pending

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue9208>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to