Column: EML/MSG (email files) columns

This script adds columns that extract values from EML (saved email) files.
Columns

  • To address
  • From address
  • Subject
  • Date

We has some tests that write heaps emails to a folder, being able to see the to address and subject helps me find the one I need.

Current version is 1.4
EmlEmailColumns.js.txt (7.8 KB)

Note, 1.4 is the same as andersonnnunes version 1.31.

2 Likes

Hi wow! o)

Any chance to get the subject lines decoded correctly?
Most of my eml files have subjects like shown below, which are barely readable in the subject column.

=?UTF-8?Q?1_Neu:kadett__e(relingtr=C3=A4ger,dachtr=C3=A4ger,dachg...?=
=?UTF-8?B?Rm9ydW0gcG9zdCBub3RpZmljYXRpb24gLSAiQ29mZmVlc2hvcCI=?=
=?Cp1252?Q?Hier_finden_Sie_die_Angaben_des_?= =?Cp1252?Q?Verk=E4ufers_zum_Widerrufs-_oder_R=FC?=

Hi tbone,
I'm guessing they display like that as your emails are not English and have chars not in ASCII. These need to be encoded to send over SMTP.
This script was a quick job to solve a specific problem, adding encoding and decoding for extended chars was not required.
I don't know if I will get around to adding support.

However for reference this StackOverflow post is a good starting point if ether of us are so inclined.

Here's an updated version that displays the subject lines properly, providing you have the current beta version (11.13.3) installed. It uses the new StringTools object to decode the encoded string.
EmlEmailColumns.js.txt (2.46 KB)

Thanks Jon, made short work of that problem. Kudos.
I have updated the initial post with your changes, also added filter on file extension.

Thanks, wowbagger, for this useful script. One example — many internet receipts are emails, to be "saved as . . ." and stored for reference at tax time (which has just come up, sigh), so toggling these columns on and off is a great help. Four comments:

MSG FILES: I have long given up on .eml files because of their file-date problem, and I now save any required emails as .msg files (which are essentially the same thing). I therefore replaced line 61 by:

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

and the script now picks up the column information for .msg files as well as for .eml files. So I'm happy!

DATES: The dates come out awkwardly as "Mon, 1 Jun 2015 09:19:32 +1000", rather than the shorter "01/06/15 09:20", but I don't understand the JScript date object well enough to get the date into a copy of the JScript date object so that the output can be massaged into the more convenient form. Some further editing here would be very useful.

A BUTTON: Here is a button that toggles the four columns on and off (the four lines can easily be written as one line):

Set ColumnsToggle="scp:EmlEmailColumns/Date"
Set ColumnsToggle="scp:EmlEmailColumns/ToAddres(*,200)"
Set ColumnsToggle="scp:EmlEmailColumns/Subject(*,200)"
Set ColumnsToggle="scp:EmlEmailColumns/FromAddress(*,200)"

The reason that I have omitted any custom width on the first line is that if I change it to

Set ColumnsToggle="scp:EmlEmailColumns/Date(*,200)"

then the "Date" column is replaced by a column containing the file extensions and headed "CS1". This strange column comes from the script "Custom Sort Column", which happens to lie immediately above your script in my list at "Preferences - - > Toolbars - - > Scripts" — this may indicate that some sort of curious bug is causing this problem. (When the order of the lines in the button is changed, the "Date" column is still consistently replaced by the "CS1" column.) If the date were rewritten as "01/06/15 09:20", there would be no problem.

IS LINE 9 A TYPO: Should "ToAddres" be "ToAddress"? There are no other mentions of "ToAddres", so I tried changing it to "To Address" (in the script and in the button). But when I do that, the "To Address" and "From Address" columns either fail to appear, or are replaced by two identical "From Address" columns. Could some sort of bug causing this behaviour?

DATES SOLVED: After reading Item date that is parse-able by js, and then reading the URL that playful gives there in his initial post, I realised, with some embarrassment, that the "awkward" form of the date conforms to the ECMA standard and can be read in directly by the Date object. I then added, immediately after line 92, the following lines:

  FileDate = new Date (results[config.columns[3].name])
  TheText = new String ("")
  if (FileDate.getDate()<10) 
  	TheText += 0
  TheText += FileDate.getDate() + "/"
  if (FileDate.getMonth()<9) 
	TheText += 0
  TheText += 1 + FileDate.getMonth() + "/"
  TempYear = new String (FileDate.getYear())
  TheText += TempYear.substr(2,2) + " "
  if (FileDate.getHours()<10) 
	TheText += 0
  TheText += FileDate.getHours() + ":"
  if (FileDate.getMinutes()<10) 
	TheText += 0
  TheText += FileDate.getMinutes() 
  results[config.columns[3].name] = TheText 

The result is that the dates now have the desired form 01/06/14 09:19.

Wowbagger, I am a complete beginner with JScript and with objects, and that's the best I can do for now (in particular, I've ignored the date object provided by DOpus), so I won't presume to attempt any update of the script. Also, you may want to add into "Configure" some option to format the date according to the Windows Default.

I still have no idea what is going on with my third and fourth comments in the previous posts.

@julianon, nice work :slight_smile:
did you try this jscript method? I have not tested it at all.
https://technet.microsoft.com/en-us/library/k4w173wk(v=vs.84).aspx

As to your other points.
Good idea re the extra extension, I will add that.
I agree the date is nasty. Would be good to parse it to a proper date. I was a bit lazy.
Maybe date is a reserved word, and that is what causes the issue you see with the columns.
Def a typo, I would need to check exactly whats happening there.

I will look at making a new version based on your suggestions.

I did fiddle with Date.parse, but before I got it working, I realised that all I needed was the Date object with the ECMA-approved string that the email headers already contain. For example,
FileDate = new Date ("Mon, 1 Jun 2015 09:19:32 +1000")
creates a new date object, and gives it its value, all in one line. Thus all I had to do was just feed in the email date results[config.columns[3].name] from your code as the date.

The only reason that my bit of code has so many lines is to output the constant-length string "01/09/15 09:19" instead of the variable-length string "1/9/2015 9:19", but I'm sure that there are easier ways to do this with the DOpus Date object.

In case there was a reserved word clash, I replaced name:"Date", by name:"DateXXX", (line 21) and similarly in the DOpus button, and I also changed the column heading to DateYYY (line 22). But adding (*, 250) still gave problems, even after a reboot — instead of a "Date" column, I got a column with no entries headed "From Address" — so it's still a mystery.

You know you can pass date information to a date-type script column to let DO format the value for you automaticaly? This also happens based on the locale settings the people use, so I'd assume that's the easiest and most compatible way to do it?

Parsing the date beforehand is probably a different story.. o)

I have updated the script to version 1.2 based on Julianon's suggestions.
[ul]
[li]Allow msg files[/li]
[li]Changed Date column from string to datetime[/li]
[li]Fixed typo in column name ToAddres[/li][/ul]

@Julianon the issue you saw when renaming the column is due to the way dopus works with columns. If you have the column displayed when you change the name you need to close the window to remove the column. Its normally only a problem when building the scripts.
Not sure why you got that odd error when displaying the date column Via your button. But maybe now its a proper date column it will be different for you.

@wowbagger, there are still a few problems on my computer. Here are the details:

  1. The versions are wrongly labelled at the top of the webpage. The one on the top is V1.2, the one underneath is v1.1.

  2. The following button correctly toggles the four columns on, and then off:
    Set ColumnsToggle="scp:EmlEmailColumns/Date"
    Set ColumnsToggle="scp:EmlEmailColumns/ToAddress"
    Set ColumnsToggle="scp:EmlEmailColumns/Subject(*,250)"
    Set ColumnsToggle="scp:EmlEmailColumns/FromAddress"
    But of course the "To Address" and "From Address" columns are too narrow for comfort.

  3. If I change lines 2 and 4 of my button to
    . . . /ToAddress(,250)" and . . . /FromAddress(,250)"
    then the button does not bring these two columns up at all. I can add them by right-clicking on the top and selecting them from Columns - - > Script - - > EmlEmailColumns, but when I do that, the button does not toggle them off.

  4. If I change line 1 of my button to . . . Date(*,250) I get a column only 88 wide headed CS1, containing file extensions. Checking by right clicking on the top and then Columns - - > Script - - > Custom Sort Column verifies that it has in fact come from the "Custom Sort Column" script Addin that I've had installed for a while. This one doesn't actually matter, because the column that comes up with just . . . Date is exactly the right size for the date, but it may give some clue as to what the problem is. I have no idea.


Shutting down the lister, or even DOpus, in between actions doesn't seem to affect anything. Also, I think the column width can be set within the script, so I may have a go at that when I get a moment — altering the widths there would make the widths in the button unnecessary.

I have fixed the column widths within the script.

  • I added a fifth and final parameter "Width" to the function "AddFolderDateCol".
  • Then I added the command col.defwidth = Width; to the function "AddFolderDateCol".
  • Then at line 48 I added an array TheWidth = new Array (18, 18, 20, 8) specifying the four column widths.
  • Then I added TheWidth[i] as the fifth and final parameter when "AddFolderDateCol" is called.

Lines 48–64 thus become:

 TheWidth = new Array (18, 18, 20, 8)

  for(i=0;i<config.columns.length;i++) {
    AddFolderDateCol(initData,config.columns[i].name,config.columns[i].displayName,config.columns[i].type,TheWidth[i]);
  }
}

function AddFolderDateCol(initData,name,label,type,Width){
  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;
  col.defwidth = Width;
}

It would probably be better to add these four column widths to the configuration of the addin, because people will want to be able change them quickly depending on their screen size and what they are doing. They should be in pixels, but I couldn't make it work.

All four widths can now be omitted from my button, and the problems are gone. It doesn't solve the mystery of what was going wrong, however.

Thanks for doing the date thing, wow! o)

50% of my eml files don't work though (just as before). The script errors in line 100 now, failing to Decode() (invalid procedure call or argument).
I just tell you, because you told me the ScriptWizard errors too! An eye for an eye.. just kidding! o))

I noticed when testing with the current email-column script you upped and this thread against the "current" version of SW I use.
I recently tried to fix that decoding issue here by myself, but did not come to a quick and satisfying solution. The Decode() chokes when there are multiple decoded strings in the string passed, if i remember correctly.

I forgot:

@Jon
Would you mind removing your upload to not confuse people? o)

@wow
Your current v1.2 is labeled v1.1 and the real v1.2 carries v1.1 version description. I determined "by size" that I maybe downloaded the wrong file.
Please, let there be an upload-date in the script/file comments as well to make finding the right download more easy. It also serves as some kind of fall back information once version strings get mixed up or not updated properly.

uploaded version 1.3,
Added Default column widths

What changed? o)

I added Default column widths.
I actually thought this had been uploaded a long time ago. I only noticed it was not there when I needed the script and noted it was missing the change.

Thanks! o)

Thank you so much for this script!

But there is still a problem: Reading out the values of the new columns while renaming files doesn't work. Any suggestions?