[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
mail's "file" command incorrectly handles folders (w/ patch)...
From: |
Matthew Whitworth |
Subject: |
mail's "file" command incorrectly handles folders (w/ patch)... |
Date: |
Sun, 14 Jul 2002 22:18:29 -0700 |
The mail utility's file command incorrectly handles arguments that
begin with '+'.
According to the Single Unix Specification (and I'm assuming POSIX),
arguments that begin with '+' refer to files named in the "folder"
directory, and the "folder" directory is the user's home directory
concatenated with the value of the "folder" variable.
Currently when mail_file() handles an argument beginning with '+' it
passes the value of the "folder" variable as the name of the mailbox
that it tries to open intead of further processing its argv[1]:
---
switch (argv[1][0])
{
[...]
case '+':
env = util_find_env ("folder");
if (env->set)
name = env->value; /* this neglects the full argument...! */
else
name = argv[1];
break;
---
I've got a patch, but the solution is fugly. The 'name' variable
typically receives a pointer to separately managed memory. But in order
to concatenate the user's home directory, the folder directory and the
file name I needed to allocate my own memory. To keep track of this,
I had to set a flag and check it (freeing the memory if needed) before
any returns.
---
Index: file.c
===================================================================
RCS file: /cvsroot/mailutils/mailutils/mail/file.c,v
retrieving revision 1.7
diff -r1.7 file.c
51c51,52
<
---
> int name_allocated = 0;
>
69,71c70,80
< if (env->set)
< name = env->value;
< else
---
> if ((env->set) && (argv[1][1])) {
> name_allocated = 1;
> name = xmalloc (strlen (getenv ("HOME")) + 1 +
> strlen (env->value) + 1 +
> strlen (argv[1]+1) + 1);
> strcpy (name, getenv ("HOME"));
> strcat (name, "/");
> strcat (name, env->value);
> strcat (name, "/");
> strcat (name, argv[1]+1);
> } else {
72a82
> }
81a92,93
> if (name_allocated)
> free (name);
91a104,105
> if (name_allocated)
> free (name);
110a125,126
> if (name_allocated)
> free (name);
> strcat (name, argv[1]+1);
> }
72c83,85
< name = argv[1];
---
> {
> name = argv[1];
> }
81a95,96
> if (name_allocated)
> free (name);
87a103,105
> if (name_allocated)
> free (name);
>
---
Maybe there's an easier way to do this....
Matthew
- mail's "file" command incorrectly handles folders (w/ patch)...,
Matthew Whitworth <=