Skip to content

Instantly share code, notes, and snippets.

@rjbs
Created April 1, 2021 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjbs/8505f1dbaa211411c413f01ee3da2660 to your computer and use it in GitHub Desktop.
Save rjbs/8505f1dbaa211411c413f01ee3da2660 to your computer and use it in GitHub Desktop.
my $client = Fastmail::Client->....;
my $mbox_res = $client->request([
[ 'Mailbox/get', { accountId => ... } ],
]);
# Get all the mailbox objects:
my @boxes = $mbox_res->single_sentence('Mailbox/get')->arguments->{list}->@*;
my ($newsletter) = grep {; $_->{name} eq 'Newsletters' } @boxes;
die "WTF?!" unless $newsletter;
# NOTE: this will only find *direct* children; finding deep ancestors is left
# as an exercise for the reader (or, like, don't do that)
my @boxes_of_interest = grep {; $_->{parentId} eq $newsletter->{id} } @boxes;
exit unless @boxes_of_interest; # I guess we don't have any...
my $mail_res = $client->request([
[
'Email/query',
{
filter => {
createdAfter => '30 days ago',
also => {
operator => 'or',
conditions => [
map {; { mailboxId => $_->{id} } } @boxes_of_interest
],
}
}
},
'a',
],
[
'Email/get',
{
properties => [ ??? ],
'#ids' => {
resultOf => 'a',
name => 'Email/query',
path => '/ids',
}
},
],
]);
my @mail = $mail_res->sentence_named('Email/get')->arguments->{list}->@*;
# NEXT:
# group mail into groups by the mailboxes they're in
# sort them into rev. chron order or something
# build the XML::Feed objects
# write them out
# done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment