3 # mmm Version 0.1 by Thomas Hochstein
5 # Create a MIME multipart/alternative part, containing
6 # text/plain (in Markdowen) and text/html, from a
9 # Copyright (c) 2015 Thomas Hochstein <thh@inter.net>
11 # It can be redistributed and/or modified under the same terms under
12 # which Perl itself is published.
17 use Getopt::Long qw(GetOptions);
20 # read commandline option(s)
21 my ($OptInFile,$OptHeaderFile);
22 GetOptions ('f|file=s' => \$OptInFile,
23 't|headers=s' => \$OptHeaderFile,
24 'H|help' => \&ShowPOD,
25 'V|version' => \&ShowVersion) or exit 1;
27 # read input from STDIN or --file
32 open(FILE, "< $OptInFile") or die "Can't open $OptInFile: $!";
38 # read header template
41 open(HEADERS, "< $OptHeaderFile") or die "Can't open $OptHeaderFile: $!";
44 # remove all trailing newlines
50 # convert markdown to html
51 my $html = Text::Markdown::Markdown($markdown);
54 print "$headers\n" if ($OptHeaderFile);
56 my $Boundary = &GenBoundary;
57 print "MIME-Version: 1.0\n";
58 print "Content-Type: multipart/alternative;\n";
59 printf ('boundary="%s"'."\n",$Boundary);
62 print "This is a multi-part message in MIME format.\n";
64 printf ("--%s\n",$Boundary);
65 print "Content-Type: text/plain; charset=ISO-8859-15\n";
66 print "Content-Transfer-Encoding: 8bit\n";
70 printf ("--%s\n",$Boundary);
71 print "Content-Type: text/html; charset=ISO-8859-15\n";
72 print "Content-Transfer-Encoding: 8bit\n";
73 print "X-Creator: Markdown/1.0.1\n";
77 printf ("--%s--\n",$Boundary);
81 ################################################################################
85 $hex .= sprintf("%x", rand 16) for 1..20;
86 return ( "----------" . $hex);
90 print "mmm v$VERSION\n";
91 print "MIME multipart/alternative from Markdown - MMM\n";
92 print "Copyright (c) 2015 Thomas Hochstein <thh\@inter.net>\n";
93 print "This program is free software; you may redistribute it ".
94 "and/or modify it under the same terms as Perl itself.\n";