Skip to content

Instantly share code, notes, and snippets.

@wiktor-k
Last active October 6, 2025 11:39
Show Gist options
  • Save wiktor-k/ed1e9c604e3f6954d38c36ae45a19290 to your computer and use it in GitHub Desktop.
Save wiktor-k/ed1e9c604e3f6954d38c36ae45a19290 to your computer and use it in GitHub Desktop.
#!/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