Changeset 2215

Show
Ignore:
Timestamp:
06/19/07 10:31:36
Author:
pvanhoof
Message:

Reading the unread and total counts of maildir folders

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r2214 r2215  
     12007-06-19  Philip Van Hoof  <pvanhoof@gnome.org> 
     2 
     3        * Fixed reading the unread and total counts from Maildir folders 
     4 
    152007-06-19  Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com> 
    26 
  • trunk/libtinymail-camel/camel-lite/camel/camel-file-utils.c

    r2191 r2215  
    7171} 
    7272 
     73void  
     74camel_file_util_read_counts (const gchar *spath, CamelFolderInfo *fi)  
     75{ 
     76        /* This code reads the beginning of the summary.mmap file for 
     77         * the length and unread-count of the folder. It makes it  
     78         * possible to read the total and unread values of the  
     79         * CamelFolderInfo structure without having to read the entire 
     80         * folder in (mmap it)  
     81         * It's called by get_folder_info_offline and therefore also by  
     82         * get_folder_info_online for each node in the tree. */ 
     83 
     84        FILE *f = fopen (spath, "r"); 
     85        if (f) { 
     86 
     87                gint tsize = ((sizeof (guint32) * 5) + sizeof (time_t)); 
     88                char *buffer = malloc (tsize), *ptr; 
     89                guint32 version, a; 
     90                a = fread (buffer, 1, tsize, f); 
     91                if (a == tsize)  
     92                { 
     93                        ptr = buffer; 
     94                        version = g_ntohl(get_unaligned_u32(ptr)); 
     95                        ptr += 16; 
     96                        if (fi->total == -1) 
     97                                fi->total = g_ntohl(get_unaligned_u32(ptr)); 
     98                        ptr += 4; 
     99                        if (fi->unread == -1 && (version < 0x100 && version >= 13)) 
     100                                fi->unread = g_ntohl(get_unaligned_u32(ptr)); 
     101                } 
     102                g_free (buffer); 
     103                fclose (f); 
     104        } 
     105} 
    73106 
    74107/** 
  • trunk/libtinymail-camel/camel-lite/camel/camel-file-utils.h

    r2191 r2215  
    3333#include <time.h> 
    3434#include <fcntl.h> 
     35 
     36#include <camel/camel-store.h> 
    3537 
    3638#ifndef O_BINARY 
     
    9496 
    9597char *camel_file_util_savename(const char *filename); 
     98void camel_file_util_read_counts (const gchar *spath, CamelFolderInfo *fi); 
    9699 
    97100#define get_unaligned_u32(p) ((((unsigned char*)(p))[0]) | \ 
  • trunk/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store.c

    r2195 r2215  
    32943294 
    32953295        } else if ((fi->unread == -1) || (fi->total == -1)) { 
    3296  
    3297  
    3298                 /* This code reads the beginning of the summary.mmap file for 
    3299                  * the length and unread-count of the folder. It makes it  
    3300                  * possible to read the total and unread values of the  
    3301                  * CamelFolderInfo structure without having to read the entire 
    3302                  * folder in (mmap it)  
    3303                  * It's called by get_folder_info_offline and therefore also by  
    3304                  * get_folder_info_online for each node in the tree. */ 
    3305  
    33063296                gchar *spath = g_strdup_printf ("%s/summary.mmap", folder_dir); 
    3307                 FILE *f = fopen (spath, "r"); 
     3297                camel_file_util_read_counts (spath, fi); 
    33083298                g_free (spath); 
    3309  
    3310                 if (f) { 
    3311  
    3312                         gint tsize = ((sizeof (guint32) * 5) + sizeof (time_t)); 
    3313                         char *buffer = malloc (tsize), *ptr; 
    3314                         guint32 version, a; 
    3315                         a = fread (buffer, 1, tsize, f); 
    3316                         if (a == tsize)  
    3317                         { 
    3318                                 ptr = buffer; 
    3319                                 version = g_ntohl(get_unaligned_u32(ptr)); 
    3320                                 ptr += 16; 
    3321                                 if (fi->total == -1) 
    3322                                         fi->total = g_ntohl(get_unaligned_u32(ptr)); 
    3323                                 ptr += 4; 
    3324                                 if (fi->unread == -1 && (version < 0x100 && version >= 13)) 
    3325                                         fi->unread = g_ntohl(get_unaligned_u32(ptr)); 
    3326                         } 
    3327                         g_free (buffer); 
    3328                         fclose (f); 
    3329                 } 
    33303299        } 
    33313300 
  • trunk/libtinymail-camel/camel-lite/camel/providers/local/camel-maildir-store.c

    r2180 r2215  
    4141#include "camel-maildir-summary.h" 
    4242#include "camel-string-utils.h" 
     43#include "camel-file-utils.h" 
    4344 
    4445#define d(x) 
     
    320321                camel_object_unref(folder); 
    321322        } else { 
    322                 CamelFolderSummary *s; 
    323                 /* This should be fast enough not to have to test for INFO_FAST */ 
    324                 s = (CamelFolderSummary *)camel_maildir_summary_new(NULL, path, folderpath, NULL); 
    325                 if (camel_folder_summary_header_load(s) != -1) { 
    326                         fi->unread = s->unread_count; 
    327                         fi->total = s->saved_count; 
    328                 } else { 
    329                         printf ("summary header\n"); 
    330                 } 
    331                 camel_object_unref(s); 
    332  
     323                camel_file_util_read_counts (path, fi); 
    333324        } 
    334325