This script add-in establishes custom columns for Outlook .msg email files, catering to commonly used email attributes. Like all Opus columns, these columns can also be used for renaming. The SentOn column is formatted as a date. Please note that a functional Outlook application must be on your system for this script to work.
Need more fields? All available email fields can be found here:
https://docs.microsoft.com/en-us/office/vba/api/outlook.mailitem
MailItem object (Outlook) > Properties
How to setup and use
Save ColumnOutlookMail.js.txt to ββπ
%appdata%\GPSoftware\Directory Opus\Script AddIns
Select the columns you want to see in the File Display via Script/OutlookMail...
... or toggle them with a button:
Set COLUMNSTOGGLE="scp:OutlookMail/SentOn(!,a,0)"
Set COLUMNSTOGGLE="scp:OutlookMail/SenderName(!,a,0)"
Set COLUMNSTOGGLE="scp:OutlookMail/SenderEmailAddress(!,a,0)"
Set COLUMNSTOGGLE="scp:OutlookMail/To(!,a,0)"
Set COLUMNSTOGGLE="scp:OutlookMail/CC(!,a,0)"
Set COLUMNSTOGGLE="scp:OutlookMail/BCC(!,a,0)"
Set COLUMNSTOGGLE="scp:OutlookMail/Subject(!,a,0)"
Set COLUMNSTOGGLE="scp:OutlookMail/Size(!,a,0)"
Set COLUMNSTOGGLE="scp:OutlookMail/Body(!,a,0)"
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
<label>Toggle Outlook</label>
<icon1>#usercommand</icon1>
<icon2>#email</icon2>
<function type="normal">
<instruction>Set COLUMNSTOGGLE="scp:OutlookMail/SentOn(!,a,0)"</instruction>
<instruction>Set COLUMNSTOGGLE="scp:OutlookMail/SenderName(!,a,0)"</instruction>
<instruction>Set COLUMNSTOGGLE="scp:OutlookMail/SenderEmailAddress(!,a,0)"</instruction>
<instruction>Set COLUMNSTOGGLE="scp:OutlookMail/To(!,a,0)"</instruction>
<instruction>Set COLUMNSTOGGLE="scp:OutlookMail/CC(!,a,0)"</instruction>
<instruction>Set COLUMNSTOGGLE="scp:OutlookMail/BCC(!,a,0)"</instruction>
<instruction>Set COLUMNSTOGGLE="scp:OutlookMail/Subject(!,a,0)"</instruction>
<instruction>Set COLUMNSTOGGLE="scp:OutlookMail/Size(!,a,0)"</instruction>
<instruction>Set COLUMNSTOGGLE="scp:OutlookMail/Body(!,a,0)"</instruction>
</function>
</button>
Cache Folder
To optimize folder navigation and reading speeds, the script caches the mail fields in text files in /profile\OutlookCache
. If you prefer a different location, simply change it directly in the script. Since the content of these fields is likely to remain the same, the script doesn't check if the .msg files have changed after the cache was created. Delete the text files to force the script to generate new ones.
Changelog
- 2023-09-22: Added cache functionality, fixed SentOn column
- 2021-12-01: Script shouldn't end the main Outlook.
Things you might enjoy reading
How to use buttons and scripts from this forum
The script's inner workings
JScript
function OnInit(initData) {
initData.name = 'OutlookMail';
initData.version = '2023-09-22';
initData.copyright = '';
initData.url = 'https://resource.dopus.com/t/outlook-email-custom-columns/39961';
initData.desc = 'Turn Email fields into columns';
initData.default_enable = true;
initData.min_version = '12.0';
}
function OnAddColumns(addColData) {
var col = addColData.AddColumn();
col.name = 'BCC';
col.label = 'BCC';
col.header = 'BCC';
col.justify = 'left';
col.multicol = true;
col.autogroup = true;
col.method = 'OnColumn';
var col = addColData.AddColumn();
col.name = 'Body';
col.label = 'Body';
col.header = 'Body';
col.justify = 'left';
col.multicol = true;
col.autogroup = true;
col.method = 'OnColumn';
var col = addColData.AddColumn();
col.name = 'CC';
col.label = 'CC';
col.header = 'CC';
col.justify = 'left';
col.multicol = true;
col.autogroup = true;
col.method = 'OnColumn';
var col = addColData.AddColumn();
col.name = 'SenderEmailAddress';
col.label = 'SenderEmailAddress';
col.header = 'SenderEmailAddress';
col.justify = 'left';
col.multicol = true;
col.autogroup = true;
col.method = 'OnColumn';
var col = addColData.AddColumn();
col.name = 'SenderName';
col.label = 'SenderName';
col.header = 'SenderName';
col.justify = 'left';
col.multicol = true;
col.autogroup = true;
col.method = 'OnColumn';
var col = addColData.AddColumn();
col.name = 'SentOn';
col.label = 'SentOn';
col.header = 'SentOn';
col.justify = 'right';
col.type = 'datetime';
col.multicol = true;
col.autogroup = true;
col.method = 'OnColumn';
var col = addColData.AddColumn();
col.name = 'Size';
col.label = 'Size';
col.header = 'Size';
col.justify = 'left';
col.type = 'number';
col.multicol = true;
col.autogroup = true;
col.method = 'OnColumn';
var col = addColData.AddColumn();
col.name = 'Subject';
col.label = 'Subject';
col.header = 'Subject';
col.justify = 'left';
col.multicol = true;
col.autogroup = true;
col.method = 'OnColumn';
var col = addColData.AddColumn();
col.name = 'To';
col.label = 'To';
col.header = 'To';
col.justify = 'left';
col.multicol = true;
col.autogroup = true;
col.method = 'OnColumn';
}
var cmd = DOpus.Create().Command();
var stt = DOpus.Create().StringTools();
var fsu = DOpus.FSUtil();
var cacheFolder = fsu.Resolve('/profile\\OutlookCache');
if (fsu.Exists(fsu.Resolve('{apppath|outlook}outlook.exe'))) {
var outlookApp = new ActiveXObject('Outlook.Application');
} else {
var outlookApp = null;
DOpus.Output('Outlook not found.');
}
function OnColumn(scriptColData) {
if (!outlookApp) return;
var item = scriptColData.item;
if (item.is_dir) return;
if (item.ext != '.msg') return;
var cacheItem = fsu.GetItem(cacheFolder + '\\' + String(item.realpath).replace(':', '') + '.txt');
var sep = 'GfywdfGreGf0J8OmFlwd\r\n';
if (!fsu.Exists(cacheItem)) {
cmd.RunCommand('CreateFolder NAME="' + cacheItem.path + '"');
var cacheFile = cacheItem.Open('wa'); // create a new file, always. If the file already exists it will be overwritten.
var mailItem = outlookApp.CreateItemFromTemplate(item);
var out = '';
out += '#0' + mailItem.BCC + sep;
out += '#1' + mailItem.CC + sep;
out += '#2' + mailItem.SenderEmailAddress + sep;
out += '#3' + mailItem.SenderName + sep;
out += '#4' + mailItem.SentOn + sep;
out += '#5' + mailItem.Size + sep;
out += '#6' + mailItem.Subject + sep;
out += '#7' + mailItem.To + sep;
out += '#8' + mailItem.Body + sep;
cacheFile.Write(out);
cacheFile.Close();
mailItem.Close(1); // 1 = Changes to the document are discarded.
}
if (!fsu.Exists(cacheItem)) {
DOpus.Output('Cache item could not be created.');
DOpus.Output('cacheFolder: ' + cacheFolder);
return;
}
var cacheArr = stt.Decode(cacheItem.Open().Read(), 'utf8').split(sep);
if (cacheArr.length < 9) return;
scriptColData.columns('BCC').value = cacheArr[0].substring(2);
scriptColData.columns('CC').value = cacheArr[1].substring(2);
scriptColData.columns('SenderEmailAddress').value = cacheArr[2].substring(2);
scriptColData.columns('SenderName').value = cacheArr[3].substring(2);
var sentOn = new Date(cacheArr[4].substring(2));
var sentOnOpus = DOpus.Create().Date('1970-01-01');
sentOnOpus.Add(sentOn.getTime() / 1000, 's');
scriptColData.columns('SentOn').value = sentOnOpus;
scriptColData.columns('Size').value = cacheArr[5].substring(2);
scriptColData.columns('Subject').value = cacheArr[6].substring(2);
scriptColData.columns('To').value = cacheArr[7].substring(2);
scriptColData.columns('Body').value = cacheArr[8].substring(2);
}