Skip to main content Link Search Menu Expand Document (external link)

Email Parser Tag

The email parser tag can be used to add a new email parsers to Jancy’s parser registry. Email parsers can be used with the included gmail and imap resolvers to give Jancy the ability to find and parse different email messages.

<jyl>
  <email-parser name="smsdeliverer-ticketmaster">
    <description>
      Looks for emails from the SMSDeliverer softwawre that contains SMS text messages from Ticketmaster containing a 2FA authentication code.
      This parser is only valid in the Site:Ticketmaster column and requires that the profile’s SMS Number is set.
    </description>
    <example>
      Sender: 77598
      Receiver: 12223334444
      Timestamp: 2/4/2023 5:49:02 PM
      411733 is your Ticketmaster code.
    </example>
    <can-run>
      return args.profile?.smsNumber && args.site === 'ticketmaster'
    </can-run>
    <get-query>
      if (args.resolverName === 'gmail') {
        return `(+(Receiver:) +(1${ args.profile.smsNumber }) +(is your Ticketmaster code))`
      }
      // args.resolverName == 'imap'
      return {
        body: `"Receiver:" "is your Ticketmaster code" "1${ args.profile.smsNumber }"`
      }
    </get-query>
    <parse-message>
      const match = msg.text.match(/(\d+) is your Ticketmaster code/)
      if (match) {
        return match[1]
      }
      jancy.console.log(`smsdeliverer-ticketmaster-parser: failed parsing auth code from smsdeliverer email`)
      return null
    </parse-message>
  </email-parser>
</jyl>

Format

Email parsers start and end with an email-parser tag.

Can Run Tag

The email-parser tag must contain a can-run tag. The contents of the can-run tag will be used as the body of a Javascript function.

The function generated will be called with the following arguments:

The function generated by the content of the can-run tag should return true if the parser can run based on args or false otherwise.

Get Query Tag

The email-parser tag must contain a get-query tag. The contents of the get-query tag will be used as the body of a Javascript function.

The function generated will be called with the following arguments:

The function generated by the content of the get-query tag should eihter return a query string using Gmail search operators if the current resolver is gmail or an ImapFlow SearchObject if the current resolver is imap.

Parse Message Tag

The email-parser tag must contain a parse-message tag. The contents of the parse-message tag will be used as the body of a Javascript function that will serve as a parser for the contents of the email messages passed into it.

The function generated will be called with the following arguments:

The function generated by the content of the parse-message tag should either return a string which indicates the parser was successful otherwise it should return null.

Description Tag

The email-parser tag can contain an optional description tag. The contents of the description tag should describe what types of emails the parser deals with.

Example Tag

The email-parser tag can contain an optional example tag. The contents of the example tag should provide an example of the email the parser can deal with.

The primary purpose of the description and example tags is to provide information in the Jancy parser registry. The parser registry can be accessed in app by navigating to jancy://parsers.

image info

For a slightly more detailed information about the functions generated by the various tags see the parserRegistry.registerParser method.