bug-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cmu-sieve: starting to work, patch about paths.


From: Sergey Poznyakoff
Subject: Re: cmu-sieve: starting to work, patch about paths.
Date: Thu, 10 May 2001 17:54:43 +0300

> url_path.c: Expand ~/box to /home/user/box, ~foo/box to /home/foo/box,
>   and +box or =box to /home/user/Mail/box. It tries to be smart about
>   finding where /home is, or at least not too dumb, and it just assumes
>   that your mailboxes are in ~/Mail, I don't know if there's some kind
>   of standard environment variable for that.

You can use password database for that. The home_dir() would look like:

static char* home_dir(const char* name)
{
  char* home = strdup(getenv("HOME") ? getenv("HOME") : "/home");

  if(!home)
    {
      struct passwd *pw = getpwnam(name);
      if (!pw)
        return NULL;
      home = pw->pw_dir;
    }

  /* strip trailing '/' */
  if(home[strlen(home) - 1] == '/')
    home[strlen(home) - 1] = 0;

  if(name[1] != '/')
  {
    /* it's not our home, pull home back to the parent dir. */
    char* p = strrchr(home, '/');
    if(p == home)
    {
      /* home was "/dir", so use /home */
      free(home);
      return strdup("/home/");
    }
    p[1] = 0;
    return home;
  }
  /* else it is our home */
  return home;
}


Regards,
Sergey



reply via email to

[Prev in Thread] Current Thread [Next in Thread]