"Fossies" - the Fresh Open Source Software Archive 
Member "evolution-mapi-3.46.1/src/camel/camel-mapi-folder-summary.c" (2 Dec 2022, 4685 Bytes) of package /linux/misc/evolution-mapi-3.46.1.tar.xz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "camel-mapi-folder-summary.c" see the
Fossies "Dox" file reference documentation.
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with the program; if not, see <http://www.gnu.org/licenses/>
15 *
16 *
17 * Authors:
18 * Johnny Jacob <jjohnny@novell.com>
19 *
20 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
21 *
22 */
23
24 #include "evolution-mapi-config.h"
25
26 #include <errno.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <unistd.h>
30 #include <sys/stat.h>
31
32 #include "camel-mapi-folder.h"
33 #include "camel-mapi-folder-summary.h"
34 #include "camel-mapi-store.h"
35
36 #define CAMEL_MAPI_FOLDER_SUMMARY_VERSION (1)
37
38 /*Prototypes*/
39 static CamelFIRecord *mapi_summary_header_save (CamelFolderSummary *, GError **error);
40 static gboolean mapi_summary_header_load (CamelFolderSummary *, CamelFIRecord *fir);
41
42 /*End of Prototypes*/
43
44 G_DEFINE_TYPE (CamelMapiFolderSummary, camel_mapi_folder_summary, CAMEL_TYPE_FOLDER_SUMMARY)
45
46 static void
47 camel_mapi_folder_summary_class_init (CamelMapiFolderSummaryClass *class)
48 {
49 CamelFolderSummaryClass *folder_summary_class;
50
51 folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (class);
52 folder_summary_class->message_info_type = CAMEL_TYPE_MAPI_MESSAGE_INFO;
53 folder_summary_class->summary_header_save = mapi_summary_header_save;
54 folder_summary_class->summary_header_load = mapi_summary_header_load;
55 }
56
57 static void
58 camel_mapi_folder_summary_init (CamelMapiFolderSummary *mapi_summary)
59 {
60 }
61
62 /**
63 * camel_mapi_folder_summary_new:
64 *
65 * This will create a new CamelMapiFolderSummary object and read in the
66 * summary data from disk, if it exists.
67 *
68 * Return value: A new CamelMapiFolderSummary object.
69 **/
70 CamelFolderSummary *
71 camel_mapi_folder_summary_new (CamelFolder *folder)
72 {
73 CamelFolderSummary *summary;
74 GError *local_error = NULL;
75
76 summary = g_object_new (CAMEL_TYPE_MAPI_FOLDER_SUMMARY, "folder", folder, NULL);
77
78 if (!camel_folder_summary_load (summary, &local_error)) {
79 /* FIXME: Isn't this dangerous ? We clear the summary
80 if it cannot be loaded, for some random reason.
81 We need to pass the ex and find out why it is not loaded etc. ? */
82 camel_folder_summary_clear (summary, NULL);
83 g_warning ("Unable to load summary %s\n", local_error ? local_error->message : "Unknown error");
84 }
85
86 g_clear_error (&local_error);
87
88 return summary;
89 }
90
91 static gboolean
92 mapi_summary_header_load (CamelFolderSummary *summary, CamelFIRecord *fir)
93 {
94 CamelMapiFolderSummary *mapi_summary = CAMEL_MAPI_FOLDER_SUMMARY (summary);
95 CamelFolderSummaryClass *folder_summary_class;
96 gchar *part;
97
98 folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (
99 camel_mapi_folder_summary_parent_class);
100
101 if (!folder_summary_class->summary_header_load (summary, fir))
102 return FALSE;
103
104 part = fir->bdata;
105
106 if (part)
107 mapi_summary->version = camel_util_bdata_get_number (&part, 0);
108
109 return TRUE;
110 }
111
112 static CamelFIRecord *
113 mapi_summary_header_save (CamelFolderSummary *summary, GError **error)
114 {
115 CamelFolderSummaryClass *folder_summary_class;
116 struct _CamelFIRecord *fir;
117
118 folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (camel_mapi_folder_summary_parent_class);
119
120 fir = folder_summary_class->summary_header_save (summary, error);
121
122 if (!fir)
123 return NULL;
124
125 fir->bdata = g_strdup_printf ("%d", CAMEL_MAPI_FOLDER_SUMMARY_VERSION);
126
127 return fir;
128 }
129
130 void
131 mapi_summary_clear (CamelFolderSummary *summary, gboolean uncache)
132 {
133 CamelFolderChangeInfo *changes;
134 CamelMessageInfo *info;
135 gint i;
136 const gchar *uid;
137 GPtrArray *known_uids;
138
139 changes = camel_folder_change_info_new ();
140 known_uids = camel_folder_summary_get_array (summary);
141 for (i = 0; known_uids && i < known_uids->len; i++) {
142 if (!(info = camel_folder_summary_get (summary, g_ptr_array_index (known_uids, i))))
143 continue;
144
145 uid = camel_message_info_get_uid (info);
146 camel_folder_change_info_remove_uid (changes, uid);
147 camel_folder_summary_remove_uid (summary, uid);
148 g_clear_object (&info);
149 }
150
151 camel_folder_summary_free_array (known_uids);
152 camel_folder_summary_clear (summary, NULL);
153
154 if (camel_folder_change_info_changed (changes))
155 camel_folder_changed (camel_folder_summary_get_folder (summary), changes);
156 camel_folder_change_info_free (changes);
157 }