Commit 89feaf02 89feaf0252a0a25220a86b20b287213b7c13191b by Sergey Poznyakoff

mail: further improvements in quoting code.

* mail/escape.c (quote0): Simplify by using iterators.
1 parent 04474c29
...@@ -440,12 +440,7 @@ int ...@@ -440,12 +440,7 @@ int
440 quote0 (msgset_t *mspec, mu_message_t mesg, void *data) 440 quote0 (msgset_t *mspec, mu_message_t mesg, void *data)
441 { 441 {
442 int rc; 442 int rc;
443 mu_header_t hdr;
444 mu_body_t body;
445 mu_stream_t stream; 443 mu_stream_t stream;
446 char *buffer = NULL;
447 size_t size = 0;
448 size_t n = 0;
449 char *prefix = "\t"; 444 char *prefix = "\t";
450 mu_stream_t outstr, flt; 445 mu_stream_t outstr, flt;
451 char *argv[3]; 446 char *argv[3];
...@@ -466,7 +461,7 @@ quote0 (msgset_t *mspec, mu_message_t mesg, void *data) ...@@ -466,7 +461,7 @@ quote0 (msgset_t *mspec, mu_message_t mesg, void *data)
466 argv[1] = prefix; 461 argv[1] = prefix;
467 argv[2] = NULL; 462 argv[2] = NULL;
468 rc = mu_filter_create_args (&flt, outstr, "INLINE-COMMENT", 463 rc = mu_filter_create_args (&flt, outstr, "INLINE-COMMENT",
469 2, argv, 464 2, (const char**) argv,
470 MU_FILTER_ENCODE, 465 MU_FILTER_ENCODE,
471 MU_STREAM_WRITE); 466 MU_STREAM_WRITE);
472 mu_stream_unref (outstr); 467 mu_stream_unref (outstr);
...@@ -478,27 +473,23 @@ quote0 (msgset_t *mspec, mu_message_t mesg, void *data) ...@@ -478,27 +473,23 @@ quote0 (msgset_t *mspec, mu_message_t mesg, void *data)
478 473
479 if (*(int*)data) 474 if (*(int*)data)
480 { 475 {
481 size_t i, num = 0; 476 mu_header_t hdr;
482 const char *sptr; 477 mu_body_t body;
483 478 mu_iterator_t itr;
479
484 mu_message_get_header (mesg, &hdr); 480 mu_message_get_header (mesg, &hdr);
485 mu_header_get_field_count (hdr, &num); 481 mu_header_get_iterator (hdr, &itr);
486 482 for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
487 for (i = 1; i <= num; i++) 483 mu_iterator_next (itr))
488 { 484 {
489 mu_header_sget_field_name (hdr, i, &sptr); 485 const char *name, *value;
490 if (mail_header_is_visible (sptr)) 486
491 { 487 if (mu_iterator_current_kv (itr, (const void **)&name,
492 const char *value; 488 (void**)&value) == 0 &&
493 489 mail_header_is_visible (name))
494 mu_stream_printf (flt, "%s: ", sptr); 490 mu_stream_printf (flt, "%s: %s\n", name, value);
495 if (mu_header_sget_value (hdr, sptr, &value) == 0)
496 {
497 mu_stream_write (flt, value, strlen (value), NULL);
498 mu_stream_write (flt, "\n", 1, NULL);
499 }
500 }
501 } 491 }
492 mu_iterator_destroy (&itr);
502 mu_stream_write (flt, "\n", 1, NULL); 493 mu_stream_write (flt, "\n", 1, NULL);
503 mu_message_get_body (mesg, &body); 494 mu_message_get_body (mesg, &body);
504 rc = mu_body_get_streamref (body, &stream); 495 rc = mu_body_get_streamref (body, &stream);
......