Package: archivemail
Version: 0.7.0-1
Followup-For: Bug #149955
Hi I recently added bz2 support for archivemail. patch is attached.
Please consider adding this patch.
-- System Information:
Debian Release: 4.0
APT prefers stable
APT policy: (990, 'stable'), (500, 'unstable'), (500, 'testing')
Architecture: i386 (i686)
Shell: /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18-4-686
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8)
Versions of packages archivemail depends on:
ii python 2.4.4-2 An interactive high-level object-o
archivemail recommends no packages.
-- no debconf information
--
"Herr Doktor, der Patient von Zimmer 345, der Simulant, ist letzte Nacht
gestorben." - "Oha, jetzt übertreibt er aber!"
--- /usr/bin/archivemail 2006-11-10 23:22:29.000000000 +0100
+++ archivemail_bz2 2007-07-30 07:59:43.000000000 +0200
@@ -54,7 +54,6 @@
import fcntl
import getopt
-import gzip
import mailbox
import os
import pwd
@@ -166,6 +165,8 @@
"""Class to store runtime options, including defaults"""
archive_suffix = "_archive"
archive_name = None
+ compress_bz2 = 0
+ compress_level = 5
days_old_max = 180
date_old_max = None
delete_old_mail = 0
@@ -201,7 +202,8 @@
"""
try:
opts, args = getopt.getopt(args, '?D:S:Vd:hno:F:P:qs:uv',
- ["date=", "days=", "delete", "dry-run", "help",
+ ["compress-bz2", "compress-level=", "date=",
+ "days=", "delete", "dry-run", "help",
"include-flagged", "no-compress", "output-dir=",
"filter-append=", "pwfile=", "dont-mangle",
"archive-name=",
@@ -211,14 +213,21 @@
user_error(msg)
archive_by = None
+ self.compress = "gzip"
for o, a in opts:
+ if o =='--compress-bz2':
+ self.compress_bz2 = 1
+ self.compress = "bz2"
+ if o == '--compress-level':
+ self.compress_level = int(a)
if o == '--delete':
self.delete_old_mail = 1
if o == '--include-flagged':
self.include_flagged = 1
if o == '--no-compress':
self.no_compress = 1
+ self.compress = "None"
if o == '--warn-duplicate':
self.warn_duplicates = 1
if o in ('-D', '--date'):
@@ -553,7 +562,7 @@
if options.no_compress:
self.__init_uncompressed(final_name)
else:
- self.__init_compressed(final_name)
+ self.__init_compressed(final_name)
self.__final_name = final_name
def __init_uncompressed(self, final_name):
@@ -573,22 +582,39 @@
self.mbox_file_name = temp_name
def __init_compressed(self, final_name):
+ if options.compress == "gzip":
+ import gzip
+ elif options.compress == "bz2":
+ import bz2
"""Used internally by __init__ when archives are compressed"""
assert(final_name)
- compressed_filename = final_name + ".gz"
+ if not options.compress_bz2:
+ compressed_ext = ".gz"
+ else:
+ compressed_ext = ".bz2"
+ compressed_filename = final_name + compressed_ext
if os.path.isfile(final_name):
unexpected_error("""There is already a file named '%s'!
Have you been reading this archive? You probably should re-compress it
manually, and try running me again.""" % final_name)
- temp_name = tempfile.mkstemp("archive.gz")[1]
+ temp_name = tempfile.mkstemp("archive" + compressed_ext)[1]
if os.path.isfile(compressed_filename):
vprint("file already exists that is named: %s" % \
compressed_filename)
shutil.copy2(compressed_filename, temp_name)
_stale.archive = temp_name
- self.mbox_file = gzip.GzipFile(temp_name, "a")
- self.mbox_file_name = temp_name
+ if not options.compress_bz2:
+ self.mbox_file = gzip.GzipFile(temp_name, "a", options.compress_level)
+ else:
+ # There is no append method for module bz2
+ if os.path.getsize(temp_name) == 0:
+ self.mbox_file = bz2.BZ2File(temp_name, "w", 0, options.compress_level)
+ else:
+ oldcontent=bz2.BZ2File(temp_name, "r").read()
+ self.mbox_file = bz2.BZ2File(temp_name, "w", 0, options.compress_level)
+ self.mbox_file.write(oldcontent)
+ self.mbox_file_name = temp_name
def finalise(self):
"""Close the archive and rename this archive temporary file to the
@@ -600,9 +626,12 @@
self.close()
final_name = self.__final_name
if not options.no_compress:
- final_name = final_name + ".gz"
- vprint("renaming '%s' to '%s'" % (self.mbox_file_name,
- final_name))
+ if not options.compress_bz2:
+ final_name = final_name + ".gz"
+ else:
+ final_name = final_name + ".bz2"
+ vprint("renaming '%s' to '%s'" % (self.mbox_file_name,
+ final_name))
try:
os.rename(self.mbox_file_name, final_name)
except OSError: