summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAurélien Bompard <aurelien@bompard.org>2012-11-06 15:11:27 +0100
committerAurélien Bompard <aurelien@bompard.org>2012-11-06 15:11:27 +0100
commitf509608d40c08fce20f5f836ad764bcdc71ed5cb (patch)
treeb446358f1f85845525648bf952c768aae5889f71
parentcae57f7d5951e91f2f781f37e095acd88f999d89 (diff)
downloadkittystore-f509608d40c08fce20f5f836ad764bcdc71ed5cb.tar.gz
kittystore-f509608d40c08fce20f5f836ad764bcdc71ed5cb.tar.xz
kittystore-f509608d40c08fce20f5f836ad764bcdc71ed5cb.zip
Importer: add an option to disable attachment downloading
-rw-r--r--kittystore/import.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/kittystore/import.py b/kittystore/import.py
index 5aead41..c820a8a 100644
--- a/kittystore/import.py
+++ b/kittystore/import.py
@@ -98,11 +98,12 @@ class DbImporter(object):
Import email messages into the KittyStore database using its API.
"""
- def __init__(self, mlist, store, force_import=False):
+ def __init__(self, mlist, store, opts):
self.mlist = mlist
self.store = store
self.total_imported = 0
- self.force_import = force_import
+ self.force_import = opts.duplicates
+ self.no_download = opts.no_download
def from_mbox(self, mbfile):
""" Upload all the emails in a mbox file into the database using
@@ -180,7 +181,10 @@ class DbImporter(object):
def download_attachment(self, message_id, counter, name, ctype, url):
#print "Downloading attachment from", url
- content = urllib.urlopen(url).read()
+ if self.no_download:
+ content = ""
+ else:
+ content = urllib.urlopen(url).read()
self.store.add_attachment(self.mlist, message_id, counter, name,
ctype, None, content)
@@ -194,6 +198,8 @@ def parse_args():
help="show more output")
parser.add_option("-d", "--debug", action="store_true",
help="show a whole lot more of output")
+ parser.add_option("--no-download", action="store_true",
+ help="don't download attachments")
parser.add_option("-D", "--duplicates", action="store_true",
help="do not skip duplicate emails (same Message-ID header), "
"import them with a different Message-ID")
@@ -216,7 +222,7 @@ def main():
print 'Importing messages from %s to database...' % opts.list_name
store = get_store(KITTYSTORE_URL, debug=opts.debug)
mlist = DummyMailingList(opts.list_name)
- importer = DbImporter(mlist, store, force_import=opts.duplicates)
+ importer = DbImporter(mlist, store, opts)
for mbfile in args:
print "Importing from mbox file %s" % mbfile
importer.from_mbox(mbfile)