Hi there,
This is a quick 'n dirty summary support for the Camel POP provider.
I'm not sure how this could be useful for Evolution, as Evolution
doesn't use support for summaries with POP accounts (it filters the
messages from the cache to a local folder of which its Camel provider
has summary support).
After this patch, you can use the POP Cache as only copy where the final
message is stored (if cached). It will create a summary file and
use/load that one for displaying the summary.
This has only been tested with tinymail, as I don't really feel like
adjusting Evolution not to do filtering but rather displaying POP
accounts like any other account (which is what would test this).
Note that this code is going to be slower than not supporting summaries
because I need the "TOP %s 1" of each message when refreshing the folder
info, whereas Evolution (if it uses the current filter technique) only
needs the list of UIDs (the LIST POP command).
This quick 'n dirty implementation is not tested very well. I still need
to check for silly memory leaks and stuff like that too.
As usual I send this stuff early so that the Evolution hackers have a
idea of what I'm cooking early on (I'm pro REAL development, rather than
pro bureaucratic development by only sending uber-cool finished patches:
that is not how software development works the best -- but anyway --).
Feel free to take a look at this, and let me know what you think of it.
I'm for example thinking about making it possible to disabling the
summary support (for example because Evolution, for example, doesn't
need it). It's going in tinymail's camel-lite anyhow .. but I would of
course prefer to have the delta of changes small.
--
Philip Van Hoof, software developer
home: me at pvanhoof dot be
gnome: pvanhoof at gnome dot org
http://www.pvanhoof.be/blog
Index: camel-pop3-folder.c
===
--- camel-pop3-folder.c (revision 1300)
+++ camel-pop3-folder.c (working copy)
@@ -54,8 +54,9 @@
static void pop3_sync (CamelFolder *folder, gboolean expunge, CamelException *ex);
static gint pop3_get_message_count (CamelFolder *folder);
static GPtrArray *pop3_get_uids (CamelFolder *folder);
static gboolean pop3_set_message_flags (CamelFolder *folder, const char *uid, guint32 flags, guint32 set);
+static CamelMimeMessage *pop3_get_top (CamelFolder *folder, const char *uid, gboolean full, CamelException *ex);
static void
camel_pop3_folder_class_init (CamelPOP3FolderClass *camel_pop3_folder_class)
@@ -123,19 +124,44 @@
camel_pop3_folder_new (CamelStore *parent, CamelException *ex)
{
CamelFolder *folder;
+ CamelPOP3Store *p3store = (CamelPOP3Store*) parent;
+ gchar *summary_file;
d(printf("opening pop3 INBOX folder\n"));
folder = CAMEL_FOLDER (camel_object_new (CAMEL_POP3_FOLDER_TYPE));
camel_folder_construct (folder, parent, "inbox", "inbox");
+ summary_file = g_strdup_printf ("%s/summary.mmap", p3store->root);
+ folder->summary = camel_folder_summary_new (folder);
+ camel_folder_summary_set_build_content (folder->summary, TRUE);
+ camel_folder_summary_set_filename (folder->summary, summary_file);
+
+ if (camel_folder_summary_load (folder->summary) == -1) {
+ camel_folder_summary_clear (folder->summary);
+ camel_folder_summary_touch (folder->summary);
+ camel_folder_summary_save (folder->summary);
+ camel_folder_summary_load (folder->summary);
+ }
+ g_free (summary_file);
+
+
/* mt-ok, since we dont have the folder-lock for new() */
camel_folder_refresh_info (folder, ex);/* mt-ok */
if (camel_exception_is_set (ex)) {
camel_object_unref (CAMEL_OBJECT (folder));
folder = NULL;
}
+
+ if (!folder->summary) {
+ camel_object_unref (CAMEL_OBJECT (folder));
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("Could not load summary for INBOX"));
+ return NULL;
+ }
+ folder->folder_flags |= CAMEL_FOLDER_HAS_SUMMARY_CAPABILITY;
+
return folder;
}
@@ -271,11 +297,31 @@
camel_pop3_engine_command_free(pop3_store->engine, pcl);
+ for (i=0;iuids->len;i++)
+ {
+ CamelPOP3FolderInfo *fi = pop3_folder->uids->pdata[i];
+ CamelMessageInfoBase *mi;
+
+ mi = (CamelMessageInfoBase*) camel_folder_summary_uid (folder->summary, fi->uid);
+ if (!mi)
+ {
+ if (pop3_store->engine->capa & CAMEL_POP3_CAP_TOP) {
+ CamelMimeMessage *msg = pop3_get_top (folder, fi->uid, FALSE, NULL);
+ if (msg) camel_object_unref (CAMEL_OBJECT (msg));
+ } else {
+ CamelMimeMessage *msg = pop3_get_message (folder, fi->uid, NULL);
+ if (msg) camel_object_unref (CAMEL_OBJECT (msg));
+ }
+ } else
+ camel_message_info_free (mi);
+ }
+
if (pop3_store->engine->capa & CAMEL_POP3_CAP_UIDL) {
camel_pop3_engine_command_free(pop3_store->engine, pcu);
} else {
for (i=0;iuids->len;i++) {
CamelPOP3FolderInfo *fi = pop3_folder->uids->pdata[i];
+
if (fi->cmd) {
camel_pop3_engine_command_free(pop3_store->engine, fi->cmd);
fi->cmd = NU