diff options
Diffstat (limited to 'modules/mm_archive.py')
| -rw-r--r-- | modules/mm_archive.py | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/modules/mm_archive.py b/modules/mm_archive.py index f009221d7..800373696 100644 --- a/modules/mm_archive.py +++ b/modules/mm_archive.py @@ -1,17 +1,25 @@ import sys, os, string import mm_utils, mm_mbox, mm_cfg, mm_message +ARCHIVE_PENDING = "to-archive.mail" +ARCHIVE_RETAIN = "retained.mail" + class Archiver: def InitVars(self): # Configurable self.archive = 1 self.archive_directory = os.path.join(mm_cfg.HTML_DIR, "archives/%s" % self._internal_name) + self.archive_update_frequency = \ + mm_cfg.DEFAULT_ARCHIVE_UPDATE_FREQUENCY + self.archive_volume_frequency = \ + mm_cfg.DEFAULT_ARCHIVE_VOLUME_FREQUENCY + self.archive_retain_text_copy = \ + mm_cfg.DEFAULT_ARCHIVE_RETAIN_TEXT_COPY + # Not configurable self._base_archive_url = os.path.join(mm_cfg.ARCHIVE_URL, self._internal_name) - self.archive_update_frequency = 1 # 0 = never, 1 = daily, 2 = hourly - self.archive_volume_frequency = 0 # 0 = yearly, 1 = monthly self.clobber_date = 0 def GetConfigInfo(self): @@ -21,12 +29,16 @@ class Archiver: ('archive_update_frequency', mm_cfg.Number, 3, 0, "How often should new messages be incorporated? " - "0 for no archival, typically 1 for daily, 2 for hourly"), + "0 for no archival, 1 for daily, 2 for hourly"), ('archive_volume_frequency', mm_cfg.Radio, ('Yearly', 'Monthly'), 0, 'How often should a new archive volume be started?'), + ('archive_retain_text_copy', mm_cfg.Toggle, ('No', 'Yes'), + 0, + 'Retain plain text copy of archive?'), + ('clobber_date', mm_cfg.Radio, ('When sent', 'When resent'), 0, 'Set date in archive to when the mail is claimed to have been ' 'sent, or to the time we resend it?'), @@ -38,7 +50,7 @@ class Archiver: def UpdateArchive(self): if not self.archive: return - archive_file_name = os.path.join(self._full_path, "archived.mail") + archive_file_name = os.path.join(self._full_path, ARCHIVE_PENDING) archive_dir = os.path.join(self.archive_directory, 'volume_%d' % self.volume) @@ -65,16 +77,21 @@ class Archiver: # Internal function, don't call this. def ArchiveMail(self, post): - archive_file = open(os.path.join(self._full_path, - "archived.mail"), - "a+") - archive_mbox = mm_mbox.Mailbox(archive_file) if self.clobber_date: import time olddate = post.getheader('date') post.SetHeader('Date', time.ctime(time.time())) - archive_mbox.AppendMessage(post) + self.ArchiveMailFiler(post, ARCHIVE_PENDING) + if self.archive_retain_text_copy: + self.ArchiveMailFiler(post, ARCHIVE_RETAIN) if self.clobber_date: + # Resurrect original date setting. post.SetHeader('Date', olddate) - archive_mbox.fp.close() self.Save () + + def ArchiveMailFiler(self, post, fn): + """ArchiveMail helper - given file name, actually do the save.""" + mbox = mm_mbox.Mailbox(open(os.path.join(self._full_path, fn), + "a+")) + mbox.AppendMessage(post) + mbox.fp.close() |
