remarkable2_utils

Utilities for the remarkable2 tablet
git clone https://git.e1e0.net/remarkable2_utils.git
Log | Files | Refs

conversion-filter.pl (1389B)


      1 #!/usr/bin/perl
      2 
      3 use strict;
      4 use warnings;
      5 use Email::MIME;
      6 use Email::Sender::Simple qw(sendmail);
      7 use IO::All;
      8 
      9 my $parsed = Email::MIME->new(join('', <STDIN>));
     10 my @parts = $parsed->parts;
     11 
     12 my $docfilename = 'remarkable.docx';
     13 my $docfile = "/tmp/$docfilename";
     14 my $tmpfile = '/tmp/converttmp';
     15 
     16 unlink $docfile if -e $docfile;
     17 unlink $tmpfile if -e $tmpfile;
     18 
     19 foreach my $p (@parts) {
     20 	if ($p->content_type =~ "^text/html.*") {
     21 		open(my $fh, '>', $tmpfile) or die "Could not open $tmpfile $!";
     22 		print $fh $p->body;
     23 		close $fh;
     24 		`pandoc -f html -t docx -o $docfile $tmpfile`;
     25 	}
     26 }
     27 
     28 # multipart message
     29 my @sparts = (
     30 	Email::MIME->create(
     31 		attributes => {
     32 			content_type => "text/plain",
     33 			disposition  => "inline",
     34 			encoding     => 'quoted-printable',
     35 			charset      => 'utf-8',
     36 		},
     37 		body_str => "Ja està !  Fitxer convertit a Word.\n",
     38 	),
     39 	Email::MIME->create(
     40 		attributes => {
     41 			filename     => "$docfilename",
     42 			content_type => "application/octet-stream",
     43 			disposition  => "attachment",
     44 			encoding     => "base64",
     45 			name         => "$docfilename",
     46 		},
     47 		body => io( "$docfile" )->binary->all,
     48 	),
     49 );
     50 $sparts[1]->encoding_set('base64');
     51 
     52 my $email = Email::MIME->create(
     53 	header_str => [
     54 		From    => 'conversion@example.com',
     55 		To      => [ 'destination@example.com' ],
     56 		Subject => 'Fitxer convertit.',
     57 	],
     58 	parts       => [ @sparts ],
     59 );
     60 
     61 sendmail($email);