mutt stable branch with some hacks
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Convert hcache_open to use buffer pool.

Change the namer function and mutt_hcache_per_folder to operate on a
buffer parameter.

+49 -66
+44 -61
hcache.c
··· 599 599 } 600 600 601 601 /* Append md5sumed folder to path if path is a directory. */ 602 - static const char * 603 - mutt_hcache_per_folder(const char *path, const char *folder, 602 + void 603 + mutt_hcache_per_folder(BUFFER *hcpath, const char *path, const char *folder, 604 604 hcache_namer_t namer) 605 605 { 606 - static char hcpath[_POSIX_PATH_MAX]; 606 + BUFFER *hcfile = NULL; 607 607 struct stat sb; 608 608 unsigned char md5sum[16]; 609 609 char* s; ··· 618 618 if (ret < 0 && path[plen-1] != '/') 619 619 { 620 620 #ifdef HAVE_ICONV 621 - return path; 621 + mutt_buffer_strcpy (hcpath, path); 622 622 #else 623 - snprintf (hcpath, _POSIX_PATH_MAX, "%s-%s", path, chs); 624 - return hcpath; 623 + mutt_buffer_printf (hcpath, "%s-%s", path, chs); 625 624 #endif 625 + return; 626 626 } 627 627 628 628 if (ret >= 0 && !S_ISDIR(sb.st_mode)) 629 629 { 630 630 #ifdef HAVE_ICONV 631 - return path; 631 + mutt_buffer_strcpy (hcpath, path); 632 632 #else 633 - snprintf (hcpath, _POSIX_PATH_MAX, "%s-%s", path, chs); 634 - return hcpath; 633 + mutt_buffer_printf (hcpath, "%s-%s", path, chs); 635 634 #endif 635 + return; 636 636 } 637 637 638 + hcfile = mutt_buffer_pool_get (); 639 + 638 640 if (namer) 639 641 { 640 - snprintf (hcpath, sizeof (hcpath), "%s%s", path, 641 - path[plen-1] == '/' ? "" : "/"); 642 - if (path[plen-1] != '/') 643 - plen++; 644 - 645 - ret = namer (folder, hcpath + plen, sizeof (hcpath) - plen); 642 + namer (folder, hcfile); 646 643 } 647 644 else 648 645 { 649 646 md5_buffer (folder, strlen (folder), &md5sum); 650 - 651 - /* On some systems (e.g. OS X), snprintf is defined as a macro. 652 - * Embedding directives inside macros is undefined, so we have to duplicate 653 - * the whole call: 654 - */ 647 + mutt_buffer_printf(hcfile, 648 + "%02x%02x%02x%02x%02x%02x%02x%02x" 649 + "%02x%02x%02x%02x%02x%02x%02x%02x", 650 + md5sum[0], md5sum[1], md5sum[2], md5sum[3], 651 + md5sum[4], md5sum[5], md5sum[6], md5sum[7], 652 + md5sum[8], md5sum[9], md5sum[10], md5sum[11], 653 + md5sum[12], md5sum[13], md5sum[14], md5sum[15]); 655 654 #ifndef HAVE_ICONV 656 - ret = snprintf(hcpath, _POSIX_PATH_MAX, 657 - "%s/%02x%02x%02x%02x%02x%02x%02x%02x" 658 - "%02x%02x%02x%02x%02x%02x%02x%02x" 659 - "-%s" 660 - , 661 - path, md5sum[0], md5sum[1], md5sum[2], md5sum[3], 662 - md5sum[4], md5sum[5], md5sum[6], md5sum[7], md5sum[8], 663 - md5sum[9], md5sum[10], md5sum[11], md5sum[12], 664 - md5sum[13], md5sum[14], md5sum[15] 665 - ,chs 666 - ); 667 - #else 668 - ret = snprintf(hcpath, _POSIX_PATH_MAX, 669 - "%s/%02x%02x%02x%02x%02x%02x%02x%02x" 670 - "%02x%02x%02x%02x%02x%02x%02x%02x" 671 - , 672 - path, md5sum[0], md5sum[1], md5sum[2], md5sum[3], 673 - md5sum[4], md5sum[5], md5sum[6], md5sum[7], md5sum[8], 674 - md5sum[9], md5sum[10], md5sum[11], md5sum[12], 675 - md5sum[13], md5sum[14], md5sum[15] 676 - ); 655 + mutt_buffer_addch (hcfile, '-'); 656 + mutt_buffer_addstr (hcfile, chs); 677 657 #endif 678 658 } 679 659 680 - if (ret <= 0) 681 - return path; 660 + mutt_buffer_concat_path (hcpath, path, mutt_b2s (hcfile)); 661 + mutt_buffer_pool_release (&hcfile); 682 662 683 - if (stat (hcpath, &sb) >= 0) 684 - return hcpath; 663 + if (stat (mutt_b2s (hcpath), &sb) >= 0) 664 + return; 685 665 686 - s = strchr (hcpath + 1, '/'); 666 + s = strchr (hcpath->data + 1, '/'); 687 667 while (s) 688 668 { 689 669 /* create missing path components */ 690 670 *s = '\0'; 691 - if (stat (hcpath, &sb) < 0 && (errno != ENOENT || mkdir (hcpath, 0777) < 0)) 692 - return path; 671 + if (stat (mutt_b2s (hcpath), &sb) < 0 && 672 + (errno != ENOENT || mkdir (mutt_b2s (hcpath), 0777) < 0)) 673 + { 674 + mutt_buffer_strcpy (hcpath, path); 675 + break; 676 + } 693 677 *s = '/'; 694 678 s = strchr (s + 1, '/'); 695 679 } 696 - 697 - return hcpath; 698 680 } 699 681 700 682 /* This function transforms a header into a char so that it is usable by ··· 1465 1447 struct header_cache *h = safe_calloc(1, sizeof (struct header_cache)); 1466 1448 int (*hcache_open) (struct header_cache* h, const char* path); 1467 1449 struct stat sb; 1450 + BUFFER *hcpath = NULL; 1468 1451 1469 1452 #if HAVE_QDBM 1470 1453 hcache_open = hcache_open_qdbm; ··· 1531 1514 return NULL; 1532 1515 } 1533 1516 1534 - path = mutt_hcache_per_folder(path, h->folder, namer); 1517 + hcpath = mutt_buffer_pool_get (); 1518 + mutt_hcache_per_folder(hcpath, path, h->folder, namer); 1535 1519 1536 - if (!hcache_open (h, path)) 1537 - return h; 1538 - else 1520 + if (hcache_open (h, mutt_b2s (hcpath))) 1539 1521 { 1540 1522 /* remove a possibly incompatible version */ 1541 - if (!stat (path, &sb) && !unlink (path)) 1523 + if (stat (mutt_b2s (hcpath), &sb) || 1524 + unlink (mutt_b2s (hcpath)) || 1525 + hcache_open (h, mutt_b2s (hcpath))) 1542 1526 { 1543 - if (!hcache_open (h, path)) 1544 - return h; 1527 + FREE(&h->folder); 1528 + FREE(&h); 1545 1529 } 1546 - FREE(&h->folder); 1547 - FREE(&h); 1530 + } 1548 1531 1549 - return NULL; 1550 - } 1532 + mutt_buffer_pool_release (&hcpath); 1533 + return h; 1551 1534 } 1552 1535 1553 1536 void mutt_hcache_free (void **data)
+1 -1
hcache.h
··· 24 24 struct header_cache; 25 25 typedef struct header_cache header_cache_t; 26 26 27 - typedef int (*hcache_namer_t)(const char* path, char* dest, size_t dlen); 27 + typedef void (*hcache_namer_t)(const char *path, BUFFER *dest); 28 28 29 29 header_cache_t *mutt_hcache_open(const char *path, const char *folder, 30 30 hcache_namer_t namer);
+2 -2
imap/util.c
··· 130 130 } 131 131 } 132 132 133 - static int imap_hcache_namer (const char* path, char* dest, size_t dlen) 133 + static void imap_hcache_namer (const char *path, BUFFER *dest) 134 134 { 135 - return snprintf (dest, dlen, "%s.hcache", path); 135 + mutt_buffer_printf (dest, "%s.hcache", path); 136 136 } 137 137 138 138 header_cache_t* imap_hcache_open (IMAP_DATA* idata, const char* path)
+2 -2
pop.c
··· 228 228 } 229 229 230 230 #ifdef USE_HCACHE 231 - static int pop_hcache_namer (const char *path, char *dest, size_t destlen) 231 + static void pop_hcache_namer (const char *path, BUFFER *dest) 232 232 { 233 - return snprintf (dest, destlen, "%s." HC_FEXT, path); 233 + mutt_buffer_printf (dest, "%s." HC_FEXT, path); 234 234 } 235 235 236 236 static header_cache_t *pop_hcache_open (POP_DATA *pop_data, const char *path)