Renaming option "Enable file information fields" doesn't work with EML/MSG Script Add-In

Hello,

I'm currently using the EML/MSG columns Script Add-In which is capable of extracting information like date and time from inside the e-mail files themselves, instead of relying on the often inaccurate file attributes. (Thanks, wowbagger! :thumbsup: ) However, reading out the values of these new columns while renaming files (using the "Enable file information fields" option) doesn't work. Any suggestions?

Many thanks in advance!

P.S. To the moderators: I left a short message in the download section to the script, but since there seems to be less activity there, I posted a more detailed description of the problem here.

Testing with Opus 11 and the Opus 12 public beta, but with a different script, script columns are working in the Rename dialog:




Thanks for the quick reply!

Have you really checked the entire process? Because everything seems to work fine in the preview panel, but once I click OK the following error occurs: "The process cannot access the file because it is being used by another process".

Just wanted to add that other scripts work fine, indeed.

Ah, the error message and part of the rename process which fails are important details. I thought we were talking about the script not generating a name at all.

Looking at the script, it opens the files but never closes them, so they will still be locked when the rename is attempted.

Before the if (results){ line, add fn.Close(); and see if that fixes it.

You're right, I should've mentioned that in my first post. :blush:

Thanks so much, this solved the problem! :thumbsup:

While inspecting the code, I came across an other problem: the while loop doesn't break out after the first match. This means that if per chance the exact header name (e.g. "Date: ") happens to reappear in the body of the e-mail text, the value of the real header will be overwritten by what follows the "fake" header in the text. To avoid that I replaced the following code (lignes 94-118):

function ScanEmailFile(path,filterFunc){
  var ToEmail;
  var FromEmail;
  var fn = fs.OpenTextFile(path, 1, 2);
  var results = {};
    
  while (!fn.AtEndOfStream) {
    var textLine = fn.ReadLine();
    for(i=0;i<config.columns.length;i++) {
      var match = config.columns[i].re.exec(textLine);
      if (match != null)
      {
        if (match[1].substring(0,2) == "=?")
        {
          match[1] = st.Decode(match[1]);
        }
        results[config.columns[i].name] = match[1];
      }
    }
  }

  if (results){
    return results;
  } else return null;
}

with (including your fix):

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

The two loops (for and while) had to be switched, otherwise the insertion of a break in the while loop would have terminated the for loop even if there were still columns left to be build.

Another point: Since renaming *.eml files to *.txt files allows DOpus to search inside the e-mail texts, I also added support for *.txt files by replacing line 76 with:

if (!scriptColData.item.is_dir && (scriptColData.item.ext.toLowerCase() == ".eml" || scriptColData.item.ext.toLowerCase() == ".msg" || scriptColData.item.ext.toLowerCase() == ".txt")) {

Maybe I should write a PM to the original author of the script (wowbagger), so that he can upload the corrected version to the script section.

Please do so, also please append your fixed version and a brief description of what changed to the "other" thread so things don't get lost.

Ok. Done. Please check out: