Show
Ignore:
Timestamp:
2007-04-10 17:40:11 (21 months ago)
Author:
Brendan Cully <brendan@…>
Branch:
HEAD
Message:

Make IMAP header cache layout match body cache.
You can now make them point to the same directory. Each folder will
have a folder.hcache file for the header cache.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • imap/util.c

    r5114 r5115  
    7272 
    7373#ifdef USE_HCACHE 
    74 int imap_hcache_open (IMAP_DATA* idata) 
     74static int imap_hcache_namer (const char* path, char* dest, size_t dlen) 
     75{ 
     76  return snprintf (dest, dlen, "%s.hcache", path); 
     77} 
     78 
     79header_cache_t* imap_hcache_open (IMAP_DATA* idata, const char* path) 
    7580{ 
    7681  IMAP_MBOX mx; 
    7782  ciss_url_t url; 
    7883  char cachepath[LONG_STRING]; 
     84  char mbox[LONG_STRING]; 
    7985 
    8086  if (imap_parse_path (idata->ctx->path, &mx) < 0) 
    8187    return -1; 
    8288 
     89  if (path) 
     90    imap_cachepath (idata, path, mbox, sizeof (mbox)); 
     91  else 
     92  { 
     93    imap_cachepath (idata, mx.mbox, mbox, sizeof (mbox)); 
     94    FREE (&mx.mbox); 
     95  } 
     96 
    8397  mutt_account_tourl (&idata->conn->account, &url); 
    84   url.path = mx.mbox; 
    85   url_ciss_tostring (&url, cachepath, sizeof (cachepath), 0); 
    86   FREE (&mx.mbox); 
    87  
    88   idata->hcache = mutt_hcache_open (HeaderCache, cachepath, NULL); 
    89  
    90   return idata->hcache != NULL ? 0 : -1; 
     98  url.path = mbox; 
     99  url_ciss_tostring (&url, cachepath, sizeof (cachepath), U_PATH); 
     100 
     101  return mutt_hcache_open (HeaderCache, cachepath, imap_hcache_namer); 
    91102} 
    92103 
     
    397408 
    398409  return path; 
     410} 
     411 
     412void imap_cachepath(IMAP_DATA* idata, const char* mailbox, char* dest, 
     413                    size_t dlen) 
     414{ 
     415  char* s; 
     416  const char* p = mailbox; 
     417 
     418  for (s = dest; p && *p && dlen; dlen--) 
     419  { 
     420    if (*p == idata->delim) 
     421    { 
     422      *s = '/'; 
     423      /* simple way to avoid collisions with UIDs */ 
     424      if (*(p + 1) >= '0' && *(p + 1) <= '9') 
     425      { 
     426        if (--dlen) 
     427          *++s = '_'; 
     428      } 
     429    } 
     430    else 
     431      *s = *p; 
     432    p++; 
     433    s++; 
     434  } 
     435  *s = '\0'; 
    399436} 
    400437