bigboard r7338 - in trunk/bigboard: gmailimap libgmail libgmail/ClientCookie stocks/mail
- From: marinaz svn gnome org
- To: svn-commits-list gnome org
- Subject: bigboard r7338 - in trunk/bigboard: gmailimap libgmail libgmail/ClientCookie stocks/mail
- Date: Mon, 12 May 2008 20:13:06 +0100 (BST)
Author: marinaz
Date: Mon May 12 19:13:06 2008
New Revision: 7338
URL: http://svn.gnome.org/viewvc/bigboard?rev=7338&view=rev
Log:
libgmail/libgmail.py: re-introduce the patch to get folder counts; make password a public field
libgmail/ClientCookie: remove circular imports
MailStock.py: revert to using libgmail, but preserve closing the slideout when a folder was selected and including the password when we call __update_email_box()
Added:
trunk/bigboard/libgmail/__init__.py
Modified:
trunk/bigboard/gmailimap/gmailimap.py
trunk/bigboard/libgmail/ClientCookie/_ClientCookie.py
trunk/bigboard/libgmail/ClientCookie/_Debug.py
trunk/bigboard/libgmail/ClientCookie/__init__.py
trunk/bigboard/libgmail/ClientCookie/_urllib2_support.py
trunk/bigboard/libgmail/libgmail.py
trunk/bigboard/stocks/mail/MailStock.py
Modified: trunk/bigboard/gmailimap/gmailimap.py
==============================================================================
--- trunk/bigboard/gmailimap/gmailimap.py (original)
+++ trunk/bigboard/gmailimap/gmailimap.py Mon May 12 19:13:06 2008
@@ -139,6 +139,7 @@
try:
self.AC = imaplib.IMAP4_SSL(self.imap_server,self.imap_port)
self.AC.login(self.imap_user, self.imap_pass)
+ self.logger.debug("Capabilities %s" % str(self.AC.capabilities))
except imaplib.IMAP4.error,e:
self.logger.error("imap server login raised an exception, check your ~/.imap file")
self.logger.error("reason for the exception: %s" % e)
Modified: trunk/bigboard/libgmail/ClientCookie/_ClientCookie.py
==============================================================================
--- trunk/bigboard/libgmail/ClientCookie/_ClientCookie.py (original)
+++ trunk/bigboard/libgmail/ClientCookie/_ClientCookie.py Mon May 12 19:13:06 2008
@@ -67,7 +67,6 @@
except NameError:
class StopIteration(Exception): pass
-import ClientCookie
from _HeadersUtil import split_header_words, parse_ns_headers
from _Util import startswith, endswith, isstringlike, getheaders
from _Debug import warn, getLogger
Modified: trunk/bigboard/libgmail/ClientCookie/_Debug.py
==============================================================================
--- trunk/bigboard/libgmail/ClientCookie/_Debug.py (original)
+++ trunk/bigboard/libgmail/ClientCookie/_Debug.py Mon May 12 19:13:06 2008
@@ -1,7 +1,5 @@
import sys
-import ClientCookie
-
try:
import warnings
except ImportError:
Modified: trunk/bigboard/libgmail/ClientCookie/__init__.py
==============================================================================
--- trunk/bigboard/libgmail/ClientCookie/__init__.py (original)
+++ trunk/bigboard/libgmail/ClientCookie/__init__.py Mon May 12 19:13:06 2008
@@ -38,15 +38,15 @@
except ImportError:
pass
else:
- from ClientCookie._urllib2_support import \
+ from _urllib2_support import \
Request, \
OpenerDirector, build_opener, install_opener, urlopen, \
OpenerFactory, urlretrieve, BaseHandler, HeadParser
try:
- from ClientCookie._urllib2_support import XHTMLCompatibleHeadParser
+ from _urllib2_support import XHTMLCompatibleHeadParser
except ImportError:
pass
- from ClientCookie._urllib2_support import \
+ from _urllib2_support import \
HTTPHandler, HTTPRedirectHandler, \
HTTPRequestUpgradeProcessor, \
HTTPEquivProcessor, SeekableProcessor, HTTPCookieProcessor, \
@@ -59,13 +59,13 @@
except ImportError:
pass
else:
- from ClientCookie._urllib2_support import \
+ from _urllib2_support import \
HTTPRobotRulesProcessor, RobotExclusionError
del robotparser
import httplib
if hasattr(httplib, 'HTTPS'):
- from ClientCookie._urllib2_support import HTTPSHandler
+ from _urllib2_support import HTTPSHandler
del AbstractHTTPHandler, httplib
from _Util import http2time, response_seek_wrapper
str2time = http2time
Modified: trunk/bigboard/libgmail/ClientCookie/_urllib2_support.py
==============================================================================
--- trunk/bigboard/libgmail/ClientCookie/_urllib2_support.py (original)
+++ trunk/bigboard/libgmail/ClientCookie/_urllib2_support.py Mon May 12 19:13:06 2008
@@ -13,7 +13,6 @@
import copy, time, tempfile, htmlentitydefs, re
-import ClientCookie
from _ClientCookie import CookieJar, request_host
from _Util import isstringlike, startswith, getheaders, closeable_response
from _HeadersUtil import is_html
Added: trunk/bigboard/libgmail/__init__.py
==============================================================================
--- (empty file)
+++ trunk/bigboard/libgmail/__init__.py Mon May 12 19:13:06 2008
@@ -0,0 +1 @@
+# this file needs to be present for the module to be found
Modified: trunk/bigboard/libgmail/libgmail.py
==============================================================================
--- trunk/bigboard/libgmail/libgmail.py (original)
+++ trunk/bigboard/libgmail/libgmail.py Mon May 12 19:13:06 2008
@@ -85,6 +85,7 @@
the embedded Javascript.
"""
+ 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(',,',',')
@@ -251,7 +252,7 @@
URL_GMAIL = GMAIL_URL_GMAIL
if name and pw:
self.name = name
- self._pw = pw
+ self.password = pw
self._cookieJar = ClientCookie.LWPCookieJar()
opener = ClientCookie.build_opener(ClientCookie.HTTPCookieProcessor(self._cookieJar))
@@ -278,6 +279,7 @@
self._cachedQuotaInfo = None
self._cachedLabelNames = None
+ self._cachedFolderCounts = None
def login(self):
@@ -289,12 +291,12 @@
'at' : 'null',
'service' : 'mail',
'Email': self.name,
- 'Passwd': self._pw,
+ 'Passwd': self.password,
})
else:
data = urllib.urlencode({'continue': URL_GMAIL,
'Email': self.name,
- 'Passwd': self._pw,
+ 'Passwd': self.password,
})
headers = {'Host': 'www.google.com',
@@ -369,6 +371,11 @@
# TODO: Do this better.
try:
self._cachedQuotaInfo = items[D_QUOTA]
+ self._cachedFolderCounts = {}
+ for category in items[D_CATEGORIES][0]:
+ self._cachedFolderCounts[category[CT_NAME]] = category[CT_COUNT]
+ for summary in items[D_DEFAULTSEARCH_SUMMARY][0]:
+ self._cachedFolderCounts[summary[CT_NAME]] = summary[CT_COUNT]
except KeyError:
pass
#pprint.pprint(items)
@@ -481,6 +488,15 @@
return self._cachedLabelNames
+ def getFolderCounts(self, refresh = False):
+ """
+ """
+ # TODO: Change this to a property?
+ if not self._cachedFolderCounts or refresh:
+ # TODO: Handle this better...
+ self.getMessagesByFolder(U_INBOX_SEARCH)
+
+ return self._cachedFolderCounts
def getMessagesByLabel(self, label, allPages = False):
"""
Modified: trunk/bigboard/stocks/mail/MailStock.py
==============================================================================
--- trunk/bigboard/stocks/mail/MailStock.py (original)
+++ trunk/bigboard/stocks/mail/MailStock.py Mon May 12 19:13:06 2008
@@ -14,10 +14,11 @@
import bigboard.google_stock as google_stock
from bigboard.big_widgets import CanvasHBox, CanvasVBox, Button, Header, PrelightingCanvasBox
import bigboard.libbig as libbig
-import bigboard.gmailimap.gmailimap as gmailimap
#TODO: add a scrollable view for emails
#import bigboard.scroll_ribbon as scroll_ribbon
+import bigboard.libgmail.libgmail as libgmail
+
_logger = logging.getLogger('bigboard.stocks.MailStock')
def replace_chr(m):
@@ -54,11 +55,6 @@
# Return the sanely filtered content
return textContent.getvalue()
-def make_folder_name_pretty(folder_name):
- if folder_name.find("[Gmail]/") == 0:
- return folder_name[len("[Gmail]/"):]
- return folder_name
-
class LabelSlideout(ThemedSlideout):
__gsignals__ = {
'changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING, )),
@@ -68,11 +64,12 @@
vbox = CanvasVBox(border_color=0x0000000ff, spacing=4)
self.get_root().append(vbox)
header = Header(topborder=False)
- account_text = hippo.CanvasText(classes='header', text=ga.imap_user)
+ account_text = hippo.CanvasText(classes='header', text=ga.name)
header.append(account_text, hippo.PACK_EXPAND)
vbox.append(header)
try:
- folderCounts = ga.get_folder_unread_counts()
+ folderCounts = ga.getFolderCounts()
+ folderCounts["unread"] = ga.getUnreadMsgCount()
except urllib2.URLError:
error = hippo.CanvasText(text=google_stock.FAILED_TO_CONNECT_STRING)
vbox.append(error)
@@ -83,14 +80,14 @@
box.connect('button-release-event', self.on_button_release_event, label)
vbox.append(box)
hbox = CanvasHBox(spacing=4, padding=4)
- text= hippo.CanvasText(text=make_folder_name_pretty(label), xalign=hippo.ALIGNMENT_START)
+ text= hippo.CanvasText(text=label, xalign=hippo.ALIGNMENT_START)
hbox.append(text)
text= hippo.CanvasText(text=number, xalign=hippo.ALIGNMENT_START)
hbox.append(text, flags=hippo.PACK_END)
box.append(hbox)
- def on_button_release_event (self, hippo_item, event, label):
- self.emit('changed', label)
+ def on_button_release_event (self, hippo_item, event, label_text):
+ self.emit('changed', label_text)
self.emit('close', True)
class EmailSlideout(ThemedSlideout):
@@ -99,31 +96,25 @@
vbox = CanvasVBox(border_color=0x0000000ff, spacing=4)
self.get_root().append(vbox)
self.__header = Header(topborder=False)
- self.id = thread[0]
+ self.id = thread.id
- subject = gmail_jshtml_str_parse(thread[1]['subject'])
+ subject = gmail_jshtml_str_parse(thread.subject)
subject_box = hippo.CanvasText(classes='header', text=subject)
self.__header.append(subject_box, hippo.PACK_EXPAND)
vbox.append(self.__header)
- # for key in thread[1].keys():
- # _logger.debug("key %s" % key)
-
- value = thread[1]["date"]
- s = gmail_jshtml_str_parse(value)
- box = hippo.CanvasText(text=s, xalign=hippo.ALIGNMENT_START)
- vbox.append(box)
- message = thread[1]
- while message.is_multipart():
- message = message.get_payload(0)
-
- if len(message.get_payload()) <= 200:
- value = message.get_payload()
- else:
- value = message.get_payload()[:200] + "..."
- box = hippo.CanvasText(text=value, xalign=hippo.ALIGNMENT_START)
- vbox.append(box)
+ for key in ("date", "categories", "snippet"):
+ value = getattr(thread, key, None)
+ if value:
+ if type(value) is list:
+ s = ", ".join(value)
+ if type(value) is str:
+ _logger.debug("passing in %s" % value)
+ s = gmail_jshtml_str_parse(value)
+
+ box = hippo.CanvasText(text=s, xalign=hippo.ALIGNMENT_START)
+ vbox.append(box)
#todo: nicify email, strip out junk, and show actual email
#email_source = thread[len(thread)-1].source
@@ -163,9 +154,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
@@ -177,65 +169,61 @@
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.imap_user or \
- password != self.__google_account.imap_pass:
- self.__google_account = gmailimap.ImapAccount({'imap_server' : 'imap.gmail.com', 'imap_port' : 993, 'imap_user' : username, 'imap_pass' : password, 'smtp_server' : 'smtp.gmail.com', 'smtp_port' : 587})
- self.__google_account.login_ssl()
+ if self.__google_account is None or username != self.__google_account.name or \
+ password != self.__google_account.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_ssl()
+ self.__google_account.login()
self.__logged_in = True
- threads = self.__google_account.get_messages_by_folder(self.__folder, max_count=self.__display_limit)
-
+ if self.__folder == 'inbox':
+ threads = self.__google_account.getMessagesByFolder(self.__folder)
+ elif self.__folder == 'unread':
+ threads = self.__google_account.getUnreadMessages()
+ else:
+ threads = self.__google_account.getMessagesByLabel(self.__folder)
+
self._box.remove_all()
- account = hippo.CanvasText(classes='header', text=self.__google_account.imap_user)
+ account = hippo.CanvasText(classes='header', text=self.__google_account.name)
self._box.append(account)
box = PrelightingCanvasBox()
box.connect("button-press-event", self.create_label_slideout, self.__google_account)
self._box.append(box)
- label = hippo.CanvasText(text=make_folder_name_pretty(self.__folder), font="14px Bold Italic")
+ label = hippo.CanvasText(text=self.__folder, font="14px Bold Italic")
box.append(label)
i = 0
for thread in threads:
if i >= self.__display_limit: break
- subject = gmail_jshtml_str_parse(thread[1]['subject'], True)
+ subject = gmail_jshtml_str_parse(thread.subject, True)
box = PrelightingCanvasBox()
box.connect("button-press-event", self.create_email_slideout, thread)
self._box.append(box)
- seenFlag = thread[2]
- if seenFlag:
- email = hippo.CanvasText(markup=subject, xalign=hippo.ALIGNMENT_START)
- else:
- email = hippo.CanvasText(markup=subject, xalign=hippo.ALIGNMENT_START, font="Bold")
+ email = hippo.CanvasText(markup=subject, xalign=hippo.ALIGNMENT_START)
box.append(email)
i += 1
- folder_unread_count = self.__google_account.get_folder_unread_count(self.__folder)
- footer = hippo.CanvasText(classes='footer', text="%s unread" % folder_unread_count, font="14px Bold Italic")
+ labelsDict = self.__google_account.getFolderCounts()
+ footer = hippo.CanvasText(classes='footer', text="%s unread" % labelsDict['inbox'], font="14px Bold Italic")
self._box.append(footer)
print "updated mailbox"
- except gmailimap.NoLoginError, e:
+ except libgmail.GmailLoginFailure:
self._box.remove_all()
self.__logged_in = False
if self._login_button.get_property("text") == google_stock.CHECKING_LOGIN_STRING:
- error_text = google_stock.FAILED_TO_LOGIN_STRING
- elif str(e.message).find("not enabled for IMAP") >=0:
- # TODO: provide a link to the settings page once the mail stock design is finalized
- error_text = "Enable IMAP in your Google mail settings for " + username
- # this will force us to check the account again during the next polling task
- self.__google_account = None
- else:
- error_text = e.message
- error = hippo.CanvasText(text=error_text, size_mode=hippo.CANVAS_SIZE_WRAP_WORD)
- self._box.append(error)
+ error = hippo.CanvasText(text=google_stock.FAILED_TO_LOGIN_STRING, size_mode=hippo.CANVAS_SIZE_WRAP_WORD)
+ self._box.append(error)
self._login_button.set_property('text', google_stock.LOGIN_TO_GOOGLE_STRING)
self._box.append(self._login_button)
except urllib2.URLError:
@@ -270,16 +258,16 @@
self.show_slideout(widget)
def create_email_slideout(self, widget, hippo_event, data):
- if type(self.__slideout) is EmailSlideout and self.__slideout.id == data[0] and \
+ if type(self.__slideout) is EmailSlideout and self.__slideout.id == data.id and \
self.__last_slideout_event_time == gtk.get_current_event_time():
self.__slideout = None
return
self.__slideout = EmailSlideout(data)
self.show_slideout(widget)
- def on_label_changed (self, slideout, label):
+ def on_label_changed(self, slideout, label):
self.__folder = label
- self.__update_email_box(self.__google_account.imap_user, self.__google_account.imap_pass)
+ self.__update_email_box(self.__google_account.name, self.__google_account.password, self.__google_account.domain)
def __on_more_button(self):
libbig.show_url("http://mail.google.com/mail")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]