ALT Linux Community general discussions
 help / color / mirror / Atom feed
* [mdk-re] mailrotate.sh
@ 2001-10-20 23:09 Michael Shigorin
  0 siblings, 0 replies; only message in thread
From: Michael Shigorin @ 2001-10-20 23:09 UTC (permalink / raw)
  To: ALT Linux


[-- Attachment #1.1: Type: text/plain, Size: 780 bytes --]

	Здравствуйте.
Вот, соорудил сегодня mailrotate.

Фичи:
- делает rotation указанных (в т.ч. с шаблонами) mbox'ов в
  "левый" каталог (у меня -- из ~/mail/some_mbox в
  ~/mail/archive/some_mbox/YYYY-MM-DD).
- при этом оставляет контекст -- письма за указанное количество
  времени ago ("7 days").

Баги:
- пока без ~/.___rc, рисую тиклевый конфигуратор (но уже
  споткнулся), так что все в голове скрипта.
- требует пару перловых модулей (впрочем, оно скажет).
- дважды парсит мейлбокс -- я не нашел, чтобы grepmail умел
  разбирать ящик на два потока (+/-). Что ли автора попросить?

-- 
WBR, Michael Shigorin -- webmaster at www.chem.univ.kiev.ua
>Home Page:  http://visa.chem.univ.kiev.ua/~mike/  ICQ: 113344029
>Brainbench: http://www.brainbench.com/transcript.jsp?pid=2434729

[-- Attachment #1.2: mailrotate.sh --]
[-- Type: text/plain, Size: 1459 bytes --]

#!/bin/sh
# A free script to rotate mail by Michael Shigorin <mike@altlinux.ru>
# v20011020

# moves $MBOXES (wildcards allowed) in $MAIL to files named after $DATEFMT in
# directories under $ARCROOT, leaving fresher than $KEEP (see also $SINCEAFTER)
# not to leave mailboxes empty.

# WARNING: BACKUP YOUR MAIL BEFORE USING! NO WARRANTIES!

MDIR=$HOME/mail
ARCROOT=$MDIR/archive
MBOXES="_* READ MDS"
KEEP="7 days"	# to leave me in context
MODE=644	# mktemp will 
DATEFMT=%Y-%m-%d
SINCEAFTER=after	# ...or "since". One day difference.

perl -e 'require Datei::Parse; require Date::Manip' || {
	echo "ERROR: grepmail needs Date::Parse and Date::Manip to" >&2
	echo "       enable -d option (which we need)." >&2
	echo >&2
	echo "Exiting to keep your mail safe; please run" >&2
	echo "perl -MCPAN -e 'install Date::Parse' && perl -MCPAN -e 'install Date::Manip'" >&2
	echo "as root to install the needed modules!" >&2
	exit 1
}

[ -d "$ARCROOT" ] || {
	mkdir -p "$ARCROOT" || {
		echo "ERROR: can't mkdir -p $ARCROOT!" >&2
		exit 1
	}
}

cd "$MDIR"
for i in $MBOXES; do
	[ -f "$i" ] || continue
	ARCDIR="$ARCROOT/$i"
	[ -d "$ARCDIR" ] || mkdir "$ARCDIR"
	ARCMBOX="$ARCDIR/`date -d "$KEEP ago" +$DATEFMT`"
	TMPFILE="`mktemp $i.tmp-XXXXXX`"
	grepmail -had "$SINCEAFTER $KEEP ago" "$i" > "$TMPFILE"
	[ -f "$ARCMBOX" ] && echo "WARNING: $ARCMBOX already exists!"
	grepmail -vhad "$SINCEAFTER $KEEP ago" "$i" >> "$ARCMBOX"
	mv "$TMPFILE" "$i"
	chmod $MODE "$i"
done

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2001-10-20 23:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-20 23:09 [mdk-re] mailrotate.sh Michael Shigorin

ALT Linux Community general discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
		mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
	public-inbox-index community

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.community


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git