[mhonarc] get rid of storing archivepath in the class instance
- From: Olav Vitters <ovitters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mhonarc] get rid of storing archivepath in the class instance
- Date: Tue, 12 Feb 2013 20:46:40 +0000 (UTC)
commit ed19566685ec837ff03c10d5aafd88aa2bea63f0
Author: Olav Vitters <olav vitters nl>
Date: Tue Feb 12 21:46:37 2013 +0100
get rid of storing archivepath in the class instance
archive.py | 42 +++++++++++++++++++++++-------------------
1 files changed, 23 insertions(+), 19 deletions(-)
---
diff --git a/archive.py b/archive.py
index d76b947..3f5215f 100755
--- a/archive.py
+++ b/archive.py
@@ -48,20 +48,19 @@ class Archiver:
self.start_time = None
self.end_time = None
- self.archivepath = None
self.tmpfile = None
self.start_time = None
self.end_time = None
- def output(self, last):
- if self.archivepath is None:
+ def output(self, archivepath, last):
+ if archivepath is None:
return False
tmpname = self.tmpname
- path = os.path.join(self.PRIVATE_ARCHIVE_DIR, self.listname, self.archivepath)
+ path = os.path.join(self.PRIVATE_ARCHIVE_DIR, self.listname, archivepath)
if not os.path.exists(path):
os.makedirs(path, 0755)
@@ -71,7 +70,7 @@ class Archiver:
# Call mhonarc for all messages in 'tmpfile'
with open(self.ERRORLOG, "a") as error_fd:
cmd = ['mhonarc', '-umask', '022', '-rcfile', rcfile, '-add', '-output', path, tmpname,
- '-definevar', 'ARCHDATE=%s LISTNAME=%s' % (self.archivepath, self.listname)]
+ '-definevar', 'ARCHDATE=%s LISTNAME=%s' % (archivepath, self.listname)]
#subprocess.call(cmd, stdout=error_fd, stderr=subprocess.STDOUT)
@@ -95,7 +94,8 @@ class Archiver:
pass
- def handle_message(self, fd):
+ def determine_received_time(self, fd):
+ """Determines the received time of a message"""
msg = email.message_from_file(fd)
received_texts = msg.get_all('received')
@@ -123,7 +123,7 @@ class Archiver:
if received_time is None:
# XXX - do some debug stuff
- return False
+ return None
if self.start_time and received_time < self.start_time:
return False
@@ -132,16 +132,18 @@ class Archiver:
return False
# Archive emails per month
- path = received_time.strftime("%Y-%B")
+ return received_time.strftime("%Y-%B")
+
+ def handle_message(self, fd, archivepath):
+ path = self.determine_received_time(fd)
+
+ if path == False:
+ return archivepath
- # mhonarc can archive multiple emails at once, so only run mhonarc
- # once output path changes
- if self.archivepath is not None and self.archivepath != path:
- self.output(False)
+ if archivepath is not None and path is not None and archivepath != path:
+ self.output(archivepath, False)
- self.archivepath = path
- self.last_time = received_time
- self.last_parseable_time = received_time_text
+ return path
def process_fd(self, fd):
"""Process a filedescriptor for multiple emails seperated using the mbox format
@@ -155,6 +157,7 @@ class Archiver:
blank = True
msg = StringIO()
+ archivepath = None
while 1:
line = fd.readline()
if line == "":
@@ -170,17 +173,18 @@ class Archiver:
if msg.tell():
msg.seek(0)
- self.handle_message(msg)
+
+ archivepath = self.handle_message(msg, archivepath)
+
msg.seek(0)
msg.truncate(0)
msg.write(line)
if msg.tell():
- self.handle_message(msg)
-
- self.output(True)
+ archivepath = self.handle_message(msg, archivepath)
+ self.output(archivepath, True)
@classmethod
def make_index(listname, private=False):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]