# # ITSV GmbH # CCDB - Command and Control Database # # FILE: dquerymfile_MAILEXTRACT.txt # DESCRIPTION: dquery definition for MAILEXTRACT # this calls the ReceiveMail external program with special profiles # to extract received mails form an IMAP server to special file directories # @group ADMIN @querytitle E-Mails extrahieren @querydescription E-Mails von Mailserver abholen und Fallspezifisch speichern @attributenames profile:string:{{profileoptions}} @profileoptions { type: { structure: "scalar.enum", vlist: "rx432:RX432: extrahiere Emails mit Auswertung_MeldungenClearingfaelle,"+ "rx57:RX57:klassifiziere Bounced-Emails an noreply-clearing" }, labeltext: "Ablaufprofil", typedesc: "Name des Profils, das zur Steuerung des Mailabruifs verwendet werden soll" } ~query.tsteps # # <>: prepare OS-command to be executed on windows # qexpression proc: { logger.debug(this.phead("queryparameters")+".query: "+aux.objTxt(this.query)); if (!this.query.hasOwnProperty("profile")) { this.errcoll.collect(null,"no \"profile\" parameter given",this.query); break proc; } this.batfilename = aux.makeUniqueTempFileName() + "_MAILEXTRACT.bat"; this.batfilename = this.batfilename.replace("/","\\"); this.batcmds = "@echo off\r\n"; this.batcmds += "rem\r\n"; this.batcmds += "rem temporary execution command file for DQUERY MAILEXTRACT\r\n"; this.batcmds += "rem\r\n"; this.batcmds += "C:\r\n"; this.batcmds += "cd C:\\ta3j\\prg\\pmtools\\ccdb\\email\\receivemail\r\n"; this.batcmds += "call setup.bat\r\n"; if (this.query.profile=="rx432") { this.resultfilename = aux.makeUniqueTempFileName() + "_RX432result.csv"; this.batcmds += "call rx432.bat " + this.resultfilename + "\r\n"; } else if (this.query.profile=="rx57") { this.resultfilename = aux.makeUniqueTempFileName() + "_RX57_analysis_result.csv"; this.batcmds += "call rx57.bat " + this.resultfilename + "\r\n"; } else { this.errcoll.collect(null,"invalid profile name \""+this.query.profile+"\"",this.query); break proc; } this.batcmds += "echo === INFO: RESULTFILENAME="+this.resultfilename+"\r\n"; this.batcmds += "echo ========================= START RESULTFILE ====================\r\n"; this.batcmds += "type "+this.resultfilename.replace("/","\\")+"\r\n"; this.batcmds += "echo ========================== END RESULTFILE =====================\r\n"; try { fs.writeFileSync(this.batfilename,this.batcmds); } catch (err) { this.errcoll.collect(err,"Error writing batch file \""+this.batfilename+"\""); break proc; } this.shellcmd = this.batfilename; } # # <>: execute command for windows # aexpression childprocess.exec(this.shellcmd, { timeout: 1000000 }, /* 20220332: 30000->100000 beacuse of recurring SIGTERM on windows, 20230213: 100k->1Mio msec == 16:45 Minutes */ function(err,stdout,stderr) { logger.debug(this.phead("EXEC_CALLBACK")); if (err) { logger.error("Error in executing child process"); logger.error("Error: "+aux.objTxt({ err:err, stdout: stdout, stderr: stderr },9999,999999)); this.errcoll.collect(err,"Error in email-extracting with profile "+this.query.profile+", executing \""+this.shellcmd+"\"", { err: err, stdout: stdout, stderr: stderr }); this(); return; } this.stdout = stdout; this.stderr = stderr; this.ppush([this.phead("cmdlineexecuted"),{ rawhtml: "STDOUT:
"+stdout+"
" },{ rawhtml: "STDERR:
"+stderr+"
"},""]); this(); }.bind(this) ); # # 2: prepare result # qexpression this.result = new aux.Result({ resulttype: 'object', title: "MAILEXTRACT("+this.query.profile+") abgeschlossen", resultobject: { stderr: this.stderr.split("\r\n"), stdout: this.stdout.split("\r\n"), resultfilename: this.resultfilename }});