~james-page/ubuntu/raring/dovecot/autopkgtest

« back to all changes in this revision

Viewing changes to src/plugins/fts/decode2text.sh

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-06-11 11:11:54 UTC
  • mfrom: (1.15.2) (4.1.27 sid)
  • Revision ID: package-import@ubuntu.com-20120611111154-678cwbdj6ktgsv1h
Tags: 1:2.1.7-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/{control,rules}: enable PIE hardening.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + d/control: Added Pre-Depends: dpkg (>= 1.15.6) to dovecot-dbg to support
    xz compression in Ubuntu.
  + d/control: Demote dovecot-common Recommends: to Suggests: to prevent
    install of extra packages on upgrade.
  + d/patches/dovecot-drac.patch: Updated with version for dovecot >= 2.0.0.
  + d/control: Drop B-D on systemd.
* Dropped changes:
  + d/patches/fix-racey-restart.patch: part of 2.1.x, no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
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.)
 
6
 
 
7
# The attachment decoding is enabled by setting:
 
8
#
 
9
# plugin {
 
10
#   fts_decoder = decode2text
 
11
# }
 
12
# service decode2text {
 
13
#   executable = script /usr/local/libexec/dovecot/decode2text.sh
 
14
#   user = dovecot
 
15
#   unix_listener decode2text {
 
16
#     mode = 0666
 
17
#   }
 
18
# }
 
19
 
 
20
content_type=$1
 
21
 
 
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
 
26
application/x-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
 
39
'
 
40
 
 
41
if [ "$content_type" = "" ]; then
 
42
  echo "$formats"
 
43
  exit 0
 
44
fi
 
45
 
 
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
 
49
  exit 1
 
50
fi
 
51
 
 
52
# most decoders can't handle stdin directly, so write the attachment
 
53
# to a temp file
 
54
path=`mktemp`
 
55
trap "rm -f $path" 0 1 2 3 14 15
 
56
cat > $path
 
57
 
 
58
xmlunzip() {
 
59
  name=$1
 
60
 
 
61
  tempdir=`mktemp -d`
 
62
  if [ "$tempdir" = "" ]; then 
 
63
    exit 1
 
64
  fi
 
65
  trap "rm -rf $path $tempdir" 0 1 2 3 14 15
 
66
  cd $tempdir || exit 1
 
67
  unzip -q "$path" 2>/dev/null || exit 0
 
68
  find . -name "$name" -print0 | xargs -0 cat |
 
69
    /usr/local/libexec/dovecot/xml2text
 
70
}
 
71
 
 
72
wait_timeout() {
 
73
  childpid=$!
 
74
  trap "kill -9 $childpid; rm -f $path" 1 2 3 14 15
 
75
  wait $childpid
 
76
}
 
77
 
 
78
LANG=en_US.UTF-8
 
79
export LANG
 
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
 
99
  xmlunzip "slide*.xml"
 
100
else
 
101
  echo "Buggy decoder script: $fmt not handled" >&2
 
102
  exit 1
 
103
fi
 
104
exit 0