~ubuntu-dev/ubuntu/lucid/mutt/lucid-201002110857

« back to all changes in this revision

Viewing changes to handler.c

  • Committer: Bazaar Package Importer
  • Author(s): أحمد المحمودي (Ahmed El-Mahmoudy)
  • Date: 2009-06-17 17:17:28 UTC
  • mfrom: (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20090617171728-61dkl7w5fgn7ybdq
Tags: upstream-1.5.20
Import upstream version 1.5.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
173
173
                            int last)
174
174
{
175
175
  char *d, *s;
176
 
  char c;
 
176
  char c = 0;
177
177
 
178
 
  int kind;
 
178
  int kind = -1;
179
179
  int soft = 0;
180
180
 
181
181
  /* decode the line */
191
191
  }
192
192
 
193
193
  if (!soft && last == '\n')
194
 
    *d++ = '\n';
 
194
  {
 
195
    /* neither \r nor \n as part of line-terminating CRLF
 
196
     * may be qp-encoded, so remove \r and \n-terminate;
 
197
     * see RfC2045, sect. 6.7, (1): General 8bit representation */
 
198
    if (kind == 0 && c == '\r')
 
199
      *(d-1) = '\n';
 
200
    else
 
201
      *d++ = '\n';
 
202
  }
195
203
  
196
204
  *d = '\0';
197
205
  *l = d - dest;
427
435
  RICH_FLUSHRIGHT, RICH_COLOR, RICH_LAST_TAG };
428
436
 
429
437
static struct {
430
 
  const char *tag_name;
 
438
  const wchar_t *tag_name;
431
439
  int index;
432
440
} EnrichedTags[] = {
433
 
  { "param",            RICH_PARAM },
434
 
  { "bold",             RICH_BOLD },
435
 
  { "italic",           RICH_ITALIC },
436
 
  { "underline",        RICH_UNDERLINE },
437
 
  { "nofill",           RICH_NOFILL },
438
 
  { "excerpt",          RICH_EXCERPT },
439
 
  { "indent",           RICH_INDENT },
440
 
  { "indentright",      RICH_INDENT_RIGHT },
441
 
  { "center",           RICH_CENTER },
442
 
  { "flushleft",        RICH_FLUSHLEFT },
443
 
  { "flushright",       RICH_FLUSHRIGHT },
444
 
  { "flushboth",        RICH_FLUSHLEFT },
445
 
  { "color",            RICH_COLOR },
446
 
  { "x-color",          RICH_COLOR },
 
441
  { L"param",           RICH_PARAM },
 
442
  { L"bold",            RICH_BOLD },
 
443
  { L"italic",          RICH_ITALIC },
 
444
  { L"underline",       RICH_UNDERLINE },
 
445
  { L"nofill",          RICH_NOFILL },
 
446
  { L"excerpt",         RICH_EXCERPT },
 
447
  { L"indent",          RICH_INDENT },
 
448
  { L"indentright",     RICH_INDENT_RIGHT },
 
449
  { L"center",          RICH_CENTER },
 
450
  { L"flushleft",       RICH_FLUSHLEFT },
 
451
  { L"flushright",      RICH_FLUSHRIGHT },
 
452
  { L"flushboth",       RICH_FLUSHLEFT },
 
453
  { L"color",           RICH_COLOR },
 
454
  { L"x-color",         RICH_COLOR },
447
455
  { NULL,               -1 }
448
456
};
449
457
 
466
474
  STATE *s;
467
475
};
468
476
 
469
 
static int enriched_cmp (const char *a, const wchar_t *b)
470
 
{
471
 
  register const char *p = a;
472
 
  register const wchar_t *q = b;
473
 
  int i;
474
 
 
475
 
  if (!a && !b)
476
 
    return 0;
477
 
  if (!a && b)
478
 
    return -1;
479
 
  if (a && !b)
480
 
    return 1;
481
 
 
482
 
  for ( ; *p || *q; p++, q++)
483
 
  {
484
 
    if ((i = ascii_tolower (*p)) - ascii_tolower (((char) *q) & 0x7f))
485
 
      return i;
486
 
  }
487
 
  return 0;
488
 
}
489
 
 
490
477
static void enriched_wrap (struct enriched_state *stte)
491
478
{
492
479
  int x;
618
605
    stte->word_len = 0;
619
606
    stte->buff_used = 0;
620
607
  }
621
 
  if (wrap) 
 
608
  if (wrap)
622
609
    enriched_wrap(stte);
 
610
  fflush (stte->s->fpout);
623
611
}
624
612
 
625
613
 
716
704
    tagptr++;
717
705
  
718
706
  for (i = 0, j = -1; EnrichedTags[i].tag_name; i++)
719
 
    if (enriched_cmp (EnrichedTags[i].tag_name, tagptr) == 0)
 
707
    if (wcscasecmp (EnrichedTags[i].tag_name, tagptr) == 0)
720
708
    {
721
709
      j = EnrichedTags[i].index;
722
710
      break;
734
722
      if ((stte->s->flags & M_DISPLAY) && j == RICH_PARAM && stte->tag_level[RICH_COLOR])
735
723
      {
736
724
        stte->param[stte->param_used] = (wchar_t) '\0';
737
 
        if (!enriched_cmp("black", stte->param))
 
725
        if (!wcscasecmp(L"black", stte->param))
738
726
        {
739
727
          enriched_puts("\033[30m", stte);
740
728
        }
741
 
        else if (!enriched_cmp("red", stte->param))
 
729
        else if (!wcscasecmp(L"red", stte->param))
742
730
        {
743
731
          enriched_puts("\033[31m", stte);
744
732
        }
745
 
        else if (!enriched_cmp("green", stte->param))
 
733
        else if (!wcscasecmp(L"green", stte->param))
746
734
        {
747
735
          enriched_puts("\033[32m", stte);
748
736
        }
749
 
        else if (!enriched_cmp("yellow", stte->param))
 
737
        else if (!wcscasecmp(L"yellow", stte->param))
750
738
        {
751
739
          enriched_puts("\033[33m", stte);
752
740
        }
753
 
        else if (!enriched_cmp("blue", stte->param))
 
741
        else if (!wcscasecmp(L"blue", stte->param))
754
742
        {
755
743
          enriched_puts("\033[34m", stte);
756
744
        }
757
 
        else if (!enriched_cmp("magenta", stte->param))
 
745
        else if (!wcscasecmp(L"magenta", stte->param))
758
746
        {
759
747
          enriched_puts("\033[35m", stte);
760
748
        }
761
 
        else if (!enriched_cmp("cyan", stte->param))
 
749
        else if (!wcscasecmp(L"cyan", stte->param))
762
750
        {
763
751
          enriched_puts("\033[36m", stte);
764
752
        }
765
 
        else if (!enriched_cmp("white", stte->param))
 
753
        else if (!wcscasecmp(L"white", stte->param))
766
754
        {
767
755
          enriched_puts("\033[37m", stte);
768
756
        }
1101
1089
  {
1102
1090
    mutt_copy_hdr (s->fpin, s->fpout, off_start, b->parts->offset,
1103
1091
        (((s->flags & M_WEED) || ((s->flags & (M_DISPLAY|M_PRINTING)) && option (OPTWEED))) ? (CH_WEED | CH_REORDER) : 0) |
1104
 
        (s->prefix ? CH_PREFIX : 0) | CH_DECODE | CH_FROM, s->prefix);
 
1092
        (s->prefix ? CH_PREFIX : 0) | CH_DECODE | CH_FROM |
 
1093
        (s->flags & M_DISPLAY) ? CH_DISPLAY : 0, s->prefix);
1105
1094
 
1106
1095
    if (s->prefix)
1107
1096
      state_puts (s->prefix, s);
1206
1195
      else
1207
1196
        state_putc ('\n', s);
1208
1197
    }
1209
 
    else
1210
 
    {
1211
 
      if (p->description && mutt_can_decode (p))
1212
 
        state_printf (s, "Content-Description: %s\n", p->description);
1213
 
 
1214
 
      if (p->form_name)
1215
 
        state_printf(s, "%s: \n", p->form_name);
1216
 
 
1217
 
    }
 
1198
 
1218
1199
    rc = mutt_body_handler (p, s);
1219
1200
    state_putc ('\n', s);
1220
1201
    
1444
1425
 
1445
1426
      mutt_copy_hdr(s->fpin, s->fpout, ftello (s->fpin), b->parts->offset,
1446
1427
                    (option (OPTWEED) ? (CH_WEED | CH_REORDER) : 0) |
1447
 
                    CH_DECODE, NULL);
 
1428
                    CH_DECODE | CH_DISPLAY, NULL);
1448
1429
    }
1449
1430
  }
1450
1431
  else
1461
1442
                    access_type);
1462
1443
      mutt_copy_hdr (s->fpin, s->fpout, ftello (s->fpin), b->parts->offset,
1463
1444
                     (option (OPTWEED) ? (CH_WEED | CH_REORDER) : 0) |
1464
 
                     CH_DECODE , NULL);
 
1445
                     CH_DECODE | CH_DISPLAY, NULL);
1465
1446
    }
1466
1447
  }
1467
1448
  
1505
1486
    iconv_close (cd);
1506
1487
}
1507
1488
 
 
1489
/* when generating format=flowed ($text_flowed is set) from format=fixed,
 
1490
 * strip all trailing spaces to improve interoperability;
 
1491
 * if $text_flowed is unset, simply verbatim copy input
 
1492
 */
 
1493
static int text_plain_handler (BODY *b, STATE *s)
 
1494
{
 
1495
  char buf[LONG_STRING];
 
1496
  size_t l;
 
1497
 
 
1498
  while (fgets (buf, sizeof (buf), s->fpin))
 
1499
  {
 
1500
    l = mutt_strlen (buf);
 
1501
    if (l > 0 && buf[l-1] == '\n')
 
1502
      buf[--l] = 0;
 
1503
    if (option (OPTTEXTFLOWED))
 
1504
    {
 
1505
      while (l > 0 && buf[l-1] == ' ')
 
1506
        buf[--l] = 0;
 
1507
    }
 
1508
    if (s->prefix)
 
1509
      state_puts (s->prefix, s);
 
1510
    state_puts (buf, s);
 
1511
    state_putc ('\n', s);
 
1512
  }
 
1513
 
 
1514
  return 0;
 
1515
}
 
1516
 
1508
1517
int mutt_body_handler (BODY *b, STATE *s)
1509
1518
{
1510
1519
  int decode = 0;
1545
1554
      else if (ascii_strcasecmp ("flowed", mutt_get_parameter ("format", b->parameter)) == 0)
1546
1555
        handler = rfc3676_handler;
1547
1556
      else
1548
 
        plaintext = 1;
 
1557
        handler = text_plain_handler;
1549
1558
    }
1550
1559
    else if (ascii_strcasecmp ("enriched", b->subtype) == 0)
1551
1560
      handler = text_enriched_handler;
1612
1621
      handler = crypt_smime_application_smime_handler;
1613
1622
  }
1614
1623
 
1615
 
 
1616
 
  if (plaintext || handler)
 
1624
  /* only respect disposition == attachment if we're not
 
1625
     displaying from the attachment menu (i.e. pager) */
 
1626
  if ((!option (OPTHONORDISP) || (b->disposition != DISPATTACH ||
 
1627
                                  option(OPTVIEWATTACH))) &&
 
1628
       (plaintext || handler))
1617
1629
  {
1618
1630
    fseeko (s->fpin, b->offset, 0);
1619
1631
 
1663
1675
      {
1664
1676
        b->length = ftello (s->fpout);
1665
1677
        b->offset = 0;
1666
 
        fclose (s->fpout);
 
1678
        safe_fclose (&s->fpout);
1667
1679
 
1668
1680
        /* restore final destination and substitute the tempfile for input */
1669
1681
        s->fpout = fp;
1694
1706
        b->offset = tmpoffset;
1695
1707
 
1696
1708
        /* restore the original source stream */
1697
 
        fclose (s->fpin);
 
1709
        safe_fclose (&s->fpin);
1698
1710
        s->fpin = fp;
1699
1711
      }
1700
1712
    }
1701
1713
    s->flags |= M_FIRSTDONE;
1702
1714
  }
1703
 
  else if (s->flags & M_DISPLAY)
 
1715
  /* print hint to use attachment menu for disposition == attachment
 
1716
     if we're not already being called from there */
 
1717
  else if ((s->flags & M_DISPLAY) || (b->disposition == DISPATTACH &&
 
1718
                                      !option (OPTVIEWATTACH) &&
 
1719
                                      option (OPTHONORDISP) &&
 
1720
                                      (plaintext || handler)))
1704
1721
  {
1705
1722
    state_mark_attach (s);
1706
 
    state_printf (s, _("[-- %s/%s is unsupported "), TYPE (b), b->subtype);
 
1723
    if (option (OPTHONORDISP) && b->disposition == DISPATTACH)
 
1724
      fputs (_("[-- This is an attachment "), s->fpout);
 
1725
    else
 
1726
      state_printf (s, _("[-- %s/%s is unsupported "), TYPE (b), b->subtype);
1707
1727
    if (!option (OPTVIEWATTACH))
1708
1728
    {
1709
1729
      if (km_expand_key (type, sizeof(type),