forked from 2600hz/bluebox
/
emailtopdf.php
executable file
·103 lines (92 loc) · 2.36 KB
/
emailtopdf.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/php
<?php
/* Command line wrapper for Email to pdf converter
*
* Dependencies:
* Pear::Console_Getopt
*
* emailto/emailtopdf
*/
require_once 'Console/Getopt.php';
require_once 'convertto/emailtopdf.php';
# Print usage information
function printusage($errmsg = '')
{
if ($errmsg != '')
echo 'ERROR: ' . $errmsg . "\n\n";
echo "emailtopdf converts an email (and attachments) to a pdf. ".
"You may also specify a cover file to include on the front of the pdf such as a disclaimer " .
"or instructions, etc.\n\n" .
"The following attachment types are supported:\n" .
" plain/txt, rtf, html\n" .
" gif, jpg, png, tif\n" .
" opendoc(ODF) (odt, ods, odp, ott, ots, otp)\n" .
" MS Office (doc, docx, dot, dotx, ppt, pot, potx, pptx, xls, xlsx)\n" .
" OpenOffice (stc, sti, stw, sxc, sxi, sxw)\n" .
" Flash (swf)\n" .
" PDF (pdf)\n\n" .
"Parameters:\n" .
" -c filename Include a cover page\n\n" .
"Usage:\n" .
" emailtopdf [-c filename] EMAILFILE OUTPUTFILE\n\n" .
"Notes:\n" .
" If a dash (-) is specified as the EMAILFILE or the OUTPUT FILE, then STDIN and STDOUT will be used respectively.\n" .
" If the EMAILFILE is specified, but the OUTPUTFILE is not, then the output will be written to INPUTFILE.pdf.\n";
exit(1);
}
$coverfile = '';
$infile = '';
$outfile = '';
$force = false;
$cg = new Console_Getopt();
$args = $cg->readPHPArgv();
array_shift($args);
for ($i=0; $i<count($args); $i++)
{
switch ($args[$i])
{
case '--help':
case '-h':
case '-?':
printusage('');
break;
case '-c':
$coverfile = $args[$i+1];
$i++;
break;
case '-f':
$force = true;
break;
case '-':
if ($infile == '')
$infile = 'php://stdin';
else
$outfile = 'php://stdout';
break;
default:
if ($infile == '')
$infile = $args[$i];
else
$outfile = $args[$i];
break;
}
}
if ($infile == '')
printusage('No input file specified.');
if ($outfile == '')
if ($infile != 'php://stdin')
$outfile = $infile . '.pdf';
else
printusage('No output file specified.');
# Check to see if the output file exists
if (file_exists($outfile))
{
# If it exists, check to see if we are to overwrite it.
if ($force)
unlink($outfile);
else
printusage('Output file already exists. Use -f to overwrite.');
}
touch($outfile);
emailtopdf::processemail($infile, $outfile, $coverfile);
?>