FreePOPs GMail Plugin Improvement Patch Clarence Dang 2007-07-23 Changes ~~~~~~~ * Add "includeMyEmails" option to include _all_ emails in a conversation [requested @ http://freepops.diludovico.it/recycle-bin/1346-gmail-sent-mails.html] * Fix bug without "includeMyEmails": if you ever replied to the conversation and the last message was not from you, it would not include the last message Problems ~~~~~~~~ * I'm not sure how this affects "getnew" for conversations (the previous implementation might have been wrong anyway - see the "TODO2 ... GetNew") * "sent" is buggy without "includeMyEmails". However, this bug was there before this patch Usage ~~~~~ This patch applies against :pserver:anonymous@freepops.cvs.sourceforge.net: /cvsroot/freepops/freepops/src/lua/gmail.lua -r1.44 (post 2007-01-14) with FreePOPs 0.2.5. --- gmail.lua 2007-07-22 20:58:15.000000000 +1000 +++ gmail.lua 2007-07-23 21:16:58.000000000 +1000 @@ -9,11 +9,12 @@ -- Revised by Tommaso Colombo -- Incorporating jbobowski fix posted 26 April 2006 -- Incorporating lowang fix posted 25 Aug 2006 +-- "includeMyEmails" feature and fix by 23 Jul 2007 -- -- ************************************************************************** -- -- these are used in the init function -PLUGIN_VERSION = "0.0.45" +PLUGIN_VERSION = "0.0.46" PLUGIN_NAME = "GMail.com" PLUGIN_REQUIRE_VERSION = "0.2.0" PLUGIN_LICENSE = "GNU/GPL" @@ -35,6 +36,7 @@ Se hai creato delle label personalizzate en = [[ Used for selecting the folder to operate on (inbox is the default one).
The standard folders are: inbox, starred, sent, all, spam, trash.
+Note: "sent" is buggy without "includeMyEmails".
Here is an example of a username to get the email from the starred folder:
foo@gmail.com?folder=starred

@@ -69,6 +71,16 @@ or in the My Documents directory (Window into your email client.]], } }, + {name = "includeMyEmails", description = { + en = [[ +Possible values:
+- 1: Normally, emails in conversations from your gmail address are not included. +This forces them to be included. For instance, to retrieve all emails in +starred conversations:
+foo@gmail.com?folder=starred&includeMyEmails=1
+]], + } + }, } PLUGIN_DESCRIPTIONS = { it=[[ @@ -165,6 +177,7 @@ internal_state = { strPassword = nil, strFolder = nil, strActions = nil, + strIncludeMyEmails = nil, brBrowser = nil, strCookieVal = nil, strCookieSID = nil, @@ -265,7 +278,8 @@ function key() ("gmail.com").. internal_state.strPassword.. -- this asserts strPassword ~= nil (internal_state.strFolder or "").. - (internal_state.strActions or "") + (internal_state.strActions or "").. + ("*" .. (internal_state.strIncludeMyEmails or "")) end -------------------------------------------------------------------------------- @@ -479,6 +493,13 @@ function user(pstate,username) internal_state.strFolder = folder internal_state.strActions = freepops.MODULE_ARGS.act or "" + if freepops.MODULE_ARGS.includeMyEmails == "1" then + log.say("Including own emails.\n") + internal_state.strIncludeMyEmails = "1" + else + log.say("Excluding own emails.\n") + end + return POPSERVER_ERR_OK end @@ -640,35 +661,64 @@ function stat(pstate) local iPos1, sUIDL, sFrom, iNew, iStarred local iPos2, parentUIDL, sSender local myemail = internal_state.strUserName .. "@gmail.com" + local includeMyEmails = internal_state.strIncludeMyEmails local subThreads local body, err local MessageList = {} local strMessageListRegExp = globals.strMessageListRegExp + + local convStarterEmail + + -- log.say("action_f: s='" .. s .. "'\n") _, iPos1, sUIDL, iNew, iStarred, sFrom = string.find(s, strMessageListRegExp) while sUIDL ~= nil do + -- log.say("loop: sUIDL=" .. sUIDL .. " sFrom='" .. sFrom .. "'\n") if not GetNew or (GetNew and iNew == "1") then -- Check for conversations -- + + -- sFrom is like 'A B, + -- me (3)' + -- where: + -- 1. The first is the conversation starter. + -- 2. The other 's are other contacts in the + -- conversation. + -- 3. The '(3)' is the number of messages in the conversation + -- but is not present if there is only 1 message. + -- + -- An actual sFrom is more heavily escaped than above, hence + -- the more complex regexps: subThreads = string.match(sFrom, "%((%d+)%)$") + convStarterEmail = string.match(sFrom, "^(.-)\\\"\\>") + -- log.say("\tconvStarterEmail='" .. convStarterEmail .. "'\n") - -- TODO: before adding message, check also if sender is self - -- important for threads... - -- TODO2: mark message as unread if it was new (GetNew) - -- log.say(sFrom .. " - " .. myemail .. "\n") - if string.find(sFrom, "("..myemail..")") == nil then - table.insert(MessageList, { - ["sUIDL"] = sUIDL, - ["iSize"] = 1, - ["iNew"] = iNew, - ["iStarred"] = iStarred }) - end - -- If it is a conversation, then get sub messages + -- Single message -- - if subThreads ~= nil then + if subThreads == nil then + -- TODO: For the "sent" folder, sFrom actually lists the + -- senders. If !includeMyEmails, this check is + -- bogus for that folder. + if includeMyEmails or string.find(convStarterEmail, "("..myemail..")") == nil then + -- log.say("\taccept email\n"); + -- TODO2: mark message as unread if it was new (GetNew) + -- log.say(sFrom .. " - " .. myemail .. "\n") + table.insert(MessageList, { + ["sUIDL"] = sUIDL, + ["iSize"] = 1, + ["iNew"] = iNew, + ["iStarred"] = iStarred }) + else + -- log.say("\treject email\n"); + end + + -- If it is a conversation, then get sub messages including itself + -- + else + -- log.say("\thas subthreads\n") parentUIDL = sUIDL uri = string.format( globals.strMessageThreadUrl, @@ -681,18 +731,24 @@ function stat(pstate) globals.strMessageThreadRegExp) while sUIDL ~= nil do - if sUIDL ~= parentUIDL and sSender ~= myemail then + -- log.say("\t\tsSender='" .. sSender .. "'\n") + -- TODO: For the "sent" folder, if !includeMyEmails, + -- the sender check should be reversed. + if includeMyEmails or sSender ~= myemail then + -- log.say("\t\t\taccept email\n"); table.insert(MessageList, { ["sUIDL"] = sUIDL, ["iSize"] = 1, ["iNew"] = 0, ["iStarred"] = iStarred }) + else + -- log.say("\t\t\treject email\n"); end _, iPos2, sUIDL, iStarred, sSender = string.find(body, globals.strMessageThreadRegExp, iPos2) end - end + end -- if single message end _, iPos1, sUIDL, iNew, iStarred, sFrom = string.find( s, strMessageListRegExp, iPos1)