annotate src/readpst.c @ 20:1acd3231c3a4

switch to automake/autoconf
author carl
date Sun, 19 Feb 2006 20:19:38 -0800
parents c508ee15dfca
children e5418051878c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1 /***
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
2 * readpst.c
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
3 * Part of the LibPST project
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
4 * Written by David Smith
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
5 * dave.s@earthcorp.com
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
6 */
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
7 #include <stdio.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
8 #include <stdlib.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
9 #include <time.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
10 #include <string.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
11 #include <ctype.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
12 #include <limits.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
13 #include <errno.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
14
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
15 #ifndef _WIN32
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
16 # include <unistd.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
17 # include <sys/stat.h> //mkdir
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
18
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
19 // for reading of directory and clearing in function mk_seperate_dir
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
20 # include <sys/types.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
21 # include <dirent.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
22 #else
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
23 # include <direct.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
24 # define chdir _chdir
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
25 # define int32_t __int32
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
26 #endif
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
27
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
28 #ifndef __GNUC__
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
29 # include "XGetopt.h"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
30 #endif
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
31
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
32 #include "libstrfunc.h" // for base64_encoding
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
33
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
34 #include "define.h"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
35 #include "libpst.h"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
36 #include "common.h"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
37 #include "timeconv.h"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
38 #include "lzfu.h"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
39 #define OUTPUT_TEMPLATE "%s"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
40 #define OUTPUT_KMAIL_DIR_TEMPLATE ".%s.directory"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
41 #define KMAIL_INDEX ".%s.index"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
42
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
43 // max size of the c_time char*. It will store the date of the email
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
44 #define C_TIME_SIZE 500
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
45 #define PERM_DIRS 0777
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
46
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
47 // macro used for creating directories
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
48 #ifndef WIN32
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
49 #define D_MKDIR(x) mkdir(x, PERM_DIRS)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
50 #else
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
51 #define D_MKDIR(x) mkdir(x)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
52 #endif
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
53 struct file_ll {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
54 char *name;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
55 char *dname;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
56 FILE * output;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
57 int32_t stored_count;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
58 int32_t email_count;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
59 int32_t skip_count;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
60 int32_t type;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
61 struct file_ll *next;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
62 };
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
63 void write_email_body(FILE *f, char *body);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
64 char *removeCR (char *c);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
65 int32_t usage();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
66 int32_t version();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
67 char *mk_kmail_dir(char*);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
68 int32_t close_kmail_dir();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
69 char *mk_recurse_dir(char*);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
70 int32_t close_recurse_dir();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
71 char *mk_seperate_dir(char *dir, int overwrite);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
72 int32_t close_seperate_dir();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
73 int32_t mk_seperate_file(struct file_ll *f);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
74 char *my_stristr(char *haystack, char *needle);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
75 char *check_filename(char *fname);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
76 char *rfc2426_escape(char *str);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
77 int32_t chr_count(char *str, char x);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
78 char *rfc2425_datetime_format(FILETIME *ft);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
79 char *rfc2445_datetime_format(FILETIME *ft);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
80 char *skip_header_prologue(char *headers);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
81 char *prog_name;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
82 char *output_dir = ".";
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
83 char *kmail_chdir = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
84 // Normal mode just creates mbox format files in the current directory. Each file is named
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
85 // the same as the folder's name that it represents
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
86 #define MODE_NORMAL 0
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
87 // KMail mode creates a directory structure suitable for being used directly
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
88 // by the KMail application
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
89 #define MODE_KMAIL 1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
90 // recurse mode creates a directory structure like the PST file. Each directory
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
91 // contains only one file which stores the emails in mbox format.
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
92 #define MODE_RECURSE 2
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
93 // seperate mode is similar directory structure to RECURSE. The emails are stored in
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
94 // seperate files, numbering from 1 upward. Attachments belonging to the emails are
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
95 // saved as email_no-filename (e.g. 1-samplefile.doc or 000001-Attachment2.zip)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
96 #define MODE_SEPERATE 3
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
97
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
98
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
99 // Output Normal just prints the standard information about what is going on
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
100 #define OUTPUT_NORMAL 0
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
101 // Output Quiet is provided so that only errors are printed
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
102 #define OUTPUT_QUIET 1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
103
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
104 // default mime-type for attachments that have a null mime-type
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
105 #define MIME_TYPE_DEFAULT "application/octet-stream"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
106
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
107
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
108 // output mode for contacts
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
109 #define CMODE_VCARD 0
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
110 #define CMODE_LIST 1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
111
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
112 // output settings for RTF bodies
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
113 // filename for the attachment
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
114 #define RTF_ATTACH_NAME "rtf-body.rtf"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
115 // mime type for the attachment
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
116 #define RTF_ATTACH_TYPE "application/rtf"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
117 int main(int argc, char** argv) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
118 pst_item *item = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
119 pst_file pstfile;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
120 pst_desc_ll *d_ptr;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
121 char * fname = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
122 time_t em_time;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
123 char * c_time, *d_log=NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
124 int c,x;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
125 int mode = MODE_NORMAL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
126 int output_mode = OUTPUT_NORMAL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
127 int contact_mode = CMODE_VCARD;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
128 int overwrite = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
129 int base64_body = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
130 // int encrypt = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
131 FILE *fp;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
132 char *enc; // base64 encoded attachment
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
133 char *boundary = NULL, *b1, *b2; // the boundary marker between multipart sections
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
134 char *temp = NULL; //temporary char pointer
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
135 int attach_num = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
136 int skip_child = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
137 struct file_ll *f, *head;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
138 prog_name = argv[0];
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
139
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
140 while ((c = getopt(argc, argv, "d:hko:qrSVwc:"))!= -1) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
141 switch (c) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
142 case 'c':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
143 if (optarg!=NULL && optarg[0]=='v')
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
144 contact_mode=CMODE_VCARD;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
145 else if (optarg!=NULL && optarg[0]=='l')
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
146 contact_mode=CMODE_LIST;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
147 else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
148 usage();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
149 exit(0);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
150 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
151 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
152 case 'd':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
153 d_log = optarg;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
154 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
155 case 'h':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
156 usage();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
157 exit(0);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
158 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
159 case 'V':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
160 version();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
161 exit(0);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
162 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
163 case 'k':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
164 mode = MODE_KMAIL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
165 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
166 case 'o':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
167 output_dir = optarg;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
168 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
169 case 'q':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
170 output_mode = OUTPUT_QUIET;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
171 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
172 case 'r':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
173 mode = MODE_RECURSE;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
174 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
175 case 'S':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
176 mode = MODE_SEPERATE;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
177 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
178 case 'w':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
179 overwrite = 1;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
180 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
181 default:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
182 usage();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
183 exit(1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
184 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
185 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
186 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
187
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
188 #ifdef DEBUG_ALL
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
189 // initialize log file
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
190 if (d_log == NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
191 d_log = "readpst.log";
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
192 DEBUG_INIT(d_log);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
193 DEBUG_REGISTER_CLOSE();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
194 #endif // defined DEBUG_ALL
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
195
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
196 DEBUG_ENT("main");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
197
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
198 if (argc > optind) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
199 fname = argv[optind];
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
200 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
201 usage();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
202 exit(2);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
203 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
204
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
205 if (output_mode != OUTPUT_QUIET) printf("Opening PST file and indexes...\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
206
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
207 DEBUG_MAIN(("main: Opening PST file '%s'\n", fname));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
208 RET_DERROR(pst_open(&pstfile, fname, "r"), 1, ("Error opening File\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
209 DEBUG_MAIN(("main: Loading Indexes\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
210 RET_DERROR(pst_load_index(&pstfile), 2, ("Index Error\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
211 DEBUG_MAIN(("processing file items\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
212
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
213 pst_load_extended_attributes(&pstfile);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
214
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
215 if (chdir(output_dir)) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
216 x = errno;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
217 pst_close(&pstfile);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
218 DIE(("main: Cannot change to output dir %s: %s\n", output_dir, strerror(x)));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
219 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
220
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
221 if (output_mode != OUTPUT_QUIET) printf("About to start processing first record...\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
222
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
223 d_ptr = pstfile.d_head; // first record is main record
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
224 if ((item = _pst_parse_item(&pstfile, d_ptr)) == NULL || item->message_store == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
225 DIE(("main: Could not get root record\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
226 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
227
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
228 // default the file_as to the same as the main filename if it doesn't exist
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
229 if (item->file_as == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
230 if ((temp = strrchr(fname, '/')) == NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
231 if ((temp = strrchr(fname, '\\')) == NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
232 temp = fname;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
233 else
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
234 temp++; // get past the "\\"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
235 else
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
236 temp++; // get past the "/"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
237 item->file_as = (char*)xmalloc(strlen(temp)+1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
238 strcpy(item->file_as, temp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
239 DEBUG_MAIN(("file_as was blank, so am using %s\n", item->file_as));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
240 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
241 DEBUG_MAIN(("main: Root Folder Name: %s\n", item->file_as));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
242
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
243
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
244 f = (struct file_ll*) malloc(sizeof(struct file_ll));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
245 memset(f, 0, sizeof(struct file_ll));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
246 f->email_count = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
247 f->skip_count = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
248 f->next = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
249 head = f;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
250 if (mode == MODE_KMAIL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
251 f->name = mk_kmail_dir(item->file_as);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
252 else if (mode == MODE_RECURSE)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
253 f->name = mk_recurse_dir(item->file_as);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
254 else if (mode == MODE_SEPERATE) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
255 // do similar stuff to recurse here.
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
256 mk_seperate_dir(item->file_as, overwrite);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
257 f->name = (char*) xmalloc(10);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
258 sprintf(f->name, "%09i", f->email_count);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
259 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
260 f->name = (char*) malloc(strlen(item->file_as)+strlen(OUTPUT_TEMPLATE)+1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
261 sprintf(f->name, OUTPUT_TEMPLATE, item->file_as);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
262 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
263
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
264 f->dname = (char*) malloc(strlen(item->file_as)+1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
265 strcpy(f->dname, item->file_as);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
266
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
267 if (overwrite != 1 && mode != MODE_SEPERATE) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
268 // if overwrite is set to 1 we keep the existing name and don't modify anything
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
269 // we don't want to go changing the file name of the SEPERATE items
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
270 temp = (char*) malloc (strlen(f->name)+10); //enough room for 10 digits
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
271 sprintf(temp, "%s", f->name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
272 temp = check_filename(temp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
273 x = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
274 while ((f->output = fopen(temp, "r")) != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
275 DEBUG_MAIN(("main: need to increase filename cause one already exists with that name\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
276 DEBUG_MAIN(("main: - increasing it to %s%d\n", f->name, x));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
277 x++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
278 sprintf(temp, "%s%08d", f->name, x);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
279 DEBUG_MAIN(("main: - trying \"%s\"\n", temp));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
280 if (x == 99999999) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
281 DIE(("main: Why can I not create a folder %s? I have tried %i extensions...\n", f->name, x));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
282 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
283 fclose(f->output);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
284 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
285 if (x > 0) { //then the f->name should change
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
286 free (f->name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
287 f->name = temp;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
288 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
289 free (temp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
290 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
291 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
292 if (mode != MODE_SEPERATE) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
293 f->name = check_filename(f->name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
294 if ((f->output = fopen(f->name, "w")) == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
295 DIE(("main: Could not open file \"%s\" for write\n", f->name));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
296 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
297 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
298 f->type = item->type;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
299
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
300 if ((d_ptr = pst_getTopOfFolders(&pstfile, item)) == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
301 DIE(("Top of folders record not found. Cannot continue\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
302 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
303
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
304 if (item){
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
305 _pst_freeItem(item);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
306 item = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
307 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
308
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
309 /* if ((item = _pst_parse_item(&pstfile, d_ptr)) == NULL || item->folder == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
310 DEBUG_MAIN(("main: Could not get \"Top Of Personal Folder\" record\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
311 return -2;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
312 }*/
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
313 d_ptr = d_ptr->child; // do the children of TOPF
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
314
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
315 if (output_mode != OUTPUT_QUIET) printf("Processing items...\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
316
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
317 DEBUG_MAIN(("main: About to do email stuff\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
318 while (d_ptr != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
319 DEBUG_MAIN(("main: New item record\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
320 if (d_ptr->desc == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
321 DEBUG_WARN(("main: ERROR ?? item's desc record is NULL\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
322 f->skip_count++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
323 goto check_parent;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
324 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
325 DEBUG_MAIN(("main: Desc Email ID %#x [d_ptr->id = %#x]\n", d_ptr->desc->id, d_ptr->id));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
326
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
327 item = _pst_parse_item(&pstfile, d_ptr);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
328 DEBUG_MAIN(("main: About to process item\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
329 if (item != NULL && item->email != NULL && item->email->subject != NULL &&
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
330 item->email->subject->subj != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
331 // DEBUG_EMAIL(("item->email->subject = %p\n", item->email->subject));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
332 // DEBUG_EMAIL(("item->email->subject->subj = %p\n", item->email->subject->subj));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
333 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
334 if (item != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
335 if (item->message_store != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
336 // there should only be one message_store, and we have already done it
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
337 DIE(("main: A second message_store has been found. Sorry, this must be an error.\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
338 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
339
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
340
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
341 if (item->folder != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
342 // if this is a folder, we want to recurse into it
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
343 if (output_mode != OUTPUT_QUIET) printf("Processing Folder \"%s\"\n", item->file_as);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
344 // f->email_count++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
345 DEBUG_MAIN(("main: I think I may try to go into folder \"%s\"\n", item->file_as));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
346 f = (struct file_ll*) malloc(sizeof(struct file_ll));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
347 memset(f, 0, sizeof(struct file_ll));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
348
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
349 f->next = head;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
350 f->email_count = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
351 f->type = item->type;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
352 f->stored_count = item->folder->email_count;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
353 head = f;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
354
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
355 temp = item->file_as;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
356 temp = check_filename(temp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
357
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
358 if (mode == MODE_KMAIL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
359 f->name = mk_kmail_dir(item->file_as); //create directory and form filename
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
360 else if (mode == MODE_RECURSE)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
361 f->name = mk_recurse_dir(item->file_as);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
362 else if (mode == MODE_SEPERATE) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
363 // do similar stuff to recurse here.
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
364 mk_seperate_dir(item->file_as, overwrite);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
365 f->name = (char*) xmalloc(10);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
366 memset(f->name, 0, 10);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
367 // sprintf(f->name, "%09i", f->email_count);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
368 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
369 f->name = (char*) xmalloc(strlen(item->file_as)+strlen(OUTPUT_TEMPLATE+1));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
370 sprintf(f->name, OUTPUT_TEMPLATE, item->file_as);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
371 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
372
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
373 f->dname = (char*) xmalloc(strlen(item->file_as)+1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
374 strcpy(f->dname, item->file_as);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
375
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
376 if (overwrite != 1) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
377 temp = (char*) xmalloc (strlen(f->name)+10); //enough room for 10 digits
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
378 sprintf(temp, "%s", f->name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
379 x = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
380 temp = check_filename(temp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
381 while ((f->output = fopen(temp, "r")) != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
382 DEBUG_MAIN(("main: need to increase filename cause one already exists with that name\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
383 DEBUG_MAIN(("main: - increasing it to %s%d\n", f->name, x));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
384 x++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
385 sprintf(temp, "%s%08d", f->name, x);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
386 DEBUG_MAIN(("main: - trying \"%s\"\n", f->name));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
387 if (x == 99999999) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
388 DIE(("main: Why can I not create a folder %s? I have tried %i extensions...\n", f->name, x));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
389 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
390 fclose(f->output);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
391 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
392 if (x > 0) { //then the f->name should change
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
393 free (f->name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
394 f->name = temp;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
395 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
396 free(temp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
397 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
398 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
399
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
400 DEBUG_MAIN(("main: f->name = %s\nitem->folder_name = %s\n", f->name, item->file_as));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
401 if (mode != MODE_SEPERATE) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
402 f->name = check_filename(f->name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
403 if ((f->output = fopen(f->name, "w")) == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
404 DIE(("main: Could not open file \"%s\" for write\n", f->name));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
405 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
406 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
407 if (d_ptr->child != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
408 d_ptr = d_ptr->child;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
409 skip_child = 1;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
410 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
411 DEBUG_MAIN(("main: Folder has NO children. Creating directory, and closing again\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
412 if (output_mode != OUTPUT_QUIET)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
413 printf("\tNo items to process in folder \"%s\", should have been %i\n", f->dname, f->stored_count);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
414 head = f->next;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
415 if (f->output != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
416 fclose(f->output);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
417 if (mode == MODE_KMAIL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
418 close_kmail_dir();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
419 else if (mode == MODE_RECURSE)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
420 close_recurse_dir();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
421 else if (mode == MODE_SEPERATE)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
422 close_seperate_dir();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
423 free(f->dname);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
424 free(f->name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
425 free(f);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
426
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
427 f = head;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
428 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
429 _pst_freeItem(item);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
430 item = NULL; // just for the odd situations!
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
431 goto check_parent;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
432 } else if (item->contact != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
433 // deal with a contact
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
434 // write them to the file, one per line in this format
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
435 // Desc Name <email@address>\n
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
436 if (mode == MODE_SEPERATE) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
437 mk_seperate_file(f);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
438 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
439 f->email_count++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
440
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
441 DEBUG_MAIN(("main: Processing Contact\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
442 if (f->type != PST_TYPE_CONTACT) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
443 DEBUG_MAIN(("main: I have a contact, but the folder isn't a contacts folder. "
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
444 "Will process anyway\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
445 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
446 if (item->type != PST_TYPE_CONTACT) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
447 DEBUG_MAIN(("main: I have an item that has contact info, but doesn't say that"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
448 " it is a contact. Type is \"%s\"\n", item->ascii_type));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
449 DEBUG_MAIN(("main: Processing anyway\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
450 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
451 if (item->contact == NULL) { // this is an incorrect situation. Inform user
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
452 DEBUG_MAIN(("main: ERROR. This contact has not been fully parsed. one of the pre-requisties is NULL\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
453 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
454 if (contact_mode == CMODE_VCARD) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
455 // the specification I am following is (hopefully) RFC2426 vCard Mime Directory Profile
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
456 fprintf(f->output, "BEGIN:VCARD\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
457 fprintf(f->output, "FN:%s\n", rfc2426_escape(item->contact->fullname));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
458 fprintf(f->output, "N:%s;%s;%s;%s;%s\n",
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
459 rfc2426_escape((item->contact->surname==NULL?"":item->contact->surname)),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
460 rfc2426_escape((item->contact->first_name==NULL?"":item->contact->first_name)),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
461 rfc2426_escape((item->contact->middle_name==NULL?"":item->contact->middle_name)),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
462 rfc2426_escape((item->contact->display_name_prefix==NULL?"":item->contact->display_name_prefix)),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
463 rfc2426_escape((item->contact->suffix==NULL?"":item->contact->suffix)));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
464 if (item->contact->nickname != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
465 fprintf(f->output, "NICKNAME:%s\n", rfc2426_escape(item->contact->nickname));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
466 if (item->contact->address1 != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
467 fprintf(f->output, "EMAIL:%s\n", rfc2426_escape(item->contact->address1));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
468 if (item->contact->address2 != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
469 fprintf(f->output, "EMAIL:%s\n", rfc2426_escape(item->contact->address2));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
470 if (item->contact->address3 != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
471 fprintf(f->output, "EMAIL:%s\n", rfc2426_escape(item->contact->address3));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
472 if (item->contact->birthday != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
473 fprintf(f->output, "BDAY:%s\n", rfc2425_datetime_format(item->contact->birthday));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
474 if (item->contact->home_address != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
475 fprintf(f->output, "ADR;TYPE=home:%s;%s;%s;%s;%s;%s;%s\n",
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
476 rfc2426_escape((item->contact->home_po_box!=NULL?item->contact->home_po_box:"")),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
477 "", // extended Address
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
478 rfc2426_escape((item->contact->home_street!=NULL?item->contact->home_street:"")),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
479 rfc2426_escape((item->contact->home_city!=NULL?item->contact->home_city:"")),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
480 rfc2426_escape((item->contact->home_state!=NULL?item->contact->home_state:"")),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
481 rfc2426_escape((item->contact->home_postal_code!=NULL?item->contact->home_postal_code:"")),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
482 rfc2426_escape((item->contact->home_country!=NULL?item->contact->home_country:"")));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
483 fprintf(f->output, "LABEL;TYPE=home:%s\n", rfc2426_escape(item->contact->home_address));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
484 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
485 if (item->contact->business_address != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
486 fprintf(f->output, "ADR;TYPE=work:%s;%s;%s;%s;%s;%s;%s\n",
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
487 rfc2426_escape((item->contact->business_po_box!=NULL?item->contact->business_po_box:"")),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
488 "", // extended Address
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
489 rfc2426_escape((item->contact->business_street!=NULL?item->contact->business_street:"")),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
490 rfc2426_escape((item->contact->business_city!=NULL?item->contact->business_city:"")),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
491 rfc2426_escape((item->contact->business_state!=NULL?item->contact->business_state:"")),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
492 rfc2426_escape((item->contact->business_postal_code!=NULL?item->contact->business_postal_code:"")),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
493 rfc2426_escape((item->contact->business_country!=NULL?item->contact->business_country:"")));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
494 fprintf(f->output, "LABEL;TYPE=work:%s\n", rfc2426_escape(item->contact->business_address));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
495 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
496 if (item->contact->other_address != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
497 fprintf(f->output, "ADR;TYPE=postal:%s;%s;%s;%s;%s;%s;%s\n",
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
498 rfc2426_escape((item->contact->other_po_box!=NULL?item->contact->business_po_box:"")),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
499 "", // extended Address
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
500 rfc2426_escape((item->contact->other_street!=NULL?item->contact->other_street:"")),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
501 rfc2426_escape((item->contact->other_city!=NULL?item->contact->other_city:"")),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
502 rfc2426_escape((item->contact->other_state!=NULL?item->contact->other_state:"")),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
503 rfc2426_escape((item->contact->other_postal_code!=NULL?item->contact->other_postal_code:"")),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
504 rfc2426_escape((item->contact->other_country!=NULL?item->contact->other_country:"")));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
505 fprintf(f->output, "ADR;TYPE=postal:%s\n", rfc2426_escape(item->contact->other_address));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
506 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
507 if (item->contact->business_fax != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
508 fprintf(f->output, "TEL;TYPE=work,fax:%s\n", rfc2426_escape(item->contact->business_fax));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
509 if (item->contact->business_phone != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
510 fprintf(f->output, "TEL;TYPE=work,voice:%s\n", rfc2426_escape(item->contact->business_phone));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
511 if (item->contact->business_phone2 != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
512 fprintf(f->output, "TEL;TYPE=work,voice:%s\n", rfc2426_escape(item->contact->business_phone2));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
513 if (item->contact->car_phone != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
514 fprintf(f->output, "TEL;TYPE=car,voice:%s\n", rfc2426_escape(item->contact->car_phone));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
515 if (item->contact->home_fax != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
516 fprintf(f->output, "TEL;TYPE=home,fax:%s\n", rfc2426_escape(item->contact->home_fax));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
517 if (item->contact->home_phone != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
518 fprintf(f->output, "TEL;TYPE=home,voice:%s\n", rfc2426_escape(item->contact->home_phone));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
519 if (item->contact->home_phone2 != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
520 fprintf(f->output, "TEL;TYPE=home,voice:%s\n", rfc2426_escape(item->contact->home_phone2));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
521 if (item->contact->isdn_phone != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
522 fprintf(f->output, "TEL;TYPE=isdn:%s\n", rfc2426_escape(item->contact->isdn_phone));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
523 if (item->contact->mobile_phone != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
524 fprintf(f->output, "TEL;TYPE=cell,voice:%s\n", rfc2426_escape(item->contact->mobile_phone));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
525 if (item->contact->other_phone != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
526 fprintf(f->output, "TEL;TYPE=msg:%s\n", rfc2426_escape(item->contact->other_phone));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
527 if (item->contact->pager_phone != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
528 fprintf(f->output, "TEL;TYPE=pager:%s\n", rfc2426_escape(item->contact->pager_phone));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
529 if (item->contact->primary_fax != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
530 fprintf(f->output, "TEL;TYPE=fax,pref:%s\n", rfc2426_escape(item->contact->primary_fax));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
531 if (item->contact->primary_phone != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
532 fprintf(f->output, "TEL;TYPE=phone,pref:%s\n", rfc2426_escape(item->contact->primary_phone));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
533 if (item->contact->radio_phone != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
534 fprintf(f->output, "TEL;TYPE=pcs:%s\n", rfc2426_escape(item->contact->radio_phone));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
535 if (item->contact->telex != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
536 fprintf(f->output, "TEL;TYPE=bbs:%s\n", rfc2426_escape(item->contact->telex));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
537 if (item->contact->job_title != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
538 fprintf(f->output, "TITLE:%s\n", rfc2426_escape(item->contact->job_title));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
539 if (item->contact->profession != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
540 fprintf(f->output, "ROLE:%s\n", rfc2426_escape(item->contact->profession));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
541 if (item->contact->assistant_name != NULL || item->contact->assistant_phone != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
542 fprintf(f->output, "AGENT:BEGIN:VCARD\\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
543 if (item->contact->assistant_name != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
544 fprintf(f->output, "FN:%s\\n", rfc2426_escape(item->contact->assistant_name));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
545 if (item->contact->assistant_phone != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
546 fprintf(f->output, "TEL:%s\\n", rfc2426_escape(item->contact->assistant_phone));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
547 fprintf(f->output, "END:VCARD\\n\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
548 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
549 if (item->contact->company_name != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
550 fprintf(f->output, "ORG:%s\n", rfc2426_escape(item->contact->company_name));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
551 if (item->comment != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
552 fprintf(f->output, "NOTE:%s\n", rfc2426_escape(item->comment));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
553
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
554 fprintf(f->output, "VERSION: 3.0\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
555 fprintf(f->output, "END:VCARD\n\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
556 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
557 fprintf(f->output, "%s <%s>\n", item->contact->fullname, item->contact->address1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
558 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
559 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
560 } else if (item->email != NULL &&
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
561 (item->type == PST_TYPE_NOTE || item->type == PST_TYPE_REPORT)) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
562 if (mode == MODE_SEPERATE) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
563 mk_seperate_file(f);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
564 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
565
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
566 f->email_count++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
567
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
568 DEBUG_MAIN(("main: seen an email\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
569
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
570 // convert the sent date if it exists, or set it to a fixed date
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
571 if (item->email->sent_date != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
572 em_time = fileTimeToUnixTime(item->email->sent_date, 0);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
573 c_time = ctime(&em_time);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
574 if (c_time != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
575 c_time[strlen(c_time)-1] = '\0'; //remove end \n
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
576 else
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
577 c_time = "Fri Dec 28 12:06:21 2001";
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
578 } else
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
579 c_time= "Fri Dec 28 12:06:21 2001";
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
580
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
581 // if the boundary is still set from the previous run, then free it
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
582 if (boundary != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
583 free (boundary);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
584 boundary = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
585 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
586
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
587 // we will always look at the header to discover some stuff
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
588 if (item->email->header != NULL ) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
589 // see if there is a boundary variable there
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
590 // this search MUST be made case insensitive (DONE).
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
591 // Also, some check to find out if we
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
592 // are looking at the boundary associated with content-type, and that the content
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
593 // type really is "multipart"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
594 if ((b2 = my_stristr(item->email->header, "boundary=")) != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
595 b2 += strlen("boundary="); // move boundary to first char of marker
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
596
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
597 if (*b2 == '"') {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
598 b2++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
599 b1 = strchr(b2, '"'); // find terminating quote
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
600 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
601 b1 = b2;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
602 while (isgraph(*b1)) // find first char that isn't part of boundary
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
603 b1++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
604 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
605
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
606 boundary = malloc ((b1-b2)+1); //malloc that length
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
607 memset (boundary, 0, (b1-b2)+1); // blank it
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
608 strncpy(boundary, b2, b1-b2); // copy boundary to another variable
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
609 b1 = b2 = boundary;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
610 while (*b2 != '\0') { // remove any CRs and Tabs
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
611 if (*b2 != '\n' && *b2 != '\r' && *b2 != '\t') {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
612 *b1 = *b2;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
613 b1++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
614 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
615 b2++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
616 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
617 *b1 = '\0';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
618
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
619 DEBUG_MAIN(("main: Found boundary of - %s\n", boundary));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
620 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
621
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
622 DEBUG_MAIN(("main: boundary not found in header\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
623 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
624
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
625 // also possible to set 7bit encoding detection here.
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
626 if ((b2 = my_stristr(item->email->header, "Content-Transfer-Encoding:")) != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
627 if ((b2 = strchr(b2, ':')) != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
628 b2++; // skip to the : at the end of the string
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
629
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
630 while (*b2 == ' ' || *b2 == '\t')
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
631 b2++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
632 if (pst_strincmp(b2, "base64", 6)==0) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
633 DEBUG_MAIN(("body is base64 encoded\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
634 base64_body = 1;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
635 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
636 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
637 DEBUG_WARN(("found a ':' during the my_stristr, but not after that..\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
638 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
639 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
640
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
641 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
642
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
643 DEBUG_MAIN(("main: About to print Header\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
644
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
645 if (item != NULL && item->email != NULL && item->email->subject != NULL &&
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
646 item->email->subject->subj != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
647 DEBUG_EMAIL(("item->email->subject->subj = %p\n", item->email->subject->subj));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
648 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
649 if (item->email->header != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
650 // some of the headers we get from the file are not properly defined.
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
651 // they can contain some email stuff too. We will cut off the header
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
652 // when we see a \n\n or \r\n\r\n
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
653
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
654 removeCR(item->email->header);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
655
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
656 temp = strstr(item->email->header, "\n\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
657
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
658 if (temp != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
659 DEBUG_MAIN(("main: Found body text in header\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
660 *temp = '\0';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
661 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
662
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
663 if (mode != MODE_SEPERATE) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
664 char *soh = NULL; // real start of headers.
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
665 // don't put rubbish in if we are doing seperate
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
666 fprintf(f->output, "From \"%s\" %s\n", item->email->outlook_sender_name, c_time);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
667 soh = skip_header_prologue(item->email->header);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
668 fprintf(f->output, "%s\n", soh);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
669 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
670 fprintf(f->output, "%s", item->email->header);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
671 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
672 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
673 //make up our own header!
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
674 if (mode != MODE_SEPERATE) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
675 // don't want this first line for this mode
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
676 if (item->email->outlook_sender_name != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
677 temp = item->email->outlook_sender_name;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
678 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
679 temp = "(readpst_null)";
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
680 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
681 fprintf(f->output, "From \"%s\" %s\n", temp, c_time);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
682 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
683 if ((temp = item->email->outlook_sender) == NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
684 temp = "";
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
685 fprintf(f->output, "From: \"%s\" <%s>\n", item->email->outlook_sender_name, temp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
686 if (item->email->subject != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
687 fprintf(f->output, "Subject: %s\n", item->email->subject->subj);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
688 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
689 fprintf(f->output, "Subject: \n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
690 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
691 fprintf(f->output, "To: %s\n", item->email->sentto_address);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
692 if (item->email->cc_address != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
693 fprintf(f->output, "Cc: %s\n", item->email->cc_address);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
694 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
695 if (item->email->sent_date != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
696 c_time = (char*) xmalloc(C_TIME_SIZE);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
697 strftime(c_time, C_TIME_SIZE, "%a, %d %b %Y %H:%M:%S %z", gmtime(&em_time));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
698 fprintf(f->output, "Date: %s\n", c_time);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
699 free(c_time);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
700 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
701
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
702 fprintf(f->output, "MIME-Version: 1.0\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
703 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
704 if (boundary == NULL && (item->attach ||(item->email->body && item->email->htmlbody)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
705 || item->email->rtf_compressed || item->email->encrypted_body
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
706 || item->email->encrypted_htmlbody)) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
707 // we need to create a boundary here.
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
708 DEBUG_EMAIL(("main: must create own boundary. oh dear.\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
709 boundary = malloc(50 * sizeof(char)); // allow 50 chars for boundary
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
710 boundary[0] = '\0';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
711 sprintf(boundary, "--boundary-LibPST-iamunique-%i_-_-", rand());
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
712 DEBUG_EMAIL(("main: created boundary is %s\n", boundary));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
713
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
714 /* If boundary != NULL, then it'll already be printed with existing
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
715 * headers. Otherwise, we generate it here, and print it.
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
716 */
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
717 if (item->attach != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
718 // write the boundary stuff if we have attachments
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
719 fprintf(f->output, "Content-type: multipart/mixed;\n\tboundary=\"%s\"\n",
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
720 boundary);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
721 } else if (boundary != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
722 // else if we have multipart/alternative then tell it so
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
723 fprintf(f->output, "Content-type: multipart/alternative;\n\tboundary=\"%s\"\n",
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
724 boundary);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
725 } else if (item->email->htmlbody) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
726 fprintf(f->output, "Content-type: text/html\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
727 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
728 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
729 fprintf(f->output, "\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
730
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
731 DEBUG_MAIN(("main: About to print Body\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
732
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
733 if (item->email->body != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
734 if (boundary) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
735 fprintf(f->output, "\n--%s\n", boundary);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
736 fprintf(f->output, "Content-type: text/plain\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
737 if (base64_body) fprintf(f->output, "Content-Transfer-Encoding: base64\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
738 fprintf(f->output, "\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
739 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
740 removeCR(item->email->body);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
741 if (base64_body)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
742 write_email_body(f->output, base64_encode(item->email->body,
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
743 strlen(item->email->body)));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
744 else
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
745 write_email_body(f->output, item->email->body);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
746 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
747
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
748 if (item->email->htmlbody != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
749 if (boundary) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
750 fprintf(f->output, "\n--%s\n", boundary);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
751 fprintf(f->output, "Content-type: text/html\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
752 if (base64_body) fprintf(f->output, "Content-Transfer-Encoding: base64\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
753 fprintf(f->output, "\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
754 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
755 removeCR(item->email->htmlbody);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
756 if (base64_body)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
757 write_email_body(f->output, base64_encode(item->email->htmlbody,
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
758 strlen(item->email->htmlbody)));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
759 else
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
760 write_email_body(f->output, item->email->htmlbody);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
761 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
762
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
763 attach_num = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
764
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
765 if (item->email->rtf_compressed != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
766 DEBUG_MAIN(("Adding RTF body as attachment\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
767 item->current_attach = (pst_item_attach*)xmalloc(sizeof(pst_item_attach));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
768 memset(item->current_attach, 0, sizeof(pst_item_attach));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
769 item->current_attach->next = item->attach;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
770 item->attach = item->current_attach;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
771 item->current_attach->data = lzfu_decompress(item->email->rtf_compressed);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
772 item->current_attach->filename2 = xmalloc(strlen(RTF_ATTACH_NAME)+2);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
773 strcpy(item->current_attach->filename2, RTF_ATTACH_NAME);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
774 item->current_attach->mimetype = xmalloc(strlen(RTF_ATTACH_TYPE)+2);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
775 strcpy(item->current_attach->mimetype, RTF_ATTACH_TYPE);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
776 memcpy(&(item->current_attach->size), item->email->rtf_compressed+sizeof(int32_t), sizeof(int32_t));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
777 LE32_CPU(item->current_attach->size);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
778 // item->email->rtf_compressed = ;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
779 // attach_num++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
780 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
781 if (item->email->encrypted_body || item->email->encrypted_htmlbody) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
782 // if either the body or htmlbody is encrypted, add them as attachments
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
783 if (item->email->encrypted_body) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
784 DEBUG_MAIN(("Adding Encrypted Body as attachment\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
785 item->current_attach = (pst_item_attach*) xmalloc(sizeof(pst_item_attach));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
786 memset(item->current_attach, 0, sizeof(pst_item_attach));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
787 item->current_attach->next = item->attach;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
788 item->attach = item->current_attach;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
789
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
790 item->current_attach->data = item->email->encrypted_body;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
791 item->current_attach->size = item->email->encrypted_body_size;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
792 item->email->encrypted_body = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
793 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
794 if (item->email->encrypted_htmlbody) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
795 DEBUG_MAIN(("Adding encrypted HTML body as attachment\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
796 item->current_attach = (pst_item_attach*) xmalloc(sizeof(pst_item_attach));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
797 memset(item->current_attach, 0, sizeof(pst_item_attach));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
798 item->current_attach->next = item->attach;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
799 item->attach = item->current_attach;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
800
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
801 item->current_attach->data = item->email->encrypted_htmlbody;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
802 item->current_attach->size = item->email->encrypted_htmlbody_size;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
803 item->email->encrypted_htmlbody = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
804 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
805 write_email_body(f->output, "The body of this email is encrypted. This isn't supported yet, but the body is now an attachment\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
806 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
807 base64_body = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
808 // attachments
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
809 item->current_attach = item->attach;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
810 while (item->current_attach != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
811 DEBUG_MAIN(("main: Attempting Attachment encoding\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
812 if (item->current_attach->data == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
813 DEBUG_MAIN(("main: Data of attachment is NULL!. Size is supposed to be %i\n", item->current_attach->size));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
814 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
815 if (mode == MODE_SEPERATE) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
816 f->name = check_filename(f->name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
817 if (item->current_attach->filename2 == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
818 temp = xmalloc(strlen(f->name)+15);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
819 sprintf(temp, "%s-attach%i", f->name, attach_num);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
820 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
821 temp = xmalloc(strlen(f->name)+strlen(item->current_attach->filename2)+15);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
822 fp = NULL; x=0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
823 do {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
824 if (fp != NULL) fclose(fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
825 if (x == 0)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
826 sprintf(temp, "%s-%s", f->name, item->current_attach->filename2);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
827 else
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
828 sprintf(temp, "%s-%s-%i", f->name, item->current_attach->filename2, x);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
829 } while ((fp = fopen(temp, "r"))!=NULL && ++x < 99999999);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
830 if (x > 99999999) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
831 DIE(("error finding attachment name. exhausted possibilities to %s\n", temp));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
832 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
833 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
834 DEBUG_MAIN(("main: Saving attachment to %s\n", temp));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
835 if ((fp = fopen(temp, "w")) == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
836 WARN(("main: Cannot open attachment save file \"%s\"\n", temp));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
837 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
838 if (item->current_attach->data != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
839 fwrite(item->current_attach->data, 1, item->current_attach->size, fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
840 else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
841 pst_attach_to_file(&pstfile, item->current_attach, fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
842 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
843 fclose(fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
844 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
845 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
846 DEBUG_MAIN(("main: Attachment Size is %i\n", item->current_attach->size));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
847 DEBUG_MAIN(("main: Attachment Pointer is %p\n", item->current_attach->data));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
848 if (item->current_attach->data != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
849 if ((enc = base64_encode (item->current_attach->data, item->current_attach->size)) == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
850 DEBUG_MAIN(("main: ERROR base64_encode returned NULL. Must have failed\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
851 item->current_attach = item->current_attach->next;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
852 continue;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
853 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
854 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
855 if (boundary) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
856 fprintf(f->output, "\n--%s\n", boundary);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
857 if (item->current_attach->mimetype == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
858 fprintf(f->output, "Content-type: %s\n", MIME_TYPE_DEFAULT);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
859 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
860 fprintf(f->output, "Content-type: %s\n", item->current_attach->mimetype);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
861 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
862 fprintf(f->output, "Content-transfer-encoding: base64\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
863 if (item->current_attach->filename2 == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
864 fprintf(f->output, "Content-Disposition: inline\n\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
865 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
866 fprintf(f->output, "Content-Disposition: attachment; filename=\"%s\"\n\n",
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
867 item->current_attach->filename2);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
868 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
869 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
870 if (item->current_attach->data != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
871 fwrite(enc, 1, strlen(enc), f->output);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
872 DEBUG_MAIN(("Attachment Size after encoding is %i\n", strlen(enc)));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
873 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
874 pst_attach_to_file_base64(&pstfile, item->current_attach, f->output);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
875 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
876 fprintf(f->output, "\n\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
877 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
878 item->current_attach = item->current_attach->next;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
879 attach_num++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
880 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
881 if (mode != MODE_SEPERATE) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
882 DEBUG_MAIN(("main: Writing buffer between emails\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
883 if (boundary)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
884 fprintf(f->output, "\n--%s--\n", boundary);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
885 fprintf(f->output, "\n\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
886 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
887 } else if (item->type == PST_TYPE_JOURNAL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
888 // deal with journal items
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
889 if (mode == MODE_SEPERATE) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
890 mk_seperate_file(f);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
891 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
892 f->email_count++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
893
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
894 DEBUG_MAIN(("main: Processing Journal Entry\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
895 if (f->type != PST_TYPE_JOURNAL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
896 DEBUG_MAIN(("main: I have a journal entry, but folder isn't specified as a journal type. Processing...\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
897 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
898
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
899 /* if (item->type != PST_TYPE_JOURNAL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
900 DEBUG_MAIN(("main: I have an item with journal info, but it's type is \"%s\" \n. Processing...\n",
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
901 item->ascii_type));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
902 }*/
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
903 fprintf(f->output, "BEGIN:VJOURNAL\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
904 if (item->email->subject != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
905 fprintf(f->output, "SUMMARY:%s\n", rfc2426_escape(item->email->subject->subj));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
906 if (item->email->body != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
907 fprintf(f->output, "DESCRIPTION:%s\n", rfc2426_escape(item->email->body));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
908 if (item->journal->start != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
909 fprintf(f->output, "DTSTART;VALUE=DATE-TIME:%s\n", rfc2445_datetime_format(item->journal->start));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
910 fprintf(f->output, "END:VJOURNAL\n\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
911 } else if (item->type == PST_TYPE_APPOINTMENT) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
912 // deal with Calendar appointments
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
913 if (mode == MODE_SEPERATE) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
914 mk_seperate_file(f);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
915 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
916 f->email_count++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
917
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
918 DEBUG_MAIN(("main: Processing Appointment Entry\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
919 if (f->type != PST_TYPE_APPOINTMENT) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
920 DEBUG_MAIN(("main: I have an appointment, but folder isn't specified as an appointment type. Processing...\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
921 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
922 fprintf(f->output, "BEGIN:VEVENT\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
923 if (item->create_date != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
924 fprintf(f->output, "CREATED:%s\n", rfc2445_datetime_format(item->create_date));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
925 if (item->modify_date != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
926 fprintf(f->output, "LAST-MOD:%s\n", rfc2445_datetime_format(item->modify_date));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
927 if (item->email != NULL && item->email->subject != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
928 fprintf(f->output, "SUMMARY:%s\n", rfc2426_escape(item->email->subject->subj));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
929 if (item->email != NULL && item->email->body != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
930 fprintf(f->output, "DESCRIPTION:%s\n", rfc2426_escape(item->email->body));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
931 if (item->appointment != NULL && item->appointment->start != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
932 fprintf(f->output, "DTSTART;VALUE=DATE-TIME:%s\n", rfc2445_datetime_format(item->appointment->start));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
933 if (item->appointment != NULL && item->appointment->end != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
934 fprintf(f->output, "DTEND;VALUE=DATE-TIME:%s\n", rfc2445_datetime_format(item->appointment->end));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
935 if (item->appointment != NULL && item->appointment->location != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
936 fprintf(f->output, "LOCATION:%s\n", rfc2426_escape(item->appointment->location));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
937 if (item->appointment != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
938 switch (item->appointment->showas) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
939 case PST_FREEBUSY_TENTATIVE:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
940 fprintf(f->output, "STATUS:TENTATIVE\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
941 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
942 case PST_FREEBUSY_FREE:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
943 // mark as transparent and as confirmed
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
944 fprintf(f->output, "TRANSP:TRANSPARENT\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
945 case PST_FREEBUSY_BUSY:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
946 case PST_FREEBUSY_OUT_OF_OFFICE:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
947 fprintf(f->output, "STATUS:CONFIRMED\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
948 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
949 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
950 switch (item->appointment->label) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
951 case PST_APP_LABEL_NONE:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
952 fprintf(f->output, "CATEGORIES:NONE\n"); break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
953 case PST_APP_LABEL_IMPORTANT:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
954 fprintf(f->output, "CATEGORIES:IMPORTANT\n"); break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
955 case PST_APP_LABEL_BUSINESS:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
956 fprintf(f->output, "CATEGORIES:BUSINESS\n"); break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
957 case PST_APP_LABEL_PERSONAL:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
958 fprintf(f->output, "CATEGORIES:PERSONAL\n"); break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
959 case PST_APP_LABEL_VACATION:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
960 fprintf(f->output, "CATEGORIES:VACATION\n"); break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
961 case PST_APP_LABEL_MUST_ATTEND:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
962 fprintf(f->output, "CATEGORIES:MUST-ATTEND\n"); break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
963 case PST_APP_LABEL_TRAVEL_REQ:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
964 fprintf(f->output, "CATEGORIES:TRAVEL-REQUIRED\n"); break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
965 case PST_APP_LABEL_NEEDS_PREP:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
966 fprintf(f->output, "CATEGORIES:NEEDS-PREPARATION\n"); break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
967 case PST_APP_LABEL_BIRTHDAY:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
968 fprintf(f->output, "CATEGORIES:BIRTHDAY\n"); break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
969 case PST_APP_LABEL_ANNIVERSARY:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
970 fprintf(f->output, "CATEGORIES:ANNIVERSARY\n"); break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
971 case PST_APP_LABEL_PHONE_CALL:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
972 fprintf(f->output, "CATEGORIES:PHONE-CALL\n"); break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
973 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
974 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
975 fprintf(f->output, "END:VEVENT\n\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
976 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
977 f->skip_count++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
978 DEBUG_MAIN(("main: Unknown item type. %i. Ascii1=\"%s\"\n",
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
979 item->type, item->ascii_type));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
980 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
981 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
982 f->skip_count++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
983 DEBUG_MAIN(("main: A NULL item was seen\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
984 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
985
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
986 DEBUG_MAIN(("main: Going to next d_ptr\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
987 if (boundary) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
988 free(boundary);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
989 boundary = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
990 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
991
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
992 check_parent:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
993 // _pst_freeItem(item);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
994 while (!skip_child && d_ptr->next == NULL && d_ptr->parent != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
995 DEBUG_MAIN(("main: Going to Parent\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
996 head = f->next;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
997 if (f->output != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
998 fclose(f->output);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
999 DEBUG_MAIN(("main: Email Count for folder %s is %i\n", f->dname, f->email_count));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1000 if (output_mode != OUTPUT_QUIET)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1001 printf("\t\"%s\" - %i items done, skipped %i, should have been %i\n",
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1002 f->dname, f->email_count, f->skip_count, f->stored_count);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1003 if (mode == MODE_KMAIL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1004 close_kmail_dir();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1005 else if (mode == MODE_RECURSE)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1006 close_recurse_dir();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1007 else if (mode == MODE_SEPERATE)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1008 close_seperate_dir();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1009 free(f->name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1010 free(f->dname);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1011 free(f);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1012 f = head;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1013 if (head == NULL) { //we can't go higher. Must be at start?
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1014 DEBUG_MAIN(("main: We are now trying to go above the highest level. We must be finished\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1015 break; //from main while loop
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1016 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1017 d_ptr = d_ptr->parent;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1018 skip_child = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1019 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1020
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1021 if (item != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1022 DEBUG_MAIN(("main: Freeing memory used by item\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1023 _pst_freeItem(item);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1024 item = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1025 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1026
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1027 if (!skip_child)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1028 d_ptr = d_ptr->next;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1029 else
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1030 skip_child = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1031
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1032 if (d_ptr == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1033 DEBUG_MAIN(("main: d_ptr is now NULL\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1034 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1035 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1036 if (output_mode != OUTPUT_QUIET) printf("Finished.\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1037 DEBUG_MAIN(("main: Finished.\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1038
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1039 pst_close(&pstfile);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1040 // fclose(pstfile.fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1041 while (f != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1042 if (f->output != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1043 fclose(f->output);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1044 free(f->name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1045 free(f->dname);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1046
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1047 if (mode == MODE_KMAIL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1048 close_kmail_dir();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1049 else if (mode == MODE_RECURSE)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1050 close_recurse_dir();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1051 else if (mode == MODE_SEPERATE)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1052 // DO SOMETHING HERE
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1053 ;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1054 head = f->next;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1055 free (f);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1056 f = head;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1057 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1058
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1059 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1060
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1061 return 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1062 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1063 void write_email_body(FILE *f, char *body) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1064 char *n = body;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1065 // DEBUG_MAIN(("write_email_body(): \"%s\"\n", body));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1066 DEBUG_ENT("write_email_body");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1067 while (n != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1068 if (strncmp(body, "From ", 5) == 0)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1069 fprintf(f, ">");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1070 if ((n = strchr(body, '\n'))) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1071 n++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1072 fwrite(body, n-body, 1, f); //write just a line
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1073
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1074 body = n;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1075 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1076 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1077 fwrite(body, strlen(body), 1, f);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1078 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1079 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1080 char *removeCR (char *c) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1081 // converts /r/n to /n
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1082 char *a, *b;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1083 DEBUG_ENT("removeCR");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1084 a = b = c;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1085 while (*a != '\0') {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1086 *b = *a;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1087 if (*a != '\r')
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1088 b++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1089 a++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1090 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1091 *b = '\0';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1092 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1093 return c;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1094 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1095 int usage() {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1096 DEBUG_ENT("usage");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1097 version();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1098 printf("Usage: %s [OPTIONS] {PST FILENAME}\n", prog_name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1099 printf("OPTIONS:\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1100 printf("\t-c[v|l]\t- Set the Contact output mode. -cv = VCard, -cl = EMail list\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1101 printf("\t-d\t- Debug to file. This is a binary log. Use readlog to print it\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1102 printf("\t-h\t- Help. This screen\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1103 printf("\t-k\t- KMail. Output in kmail format\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1104 printf("\t-o\t- Output Dir. Directory to write files to. CWD is changed *after* opening pst file\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1105 printf("\t-q\t- Quiet. Only print error messages\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1106 printf("\t-r\t- Recursive. Output in a recursive format\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1107 printf("\t-S\t- Seperate. Write emails in the seperate format\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1108 printf("\t-V\t- Version. Display program version\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1109 printf("\t-w\t- Overwrite any output mbox files\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1110 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1111 return 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1112 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1113 int version() {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1114 DEBUG_ENT("version");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1115 printf("ReadPST v%s\n", VERSION);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1116 #if BYTE_ORDER == BIG_ENDIAN
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1117 printf("Big Endian implementation being used.\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1118 #elif BYTE_ORDER == LITTLE_ENDIAN
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1119 printf("Little Endian implementation being used.\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1120 #else
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1121 # error "Byte order not supported by this library"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1122 #endif
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1123 #ifdef __GNUC__
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1124 printf("GCC %d.%d : %s %s\n", __GNUC__, __GNUC_MINOR__, __DATE__, __TIME__);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1125 #endif
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1126 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1127 return 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1128 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1129 char *mk_kmail_dir(char *fname) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1130 //change to that directory
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1131 //make a directory based on OUTPUT_KMAIL_DIR_TEMPLATE
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1132 //allocate space for OUTPUT_TEMPLATE and form a char* with fname
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1133 //return that value
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1134 char *dir, *out_name, *index;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1135 int x;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1136 DEBUG_ENT("mk_kmail_dir");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1137 if (kmail_chdir != NULL && chdir(kmail_chdir)) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1138 x = errno;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1139 DIE(("mk_kmail_dir: Cannot change to directory %s: %s\n", kmail_chdir, strerror(x)));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1140 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1141 dir = malloc(strlen(fname)+strlen(OUTPUT_KMAIL_DIR_TEMPLATE)+1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1142 sprintf(dir, OUTPUT_KMAIL_DIR_TEMPLATE, fname);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1143 dir = check_filename(dir);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1144 if (D_MKDIR(dir)) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1145 //error occured
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1146 if (errno != EEXIST) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1147 x = errno;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1148 DIE(("mk_kmail_dir: Cannot create directory %s: %s\n", dir, strerror(x)));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1149 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1150 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1151 kmail_chdir = realloc(kmail_chdir, strlen(dir)+1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1152 strcpy(kmail_chdir, dir);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1153 free (dir);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1154
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1155 //we should remove any existing indexes created by KMail, cause they might be different now
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1156 index = malloc(strlen(fname)+strlen(KMAIL_INDEX)+1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1157 sprintf(index, KMAIL_INDEX, fname);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1158 unlink(index);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1159 free(index);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1160
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1161 out_name = malloc(strlen(fname)+strlen(OUTPUT_TEMPLATE)+1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1162 sprintf(out_name, OUTPUT_TEMPLATE, fname);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1163 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1164 return out_name;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1165 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1166 int close_kmail_dir() {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1167 // change ..
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1168 int x;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1169 DEBUG_ENT("close_kmail_dir");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1170 if (kmail_chdir != NULL) { //only free kmail_chdir if not NULL. do not change directory
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1171 free(kmail_chdir);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1172 kmail_chdir = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1173 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1174 if (chdir("..")) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1175 x = errno;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1176 DIE(("close_kmail_dir: Cannot move up dir (..): %s\n", strerror(x)));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1177 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1178 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1179 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1180 return 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1181 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1182 // this will create a directory by that name, then make an mbox file inside
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1183 // that dir. any subsequent dirs will be created by name, and they will
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1184 // contain mbox files
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1185 char *mk_recurse_dir(char *dir) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1186 int x;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1187 char *out_name;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1188 DEBUG_ENT("mk_recurse_dir");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1189 dir = check_filename(dir);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1190 if (D_MKDIR (dir)) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1191 if (errno != EEXIST) { // not an error because it exists
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1192 x = errno;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1193 DIE(("mk_recurse_dir: Cannot create directory %s: %s\n", dir, strerror(x)));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1194 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1195 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1196 if (chdir (dir)) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1197 x = errno;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1198 DIE(("mk_recurse_dir: Cannot change to directory %s: %s\n", dir, strerror(x)));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1199 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1200 out_name = malloc(strlen("mbox")+1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1201 strcpy(out_name, "mbox");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1202 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1203 return out_name;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1204 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1205 int close_recurse_dir() {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1206 int x;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1207 DEBUG_ENT("close_recurse_dir");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1208 if (chdir("..")) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1209 x = errno;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1210 DIE(("close_recurse_dir: Cannot go up dir (..): %s\n", strerror(x)));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1211 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1212 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1213 return 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1214 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1215 char *mk_seperate_dir(char *dir, int overwrite) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1216 #if !defined(WIN32) && !defined(__CYGWIN__)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1217 DIR * sdir = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1218 struct dirent *dirent = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1219 struct stat *filestat = xmalloc(sizeof(struct stat));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1220 #endif
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1221
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1222 char *dir_name = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1223 int x = 0, y = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1224 DEBUG_ENT("mk_seperate_dir");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1225 /*#if defined(WIN32) || defined(__CYGWIN__)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1226 DIE(("mk_seperate_dir: Win32 applications cannot use this function yet.\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1227 #endif*/
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1228
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1229 dir_name = xmalloc(strlen(dir)+10);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1230
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1231 do {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1232 if (y == 0)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1233 sprintf(dir_name, "%s", dir);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1234 else
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1235 sprintf(dir_name, "%s%09i", dir, y); // enough for 9 digits allocated above
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1236
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1237 dir_name = check_filename(dir_name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1238 DEBUG_MAIN(("mk_seperate_dir: about to try creating %s\n", dir_name));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1239 if (D_MKDIR(dir_name)) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1240 if (errno != EEXIST) { // if there is an error, and it doesn't already exist
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1241 x = errno;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1242 DIE(("mk_seperate_dir: Cannot create directory %s: %s\n", dir, strerror(x)));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1243 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1244 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1245 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1246 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1247 y++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1248 } while (overwrite == 0);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1249
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1250 if (chdir (dir_name)) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1251 x = errno;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1252 DIE(("mk_recurse_dir: Cannot change to directory %s: %s\n", dir, strerror(x)));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1253 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1254
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1255 if (overwrite) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1256 // we should probably delete all files from this directory
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1257 #if !defined(WIN32) && !defined(__CYGWIN__)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1258 if ((sdir = opendir("./")) == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1259 WARN(("mk_seperate_dir: Cannot open dir \"%s\" for deletion of old contents\n", "./"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1260 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1261 while ((dirent = readdir(sdir)) != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1262 if (lstat(dirent->d_name, filestat) != -1)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1263 if (S_ISREG(filestat->st_mode)) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1264 if (unlink(dirent->d_name)) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1265 y = errno;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1266 DIE(("mk_seperate_dir: unlink returned error on file %s: %s\n", dirent->d_name, strerror(y)));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1267 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1268 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1269 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1270 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1271 #endif
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1272 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1273
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1274 // overwrite will never change during this function, it is just there so that
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1275 // if overwrite is set, we only go through this loop once.
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1276
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1277 // we don't return a filename here cause it isn't necessary.
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1278 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1279 return NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1280 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1281 int close_seperate_dir() {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1282 int x;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1283 DEBUG_ENT("close_seperate_dir");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1284 if (chdir("..")) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1285 x = errno;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1286 DIE(("close_seperate_dir: Cannot go up dir (..): %s\n", strerror(x)));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1287 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1288 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1289 return 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1290 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1291 int mk_seperate_file(struct file_ll *f) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1292 DEBUG_ENT("mk_seperate_file");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1293 DEBUG_MAIN(("mk_seperate_file: opening next file to save email\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1294 if (f->email_count > 999999999) { // bigger than nine 9's
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1295 DIE(("mk_seperate_file: The number of emails in this folder has become too high to handle"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1296 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1297 sprintf(f->name, "%09i", f->email_count);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1298 if (f->output != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1299 fclose(f->output);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1300 f->output = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1301 f->name = check_filename(f->name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1302 if ((f->output = fopen(f->name, "w")) == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1303 DIE(("mk_seperate_file: Cannot open file to save email \"%s\"\n", f->name));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1304 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1305 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1306 return 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1307 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1308 char *my_stristr(char *haystack, char *needle) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1309 // my_stristr varies from strstr in that its searches are case-insensitive
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1310 char *x=haystack, *y=needle, *z = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1311 DEBUG_ENT("my_stristr");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1312 if (haystack == NULL || needle == NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1313 return NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1314 while (*y != '\0' && *x != '\0') {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1315 if (tolower(*y) == tolower(*x)) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1316 // move y on one
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1317 y++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1318 if (z == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1319 z = x; // store first position in haystack where a match is made
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1320 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1321 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1322 y = needle; // reset y to the beginning of the needle
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1323 z = NULL; // reset the haystack storage point
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1324 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1325 x++; // advance the search in the haystack
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1326 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1327 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1328 return z;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1329 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1330 char *check_filename(char *fname) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1331 char *t = fname;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1332 DEBUG_ENT("check_filename");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1333 if (t == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1334 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1335 return fname;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1336 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1337 while ((t = strpbrk(t, "/\\:")) != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1338 // while there are characters in the second string that we don't want
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1339 *t = '_'; //replace them with an underscore
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1340 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1341 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1342 return fname;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1343 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1344 char *rfc2426_escape(char *str) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1345 static char* buf = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1346 char *ret, *a, *b;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1347 int x = 0, y, z;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1348 DEBUG_ENT("rfc2426_escape");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1349 if (str == NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1350 ret = str;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1351 else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1352
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1353 // calculate space required to escape all the following characters
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1354 x = strlen(str) +(y=(chr_count(str, ',')*2) + (chr_count(str, '\\')*2) + (chr_count(str, ';')*2) + (chr_count(str, '\n')*2));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1355 z = chr_count(str, '\r');
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1356 if (y == 0 && z == 0)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1357 // there isn't any extra space required
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1358 ret = str;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1359 else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1360 buf = (char*) realloc(buf, x+1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1361 a = str;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1362 b = buf;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1363 while (*a != '\0') {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1364 switch(*a) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1365 case ',' :
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1366 case '\\':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1367 case ';' :
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1368 case '\n':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1369 *(b++)='\\';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1370 *b=*a;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1371 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1372 case '\r':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1373 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1374 default:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1375 *b=*a;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1376 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1377 b++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1378 a++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1379 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1380 *b = '\0';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1381 ret = buf;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1382 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1383 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1384 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1385 return ret;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1386 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1387 int chr_count(char *str, char x) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1388 int r = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1389 while (*str != '\0') {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1390 if (*str == x)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1391 r++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1392 str++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1393 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1394 return r;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1395 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1396 char *rfc2425_datetime_format(FILETIME *ft) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1397 static char * buffer = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1398 struct tm *stm = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1399 DEBUG_ENT("rfc2425_datetime_format");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1400 if (buffer == NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1401 buffer = malloc(30); // should be enough for the date as defined below
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1402
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1403 stm = fileTimeToStructTM(ft);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1404 //Year[4]-Month[2]-Day[2] Hour[2]:Min[2]:Sec[2]
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1405 if (strftime(buffer, 30, "%Y-%m-%dT%H:%M:%SZ", stm)==0) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1406 DEBUG_INFO(("Problem occured formatting date\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1407 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1408 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1409 return buffer;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1410 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1411 char *rfc2445_datetime_format(FILETIME *ft) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1412 static char* buffer = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1413 struct tm *stm = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1414 DEBUG_ENT("rfc2445_datetime_format");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1415 if (buffer == NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1416 buffer = malloc(30); // should be enough
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1417 stm = fileTimeToStructTM(ft);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1418 if (strftime(buffer, 30, "%Y%m%dT%H%M%SZ", stm)==0) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1419 DEBUG_INFO(("Problem occured formatting date\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1420 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1421 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1422 return buffer;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1423 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1424 // The sole purpose of this function is to bypass the pseudo-header prologue
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1425 // that Microsoft Outlook inserts at the beginning of the internet email
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1426 // headers for emails stored in their "Personal Folders" files.
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1427 char *skip_header_prologue(char *headers) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1428 const char *bad = "Microsoft Mail Internet Headers";
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1429
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1430 if ( strncmp(headers, bad, strlen(bad)) == 0 ) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1431 // Found the offensive header prologue
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1432 char *pc;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1433
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1434 pc = strchr(headers, '\n');
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1435 return pc + 1;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1436 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1437
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1438 return headers;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1439 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1440
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1441 // vim:sw=4 ts=4:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1442 // vim600: set foldlevel=0 foldmethod=marker: