Identify and fix messages with FMD5 inconsistencies
Introduce the '--migrate-fmd5-using-nametrans' option which migrates the
FMD5 hashes from versions prior to 6.3.5.
It seems that commit 'Apply nametrans to all Foldertypes' (6b2ec956cf)
introduced a regression because it changed the FMD5 part of the filename
calculated by OfflineIMAP. Thus, OfflineIMAP believes that the messages
has been removed and adds them back.
For more information, see:
http://www.offlineimap.org/configuration/2016/02/12/debian-upgrade-from-jessie-to-stretch.html
Bug-Debian: https://bugs.debian.org/812108
Reported-by: François <francois@avalenn.eu>
Signed-off-by: Ilias Tsitsimpis <i.tsitsimpis@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
			
			
This commit is contained in:
		 Ilias Tsitsimpis
					Ilias Tsitsimpis
				
			
				
					committed by
					
						 Nicolas Sebrecht
						Nicolas Sebrecht
					
				
			
			
				
	
			
			
			 Nicolas Sebrecht
						Nicolas Sebrecht
					
				
			
						parent
						
							334571038e
						
					
				
				
					commit
					c84d23b656
				
			| @@ -485,3 +485,37 @@ class MaildirFolder(BaseFolder): | ||||
|                 os.unlink(filepath) | ||||
|             # Yep -- return. | ||||
|         del(self.messagelist[uid]) | ||||
|  | ||||
|     def migratefmd5(self, dryrun=False): | ||||
|         """Migrate FMD5 hashes from versions prior to 6.3.5 | ||||
|  | ||||
|         :param dryrun: Run in dry run mode | ||||
|         :type fix: Boolean | ||||
|         :return: None | ||||
|         """ | ||||
|         oldfmd5 = md5(self.name).hexdigest() | ||||
|         msglist = self._scanfolder() | ||||
|         for mkey, mvalue in msglist.iteritems(): | ||||
|             filename = os.path.join(self.getfullname(), mvalue['filename']) | ||||
|             match = re.search("FMD5=([a-fA-F0-9]+)", filename) | ||||
|             if match is None: | ||||
|                 self.ui.debug("maildir", | ||||
|                               "File `%s' doesn't have an FMD5 assigned" | ||||
|                               % filename) | ||||
|             elif match.group(1) == oldfmd5: | ||||
|                 self.ui.info("Migrating file `%s' to FMD5 `%s'" | ||||
|                              % (filename, self._foldermd5)) | ||||
|                 if not dryrun: | ||||
|                     newfilename = filename.replace( | ||||
|                         "FMD5=" + match.group(1), "FMD5=" + self._foldermd5) | ||||
|                     try: | ||||
|                         os.rename(filename, newfilename) | ||||
|                     except OSError as e: | ||||
|                         raise OfflineImapError( | ||||
|                             "Can't rename file '%s' to '%s': %s" % ( | ||||
|                                 filename, newfilename, e[1]), | ||||
|                             OfflineImapError.ERROR.FOLDER), None, exc_info()[2] | ||||
|             elif match.group(1) != self._foldermd5: | ||||
|                 self.ui.warn(("Inconsistent FMD5 for file `%s':" | ||||
|                               " Neither `%s' nor `%s' found") | ||||
|                              % (filename, oldfmd5, self._foldermd5)) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user