Skip to content

Instantly share code, notes, and snippets.

@warewolf
Last active March 10, 2022 23:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warewolf/ba725a85422a4e79759d65c445150a57 to your computer and use it in GitHub Desktop.
Save warewolf/ba725a85422a4e79759d65c445150a57 to your computer and use it in GitHub Desktop.
PDF/EPUB from email to remarkable cloud
#!/usr/bin/perl
use strict;
use warnings;
use MIME::Parser;
use Data::Dumper;
use List::Util qw(first);
$ENV{RMAPI_HOST}='https://rmfakecloud.example.com/';
my $parser = new MIME::Parser;
my $entity = $parser->parse(\*STDIN);
for (my $idx = 0; $idx < scalar $entity->parts() ; $idx++) {
my $part = $entity->parts($idx);
my $head = $part->head();
my $filename = $head->recommended_filename();
if (my $type = first { index($part->effective_type(),$_) == 0 } qw(application/pdf application/epub)) {
printf("Found a %s type w/ filename %s\n",$type,$filename);
my $path = $part->bodyhandle->path;
link($path,$filename);
if (-e $path) {
printf("Sending %s\n",$filename);
system("rmapi","put",$filename,"/Articles");
}
unlink($filename);
}
}
$parser->filer->purge;
@warewolf
Copy link
Author

warewolf commented Mar 9, 2022

And the procmail recipie that calls this script:

:0c H
* ^To:.*rmfakecloud@mydomain.com
| ~/bin/remarkable.pl 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment