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

« back to all changes in this revision

Viewing changes to muttlib.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:
1
1
/*
2
 
 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
3
 
 * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
 
2
 * Copyright (C) 1996-2000,2007 Michael R. Elkins <me@mutt.org>
 
3
 * Copyright (C) 1999-2008 Thomas Roessler <roessler@does-not-exist.org>
4
4
 * 
5
5
 *     This program is free software; you can redistribute it and/or modify
6
6
 *     it under the terms of the GNU General Public License as published by
734
734
void _mutt_mktemp (char *s, const char *src, int line)
735
735
{
736
736
  snprintf (s, _POSIX_PATH_MAX, "%s/mutt-%s-%d-%d-%d", NONULL (Tempdir), NONULL(Hostname), (int) getuid(), (int) getpid (), Counter++);
737
 
  dprint (1, (debugfile, "%s:%d: mutt_mktemp returns \"%s\".\n", src, line, s));
 
737
  dprint (3, (debugfile, "%s:%d: mutt_mktemp returns \"%s\".\n", src, line, s));
738
738
  unlink (s);
739
739
}
740
740
 
746
746
  {
747
747
    t = *p;
748
748
    *p = (*p)->next;
 
749
    mutt_alias_delete_reverse (t);
749
750
    FREE (&t->name);
750
751
    rfc822_free_address (&t->addr);
751
752
    FREE (&t);
753
754
}
754
755
 
755
756
/* collapse the pathname using ~ or = when possible */
756
 
void mutt_pretty_mailbox (char *s)
 
757
void mutt_pretty_mailbox (char *s, size_t buflen)
757
758
{
758
759
  char *p = s, *q = s;
759
760
  size_t len;
760
761
  url_scheme_t scheme;
 
762
  char tmp[_POSIX_PATH_MAX];
761
763
 
762
764
  scheme = url_check_scheme (s);
763
765
 
779
781
      q = strchr (p, '\0');
780
782
    p = q;
781
783
  }
782
 
  
783
 
  /* first attempt to collapse the pathname */
784
 
  while (*p)
 
784
 
 
785
  /* cleanup path */
 
786
  if (strstr (p, "//") || strstr (p, "/./"))
785
787
  {
786
 
    if (*p == '/' && p[1] == '/')
787
 
    {
788
 
      *q++ = '/';
789
 
      p += 2;
790
 
    }
791
 
    else if (p[0] == '/' && p[1] == '.' && p[2] == '/')
792
 
    {
793
 
      *q++ = '/';
794
 
      p += 3;
795
 
    }
796
 
    else
797
 
      *q++ = *p++;
 
788
    /* first attempt to collapse the pathname, this is more
 
789
     * lightweight than realpath() and doesn't resolve links
 
790
     */
 
791
    while (*p)
 
792
    {
 
793
      if (*p == '/' && p[1] == '/')
 
794
      {
 
795
        *q++ = '/';
 
796
        p += 2;
 
797
      }
 
798
      else if (p[0] == '/' && p[1] == '.' && p[2] == '/')
 
799
      {
 
800
        *q++ = '/';
 
801
        p += 3;
 
802
      }
 
803
      else
 
804
        *q++ = *p++;
 
805
    }
 
806
    *q = 0;
798
807
  }
799
 
  *q = 0;
 
808
  else if (strstr (p, "..") && 
 
809
           (scheme == U_UNKNOWN || scheme == U_FILE) &&
 
810
           realpath (p, tmp))
 
811
    strfcpy (p, tmp, buflen - (p - s));
800
812
 
801
813
  if (mutt_strncmp (s, Maildir, (len = mutt_strlen (Maildir))) == 0 &&
802
814
      s[len] == '/')
1612
1624
    safe_realloc (&buf->data, buf->dsize);
1613
1625
    buf->dptr = buf->data + doff;
1614
1626
    len = vsnprintf (buf->dptr, len, fmt, ap_retry);
1615
 
    va_end (ap_retry);
1616
1627
  }
1617
1628
  if (len > 0)
1618
1629
    buf->dptr += len;
1619
1630
 
1620
1631
  va_end (ap);
1621
 
  
 
1632
  va_end (ap_retry);
 
1633
 
1622
1634
  return len;
1623
1635
}
1624
1636