forked from imapsync/imapsync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FAQ.Folders_Mapping.txt
281 lines (173 loc) · 8.22 KB
/
FAQ.Folders_Mapping.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/bin/cat
$Id: FAQ.Folders_Mapping.txt,v 1.20 2019/07/27 20:04:57 gilles Exp gilles $
This documentation is also available online at
https://imapsync.lamiral.info/FAQ.d/
https://imapsync.lamiral.info/FAQ.d/FAQ.Folders_Mapping.txt
=======================================================================
Imapsync tips about changing folders names.
=======================================================================
By default, imapsync syncs all folders, one by one, in alphanumeric order.
By default, folders names from host1 are reproduced identical on host2,
except for the prefix and the separator which are automatically adapted
for host2.
The IMAP protocol has a specific way to code folders names,
especially when these names use non-ascii 7bit characters.
This encoding is called utf7imap.
Imapsync uses the same encoding as IMAP: utf7imap.
In order to well specify folders names on the command line, imapsync
prints the complete folder list of both sides at the beginning of each run.
The left column is the encoding you have to use, without the first enclosing
square brackets [], the right column is the human utf8 view.
This document gives most examples with the powerful but complex
option --regextrans2. Before using --regextrans2 you should
consider using --automap and --f1f2 because they are simpler
to understand and use.
--automap : guesses folders mapping, for folders like
"Sent", "Junk", "Drafts", "All", "Archive", "Flagged".
--f1f2 str1=str2 : Force folder str1 to be synced to str2,
--f1f2 overrides --automap and --regextrans2.
--subfolder2 str : Syncs the whole host1 folders hierarchy under the
host2 folder named str.
(It does it internally by adding two
--regextrans2 options before all others.
Add --debug to see what's really going on.)
Things to know and understand before playing with --regextrans2
*) --regextrans2 is used to transform folders names.
*) --regextrans2 applies after the default
inversion prefix1 <-> prefix2 and sep1 <-> sep2.
So, when elaborating the regex you should focus on
the right part of the default mapping printed by
imapsync, the part showing the host2 folder name.
The section to look at is either the folder size section
or within the folder loop located "Here" between the lines
++++ Looping on each folder
Here
++++ End looping on each folder
*) Several --regextrans2 are possible, they will be applied in the order
of the command line, each one on the result of the previous one.
*) --regextrans2 uses Perl regex mechanism so it may be hard to master
this part. It is powerful but not very simple.
*) Windows vs Unix quotes.
On windows don't use single quotes ' around the regex string,
use double quotes instead, like --regextrans2 "myregex"
On Linux/Unix use single quotes ' around the regex string, it is
easier to get what we want with single quotes since the shell
won't change the inner string. Use --regextrans2 'myregex'
*) Good method to elaborate any --regextrans2 string
First, elaborate the --regextrans2 string with --dry --justfolders options.
imapsync ... --dry --justfolders
With --dry imapsync shows the transformations it will do without
really doing them, --dry is the "do nothing" mode.
With --justfolders imapsync will work only with folders,
messages won't be taken into account, so it will be fast
and focused on the folders names.
When the output shows what you expect imapsync to do with folders
names, you can remove the --dry option. Keep the --justfolders
option in order to see if the destination server host2 accepts
to create the folders.
When everything is ok with folders you might remove --justfolders,
imapsync will also transfer messages.
Showing folders sizes is good then transferring messages, it allows
ETA calculation and it's a supplementary check on folders.
=======================================================================
Q. Give examples about --regextrans2
Examples:
1) To remove INBOX. in the name of destination folders
imapsync ... --regextrans2 's/^INBOX\.(.+)/$1/'
2) To change only INBOX to Inbox_Migrated
imapsync ... --regextrans2 's{^INBOX$}{Inbox_Migrated}'
2a) To sync all folders to INBOX
imapsync ... --regextrans2 "s/.*/INBOX/"
2b) To sync a complete account in a subfolder called FOO
With imapsync release 1.641 and former, simply use
imapsync ... --subfolder2 FOO
Examples to this subfolder problem for any release
can be seen below, in another Q/R section.
3) to substitute all characters dot "." by underscores "_"
--regextrans2 "s,\.,_,g"
3b) to substitute all doublequotes " by underscores _
On Linux/Unix:
--regextrans2 's,\",_,g'
On Windows:
--regextrans2 s,\^",_,g
3c) to substitute all characters * % . and # by underscores _
On Linux/Unix:
--regextrans2 'tr,*%.#,_,'
On Windows:
--regextrans2 "tr,*%.#,_,"
You can increase the *%.# list by any unwanted character,
plus, the order doesn't count. See 3d) for &
3d) It is a bad idea to substitute & characters since &
is a character to encode non-ascii characters in IMAP folder names.
4) to change folder names like this:
[mail/Sent Items] -> [Sent]
[mail/Test] -> [INBOX/Test]
[mail/Test2] -> [INBOX/Test2]
On Linux/Unix:
--regextrans2 's,^mail/Sent Items$,Sent,' \
--regextrans2 's,^mail/,INBOX/,'
======================================================================
Q. Is it possible to synchronize all messages from one server to
another without recreating the folder structure and the target server.
R. Yes.
For example, to synchronize all messages in all folders on host1
to folder INBOX only on host2:
1) First try (safe mode):
--regextrans2 "s/.*/INBOX/" --dry --justfolders
2) See if the output says everything you want imapsync to do,
--dry option is safe and does nothing real.
3) Remove --dry
Check the imap folder tree on the target side, you should
only have one: the classical INBOX.
4) Remove --justfolders
=======================================================================
Q. I would like to move emails from InBox to a sub-folder called,
say "2010-INBOX" based on the date. Like all emails received in the
year 2010 should be moved to the folder called "2010-INBOX".
R. 2 ways :
a) With imapsync:
-----------------
imapsync ... \
--search "SENTSINCE 1-Jan-2010 SENTBEFORE 31-Dec-2010"
--f1f2 "INBOX=2010-INBOX" \
--folder INBOX
See also the FAQ FAQ.Messages_Selection.txt
https://imapsync.lamiral.info/FAQ.d/FAQ.Messages_Selection.txt
to get more examples about how to select messages.
b) Manually:
------------
1) You create a folder INBOX.2010-INBOX
2) Mostly every email software allow sorting by date. In INBOX, you
select from 1 January to 31 December 2010 messages with the shift key.
(in mutt, use ~d)
3) Cut/paste in INBOX.2010-INBOX
=======================================================================
Q. How to sync a complete account in a subfolder called FOO,
the hard way.
R0. See the easy above using --subfolder2
R1. Several ways to do it.
a) Separator is dot character "." and "INBOX" prefixes every folder
On Linux/Unix:
--regextrans2 's,^INBOX(.*),INBOX.FOO$1,'
On Windows:
--regextrans2 "s,^INBOX(.*),INBOX.FOO$1,"
or:
b) Separator is the slash character "/" and there is no prefix
On Linux/Unix:
--regextrans2 's,(.*),FOO/$1,'
or with doublequotes
--regextrans2 "s,(.*),FOO/\$1,"
On Windows:
--regextrans2 "s,(.*),FOO/$1,"
or:
c) Any separator, any prefix solution, FOO is the subfolder:
It is a complicated line because every case is taken into account.
Type it in one line (or with the \ at the end of first line on Unix shells.
On Linux/Unix:
--regextrans2 's,${h2_prefix}(.*),${h2_prefix}FOO${h2_sep}$1,' \
--regextrans2 's,^INBOX$,${h2_prefix}FOO${h2_sep}INBOX,'
On Windows:
--regextrans2 "s,${h2_prefix}(.*),${h2_prefix}FOO${h2_sep}$1," ^
--regextrans2 "s,^INBOX$,${h2_prefix}FOO${h2_sep}INBOX,"
=======================================================================
=======================================================================