Created
March 18, 2023 13:48
-
-
Save KevinGraham-com/13060f1c713ff8dc1231af631ea64220 to your computer and use it in GitHub Desktop.
Fastmail Masked Aliases Creator
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
| <!doctype html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <meta name="robots" content="noindex,nofollow"> | |
| <title>Masked Emails</title> | |
| <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous"> | |
| </head> | |
| <body> | |
| <form action="/fastmail.php" method="POST"> | |
| <div class="container" style="margin-top: 2em;"> | |
| <div class="mt-6 mb-3"> | |
| <?php | |
| if (isset($_POST['submit'])) { | |
| // account id is the letter u followed by the value of the ?u=yyyy query string, eg ?u=yyyy would mean account ID is uyyyy | |
| // api key is from https://app.fastmail.com/settings/security/tokens, only needs "masked email" permission | |
| $account="uyyyy"; | |
| $apikey="xxxx"; | |
| if (isset($_POST['description'])) { | |
| $data='{"using": [ "urn:ietf:params:jmap:core", "https://www.fastmail.com/dev/maskedemail"], "methodCalls": [ ["MaskedEmail/set", { "accountId": "'.$account.'", "create" : { "k1" : { "state" : "enabled", "description" : "'.$_POST['description'].'" } } }, "R1"] ]}'; | |
| } | |
| if (isset($_POST['prefix'])) { | |
| $data='{"using": [ "urn:ietf:params:jmap:core", "https://www.fastmail.com/dev/maskedemail"], "methodCalls": [ ["MaskedEmail/set", { "accountId": "'.$account.'", "create" : { "k1" : { "emailPrefix" : "'.$_POST['prefix'].'", "state" : "enabled" } } }, "R1"] ]}'; | |
| } | |
| if (isset($_POST['description']) && isset($_POST['prefix'])) { | |
| $data='{"using": [ "urn:ietf:params:jmap:core", "https://www.fastmail.com/dev/maskedemail"], "methodCalls": [ ["MaskedEmail/set", { "accountId": "'.$account.'", "create" : { "k1" : { "emailPrefix" : "'.$_POST['prefix'].'", "state" : "enabled", "description" : "'.$_POST['description'].'" } } }, "R1"] ]}'; | |
| } | |
| $ch=curl_init("https://api.fastmail.com/jmap/api/"); | |
| curl_setopt($ch, CURLOPT_POSTFIELDS, $data); | |
| curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Bearer '.$apikey)); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
| $result=curl_exec($ch); | |
| $json=json_decode($result, 1); | |
| echo '<div class="alert alert-success" role="alert">'.$json['methodResponses'][0][1]['created']['k1']['email'].'</div><br><br>'; | |
| } | |
| ?> | |
| <label for="prefix" class="form-label">Prefix</label> | |
| <input type="text" name="prefix" class="form-control" id="prefix"> | |
| </div> | |
| <div class="mb-3"> | |
| <label for="description" class="form-label">Description</label> | |
| <input type="text" class="form-control" id="description" name="description"> | |
| </div> | |
| <input class="btn btn-primary" type="submit" value="Submit" name="submit"> | |
| </form></div> | |
| <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment