tnef 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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,107 @@
|
|
1
|
+
/*
|
2
|
+
* alloc.c -- Useful allocation function/defintions
|
3
|
+
*
|
4
|
+
* Copyright (C)1999-2006 Mark Simpson <damned@world.std.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 "alloc.h"
|
28
|
+
|
29
|
+
static size_t alloc_limit = 0;
|
30
|
+
|
31
|
+
void
|
32
|
+
set_alloc_limit (size_t size)
|
33
|
+
{
|
34
|
+
alloc_limit = size;
|
35
|
+
}
|
36
|
+
|
37
|
+
size_t
|
38
|
+
get_alloc_limit()
|
39
|
+
{
|
40
|
+
return alloc_limit;
|
41
|
+
}
|
42
|
+
|
43
|
+
static void
|
44
|
+
alloc_limit_failure (char *fn_name, size_t size)
|
45
|
+
{
|
46
|
+
fprintf (stderr,
|
47
|
+
"%s: Maximum allocation size exceeded "
|
48
|
+
"(maxsize = %lu; size = %lu).\n",
|
49
|
+
fn_name,
|
50
|
+
(unsigned long)alloc_limit,
|
51
|
+
(unsigned long)size);
|
52
|
+
}
|
53
|
+
|
54
|
+
void
|
55
|
+
alloc_limit_assert (char *fn_name, size_t size)
|
56
|
+
{
|
57
|
+
if (alloc_limit && size > alloc_limit)
|
58
|
+
{
|
59
|
+
alloc_limit_failure (fn_name, size);
|
60
|
+
exit (-1);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
/* attempts to malloc memory, if fails print error and call abort */
|
65
|
+
void*
|
66
|
+
xmalloc (size_t size)
|
67
|
+
{
|
68
|
+
void *ptr = malloc (size);
|
69
|
+
if (!ptr
|
70
|
+
&& (size != 0)) /* some libc don't like size == 0 */
|
71
|
+
{
|
72
|
+
perror ("xmalloc: Memory allocation failure");
|
73
|
+
abort();
|
74
|
+
}
|
75
|
+
return ptr;
|
76
|
+
}
|
77
|
+
|
78
|
+
/* Allocates memory but only up to a limit */
|
79
|
+
void*
|
80
|
+
checked_xmalloc (size_t size)
|
81
|
+
{
|
82
|
+
alloc_limit_assert ("checked_xmalloc", size);
|
83
|
+
return xmalloc (size);
|
84
|
+
}
|
85
|
+
|
86
|
+
/* xmallocs memory and clears it out */
|
87
|
+
void*
|
88
|
+
xcalloc (size_t num, size_t size)
|
89
|
+
{
|
90
|
+
void *ptr = malloc(num * size);
|
91
|
+
if (ptr)
|
92
|
+
{
|
93
|
+
memset (ptr, '\0', (num * size));
|
94
|
+
}
|
95
|
+
return ptr;
|
96
|
+
}
|
97
|
+
|
98
|
+
/* xcallocs memory but only up to a limit */
|
99
|
+
void*
|
100
|
+
checked_xcalloc (size_t num, size_t size)
|
101
|
+
{
|
102
|
+
alloc_limit_assert ("checked_xcalloc", (num *size));
|
103
|
+
return xcalloc (num, size);
|
104
|
+
}
|
105
|
+
|
106
|
+
|
107
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
/*
|
2
|
+
* alloc.h -- Useful allocation function/defintions
|
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 ALLOC_H
|
23
|
+
#define ALLOC_H
|
24
|
+
|
25
|
+
#if HAVE_CONFIG_H
|
26
|
+
# include "config.h"
|
27
|
+
#endif /* HAVE_CONFIG_H */
|
28
|
+
|
29
|
+
#include "common.h"
|
30
|
+
|
31
|
+
#if !STDC_HEADERS
|
32
|
+
extern void free (void*);
|
33
|
+
#endif /* STDC_HEADERS */
|
34
|
+
|
35
|
+
extern void set_alloc_limit (size_t size);
|
36
|
+
extern size_t get_alloc_limit();
|
37
|
+
extern void alloc_limit_assert (char *fn_name, size_t size);
|
38
|
+
extern void* checked_xmalloc (size_t size);
|
39
|
+
extern void* xmalloc (size_t size);
|
40
|
+
extern void* checked_xcalloc (size_t num, size_t size);
|
41
|
+
extern void* xcalloc (size_t num, size_t size);
|
42
|
+
|
43
|
+
#define XMALLOC(_type,_num) \
|
44
|
+
((_type*)xmalloc((_num)*sizeof(_type)))
|
45
|
+
#define XCALLOC(_type,_num) \
|
46
|
+
((_type*)xcalloc((_num), sizeof (_type)))
|
47
|
+
#define CHECKED_XMALLOC(_type,_num) \
|
48
|
+
((_type*)checked_xmalloc((_num)*sizeof(_type)))
|
49
|
+
#define CHECKED_XCALLOC(_type,_num) \
|
50
|
+
((_type*)checked_xcalloc((_num),sizeof(_type)))
|
51
|
+
#define XFREE(_ptr) \
|
52
|
+
do { if (_ptr) { free (_ptr); _ptr = 0; } } while (0)
|
53
|
+
|
54
|
+
#endif /* ALLOC_H */
|
data/ext/tnef/src/attr.c
ADDED
@@ -0,0 +1,270 @@
|
|
1
|
+
/*
|
2
|
+
* attr.h -- Functions for handling tnef attributes
|
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 "alloc.h"
|
29
|
+
#include "attr.h"
|
30
|
+
#include "tnef_types.h"
|
31
|
+
#include "tnef_names.h"
|
32
|
+
#include "date.h"
|
33
|
+
#include "options.h"
|
34
|
+
#include "util.h"
|
35
|
+
#include "write.h"
|
36
|
+
#include "debug.h"
|
37
|
+
|
38
|
+
/* Copy the date data from the attribute into a struct date */
|
39
|
+
void
|
40
|
+
copy_date_from_attr (Attr* attr, struct date* dt)
|
41
|
+
{
|
42
|
+
assert (attr);
|
43
|
+
assert (dt);
|
44
|
+
assert (attr->type == szDATE);
|
45
|
+
assert (attr->len >= 14);
|
46
|
+
|
47
|
+
date_read (dt, attr->buf);
|
48
|
+
}
|
49
|
+
|
50
|
+
void
|
51
|
+
copy_triple_from_attr (Attr* attr, TRIPLE *t)
|
52
|
+
{
|
53
|
+
assert (attr);
|
54
|
+
assert (t);
|
55
|
+
assert (attr->type == szTRIPLES);
|
56
|
+
|
57
|
+
t->trp.id = GETINT16 (attr->buf);
|
58
|
+
t->trp.chbgtrp = GETINT16 (attr->buf+2);
|
59
|
+
t->trp.cch = GETINT16 (attr->buf+4);
|
60
|
+
t->trp.cb = GETINT16 (attr->buf+6);
|
61
|
+
t->sender_display_name = (char*)(attr->buf+8);
|
62
|
+
t->sender_address = (char*)(attr->buf+8+t->trp.cch);
|
63
|
+
}
|
64
|
+
|
65
|
+
/* attr_dump
|
66
|
+
print attr to stdout. Assumes that the Debug flag has been set and
|
67
|
+
already checked */
|
68
|
+
void
|
69
|
+
attr_dump (Attr* attr)
|
70
|
+
{
|
71
|
+
char *name = get_tnef_name_str (attr->name);
|
72
|
+
char *type = get_tnef_type_str (attr->type);
|
73
|
+
size_t i;
|
74
|
+
|
75
|
+
fprintf (stdout, "(%s) %s [type: %s] [len: %lu] =",
|
76
|
+
((attr->lvl_type == LVL_MESSAGE) ? "MESS" : "ATTA"),
|
77
|
+
name, type, (unsigned long)attr->len);
|
78
|
+
|
79
|
+
switch (attr->type)
|
80
|
+
{
|
81
|
+
case szBYTE:
|
82
|
+
for (i=0; i < attr->len; i++)
|
83
|
+
{
|
84
|
+
fputc (' ', stdout);
|
85
|
+
write_byte(stdout, (uint8)attr->buf[i]);
|
86
|
+
}
|
87
|
+
break;
|
88
|
+
|
89
|
+
case szSHORT:
|
90
|
+
if (attr->len < sizeof(uint16))
|
91
|
+
{
|
92
|
+
fprintf (stdout, "Not enough data for szSHORT");
|
93
|
+
abort();
|
94
|
+
}
|
95
|
+
fputc (' ', stdout);
|
96
|
+
write_uint16 (stdout, GETINT16(attr->buf));
|
97
|
+
if (attr->len > sizeof(uint16))
|
98
|
+
{
|
99
|
+
fprintf (stdout, " [extra data:");
|
100
|
+
for (i = sizeof(uint16); i < attr->len; i++)
|
101
|
+
{
|
102
|
+
fputc (' ', stdout);
|
103
|
+
write_uint8 (stdout, (uint8)attr->buf[i]);
|
104
|
+
}
|
105
|
+
fprintf (stdout, " ]");
|
106
|
+
}
|
107
|
+
break;
|
108
|
+
|
109
|
+
case szLONG:
|
110
|
+
if (attr->len < sizeof(uint32))
|
111
|
+
{
|
112
|
+
fprintf (stdout, "Not enough data for szLONG");
|
113
|
+
abort();
|
114
|
+
}
|
115
|
+
fputc (' ', stdout);
|
116
|
+
write_uint32 (stdout, GETINT32(attr->buf));
|
117
|
+
if (attr->len > sizeof(uint32))
|
118
|
+
{
|
119
|
+
fprintf (stdout, " [extra data:");
|
120
|
+
for (i = sizeof(uint32); i < attr->len; i++)
|
121
|
+
{
|
122
|
+
fputc (' ', stdout);
|
123
|
+
write_uint8 (stdout, (uint8)attr->buf[i]);
|
124
|
+
}
|
125
|
+
fprintf (stdout, " ]");
|
126
|
+
}
|
127
|
+
break;
|
128
|
+
|
129
|
+
|
130
|
+
case szWORD:
|
131
|
+
for (i=0; i < attr->len; i+=2)
|
132
|
+
{
|
133
|
+
fputc (' ', stdout);
|
134
|
+
write_word(stdout, GETINT16(attr->buf+i));
|
135
|
+
}
|
136
|
+
break;
|
137
|
+
|
138
|
+
case szDWORD:
|
139
|
+
for (i=0; i < attr->len; i+=4)
|
140
|
+
{
|
141
|
+
fputc (' ', stdout);
|
142
|
+
write_dword (stdout, GETINT32(attr->buf+i));
|
143
|
+
}
|
144
|
+
break;
|
145
|
+
|
146
|
+
case szDATE:
|
147
|
+
{
|
148
|
+
struct date dt;
|
149
|
+
copy_date_from_attr (attr, &dt);
|
150
|
+
fputc (' ', stdout);
|
151
|
+
write_date (stdout, &dt);
|
152
|
+
}
|
153
|
+
break;
|
154
|
+
|
155
|
+
case szTEXT:
|
156
|
+
case szSTRING:
|
157
|
+
{
|
158
|
+
char* buf = CHECKED_XMALLOC (char, (attr->len + 1));
|
159
|
+
strncpy (buf, (char*)attr->buf, attr->len);
|
160
|
+
buf[attr->len] = '\0';
|
161
|
+
write_string (stdout, buf);
|
162
|
+
XFREE (buf);
|
163
|
+
}
|
164
|
+
break;
|
165
|
+
|
166
|
+
case szTRIPLES:
|
167
|
+
{
|
168
|
+
TRIPLE triple;
|
169
|
+
copy_triple_from_attr (attr, &triple);
|
170
|
+
write_triple (stdout, &triple);
|
171
|
+
}
|
172
|
+
break;
|
173
|
+
|
174
|
+
default:
|
175
|
+
fprintf (stdout, "<unknown type>");
|
176
|
+
break;
|
177
|
+
}
|
178
|
+
fprintf (stdout, "\n");
|
179
|
+
fflush( NULL );
|
180
|
+
}
|
181
|
+
|
182
|
+
void
|
183
|
+
attr_free (Attr* attr)
|
184
|
+
{
|
185
|
+
if (attr)
|
186
|
+
{
|
187
|
+
XFREE (attr->buf);
|
188
|
+
memset (attr, '\0', sizeof (Attr));
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
|
193
|
+
/* Validate the checksum against attr. The checksum is the sum of all the
|
194
|
+
bytes in the attribute data modulo 65536 */
|
195
|
+
static int
|
196
|
+
check_checksum (Attr* attr, uint16 checksum)
|
197
|
+
{
|
198
|
+
size_t i;
|
199
|
+
uint32 sum = 0;
|
200
|
+
|
201
|
+
for (i = 0; i < attr->len; i++)
|
202
|
+
{
|
203
|
+
sum = ( sum + (uint8)attr->buf[i] ) & 0xffff;
|
204
|
+
}
|
205
|
+
|
206
|
+
if (DEBUG_ON)
|
207
|
+
{
|
208
|
+
if ( sum != checksum )
|
209
|
+
{
|
210
|
+
/* for grins, figure out if it *ever* matched */
|
211
|
+
|
212
|
+
int match = -1;
|
213
|
+
uint32 mysum = 0;
|
214
|
+
|
215
|
+
for ( i=0; i < attr->len; i++ )
|
216
|
+
{
|
217
|
+
mysum = ( mysum + (uint8)attr->buf[i] ) & 0xffff;
|
218
|
+
|
219
|
+
if ( mysum == checksum ) match = i;
|
220
|
+
}
|
221
|
+
|
222
|
+
debug_print( "!!checksum error: length=%d sum=%04x checksum=%04x match=%d\n", attr->len, mysum, checksum, match );
|
223
|
+
}
|
224
|
+
}
|
225
|
+
|
226
|
+
return (sum == checksum);
|
227
|
+
}
|
228
|
+
|
229
|
+
Attr*
|
230
|
+
attr_read (FILE* in)
|
231
|
+
{
|
232
|
+
uint32 type_and_name;
|
233
|
+
uint16 checksum;
|
234
|
+
|
235
|
+
Attr *attr = CHECKED_XCALLOC (Attr, 1);
|
236
|
+
|
237
|
+
attr->lvl_type = geti8(in);
|
238
|
+
|
239
|
+
assert ((attr->lvl_type == LVL_MESSAGE)
|
240
|
+
|| (attr->lvl_type == LVL_ATTACHMENT));
|
241
|
+
|
242
|
+
type_and_name = geti32(in);
|
243
|
+
|
244
|
+
attr->type = (type_and_name >> 16);
|
245
|
+
attr->name = ((type_and_name << 16) >> 16);
|
246
|
+
attr->len = geti32(in);
|
247
|
+
attr->buf = CHECKED_XCALLOC (unsigned char, attr->len);
|
248
|
+
|
249
|
+
(void)getbuf(in, attr->buf, attr->len);
|
250
|
+
|
251
|
+
checksum = geti16(in);
|
252
|
+
if (!check_checksum(attr, checksum))
|
253
|
+
{
|
254
|
+
if ( CHECKSUM_SKIP )
|
255
|
+
{
|
256
|
+
fprintf (stderr,
|
257
|
+
"WARNING: invalid checksum, input file may be corrupted\n");
|
258
|
+
}
|
259
|
+
else
|
260
|
+
{
|
261
|
+
fprintf (stderr,
|
262
|
+
"ERROR: invalid checksum, input file may be corrupted\n");
|
263
|
+
exit( 1 );
|
264
|
+
}
|
265
|
+
}
|
266
|
+
|
267
|
+
if (DEBUG_ON) attr_dump (attr);
|
268
|
+
|
269
|
+
return attr;
|
270
|
+
}
|
data/ext/tnef/src/attr.h
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
/*
|
2
|
+
* attr.h -- Functions for handling tnef attributes
|
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 ATTR_H
|
23
|
+
#define ATTR_H
|
24
|
+
|
25
|
+
#if HAVE_CONFIG_H
|
26
|
+
# include "config.h"
|
27
|
+
#endif /* HAVE_CONFIG_H */
|
28
|
+
|
29
|
+
#include "common.h"
|
30
|
+
#include "date.h"
|
31
|
+
#include "tnef_types.h"
|
32
|
+
#include "tnef_names.h"
|
33
|
+
|
34
|
+
#define MINIMUM_ATTR_LENGTH 8
|
35
|
+
|
36
|
+
/* Object types */
|
37
|
+
enum _lvl_type
|
38
|
+
{
|
39
|
+
LVL_MESSAGE = 0x1,
|
40
|
+
LVL_ATTACHMENT = 0x2,
|
41
|
+
};
|
42
|
+
typedef enum _lvl_type level_type;
|
43
|
+
|
44
|
+
/* Attr -- storing a structure, formated according to file specification */
|
45
|
+
typedef struct
|
46
|
+
{
|
47
|
+
level_type lvl_type;
|
48
|
+
tnef_type type;
|
49
|
+
tnef_name name;
|
50
|
+
size_t len;
|
51
|
+
unsigned char* buf;
|
52
|
+
} Attr;
|
53
|
+
|
54
|
+
typedef struct
|
55
|
+
{
|
56
|
+
uint16 id;
|
57
|
+
uint16 chbgtrp;
|
58
|
+
uint16 cch;
|
59
|
+
uint16 cb;
|
60
|
+
} TRP;
|
61
|
+
|
62
|
+
typedef struct
|
63
|
+
{
|
64
|
+
TRP trp;
|
65
|
+
char* sender_display_name;
|
66
|
+
char* sender_address;
|
67
|
+
} TRIPLE;
|
68
|
+
|
69
|
+
extern void attr_dump (Attr* attr);
|
70
|
+
extern void attr_free (Attr* attr);
|
71
|
+
extern void copy_date_from_attr (Attr* attr, struct date* dt);
|
72
|
+
extern Attr* attr_read ();
|
73
|
+
|
74
|
+
#endif /* ATTR_H */
|