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

« back to all changes in this revision

Viewing changes to alias.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:
148
148
 * if someone has an address like
149
149
 *      From: Michael `/bin/rm -f ~` Elkins <me@mutt.org>
150
150
 * and the user creates an alias for this, Mutt could wind up executing
151
 
 * the backtics because it writes aliases like
 
151
 * the backticks because it writes aliases like
152
152
 *      alias me Michael `/bin/rm -f ~` Elkins <me@mutt.org>
153
 
 * To avoid this problem, use a backslash (\) to quote any backtics.  We also
 
153
 * To avoid this problem, use a backslash (\) to quote any backticks.  We also
154
154
 * need to quote backslashes as well, since you could defeat the above by
155
155
 * doing
156
156
 *      From: Michael \`/bin/rm -f ~\` Elkins <me@mutt.org>
211
211
  return adr;
212
212
}
213
213
 
 
214
static void recode_buf (char *buf, size_t buflen)
 
215
{
 
216
  char *s;
 
217
 
 
218
  if (!ConfigCharset || !*ConfigCharset || !Charset)
 
219
    return;
 
220
  s = safe_strdup (buf);
 
221
  if (!s)
 
222
    return;
 
223
  if (mutt_convert_string (&s, Charset, ConfigCharset, 0) == 0)
 
224
    strfcpy (buf, s, buflen);
 
225
  FREE(&s);
 
226
}
 
227
 
214
228
void mutt_create_alias (ENVELOPE *cur, ADDRESS *iadr)
215
229
{
216
230
  ALIAS *new, *t;
318
332
    return;
319
333
  }
320
334
 
 
335
  mutt_alias_add_reverse (new);
 
336
  
321
337
  if ((t = Aliases))
322
338
  {
323
339
    while (t->next)
340
356
    {
341
357
      if (fseek (rc, -1, SEEK_CUR) < 0)
342
358
        goto fseek_err;
343
 
      if (fread(buf, 1, 1, rc) < 0)
 
359
      if (fread(buf, 1, 1, rc) != 1)
344
360
      {
345
361
        mutt_perror (_("Error reading alias file"));
346
362
        return;
355
371
      mutt_quote_filename (buf, sizeof (buf), new->name);
356
372
    else
357
373
      strfcpy (buf, new->name, sizeof (buf));
 
374
    recode_buf (buf, sizeof (buf));
358
375
    fprintf (rc, "alias %s ", buf);
359
376
    buf[0] = 0;
360
377
    rfc822_write_address (buf, sizeof (buf), new->addr, 0);
 
378
    recode_buf (buf, sizeof (buf));
361
379
    write_safe_address (rc, buf);
362
380
    fputc ('\n', rc);
363
381
    fclose (rc);
424
442
 */
425
443
ADDRESS *alias_reverse_lookup (ADDRESS *a)
426
444
{
427
 
  ALIAS *t = Aliases;
428
 
  ADDRESS *ap;
429
 
 
430
445
  if (!a || !a->mailbox)
431
 
    return NULL;
432
 
 
433
 
  for (; t; t = t->next)
434
 
  {
435
 
    /* cycle through all addresses if this is a group alias */
436
 
    for (ap = t->addr; ap; ap = ap->next)
437
 
    {
438
 
      if (!ap->group && ap->mailbox &&
439
 
          ascii_strcasecmp (ap->mailbox, a->mailbox) == 0)
440
 
        return ap;
441
 
    }
442
 
  }
443
 
  return 0;
 
446
      return NULL;
 
447
  
 
448
  return hash_find (ReverseAlias, a->mailbox);
 
449
}
 
450
 
 
451
void mutt_alias_add_reverse (ALIAS *t)
 
452
{
 
453
  ADDRESS *ap;
 
454
  if (!t)
 
455
    return;
 
456
  
 
457
  for (ap = t->addr; ap; ap = ap->next)
 
458
  {
 
459
    if (!ap->group && ap->mailbox)
 
460
      hash_insert (ReverseAlias, ap->mailbox, ap, 1);
 
461
  }
 
462
}
 
463
 
 
464
void mutt_alias_delete_reverse (ALIAS *t)
 
465
{
 
466
  ADDRESS *ap;
 
467
  if (!t)
 
468
    return;
 
469
  
 
470
  for (ap = t->addr; ap; ap = ap->next)
 
471
  {
 
472
    if (!ap->group && ap->mailbox)
 
473
      hash_delete (ReverseAlias, ap->mailbox, ap, NULL);
 
474
  }
444
475
}
445
476
 
446
477
/* alias_complete() -- alias completion routine
566
597
/* returns TRUE if the given address belongs to the user. */
567
598
int mutt_addr_is_user (ADDRESS *addr)
568
599
{
 
600
  const char *fqdn;
 
601
 
569
602
  /* NULL address is assumed to be the user. */
570
603
  if (!addr)
571
604
  {
588
621
    dprint (5, (debugfile, "mutt_addr_is_user: yes, %s = %s @ %s \n", addr->mailbox, Username, Hostname));
589
622
    return 1;
590
623
  }
591
 
  if (string_is_address(addr->mailbox, Username, mutt_fqdn(0)))
 
624
  fqdn = mutt_fqdn (0);
 
625
  if (string_is_address(addr->mailbox, Username, fqdn))
592
626
  {
593
 
    dprint (5, (debugfile, "mutt_addr_is_user: yes, %s = %s @ %s \n", addr->mailbox, Username, mutt_fqdn (0)));
 
627
    dprint (5, (debugfile, "mutt_addr_is_user: yes, %s = %s @ %s \n", addr->mailbox, Username, NONULL(fqdn)));
594
628
    return 1;
595
629
  }
596
 
  if (string_is_address(addr->mailbox, Username, mutt_fqdn(1)))
 
630
  fqdn = mutt_fqdn (1);
 
631
  if (string_is_address(addr->mailbox, Username, fqdn))
597
632
  {
598
 
    dprint (5, (debugfile, "mutt_addr_is_user: yes, %s = %s @ %s \n", addr->mailbox, Username, mutt_fqdn (1)));
 
633
    dprint (5, (debugfile, "mutt_addr_is_user: yes, %s = %s @ %s \n", addr->mailbox, Username, NONULL(fqdn)));
599
634
    return 1;
600
635
  }
601
636