Last active
March 10, 2022 23:48
-
-
Save warewolf/ba725a85422a4e79759d65c445150a57 to your computer and use it in GitHub Desktop.
PDF/EPUB from email to remarkable cloud
This file contains 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/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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And the procmail recipie that calls this script: