From 3a807d0f2b8acb5fa1b35935876484e4b6d6b448 Mon Sep 17 00:00:00 2001 From: Eygene Ryabinkin Date: Mon, 9 Apr 2018 20:09:56 +0300 Subject: [PATCH] Create filenames with no path separators in them We use current hostname as the element of the unique file name. Sometimes there is non-/24 zone delegation, {{{ $ host 144.206.233.65 65.233.206.144.in-addr.arpa is an alias for 65.26/64.233.206.144.in-addr.arpa. }}} as per RFC 2317, https://www.rfc-editor.org/rfc/rfc2317.txt So on Un*x systems we may run into having path separator inside the file name. Not good, things will choke. Prevented this by substituting all appeared path separators in the return value. Signed-off-by: Eygene Ryabinkin Tested-at: my MacOSX instance, my FreeBSD instances --- offlineimap/folder/Maildir.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/offlineimap/folder/Maildir.py b/offlineimap/folder/Maildir.py index 82c7881..f061bcd 100644 --- a/offlineimap/folder/Maildir.py +++ b/offlineimap/folder/Maildir.py @@ -82,6 +82,10 @@ class MaildirFolder(BaseFolder): "general", "utime_from_header", False) self._utime_from_header = self.config.getdefaultboolean( self.repoconfname, "utime_from_header", utime_from_header_global) + # What do we substitute pathname separator in names (if any) + self.sep_subst = '-' + if os.path.sep == self.sep_subst: + self.sep_subst = '_' # Interface from BaseFolder def getfullname(self): @@ -286,9 +290,10 @@ class MaildirFolder(BaseFolder): :returns: String containing unique message filename""" timeval, timeseq = _gettimeseq(date) - return '%d_%d.%d.%s,U=%d,FMD5=%s%s2,%s'% \ + uniq_name = '%d_%d.%d.%s,U=%d,FMD5=%s%s2,%s' % \ (timeval, timeseq, os.getpid(), socket.gethostname(), uid, self._foldermd5, self.infosep, ''.join(sorted(flags))) + return uniq_name.replace(os.path.sep, self.sep_subst) def save_to_tmp_file(self, filename, content):