
{"id":17,"date":"2016-09-21T12:07:59","date_gmt":"2016-09-21T12:07:59","guid":{"rendered":"http:\/\/www.showerpell.de\/?p=17"},"modified":"2016-09-21T12:19:26","modified_gmt":"2016-09-21T12:19:26","slug":"mailconverter-und-filename-spielereien","status":"publish","type":"post","link":"https:\/\/www.showerpell.de\/?p=17","title":{"rendered":"Mailconverter und Filename-Spielereien"},"content":{"rendered":"<p>Vor einigen Wochen stand ich vor der Herausforderung, eine Extraktion aus einem propriet\u00e4ren Filearchivsystem eines Herstellers mit zwei Buchstaben auf einem normalen Fileshare bereitzustellen.<br \/>\nWas war archiviert?<br \/>\nDas Archivsystem hat jede Datei die archiviert wurde an eine E-Mail angeh\u00e4ngt und in einem Mailarchiv abgelegt. Die Extraktion brachte mir zwei Files:<\/p>\n<p>EINDEUTIGE-ID.info &#8211; Textdatei mit Infos zum Archivierer und urspr\u00fcnglichem Pfad zur Archivdatei<br \/>\nEINDEUTIGE-ID.data &#8211; EML-Datei mit eingebettetem Anhang<\/p>\n<p><!--more--><\/p>\n<p>Damit nicht jedes der mehreren 1000 archivierten Files manuell ge\u00f6ffnet und abgespeichert werden m\u00fcssen, habe ich mir ein Script gebastelt, welches diese Aufgabe \u00fcbernimmt.<\/p>\n<p>Als erstes wird aus dem Namen der extrahierten Dateien der Name der ID ausgelesen und in eine Variable zur weiteren Verwendung zwischengespeichert. Aus der INFO-Datei wird der Speicherpfad und der Dateiname des Anhangs ausgelesen, um anschlie\u00dfend aus der DATA-Datei, welche eigentlich eine EML-Datei ist, mittels des Tools mailconverter den Anhang zu extrahieren und auf dem Speicherpfad bereitzustellen.<br \/>\nAls &#8222;kleines&#8220; Errorhandling habe ich noch einen Schleife eingebaut, welche das vorhandensein des extrahierten Files pr\u00fcft und nach einer bestimmten Zeit einen Fehkler ausgibt, wenn das File nicht vorhanden ist bzw. nicht extrahiert werden kann. Beim eingesetzten Archivsystem leider keine Seltenheit und daher notwendig.<\/p>\n<p>Das komplette Script:<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;width:800px;height:300px;\"><div class=\"text codecolorer\"># Extraktion des HP-Filearchivs mittels HP-Export und mailconverter.<br \/>\n# 1. Schritt: Export aller Archivfiles mit acamigrate.pl aus der IAP in einen Ordner.<br \/>\n# 2. Schritt: Extraktion des Attachments der EML-Datei (archiviertes File) mittels mailconverter in den Ordner der in der .info Datei hinterlegt ist.<br \/>\n<br \/>\n# Variablen festlegen<br \/>\n$source = &quot;\\files&quot;<br \/>\n$target = &quot;\\files\\Archiv&quot;<br \/>\n$temptarget = $target+&quot;temp&quot;<br \/>\n$pathtoconverter = &quot;\\mailconverter&quot;<br \/>\n<br \/>\n# Dateien einlesen, File-ID einlesen<br \/>\nforeach ($filename in Get-ChildItem -Path $source -Filter *.data | select -expand name) <br \/>\n&nbsp; &nbsp; {<br \/>\n&nbsp; &nbsp; $iap_fileid = $filename.TrimEnd(&quot;.data&quot;)<br \/>\n&nbsp; &nbsp; $iap_fileinfo = $iap_fileid + &quot;.info&quot;<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; $infopath = $source + $iap_fileinfo<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; # Speicherpfad auslesen<br \/>\n&nbsp; &nbsp; $iapfilepath = Select-String -path $infopath -pattern &quot;ConnectorLocation:&quot;<br \/>\n&nbsp; &nbsp; $iapfilepath_trim = $iapfilepath.Line.Substring(46)<br \/>\n&nbsp; &nbsp; $iapfilepath_new = $target + $iapfilepath_trim<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; # Dateiname auslesen<br \/>\n&nbsp; &nbsp; $iapfilename = Select-String -path $infopath -pattern &quot;ConnectorSubject:&quot;<br \/>\n&nbsp; &nbsp; $iapfilename_trim = $iapfilename.Line.Substring(18)<br \/>\n&nbsp; &nbsp; $iapfilename_new = $iapfilename_trim<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; # Verzeichnis erstellen<br \/>\n&nbsp; &nbsp; New-Item -Path $iapfilepath_new -ItemType directory -ForceM<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; # .data in .eml umbennenen f\u00fcr Extrakt<br \/>\n&nbsp; &nbsp; Rename-Item $source$filename $iap_fileid&quot;.eml&quot;<br \/>\n&nbsp; &nbsp; $iap_fileid_eml = $iap_fileid+&quot;.eml&quot;<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; # Extrahieren<br \/>\n&nbsp; &nbsp; $datasource = $source+$iap_fileid_eml<br \/>\n&nbsp; &nbsp; &amp; $pathtoconverter\\mailconverter.exe $datasource $temptarget -attach<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; # Pr\u00fcfen ob Datei exisitiert<br \/>\n&nbsp; &nbsp; $sleepfile = 0<br \/>\n&nbsp; &nbsp; do <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; {<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$sleepfile++<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Start-Sleep 1<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Write-Host &quot;Check FileeExist $iapfilename in $filename - Loop $sleepfile&quot; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ($sleepfile -gt 600)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Write-Host &quot;Fehler bei Extraktion von $iapfilename in $filename&quot;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; } while ((Test-Path $temptarget$iapfilename_new) -eq $false)<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; # Verschieben an Ursprungsort<br \/>\n&nbsp; &nbsp; Move-Item $temptarget$iapfilename_new $iapfilepath_new<br \/>\n&nbsp; &nbsp; Remove-Item $temptarget*<br \/>\n&nbsp; &nbsp; }<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Vor einigen Wochen stand ich vor der Herausforderung, eine Extraktion aus einem propriet\u00e4ren Filearchivsystem eines Herstellers mit zwei Buchstaben auf einem normalen Fileshare bereitzustellen. Was war archiviert? Das Archivsystem hat jede Datei die archiviert wurde an eine E-Mail angeh\u00e4ngt und in einem Mailarchiv abgelegt. Die Extraktion brachte mir zwei Files: EINDEUTIGE-ID.info &#8211; Textdatei mit Infos [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-17","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.showerpell.de\/index.php?rest_route=\/wp\/v2\/posts\/17","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.showerpell.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.showerpell.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.showerpell.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.showerpell.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=17"}],"version-history":[{"count":2,"href":"https:\/\/www.showerpell.de\/index.php?rest_route=\/wp\/v2\/posts\/17\/revisions"}],"predecessor-version":[{"id":21,"href":"https:\/\/www.showerpell.de\/index.php?rest_route=\/wp\/v2\/posts\/17\/revisions\/21"}],"wp:attachment":[{"href":"https:\/\/www.showerpell.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=17"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.showerpell.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=17"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.showerpell.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}