summary file read/write routines.
authorbertrand <bertrand@helixcode.com>
Tue, 18 Jan 2000 19:29:48 +0000 (19:29 +0000)
committerBertrand Guiheneuf <bertrand@src.gnome.org>
Tue, 18 Jan 2000 19:29:48 +0000 (19:29 +0000)
2000-01-18  bertrand  <bertrand@helixcode.com>

* camel/providers/mbox/camel-mbox-summary.c (camel_mbox_save_summary):
(mbox_load_summary): summary file read/write routines.

* camel/providers/mbox/camel-mbox-utils.c (parsed_information_to_mbox_summary):
routine to construct the summary after the mbox
file has been parsed and the x-evolution fields
inserted.

* camel/providers/mbox/camel-mbox-utils.c (camel_mbox_write_xev):
dont use the x_evolution field but rather the uid to
determine the presence of "X-Evolution" in the mail.

* camel/providers/mbox/camel-mbox-parser.c (camel_mbox_parse_file):
parse the status and uid values if the x-evolution
has been found.

* camel/providers/mbox/camel-mbox-utils.c (camel_mbox_xev_parse_header_content):
return the parsed status field correctly.

* camel/providers/mbox/camel-mbox-utils.h:
fixed bad prototype.

* camel/providers/mbox/camel-mbox-parser.c (camel_mbox_parse_file):
parse and store the "To:" header.

* camel/providers/mbox/camel-mbox-parser.h:
added a "to" field

* camel/camel-folder-summary.c:
create the arrays here.

* camel/camel-folder-summary.h: the list of
summary information is no longer a GList but
rather a GArray.

Parsing/summary/sync-check is here. Needs testing
and integration with the rest of the folder code.

camel/camel-folder-summary.c
camel/camel-folder-summary.h
camel/providers/mbox/Makefile.am
camel/providers/mbox/camel-mbox-folder.c
camel/providers/mbox/camel-mbox-folder.h
camel/providers/mbox/camel-mbox-parser.c
camel/providers/mbox/camel-mbox-parser.h
camel/providers/mbox/camel-mbox-store.c
camel/providers/mbox/camel-mbox-store.h
camel/providers/mbox/camel-mbox-utils.c
camel/providers/mbox/camel-mbox-utils.h

index 2c6b45b..4d1745e 100644 (file)
@@ -34,8 +34,8 @@ static GtkObjectClass *parent_class=NULL;
 #define CFS_CLASS(so) CAMEL_FOLDER_SUMMARY_CLASS (GTK_OBJECT(so)->klass)
 
 
-static const GList *_get_subfolder_info_list (CamelFolderSummary *summary);
-static const GList *_get_message_info_list (CamelFolderSummary *summary);
+static const GArray *_get_subfolder_info_list (CamelFolderSummary *summary);
+static const GArray *_get_message_info_list (CamelFolderSummary *summary);
 
 static void _finalize (GtkObject *object);
 
@@ -65,8 +65,8 @@ camel_folder_summary_init (gpointer   object,  gpointer   klass)
        CamelFolderSummary *summary = CAMEL_FOLDER_SUMMARY (object);
 
        CAMEL_LOG_FULL_DEBUG ( "camel_folder_summary_init:: Entering\n");
-       summary->subfolder_info_list = NULL;
-       summary->message_info_list = NULL;
+       summary->subfolder_info_list = g_array_new (FALSE, FALSE, sizeof (CamelFolderInfo);
+       summary->message_info_list = g_array_new (FALSE, FALSE, sizeof (CamelMessageInfo);
        CAMEL_LOG_FULL_DEBUG ( "camel_folder_summary_init:: Leaving\n");
 }
 
@@ -116,14 +116,14 @@ camel_folder_summary_new ()
        return gtk_type_new (CAMEL_FOLDER_SUMMARY_TYPE);
 }
 
-static const GList *
+static const GArray *
 _get_subfolder_info_list (CamelFolderSummary *summary)
 {
        return summary->subfolder_info_list;
 }
 
 
-const GList *
+const GArray *
 camel_folder_summary_get_subfolder_info_list (CamelFolderSummary *summary)
 {
        return CFS_CLASS (summary)->get_subfolder_info_list (summary);
@@ -132,13 +132,13 @@ camel_folder_summary_get_subfolder_info_list (CamelFolderSummary *summary)
 
 
 
-static const GList *
+static const GArray *
 _get_message_info_list (CamelFolderSummary *summary)
 {
        return summary->message_info_list;
 }
 
-const GList *
+const GArray *
 camel_folder_summary_get_message_info_list (CamelFolderSummary *summary)
 {
        return CFS_CLASS (summary)->get_message_info_list (summary);
index 0c8f26e..b89c546 100644 (file)
@@ -72,9 +72,9 @@ typedef struct {
 
 typedef struct {
        GtkObject parent_object;
-
-       GList *subfolder_info_list; /* informations on subfolders */
-       GList *message_info_list;   /* informations on messages */
+       GArray *subfolder_info_list; /* informations on subfolders */
+       GArray *message_info_list;   /* informations on messages */
 
 } CamelFolderSummary;
 
@@ -100,8 +100,8 @@ GtkType camel_folder_summary_get_type (void);
 CamelFolderSummary *camel_folder_summary_new ();
 
 /* get information about the messages and the subfolders in the directory */
-const GList *camel_folder_summary_get_subfolder_info_list (CamelFolderSummary *summary);
-const GList *camel_folder_summary_get_message_info_list (CamelFolderSummary *summary);
+const GArray *camel_folder_summary_get_subfolder_info_list (CamelFolderSummary *summary);
+const GArray *camel_folder_summary_get_message_info_list (CamelFolderSummary *summary);
 
 
 
index 247ce55..5dffdc4 100644 (file)
@@ -13,14 +13,16 @@ INCLUDES = -I.. -I$(srcdir)/.. -I$(includedir)      \
 
 libcamelmbox_la_SOURCES =                      \
        camel-mbox-folder.c                     \
-       camel-mbox-store.c                      \
        camel-mbox-parser.c                     \
+       camel-mbox-store.c                      \
+       camel-mbox-summary.c                    \
        camel-mbox-utils.c
 
 libcamelmboxinclude_HEADERS =                  \
        camel-mbox-folder.h                     \
-       camel-mbox-store.h                      \
        camel-mbox-parser.h                     \
+       camel-mbox-store.h                      \
+       camel-mbox-summary.h                    \
        camel-mbox-utils.h
 
 
index 82e5bc1..2420e59 100644 (file)
@@ -2,6 +2,7 @@
 /* camel-mbox-folder.c : Abstract class for an email folder */
 
 /* 
+ * Author : Bertrand Guiheneuf <bertrand@helixcode.com> 
  *
  * Copyright (C) 1999 Helix Code .
  *
@@ -21,7 +22,6 @@
  * USA
  */
 
-/* Author : Bertrand Guiheneuf <bertrand@helixcode.com> */
 
 #include <config.h> 
 
index 6a0d8d6..1f010ce 100644 (file)
@@ -3,7 +3,9 @@
 
 /* 
  *
- * Copyright (C) 1999 Bertrand Guiheneuf <bertrand@helixcode.com> .
+ * Author : Bertrand Guiheneuf <bertrand@helixcode.com> 
+ *
+ * Copyright (C) 1999 Helix Code .
  *
  * This program is free software; you can redistribute it and/or 
  * modify it under the terms of the GNU General Public License as 
index eee41b8..7eee449 100644 (file)
@@ -3,7 +3,9 @@
 
 /* 
  *
- * Copyright (C) 1999 Bertrand Guiheneuf <bertrand@helixcode.com> .
+ * Author : Bertrand Guiheneuf <bertrand@helixcode.com> 
+ *
+ * Copyright (C) 1999 Helix Code .
  *
  * This program is free software; you can redistribute it and/or 
  * modify it under the terms of the GNU General Public License as 
@@ -24,6 +26,7 @@
 
 #include <config.h> 
 #include "camel-mbox-parser.h"
+#include "camel-mbox-utils.h"
 #include "camel-log.h"
 #include "camel-exception.h"
 #include <sys/types.h>
@@ -46,6 +49,9 @@
 #define MBOX_PARSER_SUBJECT_KW "subject:"
 #define MBOX_PARSER_SUBJECT_KW_SZ 8
 
+#define MBOX_PARSER_TO_KW "to:"
+#define MBOX_PARSER_TO_KW_SZ 3
+
 #define MBOX_PARSER_X_EVOLUTION_KW "x-evolution:"
 #define MBOX_PARSER_X_EVOLUTION_KW_SZ 12
 
@@ -100,15 +106,14 @@ clear_message_info (CamelMboxParserMessageInfo *preparsing_info)
        preparsing_info->from = NULL;
        preparsing_info->date = NULL;
        preparsing_info->subject = NULL;
-       preparsing_info->status = NULL;
        preparsing_info->priority = NULL;
        preparsing_info->references = NULL;
        preparsing_info->body_summary = NULL;
        preparsing_info->end_of_headers_offset = 0;
        
-       preparsing_info->x_evolution = NULL;
        preparsing_info->x_evolution_offset = 0;
-       /* reparsing_info->x_evolution_length = 0; */
+       preparsing_info->status = 0;
+       preparsing_info->uid = 0;
                
 }
 
@@ -571,6 +576,8 @@ camel_mbox_parse_file (int fd,
        int real_interval;
        gboolean newline;
        GArray *return_value;
+       gchar *x_ev_header_content;
+
 
        /* get file size */
        fstat_result = fstat (fd, &stat_buf);
@@ -674,6 +681,21 @@ camel_mbox_parse_file (int fd,
                                }
 
 
+                               /* is the next part a "To" header ? */
+                               if (g_strncasecmp (parser->buffer + parser->current_position, 
+                                                 MBOX_PARSER_TO_KW, 
+                                                 MBOX_PARSER_TO_KW_SZ) == 0) {
+
+                                       advance_n_chars (parser, MBOX_PARSER_TO_KW_SZ);
+                                       read_header (parser, (gchar **) ((gchar *)parser +
+                                                    G_STRUCT_OFFSET (CamelMboxPreParser, current_message_info) + 
+                                                    G_STRUCT_OFFSET (CamelMboxParserMessageInfo, to)));
+
+                                       newline = TRUE;
+                                       continue;
+                               }
+
+
                                /* is the next part a "X-evolution" header ? */
                                if (g_strncasecmp (parser->buffer + parser->current_position, 
                                                  MBOX_PARSER_X_EVOLUTION_KW, 
@@ -685,9 +707,19 @@ camel_mbox_parse_file (int fd,
                                        parser->current_message_info.x_evolution_offset = parser->real_position
                                                - parser->current_message_info.message_position;
                                        advance_n_chars (parser, MBOX_PARSER_X_EVOLUTION_KW_SZ);
-                                       read_header (parser, (gchar **) ((gchar *)parser +
-                                                    G_STRUCT_OFFSET (CamelMboxPreParser, current_message_info) + 
-                                                    G_STRUCT_OFFSET (CamelMboxParserMessageInfo, x_evolution)));
+                                       
+                                       /* read the header */
+                                       read_header (parser, &x_ev_header_content);
+                                       
+                                       /* parse it and put the result in the uid and status fields */
+                                       camel_mbox_xev_parse_header_content (x_ev_header_content,       
+                                                                            (guint32 *) ((gchar *)parser +
+                                                                                         G_STRUCT_OFFSET (CamelMboxPreParser, current_message_info) + 
+                                                                                         G_STRUCT_OFFSET (CamelMboxParserMessageInfo, uid)),
+                                                                            (guchar *) ((gchar *)parser +
+                                                                                        G_STRUCT_OFFSET (CamelMboxPreParser, current_message_info) + 
+                                                                                        G_STRUCT_OFFSET (CamelMboxParserMessageInfo, status)));
+                                       g_free (x_ev_header_content);
 
                                        /* 
                                           parser->current_message_info.x_evolution_length = 
index a4b3af9..be01c2e 100644 (file)
@@ -3,7 +3,9 @@
 
 /* 
  *
- * Copyright (C) 1999 Bertrand Guiheneuf <bertrand@helixcode.com> .
+ * Author : Bertrand Guiheneuf <bertrand@helixcode.com> 
+ *
+ * Copyright (C) 1999 Helix Code .
  *
  * This program is free software; you can redistribute it and/or 
  * modify it under the terms of the GNU General Public License as 
@@ -30,10 +32,11 @@ typedef struct {
 
        glong message_position;
        glong size;
+       
        gchar *from;
+       gchar *to;
        gchar *date;
        gchar *subject;
-       gchar *status;
        gchar *priority;
        gchar *references;
        gchar *body_summary;
@@ -41,7 +44,8 @@ typedef struct {
 
        gchar *x_evolution;
        gshort x_evolution_offset;
-       /* gshort x_evolution_length; */
+       guint32 uid;
+       guchar status;
 
 } CamelMboxParserMessageInfo;
 
index d0b1d15..83704ea 100644 (file)
@@ -3,7 +3,7 @@
 
 /* 
  *
- * Copyright (C) 1999 Bertrand Guiheneuf <bertrand@helixcode.com> .
+ * Copyright (C) 2000 HelixCode <bertrand@helixcode.com> .
  *
  * This program is free software; you can redistribute it and/or 
  * modify it under the terms of the GNU General Public License as 
index 2f93c98..8033d9d 100644 (file)
@@ -3,7 +3,7 @@
 
 /* 
  *
- * Copyright (C) 1999 Bertrand Guiheneuf <bertrand@helixcode.com> .
+ * Copyright (C) 2000 HelixCode <bertrand@helixcode.com> .
  *
  * This program is free software; you can redistribute it and/or 
  * modify it under the terms of the GNU General Public License as 
index f4cbe34..d0b0db5 100644 (file)
@@ -57,6 +57,8 @@
 #include <glib.h>
 #include "camel-mbox-utils.h"
 #include "camel-mbox-parser.h"
+#include "camel-folder-summary.h"
+#include "camel-mbox-summary.h"
 
 
 
@@ -132,7 +134,7 @@ string_to_flag (gchar string)
 void 
 camel_mbox_xev_parse_header_content (gchar header_content[6], 
                                     guint32 *uid, 
-                                    guchar status)
+                                    guchar *status)
 {
        
        /* we assume that the first 4 characters of the header content 
@@ -140,7 +142,7 @@ camel_mbox_xev_parse_header_content (gchar header_content[6],
           toooo bad. 
        */
        *uid = string_to_uid (header_content);
-       status = string_to_flag (header_content[5]);
+       *status = string_to_flag (header_content[5]);
 }
 
 void 
@@ -249,7 +251,7 @@ camel_mbox_write_xev (gchar *mbox_file_name,
                cur_msg_info = (CamelMboxParserMessageInfo *)(summary_information->data) + cur_msg;
                end_of_last_message = cur_msg_info->message_position + cur_msg_info->size;
 
-               if ( !cur_msg_info->x_evolution) {
+               if (cur_msg_info->uid == 0) {
                        
                        bytes_to_copy = cur_msg_info->message_position 
                                + cur_msg_info->end_of_headers_offset
@@ -265,9 +267,10 @@ camel_mbox_write_xev (gchar *mbox_file_name,
                                goto end;
                        }
                        
-                       printf ("Writing the x-ev header\n");
-                       printf ("Current message number : %d\n", cur_msg);
-                       camel_mbox_xev_write_header_content (xev_header + 12, next_free_uid++, 0);
+                       cur_msg_info->uid = next_free_uid;
+                       cur_msg_info->status = 0;
+                       camel_mbox_xev_write_header_content (xev_header + 12, next_free_uid, 0);
+                       next_free_uid++;
                        write (fd2, xev_header, 19);
                        cur_offset += 19;
                        cur_msg_info->size += 19;
@@ -333,5 +336,41 @@ camel_mbox_write_xev (gchar *mbox_file_name,
 
 
 
+GArray *
+parsed_information_to_mbox_summary (GArray *parsed_information)
+{
+       guint cur_msg;
+       CamelMboxParserMessageInfo *cur_msg_info;
+       GArray *mbox_summary;
+       CamelMboxSummaryInformation cur_sum_info;
+
+       mbox_summary = g_array_new (FALSE, FALSE, sizeof (CamelMboxSummaryInformation));
+       mbox_summary =  g_array_set_size (mbox_summary, parsed_information->len);
+
+       for (cur_msg = 0; cur_msg < parsed_information->len; cur_msg++) {
+               
+               cur_msg_info = (CamelMboxParserMessageInfo *)(parsed_information->data) + cur_msg;
+
+               cur_sum_info.position = cur_msg_info->message_position;
+
+               cur_sum_info.x_evolution_offset = cur_msg_info->x_evolution_offset;
+
+               cur_sum_info.uid = cur_msg_info->uid;
+
+               cur_sum_info.status = cur_msg_info->status;
 
+               cur_sum_info.subject = cur_msg_info->subject;
+               cur_msg_info->subject = NULL;
 
+               cur_sum_info.sender =  cur_msg_info->from;
+               cur_msg_info->from = NULL;
+       
+               cur_sum_info.to =  cur_msg_info->to;
+               cur_msg_info->to = NULL;
+       
+               g_array_append_vals (mbox_summary, &cur_sum_info, 1);
+               
+       }
+       
+       return mbox_summary;
+}
index cacabd2..25e6113 100644 (file)
@@ -39,7 +39,7 @@ extern "C" {
 void 
 camel_mbox_xev_parse_header_content (gchar header_content[6], 
                                     guint32 *uid, 
-                                    guchar status);
+                                    guchar *status);
 
 void 
 camel_mbox_xev_write_header_content (gchar header_content[6], 
@@ -52,6 +52,9 @@ camel_mbox_write_xev (gchar *mbox_file_name,
                      glong last_uid, 
                      CamelException *ex);
 
+GArray *
+parsed_information_to_mbox_summary (GArray *parsed_information);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */