3
# Example attachment decoder script. The attachment comes from stdin, and
4
# the script is expected to output UTF-8 data to stdout. (If the output isn't
5
# UTF-8, everything except valid UTF-8 sequences are dropped from it.)
7
# The attachment decoding is enabled by setting:
10
# fts_decoder = decode2text
12
# service decode2text {
13
# executable = script /usr/local/libexec/dovecot/decode2text.sh
15
# unix_listener decode2text {
22
# The second parameter is the format's filename extension, which is used when
23
# found from a filename of application/octet-stream. You can also add more
24
# extensions by giving more parameters.
25
formats='application/pdf pdf
27
application/msword doc
28
application/mspowerpoint ppt
29
application/vnd.ms-powerpoint ppt
30
application/ms-excel xls
31
application/x-msexcel xls
32
application/vnd.ms-excel xls
33
application/vnd.openxmlformats-officedocument.wordprocessingml.document docx
34
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
35
application/vnd.openxmlformats-officedocument.presentationml.presentation pptx
36
application/vnd.oasis.opendocument.text odt
37
application/vnd.oasis.opendocument.spreadsheet ods
38
application/vnd.oasis.opendocument.presentation odp
41
if [ "$content_type" = "" ]; then
46
fmt=`echo "$formats" | grep -w "^$content_type" | cut -d ' ' -f 2`
47
if [ "$fmt" = "" ]; then
48
echo "Content-Type: $content_type not supported" >&2
52
# most decoders can't handle stdin directly, so write the attachment
55
trap "rm -f $path" 0 1 2 3 14 15
62
if [ "$tempdir" = "" ]; then
65
trap "rm -rf $path $tempdir" 0 1 2 3 14 15
67
unzip -q "$path" 2>/dev/null || exit 0
68
find . -name "$name" -print0 | xargs -0 cat |
69
/usr/local/libexec/dovecot/xml2text
74
trap "kill -9 $childpid; rm -f $path" 1 2 3 14 15
80
if [ $fmt = "pdf" ]; then
81
/usr/bin/pdftotext $path - 2>/dev/null&
82
wait_timeout 2>/dev/null
83
elif [ $fmt = "doc" ]; then
84
(/usr/bin/catdoc $path; true) 2>/dev/null&
85
wait_timeout 2>/dev/null
86
elif [ $fmt = "ppt" ]; then
87
(/usr/bin/catppt $path; true) 2>/dev/null&
88
wait_timeout 2>/dev/null
89
elif [ $fmt = "xls" ]; then
90
(/usr/bin/xls2csv $path; true) 2>/dev/null&
91
wait_timeout 2>/dev/null
92
elif [ $fmt = "odt" -o $fmt = "ods" -o $fmt = "odp" ]; then
93
xmlunzip "content.xml"
94
elif [ $fmt = "docx" ]; then
95
xmlunzip "document.xml"
96
elif [ $fmt = "xlsx" ]; then
97
xmlunzip "sharedStrings.xml"
98
elif [ $fmt = "pptx" ]; then
101
echo "Buggy decoder script: $fmt not handled" >&2