annotate src/readpst.c @ 25:73e8959cd86b

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