File: zip_script

package info (click to toggle)
sanitizer 1.76-3
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 940 kB
  • ctags: 184
  • sloc: perl: 5,276; sh: 2,107; makefile: 51
file content (53 lines) | stat: -rwxr-xr-x 1,627 bytes parent folder | download | duplicates (6)
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
#!/bin/bash
#
# This is a sample script for encapsulating incoming attachments in 
# .ZIP files on the fly, based on the ideas expressed in this post:
#
#  http://mailtools.anomy.net/archives/anomy-list/2002-10/0008.shtml
#
# Enable by adding to your sanitizer configuration the following
# lines:
#
#  file_list_12_scanner = 0:::/path/to/zip_script %FILENAME %ATTNAME
#  file_list_12_policy  = accept:unknown:unknown:unknown
#  file_list_12 = .*
#
# Using some other list (other than 12) will alter the priority of the
# zip rule - using 12 will by default ZIP any incoming Office documents,
# the "Miscellanious" category and unknown attachments - archives and
# static data (gifs, jpgs, text, html, etc) will not be zipped.
#
# Similar tricks can be used to convert from one data type to another.
#
# Paranoid admins could use the -P flag for the zip command to put a
# password on the created zip files...
#
ZIP=$(which zip)
[ "$ZIP" = "" ] && exit 2
SED=$(which sed)
[ "$SED" = "" ] && exit 3

FILE=$1
NAME=$(echo "$2" | sed -e 's/\//_/g');
[ -f "$FILE"   ] || exit 1
[ "$NAME" = "" ] && NAME="$FILE"

# Do stuff within a temporary directory...
mkdir -p "/tmp/zip_script.$$" || exit 5
cd "/tmp/zip_script.$$"       || exit 6
ln "$FILE" "$NAME"

FILE2=$(echo "$FILE" | sed -e 's/\./_/g').zip
NAME2=$(echo "$NAME" | sed -e 's/\./_/g').zip
zip -Dkm $FILE2 "$NAME" 2>/dev/null 1>/dev/null || exit 4

# Cleanup
cd /
rm -rf "/tmp/zip_script.$$" "$FILE"

echo Anomy-FileScan-NewFile: $FILE2
echo Anomy-FileScan-NewName: $NAME2
echo Anomy-FileScan-NewType: application/octet-stream
echo Anomy-FileScan-NewEnc:  Base64
echo
exit 0