Last active
October 6, 2025 11:39
-
-
Save wiktor-k/ed1e9c604e3f6954d38c36ae45a19290 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env node | |
| // SPDX-License-Identifier: Apache-2.0 | |
| import { readFileSync } from 'fs'; | |
| const bearer = process.env.BEARER; | |
| if (!bearer) { | |
| throw 'No BEARER environment variable.' | |
| } | |
| const cookie = process.env.COOKIE; | |
| if (!cookie) { | |
| throw 'No COOKIE environment variable.' | |
| } | |
| const accountId = process.env.ACCOUNT; | |
| if (!accountId) { | |
| throw 'No ACCOUNT environment variable.' | |
| } | |
| console.log('Saving sieve...') | |
| const body = { | |
| "using": [ | |
| "https://www.fastmail.com/dev/user", | |
| "https://www.fastmail.com/dev/rules", | |
| "urn:ietf:params:jmap:core" | |
| ], | |
| "methodCalls": [ | |
| [ | |
| "SieveBlocks/set", | |
| { | |
| "accountId": accountId, | |
| "update": { | |
| "singleton": { | |
| "sieveAtMiddle": readFileSync('main.sieve', 'utf-8') | |
| } | |
| } | |
| }, | |
| "0" | |
| ] | |
| ] | |
| }; | |
| const resp = await fetch("https://api.fastmail.com/jmap/api/?u=" + accountId, { | |
| "headers": { | |
| "accept": "application/json", | |
| "authorization": "Bearer " + bearer, | |
| "content-type": "application/json;charset=UTF-8", | |
| "cookie": cookie | |
| }, | |
| "body": JSON.stringify(body), | |
| "method": "POST" | |
| }); | |
| console.log('Done: ' + resp.status) | |
| if (!resp.ok) { | |
| throw await resp.text() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment