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

« back to all changes in this revision

Viewing changes to parse.c

  • Committer: Bazaar Package Importer
  • Author(s): Bhavani Shankar
  • Date: 2009-06-07 17:30:03 UTC
  • mto: (16.2.1 experimental) (2.3.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20090607173003-rg37ui3h2bbv7wl0
Tags: upstream-1.5.19
ImportĀ upstreamĀ versionĀ 1.5.19

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
char *mutt_read_rfc822_line (FILE *f, char *line, size_t *linelen)
42
42
{
43
43
  char *buf = line;
44
 
  char ch;
 
44
  int ch;
45
45
  size_t offset = 0;
46
46
 
47
47
  FOREVER
92
92
static LIST *mutt_parse_references (char *s, int in_reply_to)
93
93
{
94
94
  LIST *t, *lst = NULL;
95
 
  int m, n = 0;
96
 
  char *o = NULL, *new, *at;
 
95
  char *m;
 
96
  const char *sp;
97
97
 
98
 
  while ((s = strtok (s, " \t;")) != NULL)
 
98
  m = mutt_extract_message_id (s, &sp);
 
99
  while (m)
99
100
  {
100
 
    /*
101
 
     * some mail clients add other garbage besides message-ids, so do a quick
102
 
     * check to make sure this looks like a valid message-id
103
 
     * some idiotic clients also break their message-ids between lines, deal
104
 
     * with that too (give up if it's more than two lines, though)
105
 
     */
106
 
    t = NULL;
107
 
    new = NULL;
108
 
 
109
 
    if (*s == '<')
110
 
    {
111
 
      n = strlen (s);
112
 
      if (s[n-1] != '>')
113
 
      {
114
 
        o = s;
115
 
        s = NULL;
116
 
        continue;
117
 
      }
118
 
 
119
 
      new = safe_strdup (s);
120
 
    }
121
 
    else if (o)
122
 
    {
123
 
      m = strlen (s);
124
 
      if (s[m - 1] == '>')
125
 
      {
126
 
        new = safe_malloc (sizeof (char) * (n + m + 1));
127
 
        strcpy (new, o);        /* __STRCPY_CHECKED__ */
128
 
        strcpy (new + n, s);    /* __STRCPY_CHECKED__ */
129
 
      }
130
 
    }
131
 
    if (new)
132
 
    {
133
 
      /* make sure that this really does look like a message-id.
134
 
       * it should have exactly one @, and if we're looking at
135
 
       * an in-reply-to header, make sure that the part before
136
 
       * the @ has more than eight characters or it's probably
137
 
       * an email address
138
 
       */
139
 
      if (!(at = strchr (new, '@')) || strchr (at + 1, '@')
140
 
          || (in_reply_to && at - new <= 8))
141
 
        FREE (&new);
142
 
      else
143
 
      {
144
 
        t = (LIST *) safe_malloc (sizeof (LIST));
145
 
        t->data = new;
146
 
        t->next = lst;
147
 
        lst = t;
148
 
      }
149
 
    }
150
 
    o = NULL;
151
 
    s = NULL;
 
101
    t = safe_malloc (sizeof (LIST));
 
102
    t->data = m;
 
103
    t->next = lst;
 
104
    lst = t;
 
105
 
 
106
    m = mutt_extract_message_id (NULL, &sp);
152
107
  }
153
108
 
154
 
  return (lst);
 
109
  return lst;
155
110
}
156
111
 
157
112
int mutt_check_encoding (const char *c)
341
296
    /* Some pre-RFC1521 gateways still use the "name=filename" convention,
342
297
     * but if a filename has already been set in the content-disposition,
343
298
     * let that take precedence, and don't set it here */
344
 
    if ((pc = mutt_get_parameter( "name", ct->parameter)) != 0 && !ct->filename)
 
299
    if ((pc = mutt_get_parameter( "name", ct->parameter)) && !ct->filename)
345
300
      ct->filename = safe_strdup(pc);
346
301
    
347
302
#ifdef SUN_ATTACHMENT
348
303
    /* this is deep and utter perversion */
349
 
    if ((pc = mutt_get_parameter ("conversions", ct->parameter)) != 0)
 
304
    if ((pc = mutt_get_parameter ("conversions", ct->parameter)))
350
305
      ct->encoding = mutt_check_encoding (pc);
351
306
#endif
352
307
    
425
380
  {
426
381
    s++;
427
382
    SKIPWS (s);
428
 
    if ((s = mutt_get_parameter ("filename", (parms = parse_parameters (s)))) != 0)
 
383
    if ((s = mutt_get_parameter ("filename", (parms = parse_parameters (s)))))
429
384
      mutt_str_replace (&ct->filename, s);
430
 
    if ((s = mutt_get_parameter ("name", parms)) != 0)
 
385
    if ((s = mutt_get_parameter ("name", parms)))
431
386
      ct->form_name = safe_strdup (s);
432
387
    mutt_free_parameter (&parms);
433
388
  }
925
880
  return (mutt_mktime (&tm, 0) + tz_offset);
926
881
}
927
882
 
928
 
/* extract the first substring that looks like a message-id */
929
 
char *mutt_extract_message_id (const char *s)
 
883
/* extract the first substring that looks like a message-id.
 
884
 * call back with NULL for more (like strtok).
 
885
 */
 
886
char *mutt_extract_message_id (const char *s, const char **saveptr)
930
887
{
931
 
  const char *p;
932
 
  char *r;
933
 
  size_t l;
934
 
 
935
 
  if ((s = strchr (s, '<')) == NULL || (p = strchr (s, '>')) == NULL)
936
 
    return (NULL);
937
 
  l = (size_t)(p - s) + 1;
938
 
  r = safe_malloc (l + 1);
939
 
  memcpy (r, s, l);
940
 
  r[l] = 0;
941
 
  return (r);
 
888
  const char *o, *onull, *p;
 
889
  char *ret = NULL;
 
890
 
 
891
  if (s)
 
892
    p = s;
 
893
  else if (saveptr)
 
894
    p = *saveptr;
 
895
  else
 
896
    return NULL;
 
897
 
 
898
  for (s = NULL, o = NULL, onull = NULL;
 
899
       (p = strpbrk (p, "<> \t;")) != NULL; ++p)
 
900
  {
 
901
    if (*p == '<')
 
902
    {
 
903
      s = p; 
 
904
      o = onull = NULL;
 
905
      continue;
 
906
    }
 
907
 
 
908
    if (!s)
 
909
      continue;
 
910
 
 
911
    if (*p == '>')
 
912
    {
 
913
      size_t olen = onull - o, slen = p - s + 1;
 
914
      ret = safe_malloc (olen + slen + 1);
 
915
      if (o)
 
916
        memcpy (ret, o, olen);
 
917
      memcpy (ret + olen, s, slen);
 
918
      ret[olen + slen] = '\0';
 
919
      if (saveptr)
 
920
        *saveptr = p + 1; /* next call starts after '>' */
 
921
      return ret;
 
922
    }
 
923
 
 
924
    /* some idiotic clients break their message-ids between lines */
 
925
    if (s == p) 
 
926
      /* step past another whitespace */
 
927
      s = p + 1;
 
928
    else if (o)
 
929
      /* more than two lines, give up */
 
930
      s = o = onull = NULL;
 
931
    else
 
932
    {
 
933
      /* remember the first line, start looking for the second */
 
934
      o = s;
 
935
      onull = p;
 
936
      s = p + 1;
 
937
    }
 
938
  }
 
939
 
 
940
  return NULL;
942
941
}
943
942
 
944
943
void mutt_parse_mime_message (CONTEXT *ctx, HEADER *cur)
1132
1131
    {
1133
1132
      /* We add a new "Message-ID:" when building a message */
1134
1133
      FREE (&e->message_id);
1135
 
      e->message_id = mutt_extract_message_id (p);
 
1134
      e->message_id = mutt_extract_message_id (p, NULL);
1136
1135
      matched = 1;
1137
1136
    }
1138
1137
    else if (!ascii_strncasecmp (line + 1, "ail-", 4))
1485
1484
}
1486
1485
 
1487
1486
/* Compares mime types to the ok and except lists */
1488
 
int count_body_parts_check(LIST **checklist, BODY *b, int dflt)
 
1487
static int count_body_parts_check(LIST **checklist, BODY *b, int dflt)
1489
1488
{
1490
1489
  LIST *type;
1491
1490
  ATTACH_MATCH *a;
1521
1520
#define AT_COUNT(why)   { shallcount = 1; }
1522
1521
#define AT_NOCOUNT(why) { shallcount = 0; }
1523
1522
 
1524
 
int count_body_parts (BODY *body, int flags)
 
1523
static int count_body_parts (BODY *body, int flags)
1525
1524
{
1526
1525
  int count = 0;
1527
1526
  int shallcount, shallrecurse;
1600
1599
      count++;
1601
1600
    bp->attach_qualifies = shallcount ? 1 : 0;
1602
1601
 
1603
 
    dprint(5, (debugfile, "cbp: %08x shallcount = %d\n", (unsigned int)bp, shallcount));
 
1602
    dprint(5, (debugfile, "cbp: %p shallcount = %d\n", (void *)bp, shallcount));
1604
1603
 
1605
1604
    if (shallrecurse)
1606
1605
    {
1607
 
      dprint(5, (debugfile, "cbp: %08x pre count = %d\n", (unsigned int)bp, count));
 
1606
      dprint(5, (debugfile, "cbp: %p pre count = %d\n", (void *)bp, count));
1608
1607
      bp->attach_count = count_body_parts(bp->parts, flags & ~M_PARTS_TOPLEVEL);
1609
1608
      count += bp->attach_count;
1610
 
      dprint(5, (debugfile, "cbp: %08x post count = %d\n", (unsigned int)bp, count));
 
1609
      dprint(5, (debugfile, "cbp: %p post count = %d\n", (void *)bp, count));
1611
1610
    }
1612
1611
  }
1613
1612