mutt stable branch with some hacks
0
fork

Configure Feed

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

Add mutt_buffer_expand_path().

TODO: '@' expansion using mutt_default_save() is still using a fixed size
string parameter.

Convert imap_expand_path() and mutt_rx_sanitize_string() to use
BUFFERS instead.

Add url_ciss_tobuffer().

+92 -67
+1 -1
imap/imap.h
··· 62 62 void imap_logout_all (void); 63 63 64 64 /* util.c */ 65 - int imap_expand_path (char* path, size_t len); 65 + int imap_expand_path (BUFFER* path); 66 66 int imap_parse_path (const char* path, IMAP_MBOX* mx); 67 67 void imap_pretty_mailbox (char* path, size_t pathlen); 68 68
+5 -6
imap/util.c
··· 45 45 46 46 /* imap_expand_path: IMAP implementation of mutt_expand_path. Rewrite 47 47 * an IMAP path in canonical and absolute form. 48 - * Inputs: a buffer containing an IMAP path, and the number of bytes in 49 - * that buffer. 48 + * Inputs: a buffer containing an IMAP path. 50 49 * Outputs: The buffer is rewritten in place with the canonical IMAP path. 51 - * Returns 0 on success, or -1 if imap_parse_path chokes or url_ciss_tostring 50 + * Returns 0 on success, or -1 if imap_parse_path chokes or url_ciss_tobuffer 52 51 * fails, which it might if there isn't enough room in the buffer. */ 53 - int imap_expand_path (char* path, size_t len) 52 + int imap_expand_path (BUFFER* path) 54 53 { 55 54 IMAP_MBOX mx; 56 55 IMAP_DATA* idata; ··· 58 57 char fixedpath[LONG_STRING]; 59 58 int rc; 60 59 61 - if (imap_parse_path (path, &mx) < 0) 60 + if (imap_parse_path (mutt_b2s (path), &mx) < 0) 62 61 return -1; 63 62 64 63 idata = imap_conn_find (&mx.account, MUTT_IMAP_CONN_NONEW); ··· 66 65 imap_fix_path (idata, mx.mbox, fixedpath, sizeof (fixedpath)); 67 66 url.path = fixedpath; 68 67 69 - rc = url_ciss_tostring (&url, path, len, U_DECODE_PASSWD); 68 + rc = url_ciss_tobuffer (&url, path, U_DECODE_PASSWD); 70 69 FREE (&mx.mbox); 71 70 72 71 return rc;
+58 -43
muttlib.c
··· 435 435 436 436 char *_mutt_expand_path (char *s, size_t slen, int rx) 437 437 { 438 - char p[_POSIX_PATH_MAX] = ""; 439 - char q[_POSIX_PATH_MAX] = ""; 440 - char tmp[_POSIX_PATH_MAX]; 441 - char *t; 438 + BUFFER *s_buf; 439 + 440 + s_buf = mutt_buffer_pool_get (); 441 + 442 + mutt_buffer_addstr (s_buf, s); 443 + mutt_buffer_expand_path (s_buf, rx); 444 + strfcpy (s, mutt_b2s (s_buf), slen); 445 + 446 + mutt_buffer_pool_release (&s_buf); 442 447 443 - char *tail = ""; 448 + return s; 449 + } 444 450 451 + void mutt_buffer_expand_path (BUFFER *src, int rx) 452 + { 453 + BUFFER *p, *q, *tmp; 454 + const char *s, *tail = ""; 455 + char *t; 445 456 int recurse = 0; 446 457 458 + p = mutt_buffer_pool_get (); 459 + q = mutt_buffer_pool_get (); 460 + tmp = mutt_buffer_pool_get (); 461 + 447 462 do 448 463 { 449 464 recurse = 0; 465 + s = src->data; 450 466 451 467 switch (*s) 452 468 { ··· 454 470 { 455 471 if (*(s + 1) == '/' || *(s + 1) == 0) 456 472 { 457 - strfcpy (p, NONULL(Homedir), sizeof (p)); 473 + mutt_buffer_strcpy (p, NONULL(Homedir)); 458 474 tail = s + 1; 459 475 } 460 476 else ··· 465 481 466 482 if ((pw = getpwnam (s + 1))) 467 483 { 468 - strfcpy (p, pw->pw_dir, sizeof (p)); 484 + mutt_buffer_strcpy (p, pw->pw_dir); 469 485 if (t) 470 486 { 471 487 *t = '/'; ··· 479 495 /* user not found! */ 480 496 if (t) 481 497 *t = '/'; 482 - *p = '\0'; 498 + mutt_buffer_clear (p); 483 499 tail = s; 484 500 } 485 501 } ··· 494 510 if (mx_is_imap (NONULL (Maildir)) && 495 511 (Maildir[strlen (Maildir) - 1] == '}' || 496 512 Maildir[strlen (Maildir) - 1] == '/')) 497 - strfcpy (p, NONULL (Maildir), sizeof (p)); 513 + mutt_buffer_strcpy (p, NONULL (Maildir)); 498 514 else 499 515 #endif 500 516 if (Maildir && *Maildir && Maildir[strlen (Maildir) - 1] == '/') 501 - strfcpy (p, NONULL (Maildir), sizeof (p)); 517 + mutt_buffer_strcpy (p, NONULL (Maildir)); 502 518 else 503 - snprintf (p, sizeof (p), "%s/", NONULL (Maildir)); 519 + mutt_buffer_printf (p, "%s/", NONULL (Maildir)); 504 520 505 521 tail = s + 1; 506 522 } ··· 518 534 h = mutt_new_header(); 519 535 h->env = mutt_new_envelope(); 520 536 h->env->from = h->env->to = alias; 521 - mutt_default_save (p, sizeof (p), h); 537 + 538 + /* TODO: fix mutt_default_save() to use BUFFER */ 539 + mutt_buffer_increase_size (p, _POSIX_PATH_MAX); 540 + mutt_default_save (p->data, p->dsize, h); 541 + mutt_buffer_fix_dptr (p); 542 + 522 543 h->env->from = h->env->to = NULL; 523 544 mutt_free_header (&h); 524 545 /* Avoid infinite recursion if the resulting folder starts with '@' */ 525 - if (*p != '@') 546 + if (*(p->data) != '@') 526 547 recurse = 1; 527 548 528 549 tail = ""; ··· 532 553 533 554 case '>': 534 555 { 535 - strfcpy (p, NONULL(Inbox), sizeof (p)); 556 + mutt_buffer_strcpy (p, NONULL(Inbox)); 536 557 tail = s + 1; 537 558 } 538 559 break; 539 560 540 561 case '<': 541 562 { 542 - strfcpy (p, NONULL(Outbox), sizeof (p)); 563 + mutt_buffer_strcpy (p, NONULL(Outbox)); 543 564 tail = s + 1; 544 565 } 545 566 break; ··· 548 569 { 549 570 if (*(s+1) == '!') 550 571 { 551 - strfcpy (p, NONULL(LastFolder), sizeof (p)); 572 + mutt_buffer_strcpy (p, NONULL(LastFolder)); 552 573 tail = s + 2; 553 574 } 554 575 else 555 576 { 556 - strfcpy (p, NONULL(Spoolfile), sizeof (p)); 577 + mutt_buffer_strcpy (p, NONULL(Spoolfile)); 557 578 tail = s + 1; 558 579 } 559 580 } ··· 561 582 562 583 case '-': 563 584 { 564 - strfcpy (p, NONULL(LastFolder), sizeof (p)); 585 + mutt_buffer_strcpy (p, NONULL(LastFolder)); 565 586 tail = s + 1; 566 587 } 567 588 break; 568 589 569 590 case '^': 570 591 { 571 - strfcpy (p, NONULL(CurrentFolder), sizeof (p)); 592 + mutt_buffer_strcpy (p, NONULL(CurrentFolder)); 572 593 tail = s + 1; 573 594 } 574 595 break; 575 596 576 597 default: 577 598 { 578 - *p = '\0'; 599 + mutt_buffer_clear (p); 579 600 tail = s; 580 601 } 581 602 } 582 603 583 - if (rx && *p && !recurse) 604 + if (rx && *(p->data) && !recurse) 584 605 { 585 - mutt_rx_sanitize_string (q, sizeof (q), p); 586 - snprintf (tmp, sizeof (tmp), "%s%s", q, tail); 606 + mutt_rx_sanitize_string (q, mutt_b2s (p)); 607 + mutt_buffer_printf (tmp, "%s%s", mutt_b2s (q), tail); 587 608 } 588 609 else 589 - snprintf (tmp, sizeof (tmp), "%s%s", p, tail); 610 + mutt_buffer_printf (tmp, "%s%s", mutt_b2s (p), tail); 590 611 591 - strfcpy (s, tmp, slen); 612 + mutt_buffer_strcpy (src, mutt_b2s (tmp)); 592 613 } 593 614 while (recurse); 594 615 616 + mutt_buffer_pool_release (&p); 617 + mutt_buffer_pool_release (&q); 618 + mutt_buffer_pool_release (&tmp); 619 + 595 620 #ifdef USE_IMAP 596 621 /* Rewrite IMAP path in canonical form - aids in string comparisons of 597 622 * folders. May possibly fail, in which case s should be the same. */ 598 - if (mx_is_imap (s)) 599 - imap_expand_path (s, slen); 623 + if (mx_is_imap (mutt_b2s (src))) 624 + imap_expand_path (src); 600 625 #endif 601 - 602 - return (s); 603 626 } 604 627 605 628 /* Extract the real name from /etc/passwd's GECOS field. ··· 866 889 867 890 static const char rx_special_chars[] = "^.[$()|*+?{\\"; 868 891 869 - int mutt_rx_sanitize_string (char *dest, size_t destlen, const char *src) 892 + int mutt_rx_sanitize_string (BUFFER *dest, const char *src) 870 893 { 871 - while (*src && --destlen > 2) 894 + mutt_buffer_clear (dest); 895 + while (*src) 872 896 { 873 897 if (strchr (rx_special_chars, *src)) 874 - { 875 - *dest++ = '\\'; 876 - destlen--; 877 - } 878 - *dest++ = *src++; 898 + mutt_buffer_addch (dest, '\\'); 899 + mutt_buffer_addch (dest, *src++); 879 900 } 880 - 881 - *dest = '\0'; 882 - 883 - if (*src) 884 - return -1; 885 - else 886 - return 0; 901 + return 0; 887 902 } 888 903 889 904 void mutt_free_alias (ALIAS **p)
+2 -1
protos.h
··· 138 138 139 139 char *mutt_charset_hook (const char *); 140 140 char *mutt_iconv_hook (const char *); 141 + void mutt_buffer_expand_path (BUFFER *, int); 141 142 char *mutt_expand_path (char *, size_t); 142 143 char *_mutt_expand_path (char *, size_t, int); 143 144 char *mutt_find_hook (int, const char *); ··· 253 254 void mutt_query_exit (void); 254 255 void mutt_query_menu (char *, size_t); 255 256 void mutt_safe_path (char *s, size_t l, ADDRESS *a); 256 - int mutt_rx_sanitize_string (char *dest, size_t destlen, const char *src); 257 + int mutt_rx_sanitize_string (BUFFER *dest, const char *src); 257 258 void mutt_save_path (char *s, size_t l, ADDRESS *a); 258 259 void mutt_score_message (CONTEXT *, HEADER *, int); 259 260 void mutt_select_fcc (char *, size_t, HEADER *);
+25 -16
url.c
··· 214 214 *dst = 0; 215 215 } 216 216 217 - /* url_ciss_tostring: output the URL string for a given CISS object. */ 218 217 int url_ciss_tostring (ciss_url_t* ciss, char* dest, size_t len, int flags) 219 218 { 220 - long l; 219 + BUFFER *dest_buf; 220 + int retval; 221 + 222 + dest_buf = mutt_buffer_pool_get (); 223 + 224 + retval = url_ciss_tobuffer (ciss, dest_buf, flags); 225 + if (!retval) 226 + strfcpy (dest, mutt_b2s (dest_buf), len); 227 + 228 + mutt_buffer_pool_release (&dest_buf); 229 + 230 + return retval; 231 + } 221 232 233 + /* url_ciss_tobuffer: output the URL string for a given CISS object. */ 234 + int url_ciss_tobuffer (ciss_url_t* ciss, BUFFER* dest, int flags) 235 + { 222 236 if (ciss->scheme == U_UNKNOWN) 223 237 return -1; 224 238 225 - snprintf (dest, len, "%s:", mutt_getnamebyvalue (ciss->scheme, UrlMap)); 239 + mutt_buffer_printf (dest, "%s:", mutt_getnamebyvalue (ciss->scheme, UrlMap)); 226 240 227 241 if (ciss->host) 228 242 { 229 243 if (!(flags & U_PATH)) 230 - safe_strcat (dest, len, "//"); 231 - len -= (l = strlen (dest)); dest += l; 244 + mutt_buffer_addstr (dest, "//"); 232 245 233 246 if (ciss->user) 234 247 { ··· 239 252 { 240 253 char p[STRING]; 241 254 url_pct_encode (p, sizeof (p), ciss->pass); 242 - snprintf (dest, len, "%s:%s@", u, p); 255 + mutt_buffer_add_printf (dest, "%s:%s@", u, p); 243 256 } 244 257 else 245 - snprintf (dest, len, "%s@", u); 246 - 247 - len -= (l = strlen (dest)); dest += l; 258 + mutt_buffer_add_printf (dest, "%s@", u); 248 259 } 249 260 250 261 if (strchr (ciss->host, ':')) 251 - snprintf (dest, len, "[%s]", ciss->host); 262 + mutt_buffer_add_printf (dest, "[%s]", ciss->host); 252 263 else 253 - snprintf (dest, len, "%s", ciss->host); 254 - 255 - len -= (l = strlen (dest)); dest += l; 264 + mutt_buffer_add_printf (dest, "%s", ciss->host); 256 265 257 266 if (ciss->port) 258 - snprintf (dest, len, ":%hu/", ciss->port); 267 + mutt_buffer_add_printf (dest, ":%hu/", ciss->port); 259 268 else 260 - snprintf (dest, len, "/"); 269 + mutt_buffer_addstr (dest, "/"); 261 270 } 262 271 263 272 if (ciss->path) 264 - safe_strcat (dest, len, ciss->path); 273 + mutt_buffer_addstr (dest, ciss->path); 265 274 266 275 return 0; 267 276 }
+1
url.h
··· 33 33 int url_parse_file (char *d, const char *src, size_t dl); 34 34 int url_parse_ciss (ciss_url_t *ciss, char *src); 35 35 int url_ciss_tostring (ciss_url_t* ciss, char* dest, size_t len, int flags); 36 + int url_ciss_tobuffer (ciss_url_t* ciss, BUFFER* dest, int flags); 36 37 int url_parse_mailto (ENVELOPE *e, char **body, const char *src); 37 38 38 39 #endif