original_docstring: Returns tar file with messages from SearchQuerySet in mmox format.
      There are various problems adding non-file objects (ie. StringIO) to tar files
      therefore the mbox files are first built on disk
      
docstring: Returns tar file with messages from SearchQuerySet in mmox format.
  There are various problems adding non-file objects  to tar files
  therefore the mbox files are first built on disk
docstring_tokens: Returns tar file with messages from SearchQuerySet in mmox format . There are various problems adding non - file objects to tar files therefore the mbox files are first built on disk
code: def build_mbox_tar(results, tar, basename):
      """Returns tar file with messages from SearchQuerySet in mmox format.
      There are various problems adding non-file objects (ie. StringIO) to tar files
      therefore the mbox files are first built on disk
      """
      mbox_date = results[0].object.date.strftime('%Y-%m')
      mbox_list = results[0].object.email_list.name
      fd, temp_path = tempfile.mkstemp()
      mbox_file = os.fdopen(fd, 'wb')
      for result in results:
          date = result.object.date.strftime('%Y-%m')
          mlist = result.object.email_list.name
          if date != mbox_date or mlist != mbox_list:
              mbox_file.close()
              tar.add(temp_path, arcname=os.path.join(basename,
                                                      mbox_list,
                                                      mbox_date + '.mbox'))
              os.remove(temp_path)
              fd, temp_path = tempfile.mkstemp()
              mbox_file = os.fdopen(fd, 'wb')
              mbox_date = date
              mbox_list = mlist
  
          with open(result.object.get_file_path(), 'rb') as input:
              # add envelope header if missing
              if not input.read(5) == b'From ':
                  from_line = smart_bytes(result.object.get_from_line()) + b'\n'
                  mbox_file.write(from_line)
              input.seek(0)
              mbox_file.write(input.read())
              mbox_file.write(b'\n')
  
      mbox_file.close()
      tar.add(temp_path, arcname=os.path.join(basename,
                                              mbox_list,
                                              mbox_date + '.mbox'))
      os.remove(temp_path)
      return tar
code_tokens: def build_mbox_tar ( results , tar , basename ) : mbox_date = results [ 0 ] . object . date . strftime ( '%Y-%m' ) mbox_list = results [ 0 ] . object . email_list . name fd , temp_path = tempfile . mkstemp ( ) mbox_file = os . fdopen ( fd , 'wb' ) for result in results : date = result . object . date . strftime ( '%Y-%m' ) mlist = result . object . email_list . name if date != mbox_date or mlist != mbox_list : mbox_file . close ( ) tar . add ( temp_path , arcname = os . path . join ( basename , mbox_list , mbox_date + '.mbox' ) ) os . remove ( temp_path ) fd , temp_path = tempfile . mkstemp ( ) mbox_file = os . fdopen ( fd , 'wb' ) mbox_date = date mbox_list = mlist with open ( result . object . get_file_path ( ) , 'rb' ) as input : if not input . read ( 5 ) == b'From ' : from_line = smart_bytes ( result . object . get_from_line ( ) ) + b'\n' mbox_file . write ( from_line ) input . seek ( 0 ) mbox_file . write ( input . read ( ) ) mbox_file . write ( b'\n' ) mbox_file . close ( ) tar . add ( temp_path , arcname = os . path . join ( basename , mbox_list , mbox_date + '.mbox' ) ) os . remove ( temp_path ) return tar
short_docstring: Returns tar file with messages from SearchQuerySet in mmox format.
short_docstring_tokens: Returns tar file with messages from SearchQuerySet in mmox format .
comment: """Returns tar file with messages from SearchQuerySet in mmox format.
      There are various problems adding non-file objects (ie. StringIO) to tar files
      therefore the mbox files are first built on disk
      """$SEP$# add envelope header if missing