Home > Net >  Extract from an email header the Authentication-Results part using an Outlook Add-in with OfficeJS
Extract from an email header the Authentication-Results part using an Outlook Add-in with OfficeJS

Time:02-10

I've been trying to the section of Authentication-Results First I tried with:

Office.context.mailbox.item.internetHeaders.getAsync

But for some reason interneHeader keeps returning undefined so I move to:

Office.context.mailbox.item.getAllInternetHeadersAsync

In my tests with Regex on it I got results from the first line of it.

But when I use it on copying email headers on regex101 or Node I got the information I need. Meaning the entire section with spf, dkim and dmarc.

I use this regex:

header.match(/^Authentication-Results:[0-9a-zA-Z =\(\)\.\n;-]*$/gm)[0]

Exemple: This is a sample of header from a Steam email:

Received: from SN1NAM02FT0054.eop-nam02.prod.protection.outlook.com
 (2603:10b6:806:127:cafe::f5) by SN7PR04CA0211.outlook.office365.com
 (2603:10b6:806:127::6) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15 via Frontend
 Transport; Tue, 1 Feb 2022 20:13:03  0000
Authentication-Results: spf=pass (sender IP is xxx.xxx.xxx.xxx)
 smtp.mailfrom=steampowered.com; dkim=pass (signature was verified)
 header.d=steampowered.com;dmarc=pass action=none
 header.from=steampowered.com;compauth=pass reason=100
Received-SPF: Pass (protection.outlook.com: domain of steampowered.com
 designates xxx.xxx.xxx.xxx as permitted sender)
 receiver=protection.outlook.com; client-ip=xxx.xxx.xxx.xxx;
 helo=smtp-03-tuk1.steampowered.com;

Using the my regex, on it it returns this:

Authentication-Results: spf=pass (sender IP is xxx.xxx.xxx.xxx)
 smtp.mailfrom=steampowered.com; dkim=pass (signature was verified)
 header.d=steampowered.com;dmarc=pass action=none
 header.from=steampowered.com;compauth=pass reason=100

But when I use with Office.context.mailbox.item.getAllInternetHeadersAsync It only returns this:

Authentication-Results: spf=pass (sender IP is xxx.xxx.xxx.xxx)

So I wanna what approach I can do to this issue?

CodePudding user response:

Basically, your operating system defines the character / character sequence for the end of the line. Your particular application might or might not follow that.

If you want to limit the change to your initial regex, adding \r is (to me) the most straightforward approach. If you want to limit the number of characters in your regex, you could go for \s -- which would encompass blank, \n and \r - but \t as well, which is not allowed at this time.

Talking of potential simplification: Within the character class (between the square brackets), escaping round brackets/parentheses and the dot / full stop is usually not required - leaving you with
^Authentication-Results:[0-9a-zA-Z =().\n\r;-]*
But you need to verify in your particular environment.

Please comment, if and as this requires adjustment / further detail.

  • Related