User Tools

Site Tools


doc:appunti:linux:sa:offlineimap3_nametrans

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
doc:appunti:linux:sa:offlineimap3_nametrans [2024/03/22 11:10] niccolodoc:appunti:linux:sa:offlineimap3_nametrans [2024/03/22 11:23] (current) – [The configuration file] niccolo
Line 1: Line 1:
 ====== offlineimap3 IMAP syncronization: nametrans ====== ====== offlineimap3 IMAP syncronization: nametrans ======
 +
 +In this page we study a case of IMAP syncronization from a source IMAP server to a Maildir structure on local disk, using the **[[https://github.com/OfflineIMAP/offlineimap3|offlineimap3]]** tool.
 +
 +The main issue is the need to **map the source directory tree** into a tree compatible with the receiving Maildir hierarchy. Here are the issues:
  
 The **source IMAP** server has the following characteristics: The **source IMAP** server has the following characteristics:
Line 13: Line 17:
   * The "." character is not allowed in folder names.   * The "." character is not allowed in folder names.
  
-In this case we need a very special **nametrans** expression.+In this case we need a very special **nametrans** expression into the [[https://github.com/OfflineIMAP/offlineimap3|offlineimap3 configuration file]].
  
 :!: **NOTICE**: The mapping of the top-level folders under the INBOX during the transfer from IMAP to Maildir prevents the reverse mapping from Maildir to IMAP, therefore only synchronization from IMAP to Maildir will be possible and not vice versa. :!: **NOTICE**: The mapping of the top-level folders under the INBOX during the transfer from IMAP to Maildir prevents the reverse mapping from Maildir to IMAP, therefore only synchronization from IMAP to Maildir will be possible and not vice versa.
 +
 +===== Testing the nametrans option =====
  
 It is possibile to write a simple Python script to test the **nametrans** expression: It is possibile to write a simple Python script to test the **nametrans** expression:
Line 63: Line 69:
  
 :!: **NOTICE**: The translated name of a sub-subfolder contains the original **directory separator** (.e.g. ''.Archives/2013''), this is OK because offlineimap3 is aware of the differencies in directory separator from the IMAP surce (the "/" is detected automatically) and the destination Mailird ("." is the default). So the destination folder is correctly created as ''.Archives.2013''. :!: **NOTICE**: The translated name of a sub-subfolder contains the original **directory separator** (.e.g. ''.Archives/2013''), this is OK because offlineimap3 is aware of the differencies in directory separator from the IMAP surce (the "/" is detected automatically) and the destination Mailird ("." is the default). So the destination folder is correctly created as ''.Archives.2013''.
 +
 +===== The configuration file =====
 +
 +This is the overall **offlineimap.conf** file:
 +
 +<file>
 +[general]
 +accounts = CopyFromIMAP
 +
 +[Account CopyFromIMAP]
 +remoterepository = OldServer
 +localrepository = NewServer
 +
 +[Repository OldServer]
 +type = IMAP
 +nametrans = lambda foldername: re.sub(r'^\.INBOX$', '', '.' + re.sub(r'^INBOX/', '', foldername.replace('.', '_')))
 +remotehost = mail.oldserver.com
 +remoteuser = username@oldserver.com
 +remotepass = MySecret
 +createfolders = False
 +
 +[Repository NewServer]
 +type = Maildir
 +localfolders = /home/username/Maildir
 +</file>
 +
 +Notice the ''createfolders = False'' for the source IMAP server. As explained above the syncronization is uni-directional from IMAP to Maildir, so we avoid to propagate directories backward.
 +
 +To run the command with some debugging:
 +
 +<code>
 +offlineimap -1 -c ./offlineimap.conf -d imap,maildir -l offlineimap.log
 +</code>
  
 ===== Web References ===== ===== Web References =====
doc/appunti/linux/sa/offlineimap3_nametrans.1711102209.txt.gz · Last modified: 2024/03/22 11:10 by niccolo