]> git.sommitrealweird.co.uk Git - rss2maildir.git/commitdiff
Create Maildirs and Maildir root if possible for the feeds
authorBrett Parker <iDunno@sommitrealweird.co.uk>
Wed, 19 Dec 2007 14:40:35 +0000 (14:40 +0000)
committerBrett Parker <iDunno@sommitrealweird.co.uk>
Wed, 19 Dec 2007 14:40:35 +0000 (14:40 +0000)
CHANGES
rss2maildir.py

diff --git a/CHANGES b/CHANGES
index bdb9fd5b856a2b3b2cf0c0441815d50653c66b62..45e718732f57801a473f3354672479f317ed90ed 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,5 @@
 2007-12-19
 ----------
 
 2007-12-19
 ----------
 
-Initial starting points, config parser and option parsers
+* Initial starting points, config parser and option parsers
+* Creation of directories for maildir usage
index cece6969e6f232e436c1c53bfbd62022b4970091..41654dd5fccc35da406bc754665d54558f6729a4 100755 (executable)
@@ -3,6 +3,8 @@
 import mailbox
 import sys
 import os
 import mailbox
 import sys
 import os
+import stat
+import urllib
 
 from optparse import OptionParser
 from ConfigParser import SafeConfigParser
 
 from optparse import OptionParser
 from ConfigParser import SafeConfigParser
@@ -54,6 +56,18 @@ maildir_root = "RSSMaildir"
 if scp.has_option("general", "maildir_root"):
     maildir_root = scp.get("general", "maildir_root")
 
 if scp.has_option("general", "maildir_root"):
     maildir_root = scp.get("general", "maildir_root")
 
+try:
+    mode = os.stat(maildir_root)[stat.ST_MODE]
+    if not stat.S_ISDIR(mode):
+        sys.stderr.write("Maildir Root %s is not a directory\n" %(maildir_root))
+        sys.exit(1)
+except:
+    try:
+        os.mkdir(maildir_root)
+    except:
+        sys.stderr.write("Couldn't create Maildir Root %s\n" %(maildir_root))
+        sys.exit(1)
+
 feeds = scp.sections()
 try:
     feeds.remove("general")
 feeds = scp.sections()
 try:
     feeds.remove("general")
@@ -61,6 +75,42 @@ except:
     pass
 
 for section in feeds:
     pass
 
 for section in feeds:
-    print section
-    print "-" * len(section)
-    print scp.items(section)
+    # check if the directory exists
+    maildir = None
+    try:
+        maildir = scp.get(section, "maildir")
+    except:
+        maildir = section
+
+    maildir = urllib.urlencode(((section, maildir),)).split("=")[1]
+    maildir = os.path.join(maildir_root, maildir)
+
+    try:
+        exists = os.stat(maildir)
+        if stat.S_ISDIR(exists[stat.ST_MODE]):
+            # check if there's a new, cur and tmp directory
+            try:
+                mode = os.stat(os.path.join(maildir, "cur"))[stat.ST_MODE]
+            except:
+                os.mkdir(os.path.join(maildir, "cur"))
+                if not stat.S_ISDIR(mode):
+                    sys.stderr.write("Broken maildir: %s" %(maildir))
+            try:
+                mode = os.stat(os.path.join(maildir, "tmp"))[stat.ST_MODE]
+            except:
+                os.mkdir(os.path.join(maildir, "tmp"))
+                if not stat.S_ISDIR(mode):
+                    sys.stderr.write("Broken maildir: %s" %(maildir))
+            try:
+                mode = os.stat(os.path.join(maildir, "new"))[stat.ST_MODE]
+                if not stat.S_ISDIR(mode):
+                    sys.stderr.write("Broken maildir: %s" %(maildir))
+            except:
+                os.mkdir(os.path.join(maildir, "new"))
+        else:
+            sys.stderr.write("Broken maildir: %s" %(maildir))
+    except:
+        os.mkdir(maildir)
+        os.mkdir(os.path.join(maildir, "new"))
+        os.mkdir(os.path.join(maildir, "cur"))
+        os.mkdir(os.path.join(maildir, "tmp"))