Browse Source

new tool smd-uniform-names

Enrico Tassi 8 years ago
parent
commit
0da78a36da
7 changed files with 149 additions and 2 deletions
  1. 3
    2
      Makefile
  2. 2
    0
      TODO
  3. 1
    0
      smd-common
  4. 86
    0
      smd-uniform-names
  5. 29
    0
      smd-uniform-names.1.txt
  6. 10
    0
      tests.d/common
  7. 18
    0
      tests.d/migration/01-uniform

+ 3
- 2
Makefile View File

@@ -8,7 +8,7 @@ COPYRIGHT=© 2008-2012 Enrico Tassi <gares@fettunta.org>
8 8
 BINARIES=mddiff smd-applet
9 9
 MANPAGES1=mddiff.1 smd-server.1 smd-client.1 \
10 10
 	 smd-pull.1 smd-push.1 smd-loop.1 smd-applet.1 smd-translate.1 \
11
-	 smd-check-conf.1 smd-restricted-shell.1
11
+	 smd-check-conf.1 smd-restricted-shell.1 smd-uniform-names.1
12 12
 MANPAGES5=smd-config.5
13 13
 HTML=index.html design.html hooks.html
14 14
 DESTDIR=
@@ -17,7 +17,7 @@ SF_LOGIN=$(SF_USER),syncmaildir
17 17
 SF_WEB=htdocs
18 18
 TEST_SIZE=100
19 19
 TEST_MAILBOX=misc/Mail.TEST.tgz
20
-TEST_SUITES=mddiff client-server pull-push
20
+TEST_SUITES=mddiff client-server pull-push migration
21 21
 BENCH_SIZE=25000
22 22
 BENCH_MAILBOX=misc/Mail.BENCH.tgz
23 23
 BENCH_SUITES=benchmarks
@@ -171,6 +171,7 @@ install-bin: $(BINARIES)
171 171
 	$(call install-replacing,smd-push,bin)
172 172
 	$(call install-replacing,smd-translate,bin)
173 173
 	$(call install-replacing,smd-check-conf,bin)
174
+	$(call install-replacing,smd-uniform-names,bin)
174 175
 	$(call install-replacing,smd-restricted-shell,bin)
175 176
 	$(call install-replacing,smd-loop,bin)
176 177
 	$(call install-replacing,smd-common,share/$(PROJECTNAME))

+ 2
- 0
TODO View File

@@ -1,3 +1,5 @@
1 1
 - it seems that escaping in translator LR RL is inconsistent
2 2
 - check for .. in MAILBOX_*
3 3
 - smd-uniform-names
4
+- no delete 2nd round
5
+- autostart option in smd applet

+ 1
- 0
smd-common View File

@@ -84,6 +84,7 @@ init() {
84 84
 	LOCALEXCLUDE=
85 85
 	SMDCLIENTOPTS=
86 86
 	SMDSERVEROPTS=
87
+	RENAMEDB=~/.smd/rename-db
87 88
 
88 89
 	# default values for the configuration file
89 90
 	DEBUG=false

+ 86
- 0
smd-uniform-names View File

@@ -0,0 +1,86 @@
1
+#!/bin/sh
2
+#
3
+# Released under the terms of GPLv3 or at your option any later version.
4
+# No warranties.
5
+# Copyright Enrico Tassi <gares@fettunta.org>
6
+
7
+# the idea is:
8
+# 0) it is the first run (no db)
9
+# 1) we compute the local db with mddiff
10
+# 2) we push it to the remote host via ssh
11
+# 3) we start a special pull where smd-server uses the special db
12
+#    and where smd-client just emits a shell script with all the renaming
13
+# 4) we remove the remote db
14
+
15
+set -e
16
+#set -x
17
+
18
+PREFIX="@PREFIX@"
19
+if [ `echo "$PREFIX" | cut -c -1` = "@" ]; then
20
+	SMDROOT=.
21
+	echo "smd-uniform-names not installed, assuming smd-common is ./smd-common"
22
+else
23
+	SMDROOT=$PREFIX/share/syncmaildir
24
+fi
25
+
26
+. $SMDROOT/smd-common
27
+
28
+init
29
+parse_args "$@"
30
+read_conffile
31
+# this could be a system wide pre-hook
32
+check_lockfile
33
+setup_plumbing
34
+setup_logging
35
+setup_mailboxnames
36
+
37
+# we move to the home, since Mail paths are relative
38
+# to the home
39
+cd
40
+
41
+setup_workarea
42
+
43
+ORIG_CHILDARGS="$CHILDSARGS"
44
+
45
+CHILDSARGS="$ORIG_CHILDARGS --get-mddiff-cmdline --override-db $RENAMEDB"
46
+MDLINE=`run_local_server`
47
+
48
+
49
+gc_mktemp
50
+TMPERR="$RC"
51
+$MDLINE > /dev/null 2> $TMPERR
52
+grep -v '^warning.*unable to open db' $TMPERR || true
53
+mv $RENAMEDB.new $RENAMEDB
54
+atexit_rm $RENAMEDB.mtime.new
55
+atexit_rm $RENAMEDB
56
+
57
+CHILDSARGS="$ORIG_CHILDARGS --dump-stdin $RENAMEDB"
58
+cat $RENAMEDB | run_remote_server 
59
+
60
+($MITM $CtS > $LtS) < $CtL &
61
+LOGGER1=$!
62
+atexit_kill $LOGGER1
63
+
64
+($MITM $StC > $LtC) < $StL &
65
+LOGGER2=$!
66
+atexit_kill $LOGGER2
67
+
68
+($PROGRESS_REPORTER $CL) < $PRp &
69
+REPORTER=$!
70
+atexit_kill $REPORTER
71
+
72
+CHILDSARGS="$ORIG_CHILDARGS --rename-only --override-db $RENAMEDB"
73
+(run_local_client < $LtC 2> $PRp) > $CtL &
74
+CLIENT=$!
75
+atexit_kill $CLIENT
76
+
77
+CHILDSARGS="$ORIG_CHILDARGS --stop-after-diff --override-db $RENAMEDB"
78
+EXITCODE=0
79
+(run_remote_server < $LtS 2> $SL) > $StL  || EXITCODE=1
80
+
81
+wait $CLIENT || EXITCODE=1 
82
+wait $REPORTER || EXITCODE=1 
83
+
84
+report $EXITCODE 0 smd-push smd-pull smd-server smd-client
85
+
86
+exit $EXITCODE

+ 29
- 0
smd-uniform-names.1.txt View File

@@ -0,0 +1,29 @@
1
+NAME
2
+  smd-uniform-names - renames local mails as on the remote host
3
+
4
+SYNOPSIS
5
+  smd-uniform-names [-v|--verbose] [endpoint]
6
+
7
+DESCRIPTION
8
+  smd-uniform-names is useful to migrate from offlineimap to smd.
9
+  offlineimap may name the same email differently on the local and
10
+  remote host. This utility generates a script to be run on the local
11
+  host to uniform the names to the remote ones.
12
+
13
+  The utility generates the script '~/smd-rename.sh' that has to be run
14
+  by the user.
15
+
16
+OPTIONS
17
+  -v --verbose        Verbose output
18
+  endpoint            Is the suffix for the name of the configuration file to
19
+                      use. If it is omitted, the configuration file 
20
+                      ~/.smd/config.default is used.
21
+FILES
22
+  ~/.smd/config.*
23
+  ~/smd-rename.sh
24
+
25
+SEE ALSO
26
+  smd-pull(1), smd-push(1), smd-config(5)
27
+
28
+AUTHOR
29
+  Enrico Tassi <gares@fettunta.org>

+ 10
- 0
tests.d/common View File

@@ -104,6 +104,16 @@ mcheck(){
104 104
 		$ROOT/$TESTSUITE/$__N__/bin/smd-check-conf "$@" > log.check 2>&1
105 105
 }
106 106
 
107
+muniform(){
108
+	LUA_INIT="package.path='$ROOT/$TESTSUITE/$__N__/share/lua/5.1/?.lua;'" \
109
+	HOME=$ROOT/$TESTSUITE/$__N__/target \
110
+	PATH=$ROOT/$TESTSUITE/$__N__/bin:$PATH \
111
+	HOMES=$ROOT/$TESTSUITE/$__N__/ \
112
+		$ROOT/$TESTSUITE/$__N__/bin/smd-uniform-names "$@" \
113
+		> log.uniform 2>&1
114
+
115
+}
116
+
107 117
 assert(){
108 118
 	if [ "$1" = "$2" ]; then
109 119
 		echo -n '.'

+ 18
- 0
tests.d/migration/01-uniform View File

@@ -0,0 +1,18 @@
1
+#!/bin/sh
2
+
3
+mpull -t
4
+assert $? 0 "failed mpull -t"
5
+echo DEBUG=true >> target/.smd/config.default
6
+
7
+cp -r Mail target/Mail
8
+cd target/Mail/cur
9
+for x in *; do mv $x $x`md5sum $x | cut -d ' ' -f 1`; done
10
+cd ../../..
11
+
12
+muniform -v
13
+cd target
14
+sh smd-rename.sh
15
+cd ..
16
+
17
+test_eq Mail target/Mail 
18
+

Loading…
Cancel
Save