bug-mailutils
[Top][All Lists]
Advanced

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

mail's "copy" command incorrectly handles folders (w/ patch)...


From: Matthew Whitworth
Subject: mail's "copy" command incorrectly handles folders (w/ patch)...
Date: Mon, 15 Jul 2002 16:00:36 -0700 (PDT)

I've noticed mail's "copy" command has the same filename expansion
problems that I previously reported for the "file" command.  I've got a
patch that seems to work (based on Sergey's mail_file() mods -- see
below), but this issue has brought up two questions:

1. Should all this filename expansion be handled by mail's commands
themselves or should it be handled by the mailbox_*() functions?
mailbox_create_default() seems to want to handle this, but its plus
expansion (courtesy of plus_expand()) appears to be broken.

2. Should "copy" support the '#' (previous file) semantics available to
"file"?  It kinda makes sense, and I can see an argument in favor of it,
especially if you want to handle filename expansion at a lower level than
in the individual commands.  But that's exactly where it will cause
problems.  Trying to expand '#' in a mailbox_*() function will require
storing the previous filename somewhere accessible, rather than in the
static char *prev_file that mail_file() uses.

For the record, my patch to mail/copy.c does not support '#' expansion.

Matthew

---PATCH---

Index: mail/copy.c
===================================================================
RCS file: /cvsroot/mailutils/mailutils/mail/copy.c,v
retrieving revision 1.11
diff -c -r1.11 copy.c
*** mail/copy.c 15 Sep 2001 20:50:42 -0000      1.11
--- mail/copy.c 15 Jul 2002 22:56:47 -0000
***************
*** 37,54 ****
    msgset_t *msglist = NULL, *mp;
    int sender = 0;
    size_t total_size = 0, total_lines = 0, size;

    if (isupper (argv[0][0]))
      sender = 1;
    else if (argc >= 2)
!     filename = strdup(argv[--argc]);
    else
!     filename = strdup("mbox");

    if (msgset_parse (argc, argv, &msglist))
      {
-       if (filename)
-           free (filename);
        return 1;
      }

--- 37,84 ----
    msgset_t *msglist = NULL, *mp;
    int sender = 0;
    size_t total_size = 0, total_lines = 0, size;
+   struct mail_env_entry *env;

    if (isupper (argv[0][0]))
      sender = 1;
    else if (argc >= 2)
!     {
!       switch (argv[argc-1][0])
!       {
!       case '&':
!         filename = getenv ("MBOX");
!         break;
!
!       case '+':
!         env = util_find_env ("folder");
!         if (env->set && env->value[0] != '/' && env->value[1] != '~')
!           {
!             char *home = mu_get_homedir ();
!             filename = alloca (strlen (home) + 1 +
!                                strlen (env->value) + 1 +
!                                strlen (argv[argc-1] + 1) + 1);
!             if (!filename)
!               {
!                 util_error ("Not enough memory");
!                 return 1;
!               }
!             sprintf (filename, "%s/%s/%s",
!                      home, env->value, argv[argc-1] + 1);
!           }
!         else
!           filename = argv[argc-1];
!         break;
!
!       default:
!         filename = argv[argc-1];
!       }
!       --argc;
!     }
    else
!     filename = getenv ("MBOX");

    if (msgset_parse (argc, argv, &msglist))
      {
        return 1;
      }

***************
*** 66,72 ****
        || mailbox_open (mbx, MU_STREAM_WRITE | MU_STREAM_CREAT))
      {
        util_error ("can't create mailbox %s", filename);
-       free (filename);
        msgset_free (msglist);
        return 1;
      }
--- 96,101 ----
***************
*** 94,100 ****
    mailbox_close (mbx);
    mailbox_destroy (&mbx);

-   free (filename);
    msgset_free (msglist);
    return 0;
  }
--- 123,128 ----







reply via email to

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