| | 417 | /* |
| | 418 | * cum_attachs_size: Cumulative Attachments Size |
| | 419 | * |
| | 420 | * |
| | 421 | * Returns the total number of bytes used by the attachments in the |
| | 422 | * attachment list. |
| | 423 | */ |
| | 424 | |
| | 425 | static unsigned long cum_attachs_size (MUTTMENU *menu) |
| | 426 | { |
| | 427 | size_t s; |
| | 428 | unsigned short i; |
| | 429 | ATTACHPTR **idx = menu->data; |
| | 430 | CONTENT *info; |
| | 431 | |
| | 432 | for (i = 0, s = 0; i < menu->max; i++) |
| | 433 | { |
| | 434 | if ((info = idx[i]->content->content)) |
| | 435 | { |
| | 436 | switch (idx[i]->content->encoding) |
| | 437 | { |
| | 438 | case ENCQUOTEDPRINTABLE: |
| | 439 | s += 3 * (info->lobin + info->hibin) + info->ascii; |
| | 440 | break; |
| | 441 | case ENCBASE64: |
| | 442 | s += (4 * (info->lobin + info->hibin + info->ascii)) / 3; |
| | 443 | break; |
| | 444 | default: |
| | 445 | s += info->lobin + info->hibin + info->ascii; |
| | 446 | break; |
| | 447 | } |
| | 448 | } |
| | 449 | } |
| | 450 | |
| | 451 | return s; |
| | 452 | } |
| | 453 | |
| | 454 | /* prototype for use below */ |
| | 455 | void compose_status_line (char *buf, size_t buflen, MUTTMENU *menu, |
| | 456 | const char *p); |
| | 457 | |
| | 458 | /* |
| | 459 | * compose_format_str() |
| | 460 | * |
| | 461 | * %a = total number of attachments |
| | 462 | * %h = hostname [option] |
| | 463 | * %l = approx. length of current message (in bytes) |
| | 464 | * %v = Mutt version |
| | 465 | * |
| | 466 | * This function is similar to status_format_str(). Look at that function for |
| | 467 | * help when modifying this function. |
| | 468 | */ |
| | 469 | |
| | 470 | static const char * |
| | 471 | compose_format_str (char *buf, size_t buflen, char op, const char *src, |
| | 472 | const char *prefix, const char *ifstring, |
| | 473 | const char *elsestring, |
| | 474 | unsigned long data, format_flag flags) |
| | 475 | { |
| | 476 | char fmt[SHORT_STRING], tmp[SHORT_STRING]; |
| | 477 | int optional = (flags & M_FORMAT_OPTIONAL); |
| | 478 | MUTTMENU *menu = (MUTTMENU *) data; |
| | 479 | |
| | 480 | *buf = 0; |
| | 481 | switch (op) |
| | 482 | { |
| | 483 | case 'a': /* total number of attachments */ |
| | 484 | snprintf (fmt, sizeof (fmt), "%%%sd", prefix); |
| | 485 | snprintf (buf, buflen, fmt, menu->max); |
| | 486 | break; |
| | 487 | |
| | 488 | case 'h': /* hostname */ |
| | 489 | snprintf (fmt, sizeof (fmt), "%%%ss", prefix); |
| | 490 | snprintf (buf, buflen, fmt, NONULL(Hostname)); |
| | 491 | break; |
| | 492 | |
| | 493 | case 'l': /* approx length of current message in bytes */ |
| | 494 | snprintf (fmt, sizeof (fmt), "%%%ss", prefix); |
| | 495 | mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size(menu) : 0); |
| | 496 | snprintf (buf, buflen, fmt, tmp); |
| | 497 | break; |
| | 498 | |
| | 499 | case 'v': |
| | 500 | snprintf (fmt, sizeof (fmt), "Mutt %%s"); |
| | 501 | snprintf (buf, buflen, fmt, MUTT_VERSION); |
| | 502 | break; |
| | 503 | |
| | 504 | case 0: |
| | 505 | *buf = 0; |
| | 506 | return (src); |
| | 507 | |
| | 508 | default: |
| | 509 | snprintf (buf, buflen, "%%%s%c", prefix, op); |
| | 510 | break; |
| | 511 | } |
| | 512 | |
| | 513 | if (optional) |
| | 514 | compose_status_line (buf, buflen, menu, ifstring); |
| | 515 | else if (flags & M_FORMAT_OPTIONAL) |
| | 516 | compose_status_line (buf, buflen, menu, elsestring); |
| | 517 | |
| | 518 | return (src); |
| | 519 | } |
| | 520 | |
| | 521 | void compose_status_line (char *buf, size_t buflen, MUTTMENU *menu, |
| | 522 | const char *p) |
| | 523 | { |
| | 524 | mutt_FormatString (buf, buflen, p, compose_format_str, |
| | 525 | (unsigned long) menu, 0); |
| | 526 | } |
| | 527 | |
| | 528 | |