annotate src/readpst.c @ 24:f4643b609bdf stable-0-5-3 **INVALID**

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