code: def compress_and_sort_index(self):
          idx_fname = '{name}.{date}.mbox.csv'.format(**self.__dict__)
          try:
              reader = csv.reader(open(idx_fname), dialect='excel-tab')
          except IOError:
              return False
          index = [x for x in reader if x]
          sorted_index = sorted(index, key=itemgetter(0))
          gzip_idx_fname = idx_fname + '.gz'
          header = [
              '\xef\xbb\xbf
              'start', 'length',
          ]
          s = cStringIO.StringIO()
          writer = csv.writer(s, dialect='excel-tab')
          writer.writerow(header)
          for line in sorted_index:
              writer.writerow(line)
          compressed_index = inline_compress_chunk(s.getvalue())
          s.close()
          with open(gzip_idx_fname, 'ab') as fp:
              fp.write(compressed_index)
          os.remove(idx_fname)
          return True