Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match arbitrary header #67

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mlsad3
Copy link
Contributor

@mlsad3 mlsad3 commented Aug 5, 2022

Match on arbitrary header and value.

Resolves #36, allows matching on any header and value.

(header X-Custom-Header /value/)

As we use GmailMessage.getHeader function, the header name used in the condition must be case-sensitive.

Overall flow:

  • Rules are parsed, and a list of condition-requested-headers is created.
  • ThreadData reads in the message data, and all the headers
    that were requested in the rules (we have to pass SessionData to ThreadData so it knows which headers to search).
  • Condition.match checks what header to match with, and compares the header's value with the rule's value.

In order to get the SessionData.mock.ts to work, SessionData.labels had to be made public. This seems to be a limitation we will continue to hit in testing if we want to test on Sheet Apps, since we cannot use other better libraries.

NOTE: This utilizes @aaronj1335 's Utils PR (or I could not run anything).
NOTE2: This also utilizes my #65 Refactor tests, so that we can more easily test this feature.

@mlsad3 mlsad3 force-pushed the match-arbitrary-header branch 2 times, most recently from 42b0114 to 4528a0a Compare August 6, 2022 20:48
@mlsad3 mlsad3 force-pushed the match-arbitrary-header branch 5 times, most recently from 456c4fe to a6fb5b2 Compare August 16, 2022 15:58
Based on Issue ranmocy#36, allows matching on any header and value.
```
(header X-Custom-Header /value/)
```

As we use `GmailMessage.getHeader` function, the header name
used in the condition must be case-sensitive.

Overall flow:
 - Rules are parsed, and a list of condition-requested-headers is
   created.
 - ThreadData reads in the message data, and all the headers
   that were requested in the rules (we have to pass SessionData
   to ThreadData so it knows which headers to search).
 - Condition.match checks what header to match with, and compares
   the header's value with the rule's value.

In order to get the SessionData.mock.ts to work, SessionData.labels
had to be made public. This seems to be a limitation we will continue
to hit in testing if we want to test on Sheet Apps, since we cannot use
other better libraries.
@mlsad3 mlsad3 force-pushed the match-arbitrary-header branch from a6fb5b2 to 3e6fa8d Compare August 19, 2022 01:27
@mlsad3
Copy link
Contributor Author

mlsad3 commented Nov 8, 2022

Hi @ranmocy ,

Any thoughts on this PR?

@@ -94,8 +97,9 @@ export default class Condition {
`Condition ${condition_str} should be surrounded by ().`);
const first_space = condition_str.indexOf(" ");
const type_str = condition_str.substring(1, first_space).trim().toUpperCase();
const rest_str = condition_str.substring(first_space + 1, condition_str.length - 1).trim();
let rest_str = condition_str.substring(first_space + 1, condition_str.length - 1).trim();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .length - 1 was clipping the last letter off the value I was using

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Match on any arbitrary header and value
2 participants