Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
new tool smd-uniform-names
Browse files Browse the repository at this point in the history
  • Loading branch information
Enrico Tassi committed May 19, 2012
1 parent 661fb3e commit 0da78a3
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Makefile
Expand Up @@ -8,7 +8,7 @@ COPYRIGHT=© 2008-2012 Enrico Tassi <gares@fettunta.org>
BINARIES=mddiff smd-applet
MANPAGES1=mddiff.1 smd-server.1 smd-client.1 \
smd-pull.1 smd-push.1 smd-loop.1 smd-applet.1 smd-translate.1 \
smd-check-conf.1 smd-restricted-shell.1
smd-check-conf.1 smd-restricted-shell.1 smd-uniform-names.1
MANPAGES5=smd-config.5
HTML=index.html design.html hooks.html
DESTDIR=
Expand All @@ -17,7 +17,7 @@ SF_LOGIN=$(SF_USER),syncmaildir
SF_WEB=htdocs
TEST_SIZE=100
TEST_MAILBOX=misc/Mail.TEST.tgz
TEST_SUITES=mddiff client-server pull-push
TEST_SUITES=mddiff client-server pull-push migration
BENCH_SIZE=25000
BENCH_MAILBOX=misc/Mail.BENCH.tgz
BENCH_SUITES=benchmarks
Expand Down Expand Up @@ -171,6 +171,7 @@ install-bin: $(BINARIES)
$(call install-replacing,smd-push,bin)
$(call install-replacing,smd-translate,bin)
$(call install-replacing,smd-check-conf,bin)
$(call install-replacing,smd-uniform-names,bin)
$(call install-replacing,smd-restricted-shell,bin)
$(call install-replacing,smd-loop,bin)
$(call install-replacing,smd-common,share/$(PROJECTNAME))
Expand Down
2 changes: 2 additions & 0 deletions TODO
@@ -1,3 +1,5 @@
- it seems that escaping in translator LR RL is inconsistent
- check for .. in MAILBOX_*
- smd-uniform-names
- no delete 2nd round
- autostart option in smd applet
1 change: 1 addition & 0 deletions smd-common
Expand Up @@ -84,6 +84,7 @@ init() {
LOCALEXCLUDE=
SMDCLIENTOPTS=
SMDSERVEROPTS=
RENAMEDB=~/.smd/rename-db

# default values for the configuration file
DEBUG=false
Expand Down
86 changes: 86 additions & 0 deletions smd-uniform-names
@@ -0,0 +1,86 @@
#!/bin/sh
#
# Released under the terms of GPLv3 or at your option any later version.
# No warranties.
# Copyright Enrico Tassi <gares@fettunta.org>

# the idea is:
# 0) it is the first run (no db)
# 1) we compute the local db with mddiff
# 2) we push it to the remote host via ssh
# 3) we start a special pull where smd-server uses the special db
# and where smd-client just emits a shell script with all the renaming
# 4) we remove the remote db

set -e
#set -x

PREFIX="@PREFIX@"
if [ `echo "$PREFIX" | cut -c -1` = "@" ]; then
SMDROOT=.
echo "smd-uniform-names not installed, assuming smd-common is ./smd-common"
else
SMDROOT=$PREFIX/share/syncmaildir
fi

. $SMDROOT/smd-common

init
parse_args "$@"
read_conffile
# this could be a system wide pre-hook
check_lockfile
setup_plumbing
setup_logging
setup_mailboxnames

# we move to the home, since Mail paths are relative
# to the home
cd

setup_workarea

ORIG_CHILDARGS="$CHILDSARGS"

CHILDSARGS="$ORIG_CHILDARGS --get-mddiff-cmdline --override-db $RENAMEDB"
MDLINE=`run_local_server`


gc_mktemp
TMPERR="$RC"
$MDLINE > /dev/null 2> $TMPERR
grep -v '^warning.*unable to open db' $TMPERR || true
mv $RENAMEDB.new $RENAMEDB
atexit_rm $RENAMEDB.mtime.new
atexit_rm $RENAMEDB

CHILDSARGS="$ORIG_CHILDARGS --dump-stdin $RENAMEDB"
cat $RENAMEDB | run_remote_server

($MITM $CtS > $LtS) < $CtL &
LOGGER1=$!
atexit_kill $LOGGER1

($MITM $StC > $LtC) < $StL &
LOGGER2=$!
atexit_kill $LOGGER2

($PROGRESS_REPORTER $CL) < $PRp &
REPORTER=$!
atexit_kill $REPORTER

CHILDSARGS="$ORIG_CHILDARGS --rename-only --override-db $RENAMEDB"
(run_local_client < $LtC 2> $PRp) > $CtL &
CLIENT=$!
atexit_kill $CLIENT

CHILDSARGS="$ORIG_CHILDARGS --stop-after-diff --override-db $RENAMEDB"
EXITCODE=0
(run_remote_server < $LtS 2> $SL) > $StL || EXITCODE=1

wait $CLIENT || EXITCODE=1
wait $REPORTER || EXITCODE=1

report $EXITCODE 0 smd-push smd-pull smd-server smd-client

exit $EXITCODE
29 changes: 29 additions & 0 deletions smd-uniform-names.1.txt
@@ -0,0 +1,29 @@
NAME
smd-uniform-names - renames local mails as on the remote host

SYNOPSIS
smd-uniform-names [-v|--verbose] [endpoint]

DESCRIPTION
smd-uniform-names is useful to migrate from offlineimap to smd.
offlineimap may name the same email differently on the local and
remote host. This utility generates a script to be run on the local
host to uniform the names to the remote ones.

The utility generates the script '~/smd-rename.sh' that has to be run
by the user.

OPTIONS
-v --verbose Verbose output
endpoint Is the suffix for the name of the configuration file to
use. If it is omitted, the configuration file
~/.smd/config.default is used.
FILES
~/.smd/config.*
~/smd-rename.sh

SEE ALSO
smd-pull(1), smd-push(1), smd-config(5)

AUTHOR
Enrico Tassi <gares@fettunta.org>
10 changes: 10 additions & 0 deletions tests.d/common
Expand Up @@ -104,6 +104,16 @@ mcheck(){
$ROOT/$TESTSUITE/$__N__/bin/smd-check-conf "$@" > log.check 2>&1
}

muniform(){
LUA_INIT="package.path='$ROOT/$TESTSUITE/$__N__/share/lua/5.1/?.lua;'" \
HOME=$ROOT/$TESTSUITE/$__N__/target \
PATH=$ROOT/$TESTSUITE/$__N__/bin:$PATH \
HOMES=$ROOT/$TESTSUITE/$__N__/ \
$ROOT/$TESTSUITE/$__N__/bin/smd-uniform-names "$@" \
> log.uniform 2>&1

}

assert(){
if [ "$1" = "$2" ]; then
echo -n '.'
Expand Down
18 changes: 18 additions & 0 deletions tests.d/migration/01-uniform
@@ -0,0 +1,18 @@
#!/bin/sh

mpull -t
assert $? 0 "failed mpull -t"
echo DEBUG=true >> target/.smd/config.default

cp -r Mail target/Mail
cd target/Mail/cur
for x in *; do mv $x $x`md5sum $x | cut -d ' ' -f 1`; done
cd ../../..

muniform -v
cd target
sh smd-rename.sh
cd ..

test_eq Mail target/Mail

0 comments on commit 0da78a3

Please sign in to comment.