"Fossies" - the Fresh Open Source Software Archive

Member "evolution-mapi-3.46.1/src/camel/camel-mapi-store-summary.c" (2 Dec 2022, 8991 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-store-summary.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 3.44.2_vs_3.45.1.

    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 <ctype.h>
   27 #include <errno.h>
   28 #include <stdlib.h>
   29 #include <string.h>
   30 #include <unistd.h>
   31 #include <glib.h>
   32 
   33 #include <e-mapi-utils.h>
   34 
   35 #include "camel-mapi-store.h"
   36 #include "camel-mapi-store-summary.h"
   37 
   38 #define d(x) 
   39 
   40 #define MAPI_STORE_SUMMARY_MARKER   0x0b0e1107
   41 #define MAPI_STORE_SUMMARY_VERSION  2
   42 
   43 static gint summary_header_load (CamelStoreSummary *, FILE *);
   44 static gint summary_header_save (CamelStoreSummary *, FILE *);
   45 static CamelStoreInfo *store_info_load (CamelStoreSummary *s, FILE *in);
   46 static gint store_info_save (CamelStoreSummary *s, FILE *out, CamelStoreInfo *mi);
   47 static void store_info_free (CamelStoreSummary *s, CamelStoreInfo *mi);
   48 static void store_info_set_value (CamelStoreSummary *s, CamelStoreInfo *mi, gint type, const gchar *str);
   49 
   50 G_DEFINE_TYPE (CamelMapiStoreSummary, camel_mapi_store_summary, CAMEL_TYPE_STORE_SUMMARY)
   51 
   52 static void
   53 camel_mapi_store_summary_class_init (CamelMapiStoreSummaryClass *class)
   54 {
   55     CamelStoreSummaryClass *store_summary_class;
   56 
   57     store_summary_class = CAMEL_STORE_SUMMARY_CLASS (class);
   58     store_summary_class->store_info_size = sizeof (CamelMapiStoreInfo);
   59     store_summary_class->summary_header_load = summary_header_load;
   60     store_summary_class->summary_header_save = summary_header_save;
   61     store_summary_class->store_info_load = store_info_load;
   62     store_summary_class->store_info_save = store_info_save;
   63     store_summary_class->store_info_free = store_info_free;
   64     store_summary_class->store_info_set_value = store_info_set_value;
   65 }
   66 
   67 static void
   68 camel_mapi_store_summary_init (CamelMapiStoreSummary *mapi_store_summary)
   69 {
   70 }
   71 
   72 static gint
   73 summary_header_load (CamelStoreSummary *s, FILE *in)
   74 {
   75     CamelStoreSummaryClass *store_summary_class;
   76     guint32 marker = 0, zero = 1, version = 0;
   77 
   78     store_summary_class = CAMEL_STORE_SUMMARY_CLASS (camel_mapi_store_summary_parent_class);
   79 
   80     if (store_summary_class->summary_header_load (s, in) == -1)
   81         return -1;
   82 
   83     if (camel_file_util_decode_uint32 (in, &marker) == -1 ||
   84         camel_file_util_decode_uint32 (in, &zero) == -1 ||
   85         camel_file_util_decode_uint32 (in, &version) == -1)
   86         return -1;
   87 
   88     if (marker != MAPI_STORE_SUMMARY_MARKER ||
   89         zero != 0 ||
   90         version > MAPI_STORE_SUMMARY_VERSION ||
   91         version < 2) /* when the version saving begun */
   92         return -1;
   93 
   94     return 0;
   95 }
   96 
   97 static gint
   98 summary_header_save (CamelStoreSummary *s, FILE *out)
   99 {
  100     CamelStoreSummaryClass *store_summary_class;
  101 
  102     store_summary_class = CAMEL_STORE_SUMMARY_CLASS (camel_mapi_store_summary_parent_class);
  103 
  104     if (store_summary_class->summary_header_save (s, out) == -1)
  105         return -1;
  106 
  107     if (camel_file_util_encode_uint32 (out, MAPI_STORE_SUMMARY_MARKER) == -1 ||
  108         camel_file_util_encode_uint32 (out, 0) == -1 ||
  109         camel_file_util_encode_uint32 (out, MAPI_STORE_SUMMARY_VERSION) == -1)
  110         return -1;
  111 
  112     return 0;
  113 }
  114 
  115 static CamelStoreInfo *
  116 store_info_load (CamelStoreSummary *s, FILE *in)
  117 {
  118     CamelStoreSummaryClass *store_summary_class;
  119     CamelStoreInfo *si;
  120     CamelMapiStoreInfo *msi;
  121 
  122     store_summary_class = CAMEL_STORE_SUMMARY_CLASS (camel_mapi_store_summary_parent_class);
  123 
  124     si = store_summary_class->store_info_load (s, in);
  125     if (si) {
  126         gchar *folder_id_str = NULL, *parent_id_str = NULL;
  127 
  128         msi = (CamelMapiStoreInfo *) si;
  129         if (camel_file_util_decode_string (in, &folder_id_str) == -1
  130             || camel_file_util_decode_string (in, &parent_id_str) == -1
  131             || camel_file_util_decode_uint32 (in, &msi->camel_folder_flags) == -1
  132             || camel_file_util_decode_uint32 (in, &msi->mapi_folder_flags) == -1
  133             || camel_file_util_decode_string (in, &msi->foreign_username) == -1
  134             || !e_mapi_util_mapi_id_from_string (folder_id_str, &msi->folder_id)
  135             || !e_mapi_util_mapi_id_from_string (parent_id_str, &msi->parent_id)) {
  136             camel_store_info_unref (si);
  137             si = NULL;
  138         } else {
  139             if (msi->foreign_username && !*msi->foreign_username) {
  140                 g_free (msi->foreign_username);
  141                 msi->foreign_username = NULL;
  142             }
  143 
  144             /* personal folders are not subscribable */
  145             if ((msi->mapi_folder_flags & CAMEL_MAPI_STORE_FOLDER_FLAG_PERSONAL) != 0) {
  146                 si->flags &= ~(CAMEL_STORE_INFO_FOLDER_SUBSCRIBED | CAMEL_FOLDER_SUBSCRIBED);
  147                 msi->camel_folder_flags &= ~(CAMEL_STORE_INFO_FOLDER_SUBSCRIBED | CAMEL_FOLDER_SUBSCRIBED);
  148             }
  149         }
  150 
  151         g_free (folder_id_str);
  152         g_free (parent_id_str);
  153     }
  154 
  155     return si;
  156 }
  157 
  158 static gint
  159 store_info_save (CamelStoreSummary *s, FILE *out, CamelStoreInfo *si)
  160 {
  161     CamelMapiStoreInfo *msi = (CamelMapiStoreInfo *) si;
  162     CamelStoreSummaryClass *store_summary_class;
  163     gchar *folder_id_str = NULL, *parent_id_str = NULL;
  164     gint res = -1;
  165 
  166     store_summary_class = CAMEL_STORE_SUMMARY_CLASS (camel_mapi_store_summary_parent_class);
  167 
  168     folder_id_str = e_mapi_util_mapi_id_to_string (msi->folder_id);
  169     parent_id_str = e_mapi_util_mapi_id_to_string (msi->parent_id);
  170 
  171     if (store_summary_class->store_info_save (s, out, si) == -1
  172         || camel_file_util_encode_string (out, folder_id_str) == -1
  173         || camel_file_util_encode_string (out, parent_id_str) == -1
  174         || camel_file_util_encode_uint32 (out, msi->camel_folder_flags) == -1
  175         || camel_file_util_encode_uint32 (out, msi->mapi_folder_flags) == -1
  176         || camel_file_util_encode_string (out, msi->foreign_username ? msi->foreign_username : "") == -1)
  177         res = -1;
  178     else
  179         res = 0;
  180 
  181     g_free (folder_id_str);
  182     g_free (parent_id_str);
  183 
  184     return res;
  185 }
  186 
  187 static void
  188 store_info_free (CamelStoreSummary *s, CamelStoreInfo *si)
  189 {
  190     CamelMapiStoreInfo *msi = (CamelMapiStoreInfo *) si;
  191 
  192     g_free (msi->foreign_username);
  193 
  194     CAMEL_STORE_SUMMARY_CLASS (camel_mapi_store_summary_parent_class)->store_info_free (s, si);
  195 }
  196 
  197 static void
  198 store_info_set_value (CamelStoreSummary *s, CamelStoreInfo *si, gint type, const gchar *str)
  199 {
  200     CamelMapiStoreInfo *msi = (CamelMapiStoreInfo *) si;
  201 
  202     if (type == CAMEL_MAPI_STORE_INFO_FOREIGN_USERNAME) {
  203         g_free (msi->foreign_username);
  204         msi->foreign_username = g_strdup (str);
  205 
  206         camel_store_summary_touch (s);
  207     } else
  208         CAMEL_STORE_SUMMARY_CLASS (camel_mapi_store_summary_parent_class)->store_info_set_value (s, si, type, str);
  209 }
  210 
  211 CamelStoreSummary *
  212 camel_mapi_store_summary_new (void)
  213 {
  214     return g_object_new (CAMEL_TYPE_MAPI_STORE_SUMMARY, NULL);
  215 }
  216 
  217 CamelStoreInfo *
  218 camel_mapi_store_summary_add_from_full (CamelStoreSummary *s,
  219                     const gchar *path,
  220                     mapi_id_t folder_id,
  221                     mapi_id_t parent_id,
  222                     guint32 camel_folder_flags,
  223                     guint32 mapi_folder_flags,
  224                     const gchar *foreign_username)
  225 {
  226     CamelStoreInfo *si;
  227 
  228     si = camel_store_summary_path (s, path);
  229     if (si) {
  230         camel_store_info_unref (si);
  231         return si;
  232     }
  233 
  234     si = camel_store_summary_add_from_path (s, path);
  235     if (si) {
  236         CamelMapiStoreInfo *msi = (CamelMapiStoreInfo *) si;
  237 
  238         si->flags = camel_folder_flags;
  239 
  240         msi->folder_id = folder_id;
  241         msi->parent_id = parent_id;
  242         msi->camel_folder_flags = camel_folder_flags;
  243         msi->mapi_folder_flags = mapi_folder_flags;
  244         msi->foreign_username = g_strdup ((foreign_username && *foreign_username) ? foreign_username : NULL);
  245 
  246         msi->latest_last_modify = 0;
  247         msi->last_obj_total = -1;
  248     }
  249 
  250     return si;
  251 }
  252 
  253 /* free the returned pointer with camel_store_info_unref(), if not NULL */
  254 CamelStoreInfo *
  255 camel_mapi_store_summary_get_folder_id (CamelStoreSummary *s, mapi_id_t folder_id)
  256 {
  257     CamelStoreInfo *adept = NULL;
  258     GPtrArray *array;
  259     guint ii;
  260 
  261     array = camel_store_summary_array (s);
  262 
  263     for (ii = 0; ii < array->len; ii++) {
  264         CamelStoreInfo *si;
  265         CamelMapiStoreInfo *msi;
  266 
  267         si = g_ptr_array_index (array, ii);
  268         msi = (CamelMapiStoreInfo *) si;
  269 
  270         if (msi->folder_id == folder_id) {
  271             /* public folders can be stored in a summary twice, once as "All Public Folders/..."
  272                and once as a subscribed variant, "Favorites/...". In that case prefer
  273                the subscribed folder folder, from the general public folder
  274             */
  275             if ((msi->mapi_folder_flags & CAMEL_MAPI_STORE_FOLDER_FLAG_PUBLIC_REAL) == 0) {
  276                 if (adept)
  277                     camel_store_info_unref (adept);
  278 
  279                 adept = camel_store_info_ref (si);
  280                 break;
  281             } else {
  282                 if (adept)
  283                     camel_store_info_unref (adept);
  284                 adept = camel_store_info_ref (si);
  285             }
  286         }
  287     }
  288 
  289     camel_store_summary_array_free (s, array);
  290 
  291     return adept;
  292 }