So, after a while of hacking. I have Finally got things working. Also
doing it, recursive!

One thing that keeps bothering me : 
It opens up a "save messages" dialog for each subfolder at the same
time. Gives you alot of windows, and makes it hard to know wich folder
each window represents.

One idea i had to give that an nicer look would be to cut and paste the
'static' functions that "em_utils_save_messages" needs. NOT a nice
sollution, but that way, i could atleast get the title of the  window to
say what folder one is saving.

Anyone got a nicer sollution, i'd be glad for some input!

Best regards

/Nicklas
---- the plugin code ------
/*
 * Author : Nicklas Boman <[EMAIL PROTECTED]>
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <glib.h>
#include <glib/gi18n.h>

#include <camel/camel-session.h>
#include <camel/camel-store.h>
#include <camel/camel-url.h>

#include "mail/em-popup.h"
#include "mail/mail-mt.h"
#include "mail/mail-ops.h"
#include "mail/em-utils.h"

void org_gnome_export_mail_folder (EPlugin *ep, EMPopupTargetFolder
*target);
void do_export_mail_folder (char *uri);

extern CamelSession *session;

static void
export_mail_folder (char *uri, CamelFolder *folder, gpointer data) {
        GPtrArray *pids;

        if (folder) {
                camel_object_ref (folder);

                pids = g_ptr_array_new();
                pids = camel_folder_get_uids((CamelFolder *)folder);

                em_utils_save_messages(0, folder, pids);
        
                camel_object_unref (folder);
        }
}


static void 
export_mail_folder_recursive (char *uri, CamelFolder *folder, gpointer
data) {
        guint32  flags = CAMEL_STORE_FOLDER_INFO_FAST |
CAMEL_STORE_FOLDER_INFO_RECURSIVE;
        CamelFolderInfo *fi;
        CamelException ex;
        CamelStore *fromstore;
        CamelURL *url;
        GList *pending = NULL;
        
        camel_exception_init (&ex);
        
        if (camel_store_supports_subscriptions (fromstore)) 
                flags |= CAMEL_STORE_FOLDER_INFO_SUBSCRIBED;
        
        if (!(fromstore = camel_session_get_store (session, uri, &ex))) {
                printf("Error getting 'fromstore'\n");
                return;
        }
        
        url = camel_url_new (uri, NULL);
        
        if(!(fi = camel_store_get_folder_info (fromstore, url->fragment,flags,
&ex))){
                printf("Error getting store folder info\n");
                return;
        }

        pending = g_list_append (pending, fi);
        
        while (pending) {
                CamelFolderInfo *info = pending->data;
                
                pending = g_list_remove_link (pending, pending);

                while (info) {
                        CamelFolder *fromfolder = NULL;

                        if (info->child)
                                pending = g_list_append (pending, info->child);
                        if ((info->flags & CAMEL_FOLDER_NOSELECT) == 0) {
                                if (!(fromfolder = camel_store_get_folder 
(fromstore,
info->full_name, 0, &ex))) {
                                        printf("Error getting store folder\n");
                                        return;
                                
                                }

                                printf("Name = %s\n", info->full_name); // 
DEBUG PURPOSES

                                export_mail_folder(url,fromfolder, data);
                        }
                        info = info->next;
                }
        }

}

void 
do_export_mail_folder(char *uri) 
{
        CamelURL *camelurl;
        int fid;
        
        camelurl = camel_url_new(uri, NULL);
        
        fid =
mail_get_folder(uri,0,export_mail_folder_recursive,camelurl,mail_thread_queued_slow);
}

void
org_gnome_export_mail_folder (EPlugin *ep, EMPopupTargetFolder *target)
{
        if(target->uri == NULL)
                return;

        do_export_mail_folder(target->uri);
}

_______________________________________________
evolution-hackers maillist  -  [EMAIL PROTECTED]
http://lists.ximian.com/mailman/listinfo/evolution-hackers

Reply via email to