Modules now in 'src' folder, COPYING and README added
[imap-restore-mail] / src / file_iterator.py
similarity index 88%
rename from file_iterator.py
rename to src/file_iterator.py
index 38a59dc..c704142 100644 (file)
@@ -2,6 +2,17 @@
 restore-mail-inject.py - Tool to inject mails via IMAP
 
 Copyright (c) 2012 Intra2net AG
+Author: Plamen Dimitrov and Thomas Jarosch
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
 '''
 
 import os
@@ -51,6 +62,7 @@ class FileIterator:
             try:
                 with open(mboxlistfile, 'r') as acl_file:
                     for line in acl_file:
+
                         acls = {}
                         try:
                             linedata = MBOXFILE_LINE.match(line).groups()
@@ -91,11 +103,14 @@ class FileIterator:
             return
         # mark mailboxes that should be created
         self.created_mailboxes.append(mailpath)
+        
         subpaths = os.listdir(filepath)
         for subpath in subpaths:
             if subpath == "." or subpath == "..":
                 continue
             new_filepath = filepath + "/" + subpath
+
+            # if path is file validate name and inject
             if (os.path.isfile(new_filepath)):
                 if os.path.getsize(new_filepath) == 0:
                     logging.info("Skipping empty file %s", subpath)
@@ -109,6 +124,8 @@ class FileIterator:
                         except IOError:
                             logging.warning("Could not retrieve mail from the file %s", new_filepath)
             else:
+
+                # if path is directory do recursive call
                 if os.path.isdir(new_filepath):
                     # cyrus ^ vs . storage replacement
                     subpath = subpath.replace("^", ".")
@@ -120,6 +137,7 @@ class FileIterator:
                     for rcr in rcrs_generator:
                         yield rcr
                     logging.debug("Done with directory %s and mailbox %s", new_filepath, new_mailpath)
+
         # mark mailboxes that need acl update
         self.acl_mailboxes.append(mailpath)