0

I'm having troubles getting a variable which is set to a path with a space in the name to behave correctly.

In maildrop I want all my Mails that doesn't match the rules (in this example only "Hold") to be move to the archive folder "1. Archive".

Here is my mailfilter configuration.

## FILING RULES for "$HOME/Maildir/.1 Archiver.Filer"

#### Hold
if (/^From:.*test\@gmail\.com*/:h || \
/^Subject:.*Archive Filer Test.*/:h)
{
  TESTDIR="$HOME/Maildir/.Test"
  exception {
  # File mail in test folder
  cc "$DEALSDIR"
  # Mark mails in the folder as read
  `for x in ${TESTDIR}/new/*; do [ -f $x ] && mv $x ${TESTDIR}/cur/${x##*/}:2,S; done`
  `for x in ${TESTDIR}/cur/*:2,; do [ -f $x ] && mv $x ${TESTSDIR}/cur/${x##*/}S; done`
  to "/dev/null" 
  }
}
#### Archive everything else
if  (/^From:.*/:h)
{
  ARCHIVEDDIR="$HOME/Maildir/.1 Archive"
  exception {
  cc "$ARCHIVEDDIR"
  `for x in ${ARCHIVEDDIR}/new/*; do [ -f $x ] && mv $x ${ARCHIVEDDIR}/cur/${x##*/}:2,S; done`
  `for x in ${ARCHIVEDDIR}/cur/*:2,; do [ -f $x ] && mv $x ${ARCHIVEDDIR}/cur/${x##*/}S; done`
  to "/dev/null"
  }
}

The problem is the "#### Archive everything else" part. I tried (a) putting the variable in quotes and (b) using $HOME/Maildir/.1\ Archive/ in the mark-as-read part, but the result remains the same (maybe I missed something):

  1. The mail moves into the archive folder √
  2. It doesn't get marked as read….

If I switch the name with the space with one that doesn't have a space it works.


Side note: this mail filter doesn't run on the inbox. The original plan was to file away anything that I move into "1. Archive" automatically and if there is no rule to keep it in the archive folder.

Since I couldn't come up with a bash script that ignores files that were already matched I created a separate imap folder for filing (the "filer" dir). I pipe the contents of archive to my filing filter for maildrop with this bash script:

#!/bin/bash
cd /home/pattulus/Maildir/.1\ Archive.Filer/cur/;
if ls ./* > /dev/null 2>&1
then
    echo "There are files in that directory!"
    echo  "Filing archived Mails…"
    for MAILFILE in * ;
        do maildrop /home/pattulus/.mailfilter-archive < $MAILFILE && rm -f $MAILFILE ;
    done
    echo "-----------"
    echo "All Mails filed."
else
    echo "There are no files in that directory"
fi
patrick
  • 574
  • 3
  • 10
  • 25
  • I'm not familiar with `maildrop`, but I think you need to quote `$ARCHIVEDIR` everywhere you expand it, e.g., `for x in "${ARCHIVEDDIR}"/new/*`. Until proven otherwise, assume that all parameter expansions should be quoted. – chepner Nov 05 '13 at 17:28
  • also need to quote all references to `$x`, I believe. Good luck to all. – shellter Nov 05 '13 at 17:41
  • Still nothing – I had to "\" the path, too (http://pastebin.com/2B41eMpr) otherwise I get an `bash: line 0: [: /home/pattulus/Maildir/.1: binary operator expected`. The mails get moved but the stay marked as unread. – patrick Nov 05 '13 at 18:07
  • are you sure that the config file should have code embedded in backticks? That could certainly causing extra problems with quoting. If the `exception` block knows how to process `cc` without being in backtics, then I would expect it can process a `for ...` loop as well, but .. I don't know anything about maildrop either. Good luck! – shellter Nov 05 '13 at 23:40
  • It definitely has something to do with the backtics. For now I renamed the the folder from "1. Archive" to "Archive" and will return to that problem when I know more about maildrop (and correctly placing variables in backtics). – patrick Nov 06 '13 at 12:07

0 Answers0