FAQ.Folders_Mapping.txt 14 KB

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