diff --git a/lgconstants.py b/lgconstants.py index b4ab112..7cbde6f 100644 --- a/lgconstants.py +++ b/lgconstants.py @@ -1,4 +1,6 @@ -# +# Despite the following warning, changes were made to this file by Rafael C. +# Almeida in 2008/01/07 20:14:10 GMT+3 + # Generated file -- DO NOT EDIT # # Note: This file is now edited! 2005-04-25 @@ -215,6 +217,8 @@ U_COMPOSE_CC = "cc" U_COMPOSE_BCC = "bcc" U_COMPOSE_BODY = "body" U_PRINT_THREAD = "pth" +ARCH_EMAIL = "nvp_a_arch" +SPAM_EMAIL = "nvp_a_sp" CONV_VIEW = "conv" TLIST_VIEW = "tlist" PREFS_VIEW = "prefs" diff --git a/libgmail.py b/libgmail.py index 8e29b82..c84488b 100755 --- a/libgmail.py +++ b/libgmail.py @@ -1,11 +1,14 @@ #!/usr/bin/env python -# + +# Changes to this file were made by Rafael C. Almeida in +# 2008/01/07 20:14:10 GMT+3 + # libgmail -- Gmail access via Python # ## To get the version number of the available libgmail version. ## Reminder: add date before next release. This attribute is also ## used in the setup script. -Version = '0.1.8' # (Nov 2007) +Version = '0.1.8-rafael4' # (Nov 2007) # Original author: follower@myrealbox.com # Maintainers: Waseem (wdaher@mit.edu) and Stas Z (stas@linux.isbeter.nl) @@ -93,7 +96,10 @@ def _parsePage(pageContent): try: exec data in {'__builtins__': None}, {'D': lambda x: result.append(x)} except SyntaxError,info: - print info + # printing something is a very annoying behaviour if you want to catch + # the error and handle it. It should be passed to GmailError classe + # somehow. + #print info raise GmailError, 'Failed to parse data returned from gmail.' items = result @@ -381,7 +387,8 @@ class GmailAccount: try: resp = self.opener.open(req) except urllib2.HTTPError,info: - print info + #once again, not very nice to print stuff like that + #print info return None pageData = resp.read() @@ -564,7 +571,7 @@ class GmailAccount: return at - def sendMessage(self, msg, asDraft = False, _extraParams = None): + def sendMessage(self, msg, asDraft = False, replyTo = None, _extraParams = None): """ `msg` -- `GmailComposedMessage` instance. @@ -578,9 +585,11 @@ class GmailAccount: `id` (and `_account`) fields on success or None on failure. """ + if replyTo is None: + replyTo = "" # TODO: Handle drafts separately? params = {U_VIEW: [U_SENDMAIL_VIEW, U_SAVEDRAFT_VIEW][asDraft], - U_REFERENCED_MSG: "", + U_REFERENCED_MSG: replyTo, U_THREAD: "", U_DRAFT_MSG: "", U_COMPOSEID: "1", @@ -638,7 +647,16 @@ class GmailAccount: req = urllib2.Request(_buildURL(), data = data) req.add_header(*contentTypeHeader) - items = self._parsePage(req) + # My job is just to make dirt fixes, let the original author find a good + # way to do it :) + if replyTo: + try: + items = self._parsePage(req) + except AttributeError: + pass + return + else: + items = self._parsePage(req) # TODO: Check composeid? # Sometimes we get the success message @@ -700,6 +718,37 @@ class GmailAccount: # TODO: Mark as trashed on success? return result + def archiveThread(self, thread): + params = { + ARCH_EMAIL: '', + U_ACTION_THREAD: thread.id, + U_ACTION_TOKEN: self._getActionToken(), + } + #XXX: I only know how to get the value I need on html view, maybe + # someone can fix this later. I'm only a python programmer, I really + # don't know -- nor want -- to get into javascript mess. + tmp = _buildURL(**params) + tmp = tmp.replace('ui=1', 'ui=html') + # I don't expect the information retrival to work using html view. It's + # not that important for archiving mail anyways... + try: + self._parsePage(tmp) + except GmailError: + pass + + def reportSpam(self, thread): + params = { + SPAM_EMAIL: '', + U_ACTION_THREAD: thread.id, + U_ACTION_TOKEN: self._getActionToken(), + } + #XXX: Same as above + tmp = _buildURL(**params) + tmp = tmp.replace('ui=1', 'ui=html') + try: + self._parsePage(tmp) + except GmailError: + pass def _createUpdateRequest(self, actionId): #extraData): """ @@ -733,7 +782,7 @@ class GmailAccount: # Note: Label name cache is updated by this call as well. (Handy!) items = self._parsePage(req) - print items + #print items return (items[D_ACTION_RESULT][0][AR_SUCCESS] == 1) @@ -894,7 +943,7 @@ class GmailAccount: pageData = self._retrievePage(request) if pageData.find("The contact was successfully added") == -1: - print pageData + #print pageData if pageData.find("already has the email address") > 0: raise Exception("Someone with same email already exists in Gmail.") elif pageData.find("https://www.google.com/accounts/ServiceLogin"): @@ -947,10 +996,10 @@ class GmailAccount: # TODO: Perhaps signal this in some nice way # to the end user? - print "Unable to delete." - print "Has someone else been modifying the contacts list while we have?" - print "Old version of person:",gmailContact - print "New version of person:",newVersionOfPersonToDelete + #print "Unable to delete." + #print "Has someone else been modifying the contacts list while we have?" + #print "Old version of person:",gmailContact + #print "New version of person:",newVersionOfPersonToDelete return False ## Don't remove this. contact stas @@ -1228,7 +1277,8 @@ class GmailSearchResult: if not type(threadsInfo[0]) is types.ListType: threadsInfo = [threadsInfo] except IndexError: - print "No messages found" + #print "No messages found" + pass self._account = account self.search = search # TODO: Turn into object + format nicely.