Column: EML/MSG (email files) columns

Here is my own fixed version of the script.

CHANGES:

  1. 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).
  2. 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.
  3. 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.
  4. Two new columns - "Newsgroups: " and "Message-ID: " - have been added to support the handling of old USENET archives.
  5. 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! :thumbsup:

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;
  }
}

Thank you! o)
By whom and when this addin will be updated again, he just cannot overlook your additions! o)

Nice script, thank you for sharing.

A limitation that I found is that it is unable to work with file paths longer than 255 chars and throws an error message like:

"Error at line 112, position 5
EmlEmailColumns: Path not found (0x800a004c)"

A second limitation is that it does not seem to support ISO 8859-1 for the ToAddress.

Even so, it works well.

Release: Version 1.31

Changes since 1.3b:
Fix: ignore file if its path size can not be handled by the OpenTextFile function. Previously this would cause an error.
Fix: prevent subscription error if there is no newsgroup line on the file.
New: added option "facilitateSubjectGrouping". If it is set to true, the script will filter the displayed subject text to remove common prefixes added by mail clients (e.g. RES:, RE:, ENC:). This makes it possible to correctly group by subject all related messages.
Misc: spaces to tabs, name changes. (You can easily ignore these and insert only the functional changes on your version. Use a diff tool to help you locate these.)

Pending yet:
Better handling of "iso-8859-1" encoded string.
Columns For EML Mail.js.txt (3.86 KB)

1 Like

This is to say thanks for this script. I'm a new user and have it working along with the toggle button. I've not done any scripting.

Is there and chance of adding a few other fields that display in windows, such as:

  • Has Attachment
  • Categories
    -Task Owner
    -Task Status

I am implementing a GTD workflow and use external folders to hold mails and attachments related to a given task. Then I add a link in the task note creating a shortcut to that folder. To work on a task, I open it, click the link and do the work in the windows folder with required emails and attachments at hand...

The above fields would help, especially Has Attachment.

Ive installed QuickViewPlus and its .msg preview pane works great in Dir Op. One can even see all attachments from the msg preview and click to view.

I am using MessageSave to save to external drive from inside outlook techhit.com/messagesave/

Thanks!!

I would like to see a screenshot of that preview pane inside Opus.

I use Thunderbird and it supports saving messages to disk without any plugin/add-on. It does not have as many features as MessageSave, but, hey, it is free.

HI

If I did it correctly, below is a screenshot of QuickViewPlus prefiewing an email w attachment shown:


Also, here is an interesting program that will export email, taks, appointments, etc and populate standard windows fields:

Date created = outlook item date
Author = sender name
Title = Sent To
Comments= CC
Pages = # attachments
Tags = categories

You can see this in the same screenshot.

This also allows one to send entire outlook folders, or just the selected items

youtube.com/watch?v=C2GykV6TIsg
reliefjet.com/Essentials/Fe ... ntegration

Thanks

Sorry for another question, but I've gotten confused testing multiple msg export and viweing solutions:

If one just copy/pastes outlook emails to a Win folder, will this script populate the metadata for the columns the script uses, or does that rely require export from Outlook via a tool that adds that metadata to the msg file?

Ive texted and seem to get conflicting results, but may just be mixed up. It now seems simple copy/paste from outlook does not work with this script.

Thanks

The script assumes the data inside the mail file follows a pattern. Probably the copy-paste you tried does not produce data with that pattern. You could use a text editor to compare the raw text of a copied-pasted and of an exported file. You'll probably notice they are different.

Ok, thanks.

Do you expect to be adding additional column fields, such as:

  • Has Attachment
  • Categories
    -Task Owner
    -Task Status

Also, is it straightforward for a non-scripter to edit to add preferred fields, or is real knowledge required.

Thanks

[quote="ccclapp"]Do you expect to be adding additional column fields, such as:

  • Has Attachment
  • Categories
    -Task Owner
    -Task Status[/quote]

Right now I have no incentives to do so. Maybe someone else will do it.

Knowing the basics of programming logic should be enough (plus time to read the docs).

Thanks andersonnnunes, I made this the current version, re-numbered it to 1.4.

Since then I have made many changes to my copy of the script. I did not redistribute it yet because I made some changes yet again to the column names and to the script name. These make necessary to edit saved layouts and tool tips. I am fine with doing it, but I don't know if you guys are willing to follow along every time I make a change.

What I have now:

Handling of mht/htm files. (Columns for Webpage Subject, Webpage Date, Webpage Source, Webpage Address, Webpage Domain.)

File format recognition depends on two Opus groups that should be created (Electronic Mail and Webpages). (Instead of hard-coding the extensions on the script, these groups are used.)

Handling of subjects broken over multiple lines. (Limited, there is one corner case not covered yet.)

Other small fixes and improvements.

Except for a problem with Windows Search (link to thread), the script seems to work fine. There is a copy of it in that thread, if anyone is willing to test it.

Because of all these changes, I think it would be better for me to release it on another thread as a version 1.0. Let me know of what you think about that.

Sounds good @andersonnnunes. Look FW to trying out your script.