bigboard r7334 - trunk/bigboard/stocks/mail
- From: marinaz svn gnome org
- To: svn-commits-list gnome org
- Subject: bigboard r7334 - trunk/bigboard/stocks/mail
- Date: Wed, 7 May 2008 20:51:55 +0100 (BST)
Author: marinaz
Date: Wed May 7 19:51:55 2008
New Revision: 7334
URL: http://svn.gnome.org/viewvc/bigboard?rev=7334&view=rev
Log:
A libgmail patch for getting the cookies needed for logging in to Google Apps For Your Domain Accounts. This is a dead end though, since the page content returned has a different format from regular Gmail page content, and instead of parsing it, we are going to swicth to using IMAP.
Modified:
trunk/bigboard/stocks/mail/MailStock.py
trunk/bigboard/stocks/mail/libgmail_patched.py
Modified: trunk/bigboard/stocks/mail/MailStock.py
==============================================================================
--- trunk/bigboard/stocks/mail/MailStock.py (original)
+++ trunk/bigboard/stocks/mail/MailStock.py Wed May 7 19:51:55 2008
@@ -153,9 +153,10 @@
def update_google_data(self, gobj):
self.__current_gobj = gobj
- username = gobj.get_account().get_username_as_google_email()
+ username = gobj.get_account().get_username()
password = gobj.get_account().get_password()
- self.__update_email_box(username, password)
+ domain = gobj.get_account().get_url()
+ self.__update_email_box(username, password, domain)
def remove_google_data(self, gobj):
# sometimes we don't even get the self.__current_gobj because the polling task didn't start, so
@@ -167,12 +168,15 @@
self.__google_account = None
self.__logged_in = False
- def __update_email_box (self, username, password):
+ def __update_email_box (self, username, password, domain):
_logger.debug("will update mailbox")
try:
if self.__google_account is None or username != self.__google_account.name or \
password != self.__google_account.password:
- self.__google_account = libgmail.GmailAccount(username, password)
+ if domain and (len(domain) == 0 or domain == "gmail.com"):
+ domain = None
+ _logger.debug("username %s domain %s" % (username, domain))
+ self.__google_account = libgmail.GmailAccount(username, password, domain = domain)
self.__google_account.login()
elif not self.__logged_in:
self.__google_account.login()
Modified: trunk/bigboard/stocks/mail/libgmail_patched.py
==============================================================================
--- trunk/bigboard/stocks/mail/libgmail_patched.py (original)
+++ trunk/bigboard/stocks/mail/libgmail_patched.py Wed May 7 19:51:55 2008
@@ -84,6 +84,10 @@
the embedded Javascript.
"""
+ if LG_DEBUG:
+ # This will print the page content we are about to parse to get the e-mails.
+ # The current parsing does not work for what is returned for Google Apps For Your Domain accounts.
+ print "pageContent %s" % pageContent
lines = pageContent.splitlines()
data = '\n'.join([x for x in lines if x and x[0] in ['D', ')', ',', ']']])
#data = data.replace(',,',',').replace(',,',',')
@@ -141,8 +145,9 @@
return result
class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
- def __init__(self, cookiejar):
+ def __init__(self, cookiejar, extractCookies = False):
self.cookiejar = cookiejar
+ self.extractCookies = extractCookies
def http_error_302(self, req, fp, code, msg, headers):
# The location redirect doesn't seem to change
@@ -152,6 +157,8 @@
headers.getheader('Location'))
if new_host:
req.add_header("Host", new_host.groups()[0])
+ if self.extractCookies:
+ self.cookiejar.extractCookies(headers)
result = urllib2.HTTPRedirectHandler.http_error_302(
self, req, fp, code, msg, headers)
return result
@@ -179,10 +186,15 @@
# TODO: Do this all more nicely?
for cookie in headers.getheaders('Set-Cookie'):
name, value = (cookie.split("=", 1) + [""])[:2]
- if LG_DEBUG: print "Extracted cookie `%s`" % (name)
+ if LG_DEBUG:
+ print "Extracted cookie `%s`" % (name)
if not nameFilter or name in nameFilter:
- self._cookies[name] = value.split(";")[0]
- if LG_DEBUG: print "Stored cookie `%s` value `%s`" % (name, self._cookies[name])
+ cookie_value = value.split(";")[0]
+ # do not overwrite the HID cookie when we get information that it is expired
+ if not (name == "HID" and cookie_value == "EXPIRED"):
+ self._cookies[name] = cookie_value
+ if LG_DEBUG:
+ print "Stored cookie `%s` value `%s`" % (name, self._cookies[name])
if self._cookies[name] == "EXPIRED":
if LG_DEBUG:
print "We got an expired cookie: %s:%s, deleting." % (name, self._cookies[name])
@@ -289,7 +301,7 @@
"""
self.domain = domain
if self.domain:
- URL_LOGIN = "https://www.google.com/a/" + self.domain + "/LoginAction"
+ URL_LOGIN = "https://www.google.com/a/" + self.domain + "/LoginAction2"
URL_GMAIL = "http://mail.google.com/a/" + self.domain + "/?"
else:
URL_LOGIN = GMAIL_URL_LOGIN
@@ -306,10 +318,13 @@
gmail_transport.ConnectHTTPSHandler(proxy = PROXY_URL),
SmartRedirectHandler(self._cookieJar))
else:
+ # processing of the Google Apps For Your Domain login requires extracting cookies
+ # before redirects, so we pass self.domain for the extractCookies flag to the
+ # SmartRedirectHandler
self.opener = urllib2.build_opener(
urllib2.HTTPHandler(debuglevel=0),
urllib2.HTTPSHandler(debuglevel=0),
- SmartRedirectHandler(self._cookieJar))
+ SmartRedirectHandler(self._cookieJar, self.domain))
elif state:
# TODO: Check for stale state cookies?
self.name, self._cookieJar = state.state
@@ -331,8 +346,8 @@
data = urllib.urlencode({'continue': URL_GMAIL,
'at' : 'null',
'service' : 'mail',
- 'userName': self.name,
- 'password': self.password,
+ 'Email': self.name,
+ 'Passwd': self.password,
})
else:
data = urllib.urlencode({'continue': URL_GMAIL,
@@ -363,6 +378,14 @@
# We aren't concerned with the actual content of this page,
# just the cookie that is returned with it.
pageData = self._retrievePage(redirectURL)
+ else:
+ if LG_DEBUG:
+ print "cookie jar has HID cookie: %s" % (self._cookieJar._cookies.has_key('HID'))
+ if self._cookieJar._cookies.has_key('HID'):
+ req2 = urllib2.Request("https://mail.google.com/a/" + self.domain + "/?auth=" + self._cookieJar._cookies['HID'] + "husr=" + self.name + "@" + self.domain)
+ pageData2 = self._retrievePage(req2)
+ else:
+ raise GmailLoginFailure("Login failed. (Wrong username/password?)")
def _retrievePage(self, urlOrRequest):
"""
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]