annotate src/readpst.c @ 38:f5c024aa1dc5 stable-0-5-9

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