                     return remove_files files #cleanup
                 fields["stack-trace"] = stackdata
 
-                #make crashreport file storage folder
-                storage_dir = "#{settings.app.root}/#{CRASHREPORTS_FOLDER}/#{fields.id}"
-                fs.mkdir storage_dir, 0755, (err) ->
-                    if err? && err.code != "EEXIST"
+                #parse rich-core
+                rcoreparser.parse_rich_core files["rich-core"], (err, rcoredata) ->
+                    if err?
                         res.send {"ok":"0","errors":err}
-                        return remove_files files #cleanup after error
-
-                    # move files to storage folder
-                    move_files files, storage_dir, (err, stored_files) ->
-                        if err?
+                        return remove_files files #cleanup
+                    fields["rich-core"] = rcoredata
+
+                    #make crashreport file storage folder
+                    storage_dir = "#{settings.app.root}/#{CRASHREPORTS_FOLDER}/#{fields.id}"
+                    fs.mkdir storage_dir, 0755, (err) ->
+                        if err? && err.code != "EEXIST"
                             res.send {"ok":"0","errors":err}
                             return remove_files files #cleanup after error
 
-                        # create crashreport collection
-                        crashreport = {}
-                        _(fields).each (v,k) -> crashreport[k] = v
-                        crashreport.files = stored_files
-                        # TODO: put attachment files into an array
-
-                        #console.log "Crashreport: " + util.inspect(crashreport) #debug
-
-                        # store to mongodb
-                        save_crashreport crashreport, (err) ->
+                        # move files to storage folder
+                        move_files files, storage_dir, (err, stored_files) ->
                             if err?
-                                return res.send {"ok":"0","errors":err} #TODO: cleanup?
-                            res.send {"ok":"1","url":"#{settings.server.url}/crashreports/" + crashreport.id}
+                                res.send {"ok":"0","errors":err}
+                                return remove_files files #cleanup after error
+
+                            # create crashreport collection
+                            crashreport = {}
+                            _(fields).each (v,k) -> crashreport[k] = v
+                            crashreport.files = stored_files
+                            # TODO: put attachment files into an array and replace /\./,'_'
+
+                            #console.log "Crashreport: " + util.inspect(crashreport) #debug
+
+                            # store to mongodb
+                            save_crashreport crashreport, (err) ->
+                                if err?
+                                    return res.send {"ok":"0","errors":err} #TODO: cleanup?
+                                res.send {"ok":"1","url":"#{settings.server.url}/crashreports/" + crashreport.id}
 
 
 exports.init_import_api = init_import_api

fs          = require('fs')
_           = require('underscore')
async       = require('async')
stackparser = require('stack-trace')
query_api   = require('query-api')



# module globals
DB_CRASHREPORTS  = "" #crashreport collection in db, set by init function


update_crashreport = (crashreport_new, cb) ->
