From a4db79a6d67be58e2922bc101e9db92b5a24d6cf Mon Sep 17 00:00:00 2001 From: Iain Holmes Date: Tue, 8 Jan 2002 16:42:55 +0000 Subject: Make the mbox importer check for Mozilla status headers and act on them. svn path=/trunk/; revision=15265 --- mail/ChangeLog | 14 ++++++ mail/importers/Makefile.am | 3 +- mail/importers/evolution-mbox-importer.c | 82 ++++++++++++++++++++++++++++++-- mail/importers/mozilla-status-headers.h | 29 +++++++++++ 4 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 mail/importers/mozilla-status-headers.h diff --git a/mail/ChangeLog b/mail/ChangeLog index 962845a38b..18e9198358 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,17 @@ +2002-01-08 Iain Holmes + + * importers/evolution-mbox-importer.c (string_to_int): Takes a hex + string and converts it to an int. + (get_info_from_mozilla): Creates a CamelMessageInfo structure from + the X-Mozilla-Status header. + (process_item_fn): Check for the X-Mozilla-Status header and if it + is present call get_info_from_mozilla. If get_info_from_mozilla + returns that the message was marked as deleted but never expunged + it isn't imported. + + * importers/mozilla-status-headers.h: Stuff Evolution cares about + from the mozilla header. + 2002-01-07 Jeffrey Stedfast * mail-config.c (mail_config_set_new_mail_notify_sound_file): Renamed. diff --git a/mail/importers/Makefile.am b/mail/importers/Makefile.am index 6767fde715..aa6049ca45 100644 --- a/mail/importers/Makefile.am +++ b/mail/importers/Makefile.am @@ -16,7 +16,8 @@ liboutlook_la_SOURCES = \ evolution-outlook-importer.c liboutlook_la_LDFLAGS = -version-info 0:0:0 -libmbox_la_SOURCES = evolution-mbox-importer.c +libmbox_la_SOURCES = evolution-mbox-importer.c \ + mozilla-status-headers.h libmbox_la_LDFLAGS = -version-info 0:0:0 oafdir = $(datadir)/oaf diff --git a/mail/importers/evolution-mbox-importer.c b/mail/importers/evolution-mbox-importer.c index b977ce6ac7..1dfeb93b40 100644 --- a/mail/importers/evolution-mbox-importer.c +++ b/mail/importers/evolution-mbox-importer.c @@ -25,6 +25,7 @@ #endif #include +#include #include #include @@ -37,6 +38,8 @@ #include #include +#include "mozilla-status-headers.h" + #include "mail/mail-importer.h" #include "mail-tools.h" @@ -66,6 +69,67 @@ void mail_importer_module_init (void); /* EvolutionImporter methods */ +static int +string_to_int (const char *str) +{ + int result = 0; + char *s; + + for (s = (char *) str; *s; s++) { + char c = toupper (*s); + + result *= 16; + + if (c >= '0' && c <= '9') { + result += (c - '0'); + } else if (c >= 'A' && c <= 'F') { + result += (c - 'A'); + } + } + + g_print ("%s became %d\n", str, result); + + return result; +} + +static CamelMessageInfo * +get_info_from_mozilla (const char *mozilla_status, + gboolean *deleted) +{ + int status; + CamelMessageInfo *info; + + info = g_new0 (CamelMessageInfo, 1); + + *deleted = FALSE; + + status = string_to_int (mozilla_status); + if (status == 0) { + return info; + } + + if (status & MSG_FLAG_EXPUNGED) { + *deleted = TRUE; + g_free (info); + + return NULL; + } + + if (status & MSG_FLAG_READ) { + info->flags |= CAMEL_MESSAGE_SEEN; + } + + if (status & MSG_FLAG_MARKED) { + info->flags |= CAMEL_MESSAGE_FLAGGED; + } + + if (status & MSG_FLAG_REPLIED) { + info->flags |= CAMEL_MESSAGE_ANSWERED; + } + + return info; +} + static void process_item_fn (EvolutionImporter *eimporter, CORBA_Object listener, @@ -76,6 +140,7 @@ process_item_fn (EvolutionImporter *eimporter, MailImporter *importer = (MailImporter *) mbi; gboolean done = FALSE; CamelException *ex; + char *mozilla_status; if (importer->folder == NULL) { GNOME_Evolution_ImporterListener_notifyResult (listener, @@ -96,6 +161,7 @@ process_item_fn (EvolutionImporter *eimporter, /* Import the next message */ CamelMimeMessage *msg; CamelMessageInfo *info; + gboolean deleted; IN; msg = camel_mime_message_new (); @@ -106,10 +172,20 @@ process_item_fn (EvolutionImporter *eimporter, done = TRUE; } + mozilla_status = camel_medium_get_header (CAMEL_MEDIUM (msg), "X-Mozilla-Status"); + if (mozilla_status != NULL) { + g_print ("Got Mozilla status header: %s\n", mozilla_status); + info = get_info_from_mozilla (mozilla_status, &deleted); + } else { + info = g_new0 (CamelMessageInfo, 1); + } + + if (deleted == FALSE) { /* write the mesg */ - info = g_new0 (CamelMessageInfo, 1); - camel_folder_append_message (importer->folder, msg, info, ex); - g_free (info); + camel_folder_append_message (importer->folder, msg, info, ex); + g_free (info); + } + camel_object_unref (CAMEL_OBJECT (msg)); if (camel_exception_is_set (ex)) { g_warning ("Failed message %d", mbi->num); diff --git a/mail/importers/mozilla-status-headers.h b/mail/importers/mozilla-status-headers.h new file mode 100644 index 0000000000..f459d6ec8f --- /dev/null +++ b/mail/importers/mozilla-status-headers.h @@ -0,0 +1,29 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* mozilla-status-headers.h + * + * Authors: Iain Holmes + * + * Copyright (C) 2001 Ximian, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* Defines copied from nsMsgMessageFlags.h in Mozilla source. */ + +/* Evolution only cares about these headers I think */ +#define MSG_FLAG_READ 0x0001 +#define MSG_FLAG_REPLIED 0x0002 +#define MSG_FLAG_MARKED 0x0004 +#define MSG_FLAG_EXPUNGED 0x0008 -- cgit v1.2.3