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

On Wed, 05 Sep 2001 at 14:39:40 -0400, Matej Cepl wrote:
[...mail archival script...]
>=20
> However, I am really not a programmer and I am still slightly scare of
> Bash. Could you comment, please, on the attached script and tell me
> whether I am to shoot off my foot with this script?

Some quick comments:

- 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.

- In your -e strings for mutt, you must remember to insert the enter
  keypress after commands like "<tag-message>", as mutt doesn't do it
  for you.  "<enter>" won't do though, you either need a "\n" or a
  literal carriage return (which can be gotten in vi by pressing ^V followed
  by ^M, for example).

- You also need to surround push's arguments with quotes of some kind,
  otherwise it complains about having too many arguments.

- Unless this is really what you intended, you probably want to add a
  "<quit>" to the end of each -e string, otherwise mutt will wait
  interactively for you to quit each time.

- ... and, a minor quibble, it's a good idea to use "<tag-prefix>" in
  place of ";", in case you ever decide to remap ";".

- For find, you should escape the parentheses to prevent the shell from
  interpreting them.  Also, it's safer to quote the
    -name sent-*
  bit as
    -name 'sent-*'
  just in case your current directory happens to contain a file starting
  with "sent-".

Portability issues:

- Declare functions without the leading "function", as the latter is a
  bash thing.

- For find, instead of -not, use "!".  And, like the parens, it's best
  to escape this too.

Then, about the find statement in the script...

Currently, you have:

> find $MAILDIR/ \
>      -not ( -name sent-* -o -name trash -o -name draft ) \
>      -printf "%P\n" | xargs process

where "process" is a shell function that takes care of archiving all old
mail in the folder named by its first argument ($1).

The find statement will fail to work for two reasons:

1.  "xargs foo" takes its input and gives *all of them at once* as
    arguments for foo.  So "process" would only ever affect the first
    folder found, the rest would be ignored.
2.  xargs will never even find "process" in the first place, as it's a
    shell function.  It can only see and call `real' programs.

To get around this, you can do something like the following (sorry for
the long line):

find $MAILDIR/ \
    \! \( -name 'sent-*' -o -name trash -o -name draft \) \
    -exec mutt -f {} \
      -e 'push "<tag-message>~d -'`date --date=3D$ARCHDATE '+%d/%m/%Y'`"=0D=
<tag-prefix><save-message>{}=0D<quit>\"" \;
   =20
Don't panic. :-) Basically, this does the find, and just directly
executes mutt on each of the matching folders.

I've attached my version of your script with all of the above worked in.
Warning: it's still totally untested.  Comments welcome.

[ One minor problem so far is that the FreeBSD date(1) doesn't
understand the --date option, but has a -v option rather, with:
    -v -3m
meaning 3 months ago, and
    -v +7d
meaning 7 days from now, etc.  Does GNU date(1) support the -v option? ]

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

--M9NhX3UHpAaciwkO
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

iD8DBQE7mBMYzRUP82sZFCcRAktzAKClfCT7VwcBMjqTY8jprNK3xKoRgQCeOVIx
oBNzxtYl8c0Go51IZExr6rQ=
=5pLQ
-----END PGP SIGNATURE-----

--M9NhX3UHpAaciwkO--

Reply via email to