[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-mailutils] mail -f option processing
From: |
Sergey Poznyakoff |
Subject: |
Re: [bug-mailutils] mail -f option processing |
Date: |
Wed, 25 Jan 2006 14:07:22 EET |
Sergey Poznyakoff <address@hidden> wrote:
> the ~
> character is expanded only if it is the first symbol in an argument,
The following patch allows to expand it after the protocol specification
as well. E.g. you can run `mail -fmaildir:~/my/dir':
Index: mailbox/mbx_default.c
===================================================================
RCS file: /cvsroot/mailutils/mailutils/mailbox/mbx_default.c,v
retrieving revision 1.37
diff -p -u -r1.37 mbx_default.c
--- mailbox/mbx_default.c 15 Nov 2005 15:14:27 -0000 1.37
+++ mailbox/mbx_default.c 25 Jan 2006 12:02:53 -0000
@@ -260,48 +260,6 @@ plus_expand (const char *file, char **bu
return 0;
}
-/* Do ~ , if necessary. */
-static int
-tilde_expand (const char *file, char **buf)
-{
- char *user = NULL;
- char *path = NULL;
- char *home;
- int status;
- int len;
-
- if ((status = split_shortcut (file, "~", &user, &path)))
- return status;
-
- if (!path)
- {
- if (user)
- free (user);
- return ENOENT;
- }
-
- home = get_homedir (user);
- if (!home)
- {
- free (user);
- free (path);
- return MU_ERR_NO_SUCH_USER;
- }
-
- free (user); /* not needed anymore */
-
- len = strlen (home) + strlen (path) + 2;
- *buf = malloc (len);
- if (*buf)
- {
- sprintf (*buf, "%s/%s", home, path);
- (*buf)[len-1] = 0;
- }
-
- free (path);
- return *buf ? 0 : ENOMEM;
-}
-
static int
percent_expand (const char *file, char **mbox)
{
@@ -338,6 +296,7 @@ mu_mailbox_create_default (mu_mailbox_t
{
char *mbox = NULL;
char *tmp_mbox = NULL;
+ char *p;
int status = 0;
/* Sanity. */
@@ -362,16 +321,22 @@ mu_mailbox_create_default (mu_mailbox_t
}
}
+ p = mu_tilde_expansion (mail, "/", NULL);
+ if (tmp_mbox)
+ {
+ free (tmp_mbox);
+ tmp_mbox = p;
+ }
+ mail = p;
+ if (!mail)
+ return ENOMEM;
+
switch (mail[0])
{
case '%':
status = percent_expand (mail, &mbox);
break;
- case '~':
- status = tilde_expand (mail, &mbox);
- break;
-
case '+':
case '=':
status = plus_expand (mail, &mbox);
Index: mailbox/mu_argp.c
===================================================================
RCS file: /cvsroot/mailutils/mailutils/mailbox/mu_argp.c,v
retrieving revision 1.41
diff -p -u -r1.41 mu_argp.c
--- mailbox/mu_argp.c 27 Aug 2005 11:37:41 -0000 1.41
+++ mailbox/mu_argp.c 25 Jan 2006 12:02:54 -0000
@@ -672,7 +672,7 @@ read_rc (const char *progname, const cha
}
for (i = 0; i < n_argc; i++)
- x_argv[x_argc++] = n_argv[i];
+ x_argv[x_argc++] = mu_tilde_expansion (n_argv[i], "/", NULL);
free (n_argv);
}
Index: mailbox/mutil.c
===================================================================
RCS file: /cvsroot/mailutils/mailutils/mailbox/mutil.c,v
retrieving revision 1.70
diff -p -u -r1.70 mutil.c
--- mailbox/mutil.c 15 Nov 2005 15:14:10 -0000 1.70
+++ mailbox/mutil.c 25 Jan 2006 12:02:54 -0000
@@ -184,9 +184,33 @@ mu_get_full_path (const char *file)
char *
mu_tilde_expansion (const char *ref, const char *delim, const char *homedir)
{
- char *p = strdup (ref);
+ char *base = strdup (ref);
char *home = NULL;
+ char *proto = NULL;
+ size_t proto_len = 0;
+ char *p;
+ for (p = base; *p && isascii (*p) && isalnum (*p); p++)
+ ;
+
+ if (*p == ':')
+ {
+ p++;
+ proto_len = p - base;
+ proto = malloc (proto_len + 1);
+ if (!proto)
+ return NULL;
+ memcpy (proto, base, proto_len);
+ proto[proto_len] = 0;
+ /* Allow for extra pair of slashes after the protocol specifier */
+ if (*p == delim[0])
+ p++;
+ if (*p == delim[0])
+ p++;
+ }
+ else
+ p = base;
+
if (*p == '~')
{
p++;
@@ -197,14 +221,18 @@ mu_tilde_expansion (const char *ref, con
{
home = mu_get_homedir ();
if (!home)
- return NULL;
+ return base;
homedir = home;
}
- s = calloc (strlen (homedir) + strlen (p) + 1, 1);
- strcpy (s, homedir);
+ s = calloc (proto_len + strlen (homedir) + strlen (p) + 1, 1);
+ if (proto_len)
+ strcpy (s, proto);
+ else
+ s[0] = 0;
+ strcat (s, homedir);
strcat (s, p);
- free (--p);
- p = s;
+ free (base);
+ base = s;
}
else
{
@@ -215,26 +243,29 @@ mu_tilde_expansion (const char *ref, con
s++;
name = calloc (s - p + 1, 1);
memcpy (name, p, s - p);
- name [s - p] = '\0';
+ name[s - p] = '\0';
auth = mu_get_auth_by_name (name);
free (name);
if (auth)
{
- char *buf = calloc (strlen (auth->dir) + strlen (s) + 1, 1);
- strcpy (buf, auth->dir);
+ char *buf = calloc (proto_len + strlen (auth->dir)
+ + strlen (s) + 1, 1);
+ if (proto_len)
+ strcpy (buf, proto);
+ else
+ buf[0] = 0;
+ strcat (buf, auth->dir);
strcat (buf, s);
- free (--p);
- p = buf;
+ free (base);
+ base = buf;
mu_auth_data_free (auth);
}
- else
- p--;
}
}
if (home)
free (home);
- return p;
+ return base;
}
Regards,
Sergey