tnef 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/tnef/AUTHORS +7 -0
- data/ext/tnef/BUGS.in +5 -0
- data/ext/tnef/COPYING +340 -0
- data/ext/tnef/ChangeLog +1550 -0
- data/ext/tnef/INSTALL +234 -0
- data/ext/tnef/Makefile.am +7 -0
- data/ext/tnef/Makefile.in +699 -0
- data/ext/tnef/NEWS +177 -0
- data/ext/tnef/README +39 -0
- data/ext/tnef/THANKS +1 -0
- data/ext/tnef/TODO +7 -0
- data/ext/tnef/acinclude.m4 +47 -0
- data/ext/tnef/aclocal.m4 +1012 -0
- data/ext/tnef/configure +6815 -0
- data/ext/tnef/configure.in +67 -0
- data/ext/tnef/depcomp +584 -0
- data/ext/tnef/doc/FAQ +25 -0
- data/ext/tnef/doc/Makefile.am +6 -0
- data/ext/tnef/doc/Makefile.in +623 -0
- data/ext/tnef/doc/file-format.tex +139 -0
- data/ext/tnef/doc/tnef.1.in +183 -0
- data/ext/tnef/doc/www/Makefile.am +14 -0
- data/ext/tnef/doc/www/Makefile.in +542 -0
- data/ext/tnef/doc/www/cgi-bin/Makefile.am +14 -0
- data/ext/tnef/doc/www/cgi-bin/Makefile.in +340 -0
- data/ext/tnef/doc/www/htdocs/Makefile.am +14 -0
- data/ext/tnef/doc/www/htdocs/Makefile.in +340 -0
- data/ext/tnef/extconf.rb +3 -0
- data/ext/tnef/install-sh +507 -0
- data/ext/tnef/missing +367 -0
- data/ext/tnef/mkinstalldirs +161 -0
- data/ext/tnef/src/Makefile.am +48 -0
- data/ext/tnef/src/Makefile.in +700 -0
- data/ext/tnef/src/alloc.c +107 -0
- data/ext/tnef/src/alloc.h +54 -0
- data/ext/tnef/src/attr.c +270 -0
- data/ext/tnef/src/attr.h +74 -0
- data/ext/tnef/src/common.h +101 -0
- data/ext/tnef/src/config.h.in +111 -0
- data/ext/tnef/src/date.c +66 -0
- data/ext/tnef/src/date.h +43 -0
- data/ext/tnef/src/debug.c +45 -0
- data/ext/tnef/src/debug.h +32 -0
- data/ext/tnef/src/file.c +259 -0
- data/ext/tnef/src/file.h +48 -0
- data/ext/tnef/src/main.c +386 -0
- data/ext/tnef/src/mapi-names.data +430 -0
- data/ext/tnef/src/mapi-types.data +19 -0
- data/ext/tnef/src/mapi_attr.c +419 -0
- data/ext/tnef/src/mapi_attr.h +78 -0
- data/ext/tnef/src/mkdata.awk +100 -0
- data/ext/tnef/src/options.c +32 -0
- data/ext/tnef/src/options.h +67 -0
- data/ext/tnef/src/path.c +397 -0
- data/ext/tnef/src/path.h +34 -0
- data/ext/tnef/src/replace/Makefile.am +8 -0
- data/ext/tnef/src/replace/Makefile.in +435 -0
- data/ext/tnef/src/replace/basename.c +45 -0
- data/ext/tnef/src/replace/dummy.c +7 -0
- data/ext/tnef/src/replace/getopt_long.c +940 -0
- data/ext/tnef/src/replace/getopt_long.h +141 -0
- data/ext/tnef/src/replace/malloc.c +41 -0
- data/ext/tnef/src/replace/strdup.c +51 -0
- data/ext/tnef/src/rtf.c +362 -0
- data/ext/tnef/src/rtf.h +36 -0
- data/ext/tnef/src/tnef-names.data +34 -0
- data/ext/tnef/src/tnef-types.data +12 -0
- data/ext/tnef/src/tnef.c +396 -0
- data/ext/tnef/src/tnef.h +45 -0
- data/ext/tnef/src/util.c +112 -0
- data/ext/tnef/src/util.h +42 -0
- data/ext/tnef/src/write.c +136 -0
- data/ext/tnef/src/write.h +25 -0
- data/ext/tnef/src/xstrdup.c +41 -0
- data/ext/tnef/tests/Makefile.am +4 -0
- data/ext/tnef/tests/Makefile.in +530 -0
- data/ext/tnef/tests/cmdline/AUTHORS +8 -0
- data/ext/tnef/tests/cmdline/AUTHORS.baseline +8 -0
- data/ext/tnef/tests/cmdline/Makefile.am +33 -0
- data/ext/tnef/tests/cmdline/Makefile.in +455 -0
- data/ext/tnef/tests/cmdline/basic.baseline +4 -0
- data/ext/tnef/tests/cmdline/basic.test +39 -0
- data/ext/tnef/tests/cmdline/body-test.html.baseline +95 -0
- data/ext/tnef/tests/cmdline/body.baseline +929 -0
- data/ext/tnef/tests/cmdline/body.test +55 -0
- data/ext/tnef/tests/cmdline/debug.baseline +155 -0
- data/ext/tnef/tests/cmdline/debug.test +14 -0
- data/ext/tnef/tests/cmdline/directory.baseline +3 -0
- data/ext/tnef/tests/cmdline/directory.test +35 -0
- data/ext/tnef/tests/cmdline/help.baseline +63 -0
- data/ext/tnef/tests/cmdline/help.test +12 -0
- data/ext/tnef/tests/cmdline/interactive.test +5 -0
- data/ext/tnef/tests/cmdline/list.baseline +5 -0
- data/ext/tnef/tests/cmdline/list.test +21 -0
- data/ext/tnef/tests/cmdline/maxsize.baseline +828 -0
- data/ext/tnef/tests/cmdline/maxsize.test +43 -0
- data/ext/tnef/tests/cmdline/message.html.baseline +95 -0
- data/ext/tnef/tests/cmdline/mime-types.baseline +3 -0
- data/ext/tnef/tests/cmdline/mime-types.test +11 -0
- data/ext/tnef/tests/cmdline/overwrite.baseline +8 -0
- data/ext/tnef/tests/cmdline/overwrite.test +40 -0
- data/ext/tnef/tests/cmdline/rtf-test.rtf.baseline +0 -0
- data/ext/tnef/tests/cmdline/stdin.baseline +2 -0
- data/ext/tnef/tests/cmdline/stdin.test +18 -0
- data/ext/tnef/tests/cmdline/test.tnef +0 -0
- data/ext/tnef/tests/cmdline/triples-test-2.rtf.baseline +0 -0
- data/ext/tnef/tests/cmdline/triples-test-2.txt.baseline +0 -0
- data/ext/tnef/tests/cmdline/triples-test.txt.baseline +0 -0
- data/ext/tnef/tests/cmdline/use-path.baseline +0 -0
- data/ext/tnef/tests/cmdline/use-path.test +5 -0
- data/ext/tnef/tests/cmdline/verbose.baseline +5 -0
- data/ext/tnef/tests/cmdline/verbose.test +19 -0
- data/ext/tnef/tests/cmdline/version.baseline +17 -0
- data/ext/tnef/tests/cmdline/version.test +14 -0
- data/ext/tnef/tests/files/MAPI_ATTACH_DATA_OBJ.test +9 -0
- data/ext/tnef/tests/files/MAPI_OBJECT.test +9 -0
- data/ext/tnef/tests/files/Makefile.am +16 -0
- data/ext/tnef/tests/files/Makefile.in +636 -0
- data/ext/tnef/tests/files/baselines/AUTHORS.baseline +8 -0
- data/ext/tnef/tests/files/baselines/AUTOEXEC.BAT.baseline +0 -0
- data/ext/tnef/tests/files/baselines/CONFIG.SYS.baseline +0 -0
- data/ext/tnef/tests/files/baselines/MAPI_ATTACH_DATA_OBJ-body.rtf.baseline +0 -0
- data/ext/tnef/tests/files/baselines/MAPI_ATTACH_DATA_OBJ.baseline +229 -0
- data/ext/tnef/tests/files/baselines/MAPI_OBJECT-body.rtf.baseline +0 -0
- data/ext/tnef/tests/files/baselines/MAPI_OBJECT.baseline +153 -0
- data/ext/tnef/tests/files/baselines/Makefile.am +35 -0
- data/ext/tnef/tests/files/baselines/Makefile.in +361 -0
- data/ext/tnef/tests/files/baselines/README.baseline +31 -0
- data/ext/tnef/tests/files/baselines/TechlibDEC99-JAN00.doc.baseline +0 -0
- data/ext/tnef/tests/files/baselines/TechlibDEC99.doc.baseline +0 -0
- data/ext/tnef/tests/files/baselines/TechlibNOV99.doc.baseline +0 -0
- data/ext/tnef/tests/files/baselines/Untitled_Attachment.baseline +0 -0
- data/ext/tnef/tests/files/baselines/VIA_Nytt_1402.doc.baseline +0 -0
- data/ext/tnef/tests/files/baselines/VIA_Nytt_1402.pdf.baseline +0 -0
- data/ext/tnef/tests/files/baselines/VIA_Nytt_14021.htm.baseline +1914 -0
- data/ext/tnef/tests/files/baselines/body-body.html.baseline +95 -0
- data/ext/tnef/tests/files/baselines/body.baseline +124 -0
- data/ext/tnef/tests/files/baselines/boot.ini.baseline +6 -0
- data/ext/tnef/tests/files/baselines/data-before-name-body.rtf.baseline +0 -0
- data/ext/tnef/tests/files/baselines/data-before-name.baseline +213 -0
- data/ext/tnef/tests/files/baselines/garbage-at-end.baseline +73 -0
- data/ext/tnef/tests/files/baselines/generpts.src.baseline +1691 -0
- data/ext/tnef/tests/files/baselines/long-filename-body.rtf.baseline +26 -0
- data/ext/tnef/tests/files/baselines/long-filename.baseline +218 -0
- data/ext/tnef/tests/files/baselines/message.rtf.baseline +0 -0
- data/ext/tnef/tests/files/baselines/missing-filenames-body.rtf.baseline +20 -0
- data/ext/tnef/tests/files/baselines/missing-filenames.baseline +252 -0
- data/ext/tnef/tests/files/baselines/multi-name-property.baseline +243 -0
- data/ext/tnef/tests/files/baselines/one-file.baseline +155 -0
- data/ext/tnef/tests/files/baselines/rtf-body.rtf.baseline +0 -0
- data/ext/tnef/tests/files/baselines/rtf.baseline +167 -0
- data/ext/tnef/tests/files/baselines/triples-body.rtf.baseline +0 -0
- data/ext/tnef/tests/files/baselines/triples.baseline +254 -0
- data/ext/tnef/tests/files/baselines/two-files.baseline +186 -0
- data/ext/tnef/tests/files/body.test +9 -0
- data/ext/tnef/tests/files/data-before-name.test +9 -0
- data/ext/tnef/tests/files/datafiles/MAPI_ATTACH_DATA_OBJ.list +4 -0
- data/ext/tnef/tests/files/datafiles/MAPI_ATTACH_DATA_OBJ.tnef +0 -0
- data/ext/tnef/tests/files/datafiles/MAPI_OBJECT.list +2 -0
- data/ext/tnef/tests/files/datafiles/MAPI_OBJECT.tnef +0 -0
- data/ext/tnef/tests/files/datafiles/Makefile.am +27 -0
- data/ext/tnef/tests/files/datafiles/Makefile.in +351 -0
- data/ext/tnef/tests/files/datafiles/body.list +1 -0
- data/ext/tnef/tests/files/datafiles/body.tnef +0 -0
- data/ext/tnef/tests/files/datafiles/data-before-name.list +4 -0
- data/ext/tnef/tests/files/datafiles/data-before-name.tnef +0 -0
- data/ext/tnef/tests/files/datafiles/garbage-at-end.list +0 -0
- data/ext/tnef/tests/files/datafiles/garbage-at-end.tnef +0 -0
- data/ext/tnef/tests/files/datafiles/long-filename.list +1 -0
- data/ext/tnef/tests/files/datafiles/long-filename.tnef +0 -0
- data/ext/tnef/tests/files/datafiles/missing-filenames.list +1 -0
- data/ext/tnef/tests/files/datafiles/missing-filenames.tnef +0 -0
- data/ext/tnef/tests/files/datafiles/multi-name-property.list +0 -0
- data/ext/tnef/tests/files/datafiles/multi-name-property.tnef +0 -0
- data/ext/tnef/tests/files/datafiles/one-file.list +1 -0
- data/ext/tnef/tests/files/datafiles/one-file.tnef +0 -0
- data/ext/tnef/tests/files/datafiles/rtf.list +1 -0
- data/ext/tnef/tests/files/datafiles/rtf.tnef +0 -0
- data/ext/tnef/tests/files/datafiles/triples.list +1 -0
- data/ext/tnef/tests/files/datafiles/triples.tnef +0 -0
- data/ext/tnef/tests/files/datafiles/two-files.list +2 -0
- data/ext/tnef/tests/files/datafiles/two-files.tnef +0 -0
- data/ext/tnef/tests/files/file-util.sh +38 -0
- data/ext/tnef/tests/files/garbage-at-end.test +9 -0
- data/ext/tnef/tests/files/long-filename.test +9 -0
- data/ext/tnef/tests/files/missing-filenames.test +9 -0
- data/ext/tnef/tests/files/multi-name-property.test +9 -0
- data/ext/tnef/tests/files/one-file.test +9 -0
- data/ext/tnef/tests/files/rtf.test +9 -0
- data/ext/tnef/tests/files/triples.test +9 -0
- data/ext/tnef/tests/files/two-files.test +9 -0
- data/ext/tnef/tests/util.sh +32 -0
- data/ext/tnef/tnef.spec.in +44 -0
- data/lib/tnef.rb +30 -0
- data/lib/tnef/executable.rb +27 -0
- data/lib/tnef/version.rb +3 -0
- metadata +243 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# mkdata.awk - used to generate blah.[ch] from blah.data
|
|
2
|
+
#
|
|
3
|
+
# Copyright (C)1999-2006 Mark Simpson <damned@world.std.com>
|
|
4
|
+
#
|
|
5
|
+
# This program is free software; you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation; either version 2, or (at your option)
|
|
8
|
+
# any later version.
|
|
9
|
+
#
|
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with this program; if not, you can either send email to this
|
|
17
|
+
# program's maintainer or write to: The Free Software Foundation,
|
|
18
|
+
# Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
|
|
19
|
+
#
|
|
20
|
+
# Commentary:
|
|
21
|
+
#
|
|
22
|
+
# the file x.data was given on the command line
|
|
23
|
+
# the output of this script is redirected to the right file
|
|
24
|
+
# the environment variable TAG is used for the function name and comments
|
|
25
|
+
#
|
|
26
|
+
|
|
27
|
+
#
|
|
28
|
+
# Print headers and such.
|
|
29
|
+
#
|
|
30
|
+
BEGIN {
|
|
31
|
+
HFILE = sprintf ("%ss.h", ENVIRON["TAG"]);
|
|
32
|
+
HFILEDEF = HFILE;
|
|
33
|
+
HFILEDEF = toupper(HFILEDEF);
|
|
34
|
+
gsub("\\.","_",HFILEDEF);
|
|
35
|
+
CFILE = sprintf ("%ss.c", ENVIRON["TAG"]);
|
|
36
|
+
printf "/* This file generated by names.awk do not edit! */\n" > HFILE;
|
|
37
|
+
printf "#ifndef %s\n", HFILEDEF > HFILE;
|
|
38
|
+
printf "#define %s\n", HFILEDEF > HFILE;
|
|
39
|
+
printf "enum _%s {\n", ENVIRON["TAG"] > HFILE;
|
|
40
|
+
|
|
41
|
+
printf "/* This file generated by names.awk do not edit! */\n" > CFILE;
|
|
42
|
+
printf "#ifdef HAVE_CONFIG_H\n" > CFILE;
|
|
43
|
+
printf "#include \"config.h\"\n" > CFILE;
|
|
44
|
+
printf "#endif\n" > CFILE;
|
|
45
|
+
printf "#include \"common.h\"\n" > CFILE;
|
|
46
|
+
printf "#include \"%s\"\n", HFILE > CFILE;
|
|
47
|
+
printf "char*\n" > CFILE;
|
|
48
|
+
printf "get_%s_str(uint16 d)\n", ENVIRON["TAG"] > CFILE;
|
|
49
|
+
printf "{\n" > CFILE;
|
|
50
|
+
printf " static char buf[128];\n" > CFILE;
|
|
51
|
+
printf " static char* str;\n" > CFILE;
|
|
52
|
+
printf " switch(d) {\n" > CFILE;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
#
|
|
56
|
+
# deal with each line if it doesn't start with a '#'
|
|
57
|
+
#
|
|
58
|
+
/^[^#]/ {
|
|
59
|
+
NAME = ""
|
|
60
|
+
for (i = 3; i < NF + 1; i=i+1) {
|
|
61
|
+
if ( NAME ) {
|
|
62
|
+
NAME = sprintf ("%s %s", NAME, $(i))
|
|
63
|
+
} else {
|
|
64
|
+
NAME = $(i)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
# printf "#define %-10s\t%s\t/* %s */\n", $1, $2, NAME > HFILE;
|
|
69
|
+
printf "\t%-45s = %s,\n", $1, $2 > HFILE
|
|
70
|
+
|
|
71
|
+
printf " case %s:\n", $1 > CFILE;
|
|
72
|
+
printf " str=\"%s\";\n", NAME > CFILE;
|
|
73
|
+
printf " break;\n" > CFILE;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
#
|
|
77
|
+
# Finish off the files
|
|
78
|
+
#
|
|
79
|
+
END {
|
|
80
|
+
printf "};\n" > HFILE;
|
|
81
|
+
printf "typedef enum _%s %s;\n", ENVIRON["TAG"], ENVIRON["TAG"] > HFILE;
|
|
82
|
+
printf "extern char*\n" > HFILE;
|
|
83
|
+
printf "get_%s_str(uint16 d);\n", ENVIRON["TAG"] > HFILE;
|
|
84
|
+
printf "#endif /* %s */\n", HFILEDEF > HFILE;
|
|
85
|
+
|
|
86
|
+
printf " default:\n" > CFILE;
|
|
87
|
+
printf " str=NULL;\n" > CFILE;
|
|
88
|
+
printf " break;\n" > CFILE;
|
|
89
|
+
printf " }\n" > CFILE;
|
|
90
|
+
printf " if ( str )\n" > CFILE;
|
|
91
|
+
printf " {\n" > CFILE;
|
|
92
|
+
printf " sprintf(buf,\"%%s <%%04x>\",str,d);\n" > CFILE;
|
|
93
|
+
printf " }\n" > CFILE;
|
|
94
|
+
printf " else\n" > CFILE;
|
|
95
|
+
printf " {\n" > CFILE;
|
|
96
|
+
printf " sprintf(buf,\"%%04x\",d);\n" > CFILE;
|
|
97
|
+
printf " }\n" > CFILE;
|
|
98
|
+
printf " return buf;\n" > CFILE;
|
|
99
|
+
printf "}\n" > CFILE;
|
|
100
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* options.c -- functions for dealing with program options
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C)1999-2006 Mark Simpson <damned@theworld.com>
|
|
5
|
+
*
|
|
6
|
+
* This program is free software; you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU General Public License as published by
|
|
8
|
+
* the Free Software Foundation; either version 2, or (at your option)
|
|
9
|
+
* any later version.
|
|
10
|
+
*
|
|
11
|
+
* This program is distributed in the hope that it will be useful,
|
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
* GNU General Public License for more details.
|
|
15
|
+
*
|
|
16
|
+
* You should have received a copy of the GNU General Public License
|
|
17
|
+
* along with this program; if not, you can either send email to this
|
|
18
|
+
* program's maintainer or write to: The Free Software Foundation,
|
|
19
|
+
* Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
#ifdef HAVE_CONFIG_H
|
|
23
|
+
# include "config.h"
|
|
24
|
+
#endif /* HAVE_CONFIG_H */
|
|
25
|
+
|
|
26
|
+
#include "common.h"
|
|
27
|
+
|
|
28
|
+
#include "options.h"
|
|
29
|
+
|
|
30
|
+
/* Global variables, used by all (or nearly all) functions */
|
|
31
|
+
int g_flags = NONE; /* program options */
|
|
32
|
+
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* options.h -- functions for dealing with program options
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C)1999-2006 Mark Simpson <damned@theworld.com>
|
|
5
|
+
*
|
|
6
|
+
* This program is free software; you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU General Public License as published by
|
|
8
|
+
* the Free Software Foundation; either version 2, or (at your option)
|
|
9
|
+
* any later version.
|
|
10
|
+
*
|
|
11
|
+
* This program is distributed in the hope that it will be useful,
|
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
* GNU General Public License for more details.
|
|
15
|
+
*
|
|
16
|
+
* You should have received a copy of the GNU General Public License
|
|
17
|
+
* along with this program; if not, you can either send email to this
|
|
18
|
+
* program's maintainer or write to: The Free Software Foundation,
|
|
19
|
+
* Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
#ifndef OPTIONS_H
|
|
23
|
+
#define OPTIONS_H
|
|
24
|
+
|
|
25
|
+
#if HAVE_CONFIG_H
|
|
26
|
+
# include "config.h"
|
|
27
|
+
#endif /* HAVE_CONFIG_H */
|
|
28
|
+
|
|
29
|
+
#include "common.h"
|
|
30
|
+
|
|
31
|
+
/* Global variables, used by all (or nearly all) functions */
|
|
32
|
+
extern int g_flags; /* program options */
|
|
33
|
+
|
|
34
|
+
/* macros for dealing with program flags */
|
|
35
|
+
#define DEBUG_ON ((g_flags)&DBG_OUT)
|
|
36
|
+
#define VERBOSE_ON ((g_flags)&VERBOSE)
|
|
37
|
+
#define LIST_ONLY ((g_flags)&LIST)
|
|
38
|
+
#define SHOW_MIME ((g_flags)&LISTMIME)
|
|
39
|
+
#define USE_PATHS ((g_flags)&PATHS)
|
|
40
|
+
#define INTERACTIVE ((g_flags)&CONFIRM)
|
|
41
|
+
#define OVERWRITE_FILES ((g_flags)&OVERWRITE)
|
|
42
|
+
#define NUMBER_FILES ((g_flags)&NUMBERED)
|
|
43
|
+
#define CHECKSUM_SKIP ((g_flags)&CHECKSUM_OK)
|
|
44
|
+
#define ENCODE_SKIP ((g_flags)&ENCODE_OK)
|
|
45
|
+
#define CRUFT_SKIP ((g_flags)&CRUFT_OK)
|
|
46
|
+
#define UNIX_FS ((g_flags)&UNIX_PATHS)
|
|
47
|
+
#define ABSOLUTE_OK ((g_flags)&ABSOLUTE_PATHS)
|
|
48
|
+
|
|
49
|
+
/* flags to modify behaviour of file parsing */
|
|
50
|
+
enum { NONE = 0x00,
|
|
51
|
+
VERBOSE = 0x01,
|
|
52
|
+
DBG_OUT = 0x02,
|
|
53
|
+
LIST = 0x04,
|
|
54
|
+
PATHS = 0x08,
|
|
55
|
+
OVERWRITE= 0x10,
|
|
56
|
+
CONFIRM = 0x20,
|
|
57
|
+
NUMBERED = 0x40,
|
|
58
|
+
SAVEBODY = 0x80,
|
|
59
|
+
LISTMIME = 0x100,
|
|
60
|
+
CHECKSUM_OK = 0x200,
|
|
61
|
+
ENCODE_OK = 0x400,
|
|
62
|
+
CRUFT_OK = 0x800,
|
|
63
|
+
UNIX_PATHS = 0x1000,
|
|
64
|
+
ABSOLUTE_PATHS = 0x2000
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
#endif /* OPTIONS_H */
|
data/ext/tnef/src/path.c
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* path.c -- Utility functions for dealing with pathnames
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C)1999-2006 Mark Simpson <damned@theworld.com>
|
|
5
|
+
*
|
|
6
|
+
* This program is free software; you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU General Public License as published by
|
|
8
|
+
* the Free Software Foundation; either version 2, or (at your option)
|
|
9
|
+
* any later version.
|
|
10
|
+
*
|
|
11
|
+
* This program is distributed in the hope that it will be useful,
|
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
* GNU General Public License for more details.
|
|
15
|
+
*
|
|
16
|
+
* You should have received a copy of the GNU General Public License
|
|
17
|
+
* along with this program; if not, you can either send email to this
|
|
18
|
+
* program's maintainer or write to: The Free Software Foundation,
|
|
19
|
+
* Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
#ifdef HAVE_CONFIG_H
|
|
23
|
+
# include "config.h"
|
|
24
|
+
#endif /* HAVE_CONFIG_H */
|
|
25
|
+
|
|
26
|
+
#include "common.h"
|
|
27
|
+
#include <ctype.h>
|
|
28
|
+
|
|
29
|
+
#if HAVE_SYS_STAT_H
|
|
30
|
+
# include <sys/stat.h>
|
|
31
|
+
#endif
|
|
32
|
+
|
|
33
|
+
#include "alloc.h"
|
|
34
|
+
#include "options.h"
|
|
35
|
+
#include "path.h"
|
|
36
|
+
#include "debug.h"
|
|
37
|
+
|
|
38
|
+
/* concatenates fname1 with fname2 to make a pathname, adds '/' as needed */
|
|
39
|
+
/* strips trailing '/' */
|
|
40
|
+
|
|
41
|
+
char *
|
|
42
|
+
concat_fname (const char *fname1, const char* fname2)
|
|
43
|
+
{
|
|
44
|
+
char *filename;
|
|
45
|
+
int len;
|
|
46
|
+
|
|
47
|
+
if ( ( fname1 == NULL ) && ( fname2 == NULL ) ) return NULL;
|
|
48
|
+
|
|
49
|
+
if ( ( fname1 == NULL ) || ( *fname1 == '\0' ) )
|
|
50
|
+
{
|
|
51
|
+
filename = xstrdup (fname2);
|
|
52
|
+
}
|
|
53
|
+
else
|
|
54
|
+
{
|
|
55
|
+
len = strlen (fname1);
|
|
56
|
+
if (fname2) len += strlen (fname2);
|
|
57
|
+
|
|
58
|
+
filename = CHECKED_XMALLOC (char, (len + 2));
|
|
59
|
+
strcpy (filename, fname1);
|
|
60
|
+
|
|
61
|
+
if (fname2)
|
|
62
|
+
{
|
|
63
|
+
if ((filename[strlen(filename)-1] != '/')
|
|
64
|
+
&& (fname2[0] != '/'))
|
|
65
|
+
{
|
|
66
|
+
strcat (filename, "/");
|
|
67
|
+
}
|
|
68
|
+
strcat (filename, fname2);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/* strip trailing '/' */
|
|
73
|
+
|
|
74
|
+
while ((len=strlen(filename)) > 0)
|
|
75
|
+
{
|
|
76
|
+
if ( filename[len-1] == '/' )
|
|
77
|
+
{
|
|
78
|
+
filename[len-1] = '\0';
|
|
79
|
+
}
|
|
80
|
+
else
|
|
81
|
+
{
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if ( *filename == '\0' ) filename = NULL; /* nothing left */
|
|
87
|
+
|
|
88
|
+
return filename;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
int
|
|
92
|
+
file_exists (const char *fname)
|
|
93
|
+
{
|
|
94
|
+
static struct stat buf;
|
|
95
|
+
return (stat (fname, &buf) == 0);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* finds a filename fname.N where N >= 1 and is not the name of an existing
|
|
99
|
+
filename. Assumes that fname does not already have such an extension */
|
|
100
|
+
char *
|
|
101
|
+
find_free_number (const char *fname)
|
|
102
|
+
{
|
|
103
|
+
size_t len = (strlen(fname)
|
|
104
|
+
+ 1 /* '.' */
|
|
105
|
+
+ 5 /* big enough for our purposes (i hope) */
|
|
106
|
+
+ 1); /* NULL */
|
|
107
|
+
char *tmp = CHECKED_XMALLOC (char, len);
|
|
108
|
+
int counter = 1;
|
|
109
|
+
do
|
|
110
|
+
{
|
|
111
|
+
sprintf (tmp, "%s.%d", fname, counter++);
|
|
112
|
+
}
|
|
113
|
+
while (file_exists(tmp));
|
|
114
|
+
return tmp;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/* windows pathname manipulation routines */
|
|
118
|
+
|
|
119
|
+
/* per windows file manager, these aren't allowed in filenames */
|
|
120
|
+
|
|
121
|
+
static char unsanitary_windows_chars[] = {
|
|
122
|
+
'\\', '/', ':', '*', '?', '"', '<', '>', '|', '\0'
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/* these aren't welcomed in unix filenames */
|
|
126
|
+
|
|
127
|
+
static char unsavory_unix_chars[] = {
|
|
128
|
+
' ', ';', '`', '\'', '[', ']', '{', '}', '(', ')', '\0'
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
static int
|
|
132
|
+
could_be_a_windows_path( const char *fname )
|
|
133
|
+
{
|
|
134
|
+
const char *up;
|
|
135
|
+
|
|
136
|
+
if ( ( fname == NULL ) || ( *fname == '\0' ) ) return 0;
|
|
137
|
+
|
|
138
|
+
/*
|
|
139
|
+
we might be a windows path if...
|
|
140
|
+
we have at least one path separator and
|
|
141
|
+
we have no unsanitary windows chars and
|
|
142
|
+
we are reasonably printable
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
up = rindex( fname, '\\' );
|
|
146
|
+
|
|
147
|
+
if ( up )
|
|
148
|
+
{
|
|
149
|
+
up++;
|
|
150
|
+
if ( *up == '\0' ) return 0; /* trailing backslash doesn't cut it */
|
|
151
|
+
}
|
|
152
|
+
else
|
|
153
|
+
{
|
|
154
|
+
return 0; /* no backslash */
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
for ( up=unsanitary_windows_chars; *up; up++ )
|
|
158
|
+
{
|
|
159
|
+
if ( *up == '\\' ) continue; /* ignore backslashes */
|
|
160
|
+
|
|
161
|
+
if ( index( fname, (int)*up ) )
|
|
162
|
+
{
|
|
163
|
+
return 0; /* found something we can't stomach */
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
for ( up=fname; *up; up++ )
|
|
168
|
+
{
|
|
169
|
+
if ( iscntrl( (int)*up ) )
|
|
170
|
+
{
|
|
171
|
+
return 0; /* found something we can't see */
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/* found nothing to the contrary, so we might just be a path */
|
|
176
|
+
|
|
177
|
+
if (DEBUG_ON) debug_print( "!!windows path possible: %s\n", fname );
|
|
178
|
+
|
|
179
|
+
return 1;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
static unsigned char hex_digits[16] = {
|
|
183
|
+
'0', '1', '2', '3', '4', '5', '6', '7',
|
|
184
|
+
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
#define SLOP 4 /* a minimum rational buffer size */
|
|
188
|
+
|
|
189
|
+
static char *
|
|
190
|
+
sanitize_filename( const char *fname )
|
|
191
|
+
{
|
|
192
|
+
char *buf, *bp;
|
|
193
|
+
const char *cp, *up;
|
|
194
|
+
int flag, stet;
|
|
195
|
+
|
|
196
|
+
if ( ( fname == NULL ) || ( *fname == '\0' ) )
|
|
197
|
+
{
|
|
198
|
+
/* nothing to see here -- return small, zeroed buffer */
|
|
199
|
+
buf = CHECKED_XCALLOC( char, SLOP );
|
|
200
|
+
return buf;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/*
|
|
204
|
+
sanitize the filename by modifying unsanitary or unsavory
|
|
205
|
+
characters using the URL escape technique of c => %XX
|
|
206
|
+
return a "fresh and freeable" buffer with the sanitary filename
|
|
207
|
+
*/
|
|
208
|
+
|
|
209
|
+
buf = CHECKED_XCALLOC( char, 3*strlen(fname)+SLOP );
|
|
210
|
+
bp = buf;
|
|
211
|
+
|
|
212
|
+
for ( cp=fname; *cp; cp++ )
|
|
213
|
+
{
|
|
214
|
+
flag = 0;
|
|
215
|
+
|
|
216
|
+
while (1)
|
|
217
|
+
{
|
|
218
|
+
/* control chars */
|
|
219
|
+
|
|
220
|
+
if ( iscntrl( (int)*cp ) )
|
|
221
|
+
{
|
|
222
|
+
stet = 0;
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/* unsanitary windows chars */
|
|
227
|
+
|
|
228
|
+
for ( up=unsanitary_windows_chars; *up; up++ )
|
|
229
|
+
{
|
|
230
|
+
if ( *cp == *up )
|
|
231
|
+
{
|
|
232
|
+
flag = 1;
|
|
233
|
+
stet = 0;
|
|
234
|
+
break; /* for loop... */
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if ( flag ) break; /* while loop... */
|
|
239
|
+
|
|
240
|
+
if ( UNIX_FS )
|
|
241
|
+
{
|
|
242
|
+
/* non-ascii chars */
|
|
243
|
+
|
|
244
|
+
if ( !isascii( (int)*cp ) )
|
|
245
|
+
{
|
|
246
|
+
stet = 0;
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/* unsavory unix chars */
|
|
251
|
+
|
|
252
|
+
for ( up=unsavory_unix_chars; *up; up++ )
|
|
253
|
+
{
|
|
254
|
+
if ( *cp == *up )
|
|
255
|
+
{
|
|
256
|
+
flag = 1;
|
|
257
|
+
stet = 0;
|
|
258
|
+
break; /* for loop... */
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if ( flag ) break; /* while loop... */
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/* escape the escaper */
|
|
266
|
+
|
|
267
|
+
if ( *cp == '%' )
|
|
268
|
+
{
|
|
269
|
+
stet = 0;
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/* nothing obvious */
|
|
274
|
+
|
|
275
|
+
stet = 1;
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/* handle the char */
|
|
280
|
+
|
|
281
|
+
if ( stet )
|
|
282
|
+
{
|
|
283
|
+
*bp++ = *cp; /* keep it */
|
|
284
|
+
}
|
|
285
|
+
else
|
|
286
|
+
{
|
|
287
|
+
*bp++ = '%'; /* escape it */
|
|
288
|
+
*bp++ = hex_digits[ ((*cp)>>4)&0xf ];
|
|
289
|
+
*bp++ = hex_digits[ (*cp) &0xf ];
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return buf;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/*
|
|
297
|
+
pathname generator
|
|
298
|
+
|
|
299
|
+
takes input filename and "sanitizes" it for filesystem use
|
|
300
|
+
understands windows paths and unixisms
|
|
301
|
+
returns NULL if totally unsavory filename
|
|
302
|
+
returns (freeable) pointer to sanitized filename if at all palatable
|
|
303
|
+
*/
|
|
304
|
+
|
|
305
|
+
char *
|
|
306
|
+
munge_fname( const char *fname )
|
|
307
|
+
{
|
|
308
|
+
char *dir, *base, *p, *fpd, *fpb;
|
|
309
|
+
|
|
310
|
+
/* If we were not given a filename give up */
|
|
311
|
+
if (!fname || *fname == '\0')
|
|
312
|
+
{
|
|
313
|
+
return NULL;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if ( USE_PATHS )
|
|
317
|
+
{
|
|
318
|
+
/* evaluate windows path potential */
|
|
319
|
+
|
|
320
|
+
if ( could_be_a_windows_path( (char *)fname ) )
|
|
321
|
+
{
|
|
322
|
+
/* split fname after last path separator */
|
|
323
|
+
|
|
324
|
+
dir = strdup( fname ); fpd = dir;
|
|
325
|
+
base = rindex( dir, (int)'\\' );
|
|
326
|
+
base++;
|
|
327
|
+
*base = '\0';
|
|
328
|
+
|
|
329
|
+
base = strdup( fname ); fpb = base;
|
|
330
|
+
base = rindex( base, (int)'\\' );
|
|
331
|
+
base++;
|
|
332
|
+
|
|
333
|
+
/* flip path separators */
|
|
334
|
+
|
|
335
|
+
for ( p=dir; *p; p++ )
|
|
336
|
+
{
|
|
337
|
+
if ( *p == '\\' ) *p = '/';
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/* handle absolute path separators */
|
|
341
|
+
|
|
342
|
+
if ( *dir == '/' )
|
|
343
|
+
{
|
|
344
|
+
if ( ABSOLUTE_OK )
|
|
345
|
+
{
|
|
346
|
+
if (VERBOSE_ON) debug_print( "WARNING: absolute path: %s", fname );
|
|
347
|
+
if (DEBUG_ON) debug_print( "!!absolute path: %s", fname );
|
|
348
|
+
}
|
|
349
|
+
else
|
|
350
|
+
{
|
|
351
|
+
if (VERBOSE_ON) debug_print( "WARNING: absolute path stripped: %s", fname );
|
|
352
|
+
if (DEBUG_ON) debug_print( "!!absolute path stripped: %s", fname );
|
|
353
|
+
|
|
354
|
+
while ( *dir == '/' ) dir++;
|
|
355
|
+
|
|
356
|
+
if ( *dir == '\0' ) dir = NULL; /* nothing left */
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
else
|
|
361
|
+
{
|
|
362
|
+
/* not recognized as a windows path */
|
|
363
|
+
|
|
364
|
+
dir = NULL; fpd = NULL;
|
|
365
|
+
base = strdup( fname ); fpb = base;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
else
|
|
369
|
+
{
|
|
370
|
+
/* no paths allowed */
|
|
371
|
+
|
|
372
|
+
dir = NULL; fpd = NULL;
|
|
373
|
+
base = strdup( fname ); fpb = base;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/* cleanup the basename */
|
|
377
|
+
|
|
378
|
+
base = sanitize_filename( base );
|
|
379
|
+
|
|
380
|
+
/* build a pathname out of the pieces */
|
|
381
|
+
|
|
382
|
+
p = concat_fname( dir, base );
|
|
383
|
+
|
|
384
|
+
/* cleanup and return */
|
|
385
|
+
|
|
386
|
+
XFREE( fpd ); /* free what we may have allocated */
|
|
387
|
+
XFREE( fpb ); /* free what we may have allocated */
|
|
388
|
+
XFREE( base ); /* free what the sanitizer allocated */
|
|
389
|
+
|
|
390
|
+
if ( p && ( *p == '\0' ) )
|
|
391
|
+
{
|
|
392
|
+
XFREE( p ); /* free what we allocated and is no longer required */
|
|
393
|
+
p = NULL;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return p;
|
|
397
|
+
}
|