Control: retitle -1 mb2md: pretty wrong source and destination path expansion
Control: tag -1 + patch

Hi,

Bernd Zeimetz wrote:
> -d . does *not* use the current working directory, but $HOME/. instead.

Yeah, this is confusing but documented. I ran into it a few years ago,
too. From the man-page:

| If this begins with a '/' the path is considered to be absolute,
| otherwise it is relative to the users home directory.

"-s" shows the same behaviour, btw., but it's less clear documented
and probably less often needed.

I don't think we should change the default behaviour much, but adding
a "or with a '.'" in logic and documentation should be an improvement
which should not cause problems for scripts which depend on this
behaviour (as they wouldn't prepend dots just for fun).

My workaround so far is using "-d `pwd`".

The following patch should fix the behaviour to be more sane, but with
retaining the general "path is relative to home" behaviour:

---snip---
--- /usr/bin/mb2md      2008-03-19 14:06:58.000000000 +0100
+++ /root/bin/mb2md     2013-08-23 15:08:06.000000000 +0200
@@ -411,6 +411,7 @@
 my $dest = undef;
 my $strip_ext = undef;
 my $use_cl = undef;    # defines whether we use the Content-Length: header if 
present
+my $pwd = `pwd`; chomp($pwd);
 
 # if option "-c" is given, we use the Content-Length: header if present
 # dangerous! may be unreliable, as the whole CL stuff is a bad idea
@@ -443,7 +444,7 @@
        # it is a subdir of the users $home
        # if it does start with a "/" then
        # let's take $mbroot as a absolut path
-       $opts{s} = "$homedir/$opts{s}" if ($opts{s} !~ /^\//); 
+       $opts{s} = "$homedir/$opts{s}" if ($opts{s} !~ m(^[/.]));
 
        # check if the given source is a mbox file
        if (-f $opts{s})
@@ -493,13 +494,13 @@
 
 # if the destination is relative to the home dir,
 # check that the home dir exists
-die("Fatal: home dir $homedir doesn't exist.\n") if ($dest !~ /^\// &&  ! -e 
$homedir);
+die("Fatal: home dir $homedir doesn't exist.\n") if ($dest !~ m(^[/.]) &&  ! 
-e $homedir);
 
 #
 # form the destination value
 # slap the home dir on the front of the dest if the dest does not begin
 # with a '/'
-$dest = "$homedir/$dest" if ($dest !~ /^\//);
+$dest = "$homedir/$dest" if ($dest !~ m(^[/.]));
 # get rid of trailing /'s
 $dest =~ s/\/$//;
 
@@ -754,6 +755,7 @@
         # Change to the target mailbox directory.
 
         chdir "$maildir" ;
+        $mbox = "$pwd/$mbox";
 
                    # Converts a Mbox to multiple files
                     # in a Maildir.
---snap---

Works for me as expected with e.g. the following command-line:

# ~/bin/mb2md -s ./var-mail/abe -d ./maildir/abe

Sorry, no patch for the also needed documentation update so far.

                Regards, Axel
-- 
 ,''`.  |  Axel Beckert <[email protected]>, http://people.debian.org/~abe/
: :' :  |  Debian Developer, ftp.ch.debian.org Admin
`. `'   |  1024D: F067 EA27 26B9 C3FC 1486  202E C09E 1D89 9593 0EDE
  `-    |  4096R: 2517 B724 C5F6 CA99 5329  6E61 2FF9 CD59 6126 16B5


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to