--H1spWtNR+x+ondvy
Content-Type: multipart/mixed; boundary="y0ulUmNC+osPPQO6"
Content-Disposition: inline


--y0ulUmNC+osPPQO6
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, 06 Sep 2001 at 23:43:41 -0400, Matej Cepl wrote:
> On 7 Sep 2001, at 2:21, Piet Delport wrote:
> > - The ${foo} syntax expands to the contents of variable "foo", not
> >   to the output of command "foo".  For command substitution, either
> >   use $(foo), or `foo` (note the backticks).  The $(foo) form nests
> >   easier than the `foo` form, but the latter is more common between
> >   shells.
>=20
> Thanks, I will use $().

It's mostly a matter of personal taste, i know, but i still think `` is
better, as (AFAIK) it predates $(), and should be supported by more
shells.  Not that i can name any examples though. :-)

[snip]
> > I've attached my version of your script with all of the above worked
> > in.  Warning: it's still totally untested.  Comments welcome.
>=20
> Actually, you haven't.

Gah, my apologies.  This is the result of sending long mails in the wee
hours of the morning without proof-reading them.

> However, I have reconstructed the most of your advice and the result
> is attached. The find command you proposed wouldn't work, because the
> purpose of the command is to move messages from the folder in $MAILDIR
> to the one in $ARCHDIR, which cannot be accomplished via mere {}.

Indeed.  I was actually planning to tackle this problem with something
like basename, but completely forgot about it before pressing `send'.

> See my proposed solution, which is not optimal either, because it
> doesn't work with mailboxes in the subdirectories of $MAILDIR.  Any
> thoughts?

Looks promising, aside from a minor quoting problem (the argument for
mutt -e should be in double-quotes, as 1. single-quoted strings can't
contain single-quotes, not even escaped ones, and 2. no variable or
command substitution takes place at all in single-quoted strings,
meaning the final argument to mutt would be to save the messages in a
folder literally called "$ARCHDIR/$(basename {})" (except that {} would
still replaced by find...)).

There's a biggish problem with this approach that i've overlooked until
now though:

The -exec argument of find passes everything directly to the program
that is its argument, with no shell or expansion performed whatsoever,
aside from replacing a literal '{}' anywhere with the found file's name.
So even after fixing the quotes, the "basename {}" bit will be
interpreted too early, and *find* will be passed the basename of "{}",
which stays "{}".  So there's no net effect, mutt will still be
instructed to save the messages to {}.

I thought about this, and came up with a different approach, that (i
think :-) solves the above problem, along with correctly handling files
in sub-directories:

find $MAILDIR/ \
    \! -name 'sent-*' \
    \! -name trash \
    \! -name draft \
    -exec /bin/sh -c \
"mutt -f '{}' -e \
\"push '<tag-message>~d -\`date --date=3D$ARCHDATE +%d/%m/%Y\`=0D\
<tag-prefix><save-message>\`echo '{}' | sed -e \"s:^$MAILDIR:$ARCHDIR:\"\`=
=0D\
<quit>'\"" \;

(This is beginning to approach some the scariest shell scripting i've
written...)

Explanations (as much for my benefit as anyone else's):

- I'm listing each of the excluded folder names separately as "\! -name
  foo";  this is to make it slightly easier to add/remove folder names.

- I'm -execing /bin/sh -c, instead of mutt directly, because a sub-shell
  is needed to interpret shell constructs *after* find has replaced {}
  with the mail folder name.

- The crucial bit here is:

        `echo '{}' | sed -e "s:^$MAILDIR:$ARCHDIR:"`

  This will eventually get parsed to (say):

        `echo '/my_mail_dir/subdir/myfolder' | sed -e "s:^/my_mail_dir:/my_arch_di=
r:"`

  which should result in "/my_arch_dir/subdir/myfolder" being passed to
  mutt as the folder to save the expired messages into.

> And I still do not know how to achieve the last command (archiving of
> the sent-* mailboxes).

This isn't going to be too easy, i think.  I'm playing around with some
ideas here though, will let you know what turns up.

[snip (Free)BSD date(1) using -v for relative dates, as opposed to GNU
date(1)'s -d and --date...]

This presents a portability problem...  either non-GNU systems will have
to install GNU date or the script should have an option to switch
between the two syntaxes, neither of which is particularly fun.  Maybe
an equivalent perl one-liner can be used instead of date(1), to sidestep
the problem?

--=20
Piet Delport <[EMAIL PROTECTED]>
Today's subliminal thought is:

--y0ulUmNC+osPPQO6
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="archmail.new"

#!/bin/sh
# $Id: archmail,v 1.2 2001/09/05 14:26:09 user Exp $
#

##set variables and functions
# I prefer to have all configuration in one place (and therefore
# I do not use relative dates in mutt).
ARCHDATE="3 month ago"
TRASHDATE="1 fortnight ago"
MAILDIR="$HOME/.mail"
ARCHDIR="$HOME/archiv/`date --date=$ARCHDATE '+%Y'`/mail"       ##

# archivation process itself
find $MAILDIR/ \
    \! -name 'sent-*' \
    \! -name trash \
    \! -name draft \
    -exec sh -c \
"mutt -f '{}' -e \
\"push '<tag-message>~d -\`date --date=$ARCHDATE +%d/%m/%Y\`
\
<tag-prefix><save-message>\`echo '{}' | sed -e \"s:^$MAILDIR:$ARCHDIR:\"\`
\
<quit>'\"" \;


# delete old trash
mutt -f $MAILDIR/trash \
     -e "push '<delete-pattern>~d -`date --date=$TRASHDATE +%d/%m/%Y`
<quit>'"

#move old sent-* files to archive
# I have set in .muttrc
# set record="=sent-${date +%m}"
# how to find all sent-* folders
# with name corresponding to $ARCHDATE and older???
#??? Something like:
#??? find $MAILDIR/ -name sent-*??? -exec mv {} $ARCHDIR/ ;

--y0ulUmNC+osPPQO6--

--H1spWtNR+x+ondvy
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (FreeBSD)
Comment: For info see http://www.gnupg.org

iD8DBQE7mU1fzRUP82sZFCcRAv2QAKCb7FYuQac561JEJ1RqFp/t9+uu9QCeLJ5/
Q1GtDnpDTe/bghshXnL8o1o=
=8Cm1
-----END PGP SIGNATURE-----

--H1spWtNR+x+ondvy--

Reply via email to