[ANN] libgmail 0.0.3 -- Gmail access via Python

Follower follower at gmail.com
Tue Jul 13 00:22:57 CEST 2004


David Fraser <davidf at sjsoft.com> wrote in message 
> This is getting really cool. One suggestion: the example on the home 
> page needs a libgmail in front of the GmailAccount constructor
Thanks for the positive feedback, David. And for revealing me as a
developer who doesn't check the sample code he puts up on his web
site. :-) I appreciate you taking the time to do so and have now fixed
the page.

> I couldn't work out how to get the gmail.js required to update the 
> constants.py. Maybe being able to give username and password to 
> mkconstants to let it fetch the javascript would be a good idea?
Thanks for the suggestion, I have added a function
'_retrieveJavascript' to 'GmailAccount' to assist in doing that.
Unfortunately with the last code update Gmail stopped including the
constant definitions so 'mkconstants.py' isn't much use with the
current Javascript. (*Fortunately* my, um, "friend" might have been
lucky enough to have a sav^h^h^h cached copy of a previous version...)
Of course, I understand why they did it, it knocked ~30K from the
download so it's now "only" ~230K--many of the constant names were
longer than the associated values.

The above change is only in CVS at the moment, the next release will
include it.

BTW, the latest CVS version *also* includes a SMTP server which allows
you to send messages via Gmail with any standard mail client. Python's
(until recently) undocumented `smtpd.py` SMTP server framework made
this an incredibly easy addition, although I extended it to handle
basic EHLO & AUTH user authentication commands.

Thanks again for your feedback.

--Phil.

P.S. Apologies for the delay in replying, Google Groups seems to be
delaying c.l.p the last few days.

P.P.S. Here is a (semi-edited, so probably won't run :-)) chunk of
code for extending the SMTP server to ESMTP for posterity, if I don't
get around to reworking it as a patch for `smtpd.py` (it's pretty
rough, no real error checking etc...).

--- Code follows --->

import base64
import asyncore

import smtpd


class ESMTPProxy(smtpd.SMTPServer):
    """
    """

    def process_message(self, peer, mailfrom, rcpttos, data):
        """
        """
        # Need to process message here by subclassing...
    

    def handle_accept(self):
        conn, addr = self.accept()
        print >> smtpd.DEBUGSTREAM, \
             'Incoming connection from %s' % repr(addr)
        channel = ESMTPChannel(self, conn, addr)


class ESMTPChannel(smtpd.SMTPChannel):
    """
    """
    
    def smtp_EHLO(self, arg):
        if not arg:
            self.push('501 Syntax: EHLO hostname')
            return
        if self._SMTPChannel__greeting:
            self.push('503 Duplicate HELO/EHLO')
        else:
            self._SMTPChannel__greeting = arg
            self.push('250-%s' % self._SMTPChannel__fqdn)
            self.push('250 AUTH LOGIN PLAIN')


    def smtp_AUTH(self, arg):
        """
        """
        kind, data = arg.split(" ")
        # TODO: Ensure kind == "PLAIN"

        data = base64.decodestring(data)[1:]
        user, pw = data.split("\x00")
        
        try:
            # Try to log in here...
        except:
            self.push("535 Authorization failed")
        else:
            self.push('235 Ok')


if __name__ == "__main__":

    #smtpd.DEBUGSTREAM = sys.stderr

    server = ESMTPProxy(("localhost", 8025), None)

    asyncore.loop()



More information about the Python-list mailing list