commit 8f94962e78895a7d1d65fe998005c5ff9b03ec47
Author: Paco Esteban <paco@e1e0.net>
Date: Sat, 21 Aug 2021 15:24:51 +0200
initial hacky version of a conversion filter
Diffstat:
1 file changed, 61 insertions(+), 0 deletions(-)
diff --git a/conversion-filter.pl b/conversion-filter.pl
@@ -0,0 +1,61 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Email::MIME;
+use Email::Sender::Simple qw(sendmail);
+use IO::All;
+
+my $parsed = Email::MIME->new(join('', <STDIN>));
+my @parts = $parsed->parts;
+
+my $docfilename = 'remarkable.docx';
+my $docfile = "/tmp/$docfilename";
+my $tmpfile = '/tmp/converttmp';
+
+unlink $docfile if -e $docfile;
+unlink $tmpfile if -e $tmpfile;
+
+foreach my $p (@parts) {
+ if ($p->content_type =~ "^text/html.*") {
+ open(my $fh, '>', $tmpfile) or die "Could not open $tmpfile $!";
+ print $fh $p->body;
+ close $fh;
+ `pandoc -f html -t docx -o $docfile $tmpfile`;
+ }
+}
+
+# multipart message
+my @sparts = (
+ Email::MIME->create(
+ attributes => {
+ content_type => "text/plain",
+ disposition => "inline",
+ encoding => 'quoted-printable',
+ charset => 'utf-8',
+ },
+ body_str => "Ja està ! Fitxer convertit a Word.\n",
+ ),
+ Email::MIME->create(
+ attributes => {
+ filename => "$docfilename",
+ content_type => "application/octet-stream",
+ disposition => "attachment",
+ encoding => "base64",
+ name => "$docfilename",
+ },
+ body => io( "$docfile" )->binary->all,
+ ),
+);
+$sparts[1]->encoding_set('base64');
+
+my $email = Email::MIME->create(
+ header_str => [
+ From => 'conversion@example.com',
+ To => [ 'destination@example.com' ],
+ Subject => 'Fitxer convertit.',
+ ],
+ parts => [ @sparts ],
+);
+
+sendmail($email);