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.
Files changed (197) hide show
  1. data/ext/tnef/AUTHORS +7 -0
  2. data/ext/tnef/BUGS.in +5 -0
  3. data/ext/tnef/COPYING +340 -0
  4. data/ext/tnef/ChangeLog +1550 -0
  5. data/ext/tnef/INSTALL +234 -0
  6. data/ext/tnef/Makefile.am +7 -0
  7. data/ext/tnef/Makefile.in +699 -0
  8. data/ext/tnef/NEWS +177 -0
  9. data/ext/tnef/README +39 -0
  10. data/ext/tnef/THANKS +1 -0
  11. data/ext/tnef/TODO +7 -0
  12. data/ext/tnef/acinclude.m4 +47 -0
  13. data/ext/tnef/aclocal.m4 +1012 -0
  14. data/ext/tnef/configure +6815 -0
  15. data/ext/tnef/configure.in +67 -0
  16. data/ext/tnef/depcomp +584 -0
  17. data/ext/tnef/doc/FAQ +25 -0
  18. data/ext/tnef/doc/Makefile.am +6 -0
  19. data/ext/tnef/doc/Makefile.in +623 -0
  20. data/ext/tnef/doc/file-format.tex +139 -0
  21. data/ext/tnef/doc/tnef.1.in +183 -0
  22. data/ext/tnef/doc/www/Makefile.am +14 -0
  23. data/ext/tnef/doc/www/Makefile.in +542 -0
  24. data/ext/tnef/doc/www/cgi-bin/Makefile.am +14 -0
  25. data/ext/tnef/doc/www/cgi-bin/Makefile.in +340 -0
  26. data/ext/tnef/doc/www/htdocs/Makefile.am +14 -0
  27. data/ext/tnef/doc/www/htdocs/Makefile.in +340 -0
  28. data/ext/tnef/extconf.rb +3 -0
  29. data/ext/tnef/install-sh +507 -0
  30. data/ext/tnef/missing +367 -0
  31. data/ext/tnef/mkinstalldirs +161 -0
  32. data/ext/tnef/src/Makefile.am +48 -0
  33. data/ext/tnef/src/Makefile.in +700 -0
  34. data/ext/tnef/src/alloc.c +107 -0
  35. data/ext/tnef/src/alloc.h +54 -0
  36. data/ext/tnef/src/attr.c +270 -0
  37. data/ext/tnef/src/attr.h +74 -0
  38. data/ext/tnef/src/common.h +101 -0
  39. data/ext/tnef/src/config.h.in +111 -0
  40. data/ext/tnef/src/date.c +66 -0
  41. data/ext/tnef/src/date.h +43 -0
  42. data/ext/tnef/src/debug.c +45 -0
  43. data/ext/tnef/src/debug.h +32 -0
  44. data/ext/tnef/src/file.c +259 -0
  45. data/ext/tnef/src/file.h +48 -0
  46. data/ext/tnef/src/main.c +386 -0
  47. data/ext/tnef/src/mapi-names.data +430 -0
  48. data/ext/tnef/src/mapi-types.data +19 -0
  49. data/ext/tnef/src/mapi_attr.c +419 -0
  50. data/ext/tnef/src/mapi_attr.h +78 -0
  51. data/ext/tnef/src/mkdata.awk +100 -0
  52. data/ext/tnef/src/options.c +32 -0
  53. data/ext/tnef/src/options.h +67 -0
  54. data/ext/tnef/src/path.c +397 -0
  55. data/ext/tnef/src/path.h +34 -0
  56. data/ext/tnef/src/replace/Makefile.am +8 -0
  57. data/ext/tnef/src/replace/Makefile.in +435 -0
  58. data/ext/tnef/src/replace/basename.c +45 -0
  59. data/ext/tnef/src/replace/dummy.c +7 -0
  60. data/ext/tnef/src/replace/getopt_long.c +940 -0
  61. data/ext/tnef/src/replace/getopt_long.h +141 -0
  62. data/ext/tnef/src/replace/malloc.c +41 -0
  63. data/ext/tnef/src/replace/strdup.c +51 -0
  64. data/ext/tnef/src/rtf.c +362 -0
  65. data/ext/tnef/src/rtf.h +36 -0
  66. data/ext/tnef/src/tnef-names.data +34 -0
  67. data/ext/tnef/src/tnef-types.data +12 -0
  68. data/ext/tnef/src/tnef.c +396 -0
  69. data/ext/tnef/src/tnef.h +45 -0
  70. data/ext/tnef/src/util.c +112 -0
  71. data/ext/tnef/src/util.h +42 -0
  72. data/ext/tnef/src/write.c +136 -0
  73. data/ext/tnef/src/write.h +25 -0
  74. data/ext/tnef/src/xstrdup.c +41 -0
  75. data/ext/tnef/tests/Makefile.am +4 -0
  76. data/ext/tnef/tests/Makefile.in +530 -0
  77. data/ext/tnef/tests/cmdline/AUTHORS +8 -0
  78. data/ext/tnef/tests/cmdline/AUTHORS.baseline +8 -0
  79. data/ext/tnef/tests/cmdline/Makefile.am +33 -0
  80. data/ext/tnef/tests/cmdline/Makefile.in +455 -0
  81. data/ext/tnef/tests/cmdline/basic.baseline +4 -0
  82. data/ext/tnef/tests/cmdline/basic.test +39 -0
  83. data/ext/tnef/tests/cmdline/body-test.html.baseline +95 -0
  84. data/ext/tnef/tests/cmdline/body.baseline +929 -0
  85. data/ext/tnef/tests/cmdline/body.test +55 -0
  86. data/ext/tnef/tests/cmdline/debug.baseline +155 -0
  87. data/ext/tnef/tests/cmdline/debug.test +14 -0
  88. data/ext/tnef/tests/cmdline/directory.baseline +3 -0
  89. data/ext/tnef/tests/cmdline/directory.test +35 -0
  90. data/ext/tnef/tests/cmdline/help.baseline +63 -0
  91. data/ext/tnef/tests/cmdline/help.test +12 -0
  92. data/ext/tnef/tests/cmdline/interactive.test +5 -0
  93. data/ext/tnef/tests/cmdline/list.baseline +5 -0
  94. data/ext/tnef/tests/cmdline/list.test +21 -0
  95. data/ext/tnef/tests/cmdline/maxsize.baseline +828 -0
  96. data/ext/tnef/tests/cmdline/maxsize.test +43 -0
  97. data/ext/tnef/tests/cmdline/message.html.baseline +95 -0
  98. data/ext/tnef/tests/cmdline/mime-types.baseline +3 -0
  99. data/ext/tnef/tests/cmdline/mime-types.test +11 -0
  100. data/ext/tnef/tests/cmdline/overwrite.baseline +8 -0
  101. data/ext/tnef/tests/cmdline/overwrite.test +40 -0
  102. data/ext/tnef/tests/cmdline/rtf-test.rtf.baseline +0 -0
  103. data/ext/tnef/tests/cmdline/stdin.baseline +2 -0
  104. data/ext/tnef/tests/cmdline/stdin.test +18 -0
  105. data/ext/tnef/tests/cmdline/test.tnef +0 -0
  106. data/ext/tnef/tests/cmdline/triples-test-2.rtf.baseline +0 -0
  107. data/ext/tnef/tests/cmdline/triples-test-2.txt.baseline +0 -0
  108. data/ext/tnef/tests/cmdline/triples-test.txt.baseline +0 -0
  109. data/ext/tnef/tests/cmdline/use-path.baseline +0 -0
  110. data/ext/tnef/tests/cmdline/use-path.test +5 -0
  111. data/ext/tnef/tests/cmdline/verbose.baseline +5 -0
  112. data/ext/tnef/tests/cmdline/verbose.test +19 -0
  113. data/ext/tnef/tests/cmdline/version.baseline +17 -0
  114. data/ext/tnef/tests/cmdline/version.test +14 -0
  115. data/ext/tnef/tests/files/MAPI_ATTACH_DATA_OBJ.test +9 -0
  116. data/ext/tnef/tests/files/MAPI_OBJECT.test +9 -0
  117. data/ext/tnef/tests/files/Makefile.am +16 -0
  118. data/ext/tnef/tests/files/Makefile.in +636 -0
  119. data/ext/tnef/tests/files/baselines/AUTHORS.baseline +8 -0
  120. data/ext/tnef/tests/files/baselines/AUTOEXEC.BAT.baseline +0 -0
  121. data/ext/tnef/tests/files/baselines/CONFIG.SYS.baseline +0 -0
  122. data/ext/tnef/tests/files/baselines/MAPI_ATTACH_DATA_OBJ-body.rtf.baseline +0 -0
  123. data/ext/tnef/tests/files/baselines/MAPI_ATTACH_DATA_OBJ.baseline +229 -0
  124. data/ext/tnef/tests/files/baselines/MAPI_OBJECT-body.rtf.baseline +0 -0
  125. data/ext/tnef/tests/files/baselines/MAPI_OBJECT.baseline +153 -0
  126. data/ext/tnef/tests/files/baselines/Makefile.am +35 -0
  127. data/ext/tnef/tests/files/baselines/Makefile.in +361 -0
  128. data/ext/tnef/tests/files/baselines/README.baseline +31 -0
  129. data/ext/tnef/tests/files/baselines/TechlibDEC99-JAN00.doc.baseline +0 -0
  130. data/ext/tnef/tests/files/baselines/TechlibDEC99.doc.baseline +0 -0
  131. data/ext/tnef/tests/files/baselines/TechlibNOV99.doc.baseline +0 -0
  132. data/ext/tnef/tests/files/baselines/Untitled_Attachment.baseline +0 -0
  133. data/ext/tnef/tests/files/baselines/VIA_Nytt_1402.doc.baseline +0 -0
  134. data/ext/tnef/tests/files/baselines/VIA_Nytt_1402.pdf.baseline +0 -0
  135. data/ext/tnef/tests/files/baselines/VIA_Nytt_14021.htm.baseline +1914 -0
  136. data/ext/tnef/tests/files/baselines/body-body.html.baseline +95 -0
  137. data/ext/tnef/tests/files/baselines/body.baseline +124 -0
  138. data/ext/tnef/tests/files/baselines/boot.ini.baseline +6 -0
  139. data/ext/tnef/tests/files/baselines/data-before-name-body.rtf.baseline +0 -0
  140. data/ext/tnef/tests/files/baselines/data-before-name.baseline +213 -0
  141. data/ext/tnef/tests/files/baselines/garbage-at-end.baseline +73 -0
  142. data/ext/tnef/tests/files/baselines/generpts.src.baseline +1691 -0
  143. data/ext/tnef/tests/files/baselines/long-filename-body.rtf.baseline +26 -0
  144. data/ext/tnef/tests/files/baselines/long-filename.baseline +218 -0
  145. data/ext/tnef/tests/files/baselines/message.rtf.baseline +0 -0
  146. data/ext/tnef/tests/files/baselines/missing-filenames-body.rtf.baseline +20 -0
  147. data/ext/tnef/tests/files/baselines/missing-filenames.baseline +252 -0
  148. data/ext/tnef/tests/files/baselines/multi-name-property.baseline +243 -0
  149. data/ext/tnef/tests/files/baselines/one-file.baseline +155 -0
  150. data/ext/tnef/tests/files/baselines/rtf-body.rtf.baseline +0 -0
  151. data/ext/tnef/tests/files/baselines/rtf.baseline +167 -0
  152. data/ext/tnef/tests/files/baselines/triples-body.rtf.baseline +0 -0
  153. data/ext/tnef/tests/files/baselines/triples.baseline +254 -0
  154. data/ext/tnef/tests/files/baselines/two-files.baseline +186 -0
  155. data/ext/tnef/tests/files/body.test +9 -0
  156. data/ext/tnef/tests/files/data-before-name.test +9 -0
  157. data/ext/tnef/tests/files/datafiles/MAPI_ATTACH_DATA_OBJ.list +4 -0
  158. data/ext/tnef/tests/files/datafiles/MAPI_ATTACH_DATA_OBJ.tnef +0 -0
  159. data/ext/tnef/tests/files/datafiles/MAPI_OBJECT.list +2 -0
  160. data/ext/tnef/tests/files/datafiles/MAPI_OBJECT.tnef +0 -0
  161. data/ext/tnef/tests/files/datafiles/Makefile.am +27 -0
  162. data/ext/tnef/tests/files/datafiles/Makefile.in +351 -0
  163. data/ext/tnef/tests/files/datafiles/body.list +1 -0
  164. data/ext/tnef/tests/files/datafiles/body.tnef +0 -0
  165. data/ext/tnef/tests/files/datafiles/data-before-name.list +4 -0
  166. data/ext/tnef/tests/files/datafiles/data-before-name.tnef +0 -0
  167. data/ext/tnef/tests/files/datafiles/garbage-at-end.list +0 -0
  168. data/ext/tnef/tests/files/datafiles/garbage-at-end.tnef +0 -0
  169. data/ext/tnef/tests/files/datafiles/long-filename.list +1 -0
  170. data/ext/tnef/tests/files/datafiles/long-filename.tnef +0 -0
  171. data/ext/tnef/tests/files/datafiles/missing-filenames.list +1 -0
  172. data/ext/tnef/tests/files/datafiles/missing-filenames.tnef +0 -0
  173. data/ext/tnef/tests/files/datafiles/multi-name-property.list +0 -0
  174. data/ext/tnef/tests/files/datafiles/multi-name-property.tnef +0 -0
  175. data/ext/tnef/tests/files/datafiles/one-file.list +1 -0
  176. data/ext/tnef/tests/files/datafiles/one-file.tnef +0 -0
  177. data/ext/tnef/tests/files/datafiles/rtf.list +1 -0
  178. data/ext/tnef/tests/files/datafiles/rtf.tnef +0 -0
  179. data/ext/tnef/tests/files/datafiles/triples.list +1 -0
  180. data/ext/tnef/tests/files/datafiles/triples.tnef +0 -0
  181. data/ext/tnef/tests/files/datafiles/two-files.list +2 -0
  182. data/ext/tnef/tests/files/datafiles/two-files.tnef +0 -0
  183. data/ext/tnef/tests/files/file-util.sh +38 -0
  184. data/ext/tnef/tests/files/garbage-at-end.test +9 -0
  185. data/ext/tnef/tests/files/long-filename.test +9 -0
  186. data/ext/tnef/tests/files/missing-filenames.test +9 -0
  187. data/ext/tnef/tests/files/multi-name-property.test +9 -0
  188. data/ext/tnef/tests/files/one-file.test +9 -0
  189. data/ext/tnef/tests/files/rtf.test +9 -0
  190. data/ext/tnef/tests/files/triples.test +9 -0
  191. data/ext/tnef/tests/files/two-files.test +9 -0
  192. data/ext/tnef/tests/util.sh +32 -0
  193. data/ext/tnef/tnef.spec.in +44 -0
  194. data/lib/tnef.rb +30 -0
  195. data/lib/tnef/executable.rb +27 -0
  196. data/lib/tnef/version.rb +3 -0
  197. metadata +243 -0
@@ -0,0 +1,36 @@
1
+ /*
2
+ * rtf.h -- utility functions for dealing with RTF content
3
+ *
4
+ * Copyright (C) 1999-2006 by 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
+ * Commentary:
22
+ *
23
+ */
24
+
25
+ #ifndef RTF_H
26
+ #define RTF_H
27
+
28
+ #if HAVE_CONFIG_H
29
+ # include "config.h"
30
+ #endif /* HAVE_CONFIG_H */
31
+
32
+ #include "mapi_attr.h"
33
+
34
+ extern VarLenData** get_rtf_data (MAPI_Attr *attr);
35
+
36
+ #endif /* RTF_H */
@@ -0,0 +1,34 @@
1
+ # names.data -- data file defining names of all attributes found in TNEF file
2
+ # sym val name
3
+ attOWNER 0x0000 Owner
4
+ attSENTFOR 0x0001 Sent For
5
+ attDELEGATE 0x0002 Delegate
6
+ attDATESTART 0x0006 Date Start
7
+ attDATEEND 0x0007 Date End
8
+ attAIDOWNER 0x0008 Owner Appointment ID
9
+ attREQUESTRES 0x0009 Response Requested.
10
+ attFROM 0x8000 From
11
+ attSUBJECT 0x8004 Subject
12
+ attDATESENT 0x8005 Date Sent
13
+ attDATERECD 0x8006 Date Received
14
+ attMESSAGESTATUS 0x8007 Message Status
15
+ attMESSAGECLASS 0x8008 Message Class
16
+ attMESSAGEID 0x8009 Message ID
17
+ attPARENTID 0x800a Parent ID
18
+ attCONVERSATIONID 0x800b Conversation ID
19
+ attBODY 0x800c Body
20
+ attPRIORITY 0x800d Priority
21
+ attATTACHDATA 0x800f Attachment Data
22
+ attATTACHTITLE 0x8010 Attachment File Name
23
+ attATTACHMETAFILE 0x8011 Attachment Meta File
24
+ attATTACHCREATEDATE 0x8012 Attachment Creation Date
25
+ attATTACHMODIFYDATE 0x8013 Attachment Modification Date
26
+ attDATEMODIFY 0x8020 Date Modified
27
+ attATTACHTRANSPORTFILENAME 0x9001 Attachment Transport Filename
28
+ attATTACHRENDDATA 0x9002 Attachment Rendering Data
29
+ attMAPIPROPS 0x9003 MAPI Properties
30
+ attRECIPTABLE 0x9004 Recipients
31
+ attATTACHMENT 0x9005 Attachment
32
+ attTNEFVERSION 0x9006 TNEF Version
33
+ attOEMCODEPAGE 0x9007 OEM Codepage
34
+ attORIGNINALMESSAGECLASS 0x9008 Original Message Class
@@ -0,0 +1,12 @@
1
+ # types.data -- data file defining all types found in TNEF attachment
2
+ # sym val name
3
+ szTRIPLES 0x0000 triples
4
+ szSTRING 0x0001 string
5
+ szTEXT 0x0002 text
6
+ szDATE 0x0003 date
7
+ szSHORT 0x0004 short
8
+ szLONG 0x0005 long
9
+ szBYTE 0x0006 byte
10
+ szWORD 0x0007 word
11
+ szDWORD 0x0008 dword
12
+ szMAX 0x0009 max
@@ -0,0 +1,396 @@
1
+ /*
2
+ * tnef.c -- extract files from microsoft TNEF format
3
+ *
4
+ * Copyright (C)1999-2006 Mark Simpson <damned@theworld.com>
5
+ * Copyright (C)1997 Thomas Boll <tb@boll.ch> [ORIGINAL AUTHOR]
6
+ *
7
+ * This program is free software; you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation; either version 2, or (at your option)
10
+ * any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU General Public License
18
+ * along with this program; if not, you can either send email to this
19
+ * program's maintainer or write to: The Free Software Foundation,
20
+ * Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
21
+ *
22
+ * Commentary:
23
+ * scans tnef file and extracts all attachments
24
+ * attachments are written to their original file-names if possible
25
+ */
26
+ #ifdef HAVE_CONFIG_H
27
+ #include "config.h"
28
+ #endif /* HAVE_CONFIG_H */
29
+
30
+ #include "common.h"
31
+
32
+ #include "tnef.h"
33
+
34
+ #include "alloc.h"
35
+ #include "attr.h"
36
+ #include "debug.h"
37
+ #include "file.h"
38
+ #include "mapi_attr.h"
39
+ #include "options.h"
40
+ #include "path.h"
41
+ #include "rtf.h"
42
+ #include "util.h"
43
+
44
+ static size_t filesize;
45
+
46
+ typedef struct
47
+ {
48
+ VarLenData **text_body;
49
+ VarLenData **html_bodies;
50
+ VarLenData **rtf_bodies;
51
+ } MessageBody;
52
+
53
+ typedef enum
54
+ {
55
+ TEXT = 't',
56
+ HTML = 'h',
57
+ RTF = 'r'
58
+ } MessageBodyTypes;
59
+
60
+ /* Reads and decodes a object from the stream */
61
+
62
+ static Attr*
63
+ read_object (FILE *in)
64
+ {
65
+ Attr *attr = NULL;
66
+
67
+ /* peek to see if there is more to read from this stream */
68
+ int tmp_char = fgetc(in);
69
+ if (tmp_char == -1) return NULL;
70
+ ungetc(tmp_char, in);
71
+
72
+ attr = attr_read (in);
73
+
74
+ return attr;
75
+ }
76
+
77
+ static File**
78
+ get_body_files (const char* filename,
79
+ const char pref,
80
+ const MessageBody* body)
81
+ {
82
+ File **files = NULL;
83
+ VarLenData **data;
84
+ char *ext = "";
85
+ char *type = "unknown";
86
+ int i;
87
+
88
+ switch (pref)
89
+ {
90
+ case 'r':
91
+ data = body->rtf_bodies;
92
+ ext = ".rtf";
93
+ type = "text/rtf";
94
+ break;
95
+ case 'h':
96
+ data = body->html_bodies;
97
+ ext = ".html";
98
+ type = "text/html";
99
+ break;
100
+ case 't':
101
+ data = body->text_body;
102
+ ext = ".txt";
103
+ type = "text/plain";
104
+ break;
105
+ default:
106
+ data = NULL;
107
+ break;
108
+ }
109
+
110
+ if (data)
111
+ {
112
+ int count = 0;
113
+ char *tmp
114
+ = CHECKED_XCALLOC(char,
115
+ strlen(filename) + strlen(ext) + 1);
116
+ strcpy (tmp, filename);
117
+ strcat (tmp, ext);
118
+
119
+ char *mime = CHECKED_XCALLOC(char, strlen(type) + 1);
120
+ strcpy (mime, type);
121
+
122
+ /* first get a count */
123
+ while (data[count++]);
124
+
125
+ files = (File**)XCALLOC(File*, count + 1);
126
+ for (i = 0; data[i]; i++)
127
+ {
128
+ files[i] = (File*)XCALLOC(File, 1);
129
+ files[i]->name = tmp;
130
+ files[i]->mime_type = mime;
131
+ files[i]->len = data[i]->len;
132
+ files[i]->data
133
+ = CHECKED_XMALLOC(unsigned char, data[i]->len);
134
+ memmove (files[i]->data, data[i]->data, data[i]->len);
135
+ }
136
+ }
137
+ return files;
138
+ }
139
+
140
+ static VarLenData**
141
+ get_text_data (Attr *attr)
142
+ {
143
+ VarLenData **body = XCALLOC(VarLenData*, 2);
144
+
145
+ body[0] = XCALLOC(VarLenData, 1);
146
+ body[0]->len = attr->len;
147
+ body[0]->data = CHECKED_XCALLOC(unsigned char, attr->len);
148
+ memmove (body[0]->data, attr->buf, attr->len);
149
+ return body;
150
+ }
151
+
152
+ static VarLenData**
153
+ get_html_data (MAPI_Attr *a)
154
+ {
155
+ VarLenData **body = XCALLOC(VarLenData*, a->num_values + 1);
156
+
157
+ int j;
158
+ for (j = 0; j < a->num_values; j++)
159
+ {
160
+ body[j] = XMALLOC(VarLenData, 1);
161
+ body[j]->len = a->values[j].len;
162
+ body[j]->data = CHECKED_XCALLOC(unsigned char, a->values[j].len);
163
+ memmove (body[j]->data, a->values[j].data.buf, body[j]->len);
164
+ }
165
+ return body;
166
+ }
167
+
168
+ int
169
+ data_left (FILE* input_file)
170
+ {
171
+ int retval = 1;
172
+
173
+ if (feof(input_file)) retval = 0;
174
+ else if (input_file != stdin)
175
+ {
176
+ /* check if there is enough data left */
177
+ struct stat statbuf;
178
+ size_t pos, data_left;
179
+ fstat (fileno(input_file), &statbuf);
180
+ pos = ftell(input_file);
181
+ data_left = (statbuf.st_size - pos);
182
+
183
+ if (data_left > 0 && data_left < MINIMUM_ATTR_LENGTH)
184
+ {
185
+ if ( CRUFT_SKIP )
186
+ {
187
+ /* look for specific flavor of cruft -- trailing "\r\n" */
188
+
189
+ if ( data_left == 2 )
190
+ {
191
+ int c = fgetc( input_file );
192
+
193
+ if ( c < 0 ) /* this should never happen */
194
+ {
195
+ fprintf( stderr, "ERROR: confused beyond all redemption.\n" );
196
+ exit (1);
197
+ }
198
+
199
+ ungetc( c, input_file );
200
+
201
+ if ( c == 0x0d ) /* test for "\r" part of "\r\n" */
202
+ {
203
+ /* "trust" that next char is 0x0a and ignore this cruft */
204
+
205
+ if ( VERBOSE_ON )
206
+ fprintf( stderr, "WARNING: garbage at end of file (ignored)\n" );
207
+
208
+ if ( DEBUG_ON )
209
+ debug_print( "!!garbage at end of file (ignored)\n" );
210
+ }
211
+ else
212
+ {
213
+ fprintf( stderr, "ERROR: garbage at end of file.\n" );
214
+ }
215
+ }
216
+ else
217
+ {
218
+ fprintf (stderr, "ERROR: garbage at end of file.\n");
219
+ }
220
+ }
221
+ else
222
+ {
223
+ fprintf (stderr, "ERROR: garbage at end of file.\n");
224
+ }
225
+
226
+ retval = 0;
227
+ }
228
+ }
229
+ return retval;
230
+ }
231
+
232
+
233
+ /* The entry point into this module. This parses an entire TNEF file. */
234
+ int
235
+ parse_file (FILE* input_file, char* directory,
236
+ char *body_filename, char *body_pref,
237
+ int flags)
238
+ {
239
+ uint32 d;
240
+ uint16 key;
241
+ Attr *attr = NULL;
242
+ File *file = NULL;
243
+ int rtf_size = 0, html_size = 0;
244
+ MessageBody body;
245
+ memset (&body, '\0', sizeof (MessageBody));
246
+
247
+ /* store the program options in our file global variables */
248
+ g_flags = flags;
249
+
250
+ /* check that this is in fact a TNEF file */
251
+ d = geti32(input_file);
252
+ if (d != TNEF_SIGNATURE)
253
+ {
254
+ fprintf (stdout, "Seems not to be a TNEF file\n");
255
+ return 1;
256
+ }
257
+
258
+ /* Get the key */
259
+ key = geti16(input_file);
260
+ debug_print ("TNEF Key: %hx\n", key);
261
+
262
+ /* The rest of the file is a series of 'messages' and 'attachments' */
263
+ while ( data_left( input_file ) )
264
+ {
265
+ attr = read_object( input_file );
266
+
267
+ if ( attr == NULL ) break;
268
+
269
+ /* This signals the beginning of a file */
270
+ if (attr->name == attATTACHRENDDATA)
271
+ {
272
+ if (file)
273
+ {
274
+ file_write (file, directory);
275
+ file_free (file);
276
+ }
277
+ else
278
+ {
279
+ file = CHECKED_XCALLOC (File, 1);
280
+ }
281
+ }
282
+
283
+ /* Add the data to our lists. */
284
+ switch (attr->lvl_type)
285
+ {
286
+ case LVL_MESSAGE:
287
+ if (attr->name == attBODY)
288
+ {
289
+ body.text_body = get_text_data (attr);
290
+ }
291
+ else if (attr->name == attMAPIPROPS)
292
+ {
293
+ MAPI_Attr **mapi_attrs
294
+ = mapi_attr_read (attr->len, attr->buf);
295
+ if (mapi_attrs)
296
+ {
297
+ int i;
298
+ for (i = 0; mapi_attrs[i]; i++)
299
+ {
300
+ MAPI_Attr *a = mapi_attrs[i];
301
+
302
+ if (a->name == MAPI_BODY_HTML)
303
+ {
304
+ body.html_bodies = get_html_data (a);
305
+ html_size = a->num_values;
306
+ }
307
+ else if (a->name == MAPI_RTF_COMPRESSED)
308
+ {
309
+ body.rtf_bodies = get_rtf_data (a);
310
+ rtf_size = a->num_values;
311
+ }
312
+ }
313
+ /* cannot save attributes to file, since they
314
+ * are not attachment attributes */
315
+ /* file_add_mapi_attrs (file, mapi_attrs); */
316
+ mapi_attr_free_list (mapi_attrs);
317
+ XFREE (mapi_attrs);
318
+ }
319
+ }
320
+ break;
321
+ case LVL_ATTACHMENT:
322
+ file_add_attr (file, attr);
323
+ break;
324
+ default:
325
+ fprintf (stderr, "Invalid lvl type on attribute: %d\n",
326
+ attr->lvl_type);
327
+ return 1;
328
+ break;
329
+ }
330
+ attr_free (attr);
331
+ XFREE (attr);
332
+ }
333
+
334
+ if (file)
335
+ {
336
+ file_write (file, directory);
337
+ file_free (file);
338
+ XFREE (file);
339
+ }
340
+
341
+ /* Write the message body */
342
+ if (flags & SAVEBODY)
343
+ {
344
+ int i = 0;
345
+ int all_flag = 0;
346
+ if (strcmp (body_pref, "all") == 0)
347
+ {
348
+ all_flag = 1;
349
+ body_pref = "rht";
350
+ }
351
+
352
+ for (; i < 3; i++)
353
+ {
354
+ File **files
355
+ = get_body_files (body_filename, body_pref[i], &body);
356
+ if (files)
357
+ {
358
+ int j = 0;
359
+ for (; files[j]; j++)
360
+ {
361
+ file_write(files[j], directory);
362
+ file_free (files[j]);
363
+ XFREE(files[j]);
364
+ }
365
+ XFREE(files);
366
+ if (!all_flag) break;
367
+ }
368
+ }
369
+ }
370
+
371
+ if (body.text_body)
372
+ {
373
+ free_bodies(body.text_body, 1);
374
+ XFREE(body.text_body);
375
+ }
376
+ if (rtf_size > 0)
377
+ {
378
+ free_bodies(body.rtf_bodies, rtf_size);
379
+ XFREE(body.rtf_bodies);
380
+ }
381
+ if (html_size > 0)
382
+ {
383
+ free_bodies(body.html_bodies, html_size);
384
+ XFREE(body.html_bodies);
385
+ }
386
+ return 0;
387
+ }
388
+
389
+ void free_bodies(VarLenData **bodies, int len)
390
+ {
391
+ while (len--)
392
+ {
393
+ XFREE(bodies[len]->data);
394
+ XFREE(bodies[len]);
395
+ }
396
+ }