Here is my own fixed version of the script.
CHANGES:
- BUGFIX: The values of the new columns can now be accessed while renaming files (using the "Enable file information fields" option in the Advanced Rename dialog box).
- BUGFIX: The former code didn't check if a match had already been made for a particular column. This meant that if per chance the exact header name (e.g. "Date: " or "From: ") happened to reappear in the body of the e-mail, the value of the real header was overwritten by what followed the "fake" header in the text.
- Since renaming *.eml files to *.txt files allows DOpus to search inside the very body of the e-mails, support was added for *.txt files as well.
- Two new columns - "Newsgroups: " and "Message-ID: " - have been added to support the handling of old USENET archives.
- The version number was changed from 1.3 to 1.3b in order to reflect the aforementioned changes.
Thanks to Leo for fixing bug #1!
Maybe wowbagger, the original author, could include some or all of the changes in a new 1.4 version.
// EmlEmail (Options)
var gbUseLogging=true;
var fs = new ActiveXObject("Scripting.FileSystemObject");
var st = DOpus.Create.StringTools();
//Define columns here, includes title and regexp.
var config = {
columns: [{
name:"ToAddress",
displayName:"To Address",
re: /^To:\s(.*)$/,
type: "string",
defwidth: 18
}, {
name:"FromAddress",
displayName:"From Address",
re: /^From:\s(.*)$/,
type: "string",
defwidth: 18
}, {
name:"Subject",
displayName:"Subject",
re: /^Subject:\s(.*)$/,
type: "string",
defwidth: 20
}, {
name:"Newsgroups",
displayName:"Newsgroups",
re: /^Newsgroups:\s(.*)$/,
type: "string",
defwidth: 18
}, {
name:"Date",
displayName:"Date",
re: /^Date:\s(.*)$/,
type: "datetime",
defwidth: 10
}, {
name:"MessageID",
displayName:"Message-ID",
re: /^Message-ID:\s(.*)$/,
type: "string",
defwidth: 18
}]
}
function Log(s){
if (gbUseLogging) DOpus.Output(s);
}
// Called by Directory Opus to initialize the script
function OnInit(initData){
var uid = "60149ff2-5d64-4d4d-b63b-837d05500e24";
var url = "https://resource.dopus.com/t/column-eml-msg-email-files-columns/20780/10
initData.name = "EmlEmailColumns";
initData.desc = "Adds columns for displaying EML file properties, I.E. To address, from address, subject.";
initData.copyright = "wowbagger";
initData.version="1.3b";
initData.default_enable=true;
initData.config.exclusionFilter=DOpus.NewVector();
initData.config.displayForAll=false;
initData.min_version = "11.13.3";
for(i=0;i<config.columns.length;i++) {
AddFolderDateCol(initData,config.columns[i].name,config.columns[i].displayName,config.columns[i].type,config.columns[i].defwidth);
}
}
function AddFolderDateCol(initData,name,label,type,defwidth){
var col;
col=initData.AddColumn();
col.name = name;
col.label = label;
col.type = type;
col.method = "OnEmlEmail";
col.autogroup = true;
col.autorefresh=true;
col.justify = "left";
col.multicol=true;
if(defwidth != null && defwidth != 0)
{
col.defwidth=defwidth;
}
}
function OnEmlEmail(scriptColData){
if (!InArray(scriptColData.col,config.columns)) return;
if (!scriptColData.item.is_dir && (scriptColData.item.ext.toLowerCase() == ".eml" || scriptColData.item.ext.toLowerCase() == ".msg" || scriptColData.item.ext.toLowerCase() == ".txt")) {
var item=ScanEmailFile(scriptColData.item.realpath);
if (item){
for(i=0;i<config.columns.length;i++) {
if(config.columns[i].type == "datetime")
{
scriptColData.columns(config.columns[i].name).value = new Date(Date.parse(item[config.columns[i].name])).getVarDate();
}
else
{
scriptColData.columns(config.columns[i].name).value = item[config.columns[i].name];
}
}
}
}
}
function ScanEmailFile(path,filterFunc)
{
var result = {};
for(i=0;i<config.columns.length;i++)
{
var fn = fs.OpenTextFile(path, 1, 2);
while (!fn.AtEndOfStream)
{
var textLine = fn.ReadLine();
var match = config.columns[i].re.exec(textLine);
if (match != null)
{
fn.Close();
if (match[1].substring(0,2) == "=?")
{
match[1] = st.Decode(match[1]);
}
result[config.columns[i].name] = match[1];
break;
}
}
fn.Close();
}
if (result)
return result;
else
return null;
}
function InArray(col,arr){
for (var i=0;i<arr.length;i++){
if (col==arr[i].name) return true;
}
}